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
__class__

alias of type

__delattr__

x.__delattr__(‘name’) <==> del x.name

__dict__ = dict_proxy({'__module__': 'scitools.convergencerate', 'error_model': <staticmethod object at 0x8d4b408>, 'nonlinear_fit': <staticmethod object at 0x8d4b7c0>, '__dict__': <attribute '__dict__' of 'ManyDiscretizationPrm' objects>, '__weakref__': <attribute '__weakref__' of 'ManyDiscretizationPrm' objects>, '__doc__': '\n General tool for fitting an error model containing an\n arbitrary number of discretization parameters.\n The error is a weighted sum of each discretization parameter\n raised to a real expoenent. The weights and exponents are\n the unknown parameters to be fitted by a nonlinear\n least squares procedure.\n '})
__format__()

default object formatter

__getattribute__

x.__getattribute__(‘name’) <==> x.name

__hash__() <==> hash(x)
__init__

x.__init__(...) initializes x; see help(type(x)) for signature

__module__ = 'scitools.convergencerate'
static __new__(S, ...) → a new object with type S, a subtype of T
__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__() <==> repr(x)
__setattr__

x.__setattr__(‘name’, value) <==> x.name = value

__sizeof__() → int

size of object in memory, in bytes

__str__() <==> str(x)
static __subclasshook__()

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

__weakref__

list of weak references to the object (if defined)

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
__class__

alias of type

__delattr__

x.__delattr__(‘name’) <==> del x.name

__dict__ = dict_proxy({'__module__': 'scitools.convergencerate', 'error_model': <staticmethod object at 0x8d4b6a8>, 'nonlinear_fit': <staticmethod object at 0x8d4b750>, 'pairwise_rates': <staticmethod object at 0x8d4b788>, 'loglog_error_model': <staticmethod object at 0x8d4b6e0>, 'linear_loglog_fit': <staticmethod object at 0x8d4b718>, '__dict__': <attribute '__dict__' of 'OneDiscretizationPrm' objects>, 'analyze': <staticmethod object at 0x7c9d2b8>, '__weakref__': <attribute '__weakref__' of 'OneDiscretizationPrm' objects>, '__doc__': '\n Tools for fitting an error model with only one discretization\n parameter: e = C*h^2.\n '})
__format__()

default object formatter

__getattribute__

x.__getattribute__(‘name’) <==> x.name

__hash__() <==> hash(x)
__init__

x.__init__(...) initializes x; see help(type(x)) for signature

__module__ = 'scitools.convergencerate'
static __new__(S, ...) → a new object with type S, a subtype of T
__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__() <==> repr(x)
__setattr__

x.__setattr__(‘name’, value) <==> x.name = value

__sizeof__() → int

size of object in memory, in bytes

__str__() <==> str(x)
static __subclasshook__()

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

__weakref__

list of weak references to the object (if defined)

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