Package park :: Package fitting :: Module fit :: Class Objective

Class Objective

source code


Abstract interface to the fitness function for the park minimizer classes.

Park provides a specific implementation park.assembly.Assembly.

TODO: add a results() method to return model specific info to the TODO: fit handler.

Instance Methods
 
prepare(self)
Do the necessary work to prepare to run the objective function, such as loading large files and precalculating data structures.
source code
 
cleanup(self)
Perform any cleanup required after all evaluations are complete.
source code
 
fit_parameters(self)
Returns a list of fit parameters.
source code
 
__call__(self, p)
Returns the objective value when evaluated at point p in R^n.
source code
 
deriv(self, p)
Returns the objective value and derivatives for parameter set p .
source code
 
jacobian(self, p, step=1e-08)
Returns the derivative wrt the p at point p in R^n.
source code
 
cov(self, pvec)
Return the covariance matrix at p cov(f,p) = inv(J'J) where J is the Jacobian matrix [df(xi)/dpj]
source code
 
stderr(self, pvec)
Return parameter uncertainty.
source code
 
residuals(self, p)
Some fitters, notably Levenberg-Marquardt, operate directly on the residuals vector.
source code
 
residuals_deriv(self, p)
Returns residuals and derivatives with respect to the given parameters.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __init__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties

Inherited from object: __class__

Method Details

prepare(self)

source code 

Do the necessary work to prepare to run the objective function, such as loading large files and precalculating data structures.

This is called before before retrieving the fit parameters and running the fit.

fit_parameters(self)

source code 

Returns a list of fit parameters. Each parameter has a name, an initial value and a range.

See park.fitresult.FitParameter for an example.

On each function evaluation a new parameter set will be passed to the fitter, with values in the same order as the list of parameters.

__call__(self, p)
(Call operator)

source code 

Returns the objective value when evaluated at point p in R^n.

The default is sumsq residuals.

jacobian(self, p, step=1e-08)

source code 

Returns the derivative wrt the p at point p in R^n.

Numeric derivatives are calculated based on step, where step is the portion of the total range for parameter j, or the portion of point value p_j if the range on parameter j is infinite.

cov(self, pvec)

source code 

Return the covariance matrix at p cov(f,p) = inv(J'J) where J is the Jacobian matrix [df(xi)/dpj]

Using the singular value decomposition we have:

J = U S V'
J'J = (U S V')' (U S V')
    = V S' U' U S V'
    = V S S V'
inv(J'J) = inv(V S S V')
    = inv(V') inv(S S) inv(V)
    = V inv (S S) V'

Note that this function hangs unexpectedly for some versions of numpy on Windows. Please make sure you are using the latest version.

stderr(self, pvec)

source code 

Return parameter uncertainty.

This is just the sqrt diagonal of covariance matrix inv(J'J) at point p.

residuals(self, p)

source code 

Some fitters, notably Levenberg-Marquardt, operate directly on the residuals vector. If the individual residuals are not available, then LM cannot be used.

This method is optional.

residuals_deriv(self, p)

source code 

Returns residuals and derivatives with respect to the given parameters.

If these are unavailable in the model, then they can be approximated by numerical derivatives, though it is generally better to use a derivative free optimizer such as coliny or cobyla which can use the function evaluations more efficiently. In any case, your objective function is responsible for calculating these.

This method is optional.