BayesicFitting

Model Fitting and Evidence Calculation

View project on GitHub



class RepeatingModel( Model,Dynamic )Source

RepeatingModel is a dynamic model, that calls the same model zero or more times, each time with the next set of parameters.

RepeatingModel is a Dynamic model that grows and shrinks according to a growPrior. The growPrior defaults to ExponentialPrior, unless a maxComp (max nr of components) then it defaults to a UniformPrior with limits minComp .. maxComp.

When isDynamic is set to False or minComp == maxComp, the RepeatingModel is a normal model with a static number of parameters/components.

Priors and/or limits for the RepeatingModel are stored in the (encapsulated) model. So the priors are taken from the same set for subsequent repetitions of the model call.

It can be arranged that all similar parameters are the same, represented by the same parameters. Use keywords same=.

Attributes

  • ncomp : int
         number of repetitions
  • model : Model
         (encapsulated) model to be repeated
  • same : None or int or list of int
         indices of parameters of model that get identical values
  • index : list of int
         list of parameter indices not in same.
  • isDyna : bool
         Whether this is a Dynamic Model.

Attributes from Dynamic

     ncomp, deltaNpar, minComp, maxComp, growPrior

Attributes from Model

     parameters, stdevs, npchain, _next, _head, _operation, xUnit, yUnit

Attributes from FixedModel

     npmax, fixed, parlist, mlist

Attributes from BaseModel

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

Example

# Define a model containing between 1 and 6 VoigtModels, starting with 3
# and all with the same widths (for Gauss and Cauchy)
vgt = VoigtModel()
mdl = RepeatingModel( 3, vgt, minComp=1. maxComp=6, same=[2,3] )
print( mdl.npbase )             # 4 + 2 + 2
8
# Define a static RepeatingModel of 5 GaussModels
gm = GaussModel()
mdl = RepeatingModel( 5, gm, isDynamic=False )
print( mdl.npbase )             # 5 * 3
15
# Define a RepeatingModel with and exponential grow prior with scale 10
mdl = RepeatingModel( 1, gm, growPrior=ExponentialPrior( scale=10 ) )
print( mdl.npbase )             # 3
3

Author Do Kester

RepeatingModel( ncomp, model, minComp=0, maxComp=None, fixed=None, same=None, growPrior=None, dynamic=True, copy=None, **kwargs )

Repeating the same model several times.

Parameters

  • ncomp : int
         number of repetitions

  • model : Model
         model to be repeated

  • minComp : int (0)
         minimum number of repetitions

  • maxComp : None or int
         maximum number of repetitions

  • same : None or int or list of int
         indices of parameters of model that get identical values

  • growPrior : None or Prior
         governing the birth and death.
         ExponentialPrior (scale=2) if maxOrder is None else UniformPrior

  • dynamic : bool (True)
         Whether this is a Dynamic Model.

  • copy : RepeatingModel
         model to copy

Raises

AttributeError when fixed parameters are requested ValueError when order is outside [min..max] range

copy( )

Copy method.

changeNComp( dn )

setSame( same )
Assign similar parameters the same value.

Parameters

  • same : None or int or [int]
         similar parameters indicated as an index in encapsulated model.

grow( offset=0, rng=None, **kwargs )
Increase the the number of components by 1 (if allowed by maxComp)

Parameters

  • offset : int
         index where the dynamic model starts
  • rng : RandomState
         random numbr generator

Return

  • bool : succes

shrink( offset=0, **kwargs )
Decrease the the number of componenets by 1 (if allowed by minComp) Remove an arbitrary item.

Parameters

  • offset : int
         index where the dynamic model starts

Return

  • bool : succes

shuffle( param, offset, np, rng )
Shuffle the parameters of the components (if they are equivalent)

Parameters

  • param : array-like
         list of all parameters
  • offset : int
         index where the dynamic model starts
  • np : int
         length of the parameters of the dynamic model
  • rng : RNG
         random number generator

isDynamic( )

baseResult( xdata, params )
Returns the result of the model function.

Parameters

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

basePartial( xdata, params, parlist=None )
Returns the partials at the input value.

Parameters

  • xdata : array_like
         value at which to calculate the result
  • params : array_like
         values for the parameters
  • parlist : array_like
         list of indices of active parameter

baseDerivative( xdata, params )
Returns the derivative df/dx at the input value.

Parameters

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

xxxsetLimits( lowLimits=None, highLimits=None )

setPrior( kpar, prior=None, **kwargs )
Set the prior for the indicated parameter of the repeated model.

All repeated parameters have the same Prior.

Parameters

  • kpar : int
         parameter number of the repeated model.
  • prior : Prior
         prior for parameter kpar
  • kwargs : keyword arguments
         attributes to be passed to the prior

Raise:

IndexException
     When more Priors are set than fit inside the repeated model

hasPriors( )

basePrior( kpar )
Return the prior for parameter with index kpar.

Parameters

  • kpar : int
         index of the parameter to be selected.

baseName( )

Return a string representation of the model.

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

Parameters

  • k : int
         parameter number.

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

Parameters

  • k : int
         parameter number.

par2model( k )
Return index in model and repetition nr for param k
Methods inherited from Model,
Methods inherited from FixedModel
Methods inherited from BaseModel
Methods inherited from Dynamic