ParkFitting module contains SansParameter,Model,Data FitArrange, ParkFit,Parameter classes.All listed classes work together to perform a simple fit with park optimizer.
Bases: park.assembly.Assembly
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.
alias of type
x.__delattr__(‘name’) <==> del x.name
Delete the nth model
x.__getattribute__(‘name’) <==> x.name
Return the nth model
x.__hash__() <==> hash(x)
Build an assembly from a list of models.
Iterate through the models in order
helper for pickle
helper for pickle
x.__repr__() <==> repr(x)
x.__setattr__(‘name’, value) <==> x.name = value
Replace the nth model
x.__str__() <==> str(x)
list of weak references to the object (if defined)
Adjust the parameter set after the addition of a new model.
Interrupt the current function evaluation.
Forward this to the currently executing model if possible.
Extend result from the fit with the calculated parameters.
Add a model to the end of set.
Parameters: | fitness – the fitting model |
---|
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.)
Return the covariance matrix inv(J’J) at point p.
Recalculate the theory functions, and from them, the residuals and chisq.
Note : | Call this after the parameters have been updated. |
---|
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.
Add a model to a particular position in the set.
Returns true if the parameter set is in a feasible region of the modeling space.
Query if a particular model is fitted.
Set isfitted to value if value is supplied.
Parameters: |
|
---|
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.
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]
Set the parameters resulting from the fit into the parameter set, and update the calculated expression.
The parameter values may be retrieved by walking the assembly.parameterset tree, checking each parameter for isfitted, iscomputed, or isfixed. For example:
assembly.set_result(result)
for p in assembly.parameterset.flatten():
if p.isfitted():
print "%s %g in [%g,%g]"%(p.path,p.value,p.range[0],p.range[1])
elif p.iscomputed():
print "%s computed as %g"%(p.path.p.value)
This does not calculate the function or the residuals for these parameters. You can call assembly.eval() to do this. The residuals will be set in assembly[i].residuals. The theory and data are model specific, and can be found in assembly[i].fitness.data.
Return parameter uncertainty.
This is just the sqrt diagonal of covariance matrix inv(J’J) at point p.
Query the weight on a particular model.
Set weight to value if value is supplied.
Parameters : |
|
---|---|
Returns: | model weight |
Bases: sans.fit.AbstractFitEngine.FitEngine
ParkFit performs the Fit.This class can be used as follow: #Do the fit Park create an engine: engine = ParkFit() Use data must be of type plottable Use a sans model
Add data with a dictionnary of FitArrangeList where Uid is a key and data is saved in FitArrange object. engine.set_data(data,Uid)
Set model parameter “M1”= model.name add {model.parameter.name:value}.
Note : | Set_param() if used must always preceded set_model() for the fit to be performed. |
---|
engine.set_param( model,”M1”, {‘A’:2,’B’:4})
Add model with a dictionnary of FitArrangeList{} where Uid is a key and model is save in FitArrange object. engine.set_model(model,Uid)
engine.fit return chisqr,[model.parameter 1,2,..],[[err1....][..err2...]] chisqr1, out1, cov1=engine.fit({model.parameter.name:value},qmin,qmax)
Note : | {model.parameter.name:value} is ignored in fit function since the user should make sure to call set_param himself. |
---|
Creates a dictionary (self.fitArrangeList={})of FitArrange elements with Uid as keys
Extract sansmodel and sansdata from self.FitArrangelist ={Uid:FitArrange} Create parkmodel and park data ,form a list couple of parkmodel and parkdata create an assembly self.problem= park.Assembly([(parkmodel,parkdata)])
Performs fit with park.fit module.It can perform fit with one model and a set of data, more than two fit of one model and sets of data or fit with more than two model associated with their set of data and constraints
Parameters: |
|
---|---|
Note : | all parameter are ignored most of the time.Are just there to keep ScipyFit and ParkFit interface the same. |
Returns: | result.fitness Value of the goodness of fit metric |
Returns: | result.pvec list of parameter with the best value found during fitting |
Returns: | result.cov Covariance matrix |
Parameters: | id – id is key in the dictionary containing the model to return |
---|---|
Returns: | a model at this id or None if no FitArrange element was created with this id |
return the self.selected value of the fit problem of id
Parameters: | id – the id of the problem |
---|
remove fitarrange in id
select a couple of model and data at the id position in dictionary and set in self.selected value to value
Parameters: | value – the value to allow fitting. can only have the value one or zero |
---|
Receives plottable, creates a list of data to fit,set data in a FitArrange object and adds that object in a dictionary with key id.
Parameters: |
|
---|
set a model on a given in the fit engine.
Parameters: | model – sans.models type |
---|
Parameters: |
|
---|---|
Note : | pars must contains only name of existing model’s parameters |
Bases: sans.fit.ParkFitting.SansFitter
Monte Carlo optimizer.
This implements park.fit.Fitter.
alias of type
x.__delattr__(‘name’) <==> del x.name
x.__getattribute__(‘name’) <==> x.name
x.__hash__() <==> hash(x)
helper for pickle
helper for pickle
x.__repr__() <==> repr(x)
x.__setattr__(‘name’, value) <==> x.name = value
x.__str__() <==> str(x)
list of weak references to the object (if defined)
Run a monte carlo fit.
This procedure maps a local optimizer across a set of initial points.
Global optimizer.
This function should return immediately
Bases: park.fitresult.FitParameter
Fit result for an individual parameter.
alias of type
x.__delattr__(‘name’) <==> del x.name
x.__getattribute__(‘name’) <==> x.name
x.__hash__() <==> hash(x)
helper for pickle
helper for pickle
x.__setattr__(‘name’, value) <==> x.name = value
x.__str__() <==> str(x)
list of weak references to the object (if defined)
Return parameter range string.
E.g., ” Gold .....|.... 5.2043 in [2,7]”
Bases: park.fitresult.FitResult
alias of type
x.__delattr__(‘name’) <==> del x.name
x.__getattribute__(‘name’) <==> x.name
x.__hash__() <==> hash(x)
helper for pickle
helper for pickle
x.__repr__() <==> repr(x)
x.__setattr__(‘name’, value) <==> x.name = value
list of weak references to the object (if defined)
Return the covariance matrix inv(J’J) at point p.
Return the covariance matrix inv(J’J) at point p.
Bases: park.fitmc.FitSimplex
Local minimizer using Nelder-Mead simplex algorithm.
Simplex is robust and derivative free, though not very efficient.
This class wraps the bounds contrained Nelder-Mead simplex implementation for park.simplex.simplex.
alias of type
x.__delattr__(‘name’) <==> del x.name
x.__getattribute__(‘name’) <==> x.name
x.__hash__() <==> hash(x)
helper for pickle
helper for pickle
x.__repr__() <==> repr(x)
x.__setattr__(‘name’, value) <==> x.name = value
x.__str__() <==> str(x)
list of weak references to the object (if defined)
Cancel the fit in progress from another thread of execution
Run the fit
Stop when vertex values are within ftol of each other
Maximum number of iterations before fit terminates
Size of the initial simplex; this is a portion between 0 and 1
Stop when simplex vertices are within xtol of each other
Bases: park.fit.Fitter
alias of type
x.__delattr__(‘name’) <==> del x.name
x.__getattribute__(‘name’) <==> x.name
x.__hash__() <==> hash(x)
helper for pickle
helper for pickle
x.__repr__() <==> repr(x)
x.__setattr__(‘name’, value) <==> x.name = value
x.__str__() <==> str(x)
list of weak references to the object (if defined)
Run the actual fit in a separate thread
Global optimizer.
This function should return immediately
Bases: park.assembly.Part
Part of a fitting assembly. Part holds the model itself and associated data. The part can be initialized with a fitness object or with a pair (model,data) for the default fitness function.
sum(residuals**2); use chisq/degrees_of_freedom to get the reduced chisq value.
Get/set the weight on the given model.
assembly.weight(3) returns the weight on model 3 (0-origin) assembly.weight(3,0.5) sets the weight on model 3 (0-origin)
alias of type
x.__delattr__(‘name’) <==> del x.name
x.__getattribute__(‘name’) <==> x.name
x.__hash__() <==> hash(x)
helper for pickle
helper for pickle
x.__repr__() <==> repr(x)
x.__setattr__(‘name’, value) <==> x.name = value
x.__str__() <==> str(x)
list of weak references to the object (if defined)