BayesicFitting

Model Fitting and Evidence Calculation

View project on GitHub



class Gauss2dErrorDistribution( GaussErrorDistribution )Source

To calculate a Gauss likelihood in case of errors in X and Y

For one residual in x and y it holds

  L = 1 / ( 2 π √ det ) exp( - 0.5 ( x / s )2 )

where s is the scale. s is a hyperparameter, which might be estimated from the data.

The scale s is also the square root of the variance of this error distribution.

The function is mostly used to calculate the likelihood L over N residuals, or easier to use log likelihood, logL.

  logL = log( N / ( √( 2 π ) s ) ) - 0.5 ∑( x / s )2

Using weights this becomes

  logL = log( ∑( w ) / ( √( 2 π ) s ) ) - 0.5 ∑( w ( x / s )2 )

Author Do Kester.

Gauss2dErrorDistribution( scale=1.0, limits=None, copy=None )

Default Constructor.

Parameters

  • scale : float
         noise scale

  • limits : None or list of 2 floats [low,high]
         None : no limits implying fixed scale
         low low limit on scale (needs to be >0)
         high high limit on scale
         when limits are set, the scale is not fixed.

  • copy : GaussErrorDistribution
         distribution to be copied.

copy( )

Return copy of this.

TBDgetScale( problem, allpars=None )
Return the noise scale.

Parameters

  • problem : Problem
         to be solved
  • allpars : array_like
         None take parameters from problem.model
         list of all parameters in the problem

updateDeterminant( problem, scale )
Update the determinant of the covar matrix with scale

Parameters

  • problem : ErrorsInXandYProblem
         problem at hand
  • scale : float
         present vale for the cale

logLikelihood_alt( problem, allpars )
Return the log( likelihood ) for a Gaussian distribution.

Alternate calculation

Parameters

  • problem : Problem
         to be solved
  • allpars : array_like
         list of all parameters in the problem

logLdata( problem, allpars, mockdata=None )
Return the log( likelihood ) for each residual

logL = sum( logLdata )

Parameters

  • problem : Problem
         to be solved
  • allpars : array_like
         list of all parameters in the problem
  • mockdata : array_like
         as calculated by the model

partialLogL_alt( problem, allpars, fitIndex )
Return the partial derivative of log( likelihood ) to the parameters in fitIndex.

Alternate calculation

Parameters

  • problem : Problem
         to be solved.
  • allpars : array_like
         (hyper)parameters of the problem
  • fitIndex : array_like
         indices of parameters to be fitted

nextPartialData( problem, allpars, fitIndex, mockdata=None )
Return the partial derivative all elements of the log( likelihood ) to the parameters in fitIndex.

Parameters

  • problem : Problem
         to be solved
  • allpars : array_like
         (hyper)parameters of the problem
  • fitIndex : array_like of int
         indices of allpars to fit
  • mockdata : array_like
         as calculated for the problem
Methods inherited from GaussErrorDistribution
Methods inherited from ScaledErrorDistribution
Methods inherited from ErrorDistribution