scitools.convergencerate

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.)

class scitools.convergencerate.ManyDiscretizationPrm[source]

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
static error_model(p, d)[source]

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.

static nonlinear_fit(d, e, initial_guess)[source]
@param d: list of values of the set of discretization
parameters in each experiment: d = ((d_1,d_2,d_3),(d_1,d_2,d_3,),...); d[i] provides the values of the discretization parameters in experiement no. i.
@param e: list of error values; e = (e_1, e_2, ...):
e[i] is the error associated with the parameters d[i].

@param initial_guess: the starting value for the unknown parameters vector. @return: list of fitted paramters.

class scitools.convergencerate.OneDiscretizationPrm[source]

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
static analyze(d, e, initial_guess=None, plot_title='', filename='tmp.ps')[source]

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.

static error_model(p, d)[source]

Return e = C*h**a, where p=[C, a] and h=d[0].

static linear_loglog_fit(d, e)[source]

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]).

static loglog_error_model(p, d)[source]

As error_model if log-log data was used in the estimation.

static nonlinear_fit(d, e, p0)[source]
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.
static pairwise_rates(d, e)[source]

Compare convergence rates, where each rate is based on a formula for two successive experiments.

Previous topic

scitools.configdata

This Page