Module for estimating convergence rate of numerical algorithms, based on data from a set of experiments.
Recommended usage: Vary only discretization parameter (h in spatial problems, h/dt**q for some q so that h/dt**q=const, in time-dependent problems with time step dt). Use class OneDiscretizationPrm, or the function convergence_rate, or the analyze_filedata convenience function. Start with reading the convergence_rate function (too see an easily adapted example).
(There is support for fitting more general error models, like C1*h**r1 + C2*h*dt**r2, with nonlinear least squares, but sound fits are more challenging to obtain.)
Bases: object
General tool for fitting an error model containing an arbitrary number of discretization parameters. The error is a weighted sum of each discretization parameter raised to a real expoenent. The weights and exponents are the unknown parameters to be fitted by a nonlinear least squares procedure.
Methods
error_model(p, d) | Evaluate the theoretical error model (sum of C*h^r terms): |
nonlinear_fit(d, e, initial_guess) | @param d: list of values of the set of discretization |
alias of type
x.__delattr__(‘name’) <==> del x.name
default object formatter
x.__getattribute__(‘name’) <==> x.name
x.__init__(...) initializes x; see help(type(x)) for signature
helper for pickle
helper for pickle
x.__setattr__(‘name’, value) <==> x.name = value
size of object in memory, in bytes
Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
list of weak references to the object (if defined)
Evaluate the theoretical error model (sum of C*h^r terms): sum_i p[2*i]*d[i]**p[2*i+1]
Name | Description |
---|---|
p | sequence ofvalues of parameters (estimated) |
d | sequence of values of (known) discretization parameters |
return | error evaluated |
Note that len(p) must be 2*len(d) in this model since there are two parameters (constant and exponent) for each discretization parameter.
@param initial_guess: the starting value for the unknown parameters vector. @return: list of fitted paramters.
Bases: object
Tools for fitting an error model with only one discretization parameter: e = C*h^2.
Methods
analyze(d, e[, initial_guess, plot_title, ...]) | Run linear, nonlinear and successive rates models. |
error_model(p, d) | Return e = C*h**a, where p=[C, a] and h=d[0]. |
linear_loglog_fit(d, e) | Linear least squares algorithm. |
loglog_error_model(p, d) | As error_model if log-log data was used in the estimation. |
nonlinear_fit(d, e, p0) | |
pairwise_rates(d, e) | Compare convergence rates, where each rate is based on |
alias of type
x.__delattr__(‘name’) <==> del x.name
default object formatter
x.__getattribute__(‘name’) <==> x.name
x.__init__(...) initializes x; see help(type(x)) for signature
helper for pickle
helper for pickle
x.__setattr__(‘name’, value) <==> x.name = value
size of object in memory, in bytes
Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
list of weak references to the object (if defined)
Run linear, nonlinear and successive rates models. d: list/array of discretization parameter. e: errors corresponding to d. Plot results for comparison of the three approaches.
Linear least squares algorithm. Suitable for problems with only one distinct discretization parameter. d is the sequence of discretization parameter values, and e is the sequence of corresponding error values.
The error model the data is supposed to fit reads log(e[i]) = log(C[i]) + a*log(d[i]).
Name | Description |
---|---|
d | list of values of the (single) discretization parameter in each experiment: d[i] provides the values of the discretization, parameter in experiement no. i. |
e | list of error values; e = (e_1, e_2, ...), e[i] is the error associated with the parameters d[i] |
p0 | starting values for the unknown parameters vector |
return | a, C; a is the exponent, C is the factor in front. |