BayesicFitting

Model Fitting and Evidence Calculation

View project on GitHub



class FixedModel( BaseModel )Source

A FixedModel is a BaseModel where some parameters are permanently fixed.

A parameter can be fixed either with a constant float value or more dynamically, with another Model. The parameters of this latter model also appear as parameters of the FixedModel.

The methods result (f(x:p)) and partial (df/dp) are calculated in here. Unfortunately the methods derivative (df/dx) is model dependent. It is reset to numDerivative.

Examples

m1 = PolynomialModel( 1 )
m1 += SineModel()
print( m1.npchain )         # number of params: 2 + 3
5
fixed = { 0: 1.0, 1: m1 }
em = EtalonModel( fixed=fixed )
print( em.npbase, em.npmax, em.npchain )          # ( 4 - 2 ) + 5
7 9 7
print( em )

Attributes

  • npmax : int
         maximum number of parameters of the simple (not-fixed) model
  • fixed : dictionary of {int:float|Model}
         int index of parameter to fix permanently. Default None.
         float value for the fixed parameter.
         Model model to replace the parameter
         Attribute fixed can only be set in the constructor.
  • parlist : array_like or None
         list of active (not-fixed) indices. None is all.
  • mlist : list of Model
         list of parameter indices which are replaced by a Model in fixed.

Attributes from BaseModel

     npbase, ndim, priors, posIndex, nonZero, tiny, deltaP, parNames

Author Do Kester

FixedModel( nparams=0, ndim=1, copy=None, fixed=None, names=None, **kwargs )

FixedModel Constructor.

Parameters

  • nparams : int
         Number of parameters in the model (default: 0)
  • ndim : int
         Number of dimensions of the input (default: 1)
  • copy : BaseModel
         to be copied
  • fixed : dictionary of {int:float|Model}
         int index of parameter to fix permanently. Default None.
         float value for the fixed parameter.
         Model model to replace the parameter
         Attribute fixed can only be set in the constructor.
  • names : list of string
         names for the parameters
  • kwargs for BaseModel :
         posIndex, nonZero

copy( )

Return a copy.

select( params )
Select the relevant parameters and store them.

Parameters

  • params : array of float
         parameters of the head model

selectNames( names )
Select the relevant parameter names and store them.

Parameters

  • names : list of string
         parameter names of the head model

result( xdata, param )
Returns the result calculated at the xdatas.

Parameters

  • xdata : array_like
         values at which to calculate the result
  • params : array_like
         values for the parameters.

expand( xdata, param )
Returns a complete list of parameters, where the fixed parameters have been replaced by either a constant value or by the results of the fixed function.

partial( xdata, param )
Returns the partial derivatives calculated at the inputs.

Parameters

  • xdata : array_like
         values at which to calculate the result
  • params : array_like
         values for the parameters.

numPartial( xdata, params, parlist=None )
Returns numerical partial derivatives of the model to params.

Parameters

  • xdata : array_like
         values at which to calculate the result
  • params : array_like
         values for the parameters; default is self.parameters
  • parlist : array_like
         list of indices active parameters (or None for all)

basePartial( xdata, param, parlist=None )
Replacement for models that dont define a partial.

Parameters

  • xdata : array_like
         values at which to calculate the result
  • param : array_like
         values for the parameters.
  • parlist : array_like
         list of indices active parameters (or None for all)

derivative( xdata, param )
Returns the derivative of the model to xdata.

It is a numeric derivative as the analytic derivative is not present in the model.

If fixed contains a Model, the derivative cannot be constructed from the constituent models. Use numDerivative instead.

Parameters

  • xdata : array_like
         values at which to calculate the derivative
  • param : array_like
         values for the parameters. (default: self.parameters)

numDerivative( xdata, param )
Returns the numeric derivative of the model to input

Parameters

  • xdata : array_like
         values at which to calculate the derivative
  • param : array_like
         values for the parameters. (default: self.parameters)

Raises

ValueError when the number of xdata dimensions > 1.

Methods inherited from BaseModel