AbstractFitEngine

:mod:` sans.fit.AbstractFitEngine`

class sans.fit.AbstractFitEngine.FResult

Bases: object

Storing fit result

__class__

alias of type

__delattr__

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

__dict__ = <dictproxy object at 0x01FA56D0>
__getattribute__

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

__hash__

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

__init__()
__module__ = 'sans.fit.AbstractFitEngine'
static __new__(S, ...) → a new object with type S, a subtype of T
__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

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

__setattr__

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

__str__()
__weakref__

list of weak references to the object (if defined)

print_summary()
set_fitness()
set_model()
exception sans.fit.AbstractFitEngine.FitAbort

Bases: exceptions.Exception

Exception raise to stop the fit

__class__

alias of type

__delattr__

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

__dict__ = <dictproxy object at 0x01FA5810>
__getattribute__

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

__getitem__

x.__getitem__(y) <==> x[y]

__getslice__

x.__getslice__(i, j) <==> x[i:j]

Use of negative indices is not supported.

__hash__

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

__init__

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

__module__ = 'sans.fit.AbstractFitEngine'
static __new__(S, ...) → a new object with type S, a subtype of T
__reduce__()
__reduce_ex__()

helper for pickle

__repr__

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

__setattr__

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

__setstate__()
__str__

x.__str__() <==> str(x)

__weakref__

list of weak references to the object (if defined)

args
message

exception message

class sans.fit.AbstractFitEngine.FitArrange
__init__()

Class FitArrange contains a set of data for a given model to perform the Fit.FitArrange must contain exactly one model and at least one data for the fit to be performed.

model: the model selected by the user Ldata: a list of data what the user wants to fit

__module__ = 'sans.fit.AbstractFitEngine'
add_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()

Remove one element from the list

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

set_model save a copy of the model

Parameters:model – the model being set
set_to_fit()

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

Bases: sans.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__()

Add two data sets

Parameters:other – data set to add to the current one
Returns:new data set
Raises ValueError:
 raised when two data sets are incompatible
__div__()

Divided a data set by another

Parameters:other – data set that the current one is divided by
Returns:new data set
Raises ValueError:
 raised when two data sets are incompatible
__init__()
Parameters:smearer – is an object of class QSmearer or SlitSmearer that will smear the theory data (slit smearing or resolution smearing) when set.

The proper way to set the smearing object would be to do the following:

from DataLoader.qsmearing import smear_selection
smearer = smear_selection(some_data)
fitdata1d = FitData1D( x= [1,3,..,], 
                        y= [3,4,..,8], 
                        dx=None,
                        dy=[1,2...], smearer= smearer)
Note :that some_data _HAS_ to be of class DataLoader.data_info.Data1D Setting it back to None will turn smearing off.
__module__ = 'sans.fit.AbstractFitEngine'
__mul__()

Multiply two data sets

Parameters:other – data set to subtract from the current one
Returns:new data set
Raises ValueError:
 raised when two data sets are incompatible
__radd__()

Add two data sets

Parameters:other – data set to add to the current one
Returns:new data set
Raises ValueError:
 raised when two data sets are incompatible
__rdiv__()

Divided a data set by another

Parameters:other – data set that the current one is divided by
Returns:new data set
Raises ValueError:
 raised when two data sets are incompatible
__rmul__()

Multiply two data sets

Parameters:other – data set to subtract from the current one
Returns:new data set
Raises ValueError:
 raised when two data sets are incompatible
__rsub__()

Subtract two data sets

Parameters:other – data set to subtract from the current one
Returns:new data set
Raises ValueError:
 raised when two data sets are incompatible
__str__()

Nice printout

__sub__()

Subtract two data sets

Parameters:other – data set to subtract from the current one
Returns:new data set
Raises ValueError:
 raised when two data sets are incompatible
_perform_operation()
_validity_check()

Checks that the data lengths are compatible. Checks that the x vectors are compatible. Returns errors vectors equal to original errors vectors if they were present or vectors of zeros when none was found.

Parameters:other – other data set for operation
Returns:dy for self, dy for other [numpy arrays]
Raises ValueError:
 when lengths are not compatible
_xaxis = ''
_xunit = ''
_yaxis = ''
_yunit = ''
add_notes()

Add notes to datainfo

append_empty_process()
clone_without_data()

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
collimation = None
detector = None
dx = None
dxl = None
dxw = None
dy = None
errors = None
filename = ''
get_fit_range()

return the range of data.x to fit

instrument = ''
is_slit_smeared()

Check whether the data has slit smearing information

Returns:True is slit smearing info is present, False otherwise
meta_data = None
notes = None
process = None
residuals()

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()
Returns:residuals derivatives .
Note :in this case just return empty array
run = None
run_name = None
sample = None
set_fit_range()

to set the fit range

source = None
title = ''
x = None
x_unit = '1/A'
xaxis()

set the x axis label and unit

y = None
y_unit = '1/cm'
yaxis()

set the y axis label and unit

class sans.fit.AbstractFitEngine.FitData2D

Bases: sans.dataloader.data_info.Data2D

Wrapper class for SANS data

I_unit = '1/cm'
Q_unit = '1/A'
__add__()

Add two data sets

Parameters:other – data set to add to the current one
Returns:new data set
Raises ValueError:
 raised when two data sets are incompatible
__div__()

Divided a data set by another

