AbstractFitEngine

:mod:` sans.fit.AbstractFitEngine`

exception sans.fit.AbstractFitEngine.FitAbort

Bases: exceptions.Exception

Exception raise to stop the fit

args
message

exception message

class sans.fit.AbstractFitEngine.FitArrange
add_data(data)

add_data fill a self.data_list with data to fit

Parameters:data – Data to add in the list
get_data()
Returns:list of data data_list
get_model()
Returns:saved model
get_to_fit()

return self.selected value

remove_data(data)

Remove one element from the list

Parameters:data – Data to remove from data_list
set_model(model)

set_model save a copy of the model

Parameters:model – the model being set
set_to_fit(value=0)

set self.selected to 0 or 1 for other values raise an exception

Parameters:value – integer between 0 or 1
class sans.fit.AbstractFitEngine.FitData1D(x, y, dx=None, dy=None, smearer=None)

Bases: DataLoader.data_info.Data1D

Wrapper class for SANS data FitData1D inherits from DataLoader.data_info.Data1D. Implements a way to get residuals from data.

add_notes(message='')

Add notes to datainfo

append_empty_process()
clone_without_data(length=0, clone=None)

Clone the current object, without copying the data (which will be filled out by a subsequent operation). The data arrays will be initialized to zero.

Parameters:
  • length – length of the data array to be initialized
  • clone – if provided, the data will be copied to clone
get_fit_range()

return the range of data.x to fit

is_slit_smeared()

Check whether the data has slit smearing information

Returns:True is slit smearing info is present, False otherwise
residuals(fn)

Compute residuals.

If self.smearer has been set, use if to smear the data before computing chi squared.

Parameters:fn – function that return model value
Returns:residuals
residuals_deriv(model, pars=[])
Returns:residuals derivatives .
Note :in this case just return empty array
set_fit_range(qmin=None, qmax=None)

to set the fit range

xaxis(label, unit)

set the x axis label and unit

yaxis(label, unit)

set the y axis label and unit

class sans.fit.AbstractFitEngine.FitData2D(sans_data2d, data=None, err_data=None)

Bases: DataLoader.data_info.Data2D

Wrapper class for SANS data

add_notes(message='')

Add notes to datainfo

append_empty_process()
clone_without_data(length=0, clone=None)

Clone the current object, without copying the data (which will be filled out by a subsequent operation). The data arrays will be initialized to zero.

Parameters:
  • length – length of the data array to be initialized
  • clone – if provided, the data will be copied to clone
get_fit_range()

return the range of data.x to fit

residuals(fn)

return the residuals

residuals_deriv(model, pars=[])
Returns:residuals derivatives .
Note :in this case just return empty array
set_data(sans_data2d, qmin=None, qmax=None)

Determine the correct qx_data and qy_data within range to fit

set_fit_range(qmin=None, qmax=None)

to set the fit range

set_smearer(smearer)

Set smearer

xaxis(label, unit)

set the x axis label and unit

yaxis(label, unit)

set the y axis label and unit

zaxis(label, unit)

set the z axis label and unit

class sans.fit.AbstractFitEngine.FitEngine
get_model(id)
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
get_problem_to_fit(id)

return the self.selected value of the fit problem of id

Parameters:id – the id of the problem
remove_fit_problem(id)

remove fitarrange in id

select_problem_for_fit(id, value)

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
set_data(data, id, smearer=None, qmin=None, qmax=None)

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:
  • data – data added
  • id – unique key corresponding to a fitArrange object with data
set_model(model, id, pars=[], constraints=[])

set a model on a given in the fit engine.

Parameters:model – sans.models type
:param : is the key of the fitArrange dictionary where model is
saved as a value
Parameters:
  • pars – the list of parameters to fit
  • constraints

    list of tuple (name of parameter, value of parameters) the value of parameter must be a string to constraint 2 different parameters. Example: we want to fit 2 model M1 and M2 both have parameters A and B. constraints can be:

    constraints = [(M1.A, M2.B+2), (M1.B= M2.A *5),...,]
Note :

pars must contains only name of existing model’s parameters

class sans.fit.AbstractFitEngine.Model(sans_model, **kw)

Bases: park.model.Model

PARK wrapper for SANS models.

eval(x)

override eval method of park model.

Parameters:x – the x value used to compute a function
eval_derivs(x, pars=[])

Evaluate the model and derivatives wrt pars at x.

pars is a list of the names of the parameters for which derivatives are desired.

This method needs to be specialized in the model to evaluate the model function. Alternatively, the model can implement is own version of residuals which calculates the residuals directly instead of calling eval.

get_params(fitparams)

return a list of value of paramter to fit

Parameters:fitparams – list of paramaters name to fit
set(**kw)

Set the initial value for a set of parameters.

E.g., model.set(width=3,center=5)

set_params(paramlist, params)

Set value for parameters to fit

Parameters:params – list of value for parameters to fit
class sans.fit.AbstractFitEngine.SansAssembly(paramlist, model=None, data=None, fitresult=None, handler=None, curr_thread=None)

Sans Assembly class a class wrapper to be call in optimizer.leastsq method

check_param_range()

Check the lower and upper bound of the parameter value and set res to the inf if the value is outside of the range :limitation: the initial values must be within range.

chisq()

Calculates chi^2

Parameters:params – list of parameter values
Returns:chi^2
class sans.fit.AbstractFitEngine.SansParameter(name, model)

Bases: park.parameter.Parameter

SANS model parameters for use in the PARK fitting service. The parameter attribute value is redirected to the underlying parameter value in the SANS model.

get()

Return the current value for a parameter.

get_name()
iscomputed()
isfeasible(value)

Return true if the value is in the range

isfitted()
isfixed()
isrestrained()
name

parameter name

range

Override _getrange of park parameter return the range of parameter

set(value)

Set a parameter to a value, a range or an expression. If it is a value, the parameter will be fixed for the fit. If it is a range, the value will be varying for the fit. If it is an expression, the parameter will be calculated from the values of other parameters in the fit.

Raises ValueError if the value could not be interpreted.

setprefix(prefix)

Set the full path to the parameter as used in expressions involving the parameter name.

summarize()

Return parameter range string.

E.g., ” Gold .....|.... 5.2043 in [2,7]”

value

override the _getvalue of park parameter

:return value the parameter associates with self.name

Table Of Contents

Previous topic

Reference

Next topic

Fitting

This Page