Package park :: Package modelling :: Module assembly :: Class Assembly

Class Assembly

source code


Collection of fit models.

Assembly implements the park.fit.Objective interface.

See park.assembly for usage.

Instance variables:

residuals : array
a vector of residuals spanning all models, with model weights applied as appropriate.
degrees_of_freedom : integer
length of the residuals - number of fitted parameters
chisq : float
sum squared residuals; this is not the reduced chisq, which you can get using chisq/degrees_of_freedom

These fields are defined for the individual models as well, with degrees of freedom adjusted to the length of the individual data set. If the model is not fitted or the weight is zero, the residual will not be calculated.

The residuals fields are available only after the model has been evaluated.

Instance Methods
 
__init__(self, models=[])
Build an assembly from a list of models.
source code
 
__iter__(self)
Iterate through the models in order
source code
 
__getitem__(self, n)
Return the nth model
source code
 
__setitem__(self, n, fitness)
Replace the nth model
source code
 
__delitem__(self, n)
Delete the nth model
source code
 
weight(self, idx, value=None)
Query the weight on a particular model.
source code
 
isfitted(self, idx, value=None)
Query if a particular model is fitted.
source code
 
append(self, fitness, weight=1.0, isfitted=True)
Add a model to the end of set.
source code
 
insert(self, idx, fitness, weight=1.0, isfitted=True)
Add a model to a particular position in the set.
source code
 
eval(self)
Recalculate the theory functions, and from them, the residuals and chisq.
source code
 
jacobian(self, pvec, step=1e-08)
Returns the derivative wrt the fit parameters at point p.
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
 
isfeasible(self)
Returns true if the parameter set is in a feasible region of the modeling space.
source code
 
fit_parameters(self)
Return an alphabetical list of the fitting parameters.
source code
 
result(self, status='step')
Details to send back to the fitting client on an improved fit.
source code
 
__call__(self, pvec)
Cost function.
source code
 
abort(self)
Interrupt the current function evaluation.
source code

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

Properties
  residuals
combined residuals from all parts

Inherited from object: __class__

Method Details

__init__(self, models=[])
(Constructor)

source code 
Build an assembly from a list of models.
Overrides: object.__init__

weight(self, idx, value=None)

source code 

Query the weight on a particular model.

Set weight to value if value is supplied.

Parameters:
  • idx (integer) - model number
  • value (float) - model weight
Returns:
model weight

isfitted(self, idx, value=None)

source code 

Query if a particular model is fitted.

Set isfitted to value if value is supplied.

Parameters:
  • idx (integer) - model number
  • value

append(self, fitness, weight=1.0, isfitted=True)

source code 

Add a model to the end of set.

The fitting model can be an instance of park.assembly.Fitness, or a tuple of (park.model.Model,`park.data.Data1D`) :param weight: model weighting (usually 1.0) :param isfitted: whether model should be fit (equivalent to weight 0.)

Parameters:
  • fitness - the fitting model

eval(self)

source code 
Recalculate the theory functions, and from them, the residuals and chisq.

Note: Call this after the parameters have been updated.

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

source code 

Returns the derivative wrt the fit parameters at point p.

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.

fit_parameters(self)

source code 

Return an alphabetical list of the fitting parameters.

This function is called once at the beginning of a fit, and serves as a convenient place to precalculate what can be precalculated such as the set of fitting parameters and the parameter expressions evaluator.

result(self, status='step')

source code 

Details to send back to the fitting client on an improved fit.

status is 'start', 'step' or 'end' depending if this is the first result to return, an improved result, or the final result.

[Not implemented]

__call__(self, pvec)
(Call operator)

source code 

Cost function.

Evaluate the system for the parameter vector pvec, returning chisq as the cost function to be minimized.

Raises a runtime error if the number of fit parameters is different than the length of the vector.

abort(self)

source code 

Interrupt the current function evaluation.

Forward this to the currently executing model if possible.


Property Details

residuals

combined residuals from all parts
Get Method:
_residuals(self) - Compute the combined residuals vector as needed.