BayesicFitting

Model Fitting and Evidence Calculation

View project on GitHub



class CombiModel( BracketModel )Source

CombiModel combines a number of copies of the same model.

Fixed relations can be set between similar parameters. The relations can be either multiplicative or additive. When these relations are set, they must be set for all models.

  f( x:p ) = ∑ g( x:p )

where g( x:p ) is a model ( e.g. GaussModel )

For consistency reasons it is not possible to change the attributes of a CombiModel. It is better to make a new one with the required settings.

As we have copies of the same model, each model can have its own priors.

Attributes

  • nrepeat : int
         number of Models in this CombiModel
  • nmp : int
         number of parameters in each Model
  • expandpar : array of float
         expanded parameters. to be used in the repeated models
  • npcmax : int
         number of parameters in expandpar (= nmp * nrepeat)
  • expandindex : array of int
         converts parameter index into expandpar index
  • addindex : array of int
         indices of additively connected parameters
  • addvalue : array of float
         list of values to be added to the parameters in addindex
  • mulindex : array of int
         indices of multiplicatively connected parameters
  • mulvalue : array of float
         list of values to be multiplied to the parameters in mulindex
  • select : array of int
         indices of expandpar to get parameters

Attributes from BracketModel

  model, deep

Attributes from Model

  npchain, parameters, stdevs, xUnit, yUnit

Attributes from FixedModel

  npmax, fixed, parlist, mlist

Attributes from BaseModel

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

Examples

gauss = GaussModel( )
combi = CombiModel( gauss, 3, addCombi={1:[0,0.1,0.3]}, mulCombi={2,[0]*3} )
print( combi )
Combi of 3 times GaussModel
print( combi.npchain, combi.nrepeat, combi.nmp, combi.nexpand )
5 3 3 9
print( combi.select )
[0 1 2 3 6]
print( combi.expandindex )
[0 1 2 3 1 2 4 1 2]
print( combi.modelindex )
[0 0 0 1 2]
print( combi.addindex )
[1 4 7]
print( combi.mulindex )
[2 5 8]

Category mathematics/Fitting

Notes

  1. When all parameters are left free, precise initial parameters are needed to converge to the global optimum.
  2. The model seems to be especially unstable when the basic models are overlapping. Fixing the widths relative to each other, helps.
  3. Using a PolynomialModel ( or similar ones ) as basic model, is not going to work.

CombiModel( model, nrepeat=1, copy=None, oper='add', addCombi=None, mulCombi=None, **kwargs )

CombiModel combines several copies of the same model int one.

Parameters

  • model : Model
         model to be repeated
  • nrepeat : int
         number of repetitions
  • oper : "add" or "mul"
         the repeated models are combined using this operation
  • addCombi : None or dict
         make additive connections between parameters
         None : no additive connection
         dict : { int : array }
             key : int
                 index pointing to the key-th parameter in the model
             value : array of nrepeat floats
                 values added to each of the key-th parameters
  • mulCombi : None or dict
         make multiplicative connections between parameters
         None : no multiplicative connection
         dict : { int : array }
             key : int
                 index pointing to the key-th parameter in the model
             value : array of nrepeat floats
                 values multiplied to each of the key-th parameters

copy( )

Copy method.

combine( addCombi=None, mulCombi=None )
(re)sets the value of attributes "addindex", "addvalue", "mulindex", "mulvalue", "select" and "expandindex".

Parameters

  • addCombi : None or dict
         make additive connections between parameters
         None : no additive connection
         dict : { int : array }
             key : int
                 index pointing to the key-th parameter in the model
             value : array of nrepeat floats
                 values added to each of the key-th parameters
  • mulCombi : None or dict
         make multiplicative connections between parameters
         None : no multiplicative connection
         dict : { int : array }
             key : int
                 index pointing to the key-th parameter in the model
             value : array of nrepeat floats
                 values multiplied to each of the key-th parameters

makeExpandIndex( expandindex, amindex )
Make an expanded index enumerating the parameters for the full model

setCombi( combi )

expandParameters( param )

baseResult( xdata, params )
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.

basePartial( xdata, params, parlist=None )
Returns the partial derivatives calculated at the xdatas.

Parameters

  • xdata : array_like
         values at which to calculate the partials
  • params : array_like
         values for the parameters.
  • parlist : array_like
         Not in use

baseDerivative( xdata, params )
Returns the derivative (df/dx) calculated at the xdatas.

Parameters

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

baseName( )

Returns a string representation of the model.

baseParameterName( kpar )
Return the name of the indicated parameter.

Parameters

  • kpar : int
         parameter number.

baseParameterUnit( k )
Return the unit of the indicated parameter.

Parameters

  • k : int
         parameter number.

getPrior( kpar )
Return the prior for parameter kpar.

First try at the kpar location, possibly further in the chain; Upon failure try at the equivalent position in the head model

Parameters

  • kpar : int
         index of the parameter to be selected.
Methods inherited from BracketModel
Methods inherited from Brackets
Methods inherited from Model
Methods inherited from FixedModel
Methods inherited from BaseModel