BayesicFitting

Model Fitting and Evidence Calculation

View project on GitHub



class Engine( object )Source

Engine defines common properties of all Engines.

An Engine moves around a walker in a random way such that its likelood remain above the low-likelihood-limit.

Attributes

  • walkers : WalkerList
         list of walkers to be diffused

  • errdis : ErrorDistribution
         error distribution to be used

  • slow : int
         If slow > 0, run this engine every slow-th iteration.

  • phantoms : PhantomCollection
         Collection of valid walker positions collected during engine execution

  • maxtrials : int
         maximum number of trials for various operations

  • rng : numpy.random.RandomState
         random number generator

  • verbose : int
         if verbose > 4 report about the engines. (mostly for debugging)

  • report : list of int (read only)
         reports number of succes, accepted, rejected, failed calls. Plus the total.

  • unitRange : array_like (read only)
         present max size of the parameter cloud (in unitspace: [0,1])

  • unitMin : array_like (read only)
         present minimum values of the parameter cloud (in unitspace: [0,1])

Author Do Kester.

Engine( walkers, errdis, slow=None, phantoms=None, copy=None, seed=4213, verbose=0 )

Constructor.

Only one PhantomCollection should be present for all Engines.

Parameters

  • walkers : list of Walker
         walkers to be diffused
  • errdis : ErrorDistribution
         error distribution to be used
  • slow : None or int > 0
         Run this engine every slow-th iteration. None for all.
  • phantoms : None or PhantomCollection
         Container for all valid walkers, that have been tried. But were not kept.
         To calculate the spread of the parameters vs likelihood.
  • seed : int
         for random number generator
  • verbose : int
         report about the engines when verbose > 4
  • copy : Engine
         engine to be copied

copy( )

Return a copy of this engine.

bestBoost( problem, myFitter=None )
When a logL is found better that all the rest, try to update it using a fitter.

Parameters problem : Problem
     the problem at hand myFitter : None or Fitter
     None fetches LevenbergMarquardtFitter
     a (non-linear) fitter

setWalker( kw, problem, allpars, logL, walker=None, fitIndex=None )
Update the walker with problem, allpars, LogL and logW.

Parameters

  • walker : Sample
         sample to be updated

  • kw : int
         index in walkerlist, of the walker to be replaced

  • problem : Problem
         the problem in the walker

  • allpars : array_like
         list of all parameters

  • logL : float
         log Likelihood

  • walker : Walker or None
         Copy this walker or create new one

  • fitIndex : array_like
         (new) fitIndex

noBoost( walker )

doBoost( walker )
Check if walker is best in phantoms and try to optimize.

Parameters

  • walker : Walker
         new walker to be checked

domain2Unit( problem, dval, kpar=None )
Return value in [0,1] for the selected parameter.

Parameters

  • problem : Problem
         the problem involved
  • dval : float
         domain value for the selected parameter
  • kpar : None or array_like
         selected parameter index, where kp is index in [parameters, hyperparams]
         None means all

unit2Domain( problem, uval, kpar=None )
Return domain value for the selected parameter.

Parameters

  • problem : Problem
         the problem involved
  • uval : array_like
         unit value for the selected parameter
  • kpar : None or array_like
         selected parameter indices, where kp is index in [parameters, hyperparams]
         None means all.

startJourney( unitStart )
Calculate the starting position and reset

Parameters

  • unitStart : array_like
         start position in npars-dimensions in unit space

calcJourney( unitDistance )
Calculate the distance travelled since reset

Parameters

  • unitDistance : array_like
         step size in npars-dimensions in unit space

reportJourney( )

makeIndex( np, val )

reportCall( )

Store a call to engine

reportSuccess( )
Add 1 to the number of succesfull steps: logL < lowLhood.

reportReject( )
Add 1 to the number of rejected steps: logL > lowLhood.

reportFailed( )
Add 1 to the number of failed steps: could not construct a step.

reportBest( )
Add 1 to the number of best likelihoods found upto now.

printReport( best=False )

successRate( )
Return percentage of success.

getUnitMinmax( problem, lowLhood )
Calculate unit minimum and maximum from the Phantoms

Parameters

  • problem : Problem
         To extract the unit range for
  • lowLhood : float
         low likelihood boundary

getUnitRange( problem, lowLhood )
Calculate unit range and minimum from PhantomCollection

Parameters

  • problem : Problem
         To extract the unit range for
  • lowLhood : float
         low likelihood boundary

execute( kw, lowLhood )
Execute the engine for difusing the parameters

Parameters

  • kw : walker-id
         walker to diffuse
  • lowLhood : float
         low limit on the loglikelihood

Returns

  • int : number of succesfull moves