Parameters:other – data set that the current one is divided by
Returns:new data set
Raises ValueError:
 raised when two data sets are incompatible
__init__()
__module__ = 'sans.fit.AbstractFitEngine'
__mul__()

Multiply two data sets

Parameters:other – data set to subtract from the current one
Returns:new data set
Raises ValueError:
 raised when two data sets are incompatible
__radd__()

Add two data sets

Parameters:other – data set to add to the current one
Returns:new data set
Raises ValueError:
 raised when two data sets are incompatible
__rdiv__()

Divided a data set by another

Parameters:other – data set that the current one is divided by
Returns:new data set
Raises ValueError:
 raised when two data sets are incompatible
__rmul__()

Multiply two data sets

Parameters:other – data set to subtract from the current one
Returns:new data set
Raises ValueError:
 raised when two data sets are incompatible
__rsub__()

Subtract two data sets

Parameters:other – data set to subtract from the current one
Returns:new data set
Raises ValueError:
 raised when two data sets are incompatible
__str__()
__sub__()

Subtract two data sets

Parameters:other – data set to subtract from the current one
Returns:new data set
Raises ValueError:
 raised when two data sets are incompatible
_perform_operation()

Perform 2D operations between data sets

Parameters:
  • other – other data set
  • operation – function defining the operation
_validity_check()

Checks that the data lengths are compatible. Checks that the x vectors are compatible. Returns errors vectors equal to original errors vectors if they were present or vectors of zeros when none was found.

Parameters:other – other data set for operation
Returns:dy for self, dy for other [numpy arrays]
Raises ValueError:
 when lengths are not compatible
_xaxis = ''
_xunit = ''
_yaxis = ''
_yunit = ''
_zaxis = ''
_zunit = ''
add_notes()

Add notes to datainfo

append_empty_process()
clone_without_data()

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
collimation = None
data = None
detector = None
dqx_data = None
dqy_data = None
err_data = None
errors = None
filename = ''
get_fit_range()

return the range of data.x to fit

instrument = ''
mask = None
meta_data = None
notes = None
process = None
q_data = None
qx_data = None
qy_data = None
residuals()

return the residuals

residuals_deriv()
Returns:residuals derivatives .
Note :in this case just return empty array
run = None
run_name = None
sample = None
set_data()

Determine the correct qx_data and qy_data within range to fit

set_fit_range()

to set the fit range

set_smearer()

Set smearer

source = None
title = ''
x_bins = None
xaxis()

set the x axis label and unit

xmax = None
xmin = None
y_bins = None
yaxis()

set the y axis label and unit

ymax = None
ymin = None
zaxis()

set the z axis label and unit

class sans.fit.AbstractFitEngine.FitEngine
__init__()

Base class for scipy and park fit engine

__module__ = 'sans.fit.AbstractFitEngine'
get_model()
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()

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

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

remove fitarrange in id

select_problem_for_fit()

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

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

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

Bases: park.model.Model

PARK wrapper for SANS models.

__call__()
__class__

alias of MetaModel

__delattr__

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

__dict__ = <dictproxy object at 0x020725F0>
__getattribute__

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

__hash__

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

__init__()
Parameters:sans_model – the sans model to wrap using park interface
__metaclass__

alias of MetaModel

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

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

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

__setattr__

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

__str__

x.__str__() <==> str(x)

__weakref__

list of weak references to the object (if defined)

derivatives = []
eval()

override eval method of park model.

Parameters:x – the x value used to compute a function
eval_derivs()

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

return a list of value of paramter to fit

Parameters:fitparams – list of paramaters name to fit
parameters = []
parameterset = []
set()

Set the initial value for a set of parameters.

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

set_params()

Set value for parameters to fit

Parameters:params – list of value for parameters to fit
class sans.fit.AbstractFitEngine.SansAssembly

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

__call__()

Compute residuals

Parameters:params – value of parameters to fit
__init__()
Parameters:
  • Model – the model wrapper fro sans -model
  • Data – the data wrapper for sans data
__module__ = 'sans.fit.AbstractFitEngine'
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

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.

__class__

alias of type

__delattr__

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

__dict__ = <dictproxy object at 0x02083790>
__getattribute__

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

__hash__

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

__init__()
Parameters:
  • name – the name of the model parameter
  • model – the sans model to wrap as a park model
__module__ = 'sans.fit.AbstractFitEngine'
static __new__(S, ...) → a new object with type S, a subtype of T
__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__()
__setattr__

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

__str__()
__weakref__

list of weak references to the object (if defined)

_getname()
_getrange()

Override _getrange of park parameter return the range of parameter

_getvalue()

override the _getvalue of park parameter

:return value the parameter associates with self.name

_name = 'unknown'
_range = (-1.#INF, 1.#INF)
_setrange()

override _setrange of park parameter

Parameters:r – the value of the range to set
_setvalue()

override the _setvalue pf park parameter

Parameters:value – the value to set on a given parameter
deriv = False
expression = ''
get()

Return the current value for a parameter.

get_name()
iscomputed()
isfeasible()

Return true if the value is in the range

isfitted()
isfixed()
isrestrained()
likelihood = None
limits = (-1.#INF, 1.#INF)
name

parameter name

path = ''
range

Override _getrange of park parameter return the range of parameter

set()

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

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

status = 'fixed'
summarize()

Return parameter range string.

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

tip = 'Fitting parameter'
units = ''
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