BayesicFitting

Model Fitting and Evidence Calculation

View project on GitHub



class BernoulliErrorDistribution( ErrorDistribution )Source

To calculate a Bernoulli likelihood for categorical True/False data.

For one residual, x, it holds

     f( x ) = x if d is True
              1 - x if d is False

where x needs to be between [0,1]; use the logistic function f(x) = 1/(1+exp(-x) if necessary. And d is true if the residual belongs to the intended category.

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

     logL = log( x ) if d else log( 1 - x )

Author Do Kester.

BernoulliErrorDistribution( copy=None )

Constructor of Bernoulli Distribution.

Parameters

  • copy : BernoulliErrorDistribution
         distribution to be copied.

copy( )

Return copy of this.

acceptWeight( )
True if the distribution accepts weights. Always true for this distribution.

getScale( 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

toSigma( scale )
Return sigma, the squareroot of the variance. Parameter
  • scale : float
         the scale of this Bernoulli distribution.

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

Alternate calculation.

Outside the range the likelihood is zero, so the logL should be -inf. However for computational reasons the maximum negative value is returned.

Parameters

  • problem : Problem
         to be solved
  • allpars : array_like
         parameters of 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.

Parameters

  • problem : Problem
         to be solved
  • allpars : array_like
         parameters of the problem
  • fitIndex : array_like
         indices of parameters to be fitted

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

Parameters

  • problem : Problem
         to be solved
  • allpars : array_like
         parameters of the problem
  • fitIndex : array_like
         indices of parameters to be fitted
  • mockdata : array_like
         as calculated by the model
Methods inherited from ErrorDistribution