BayesicFitting

Model Fitting and Evidence Calculation

View project on GitHub



class Prior( object )[source]

Base class defining prior distributions.

Two methods need to be defined in specific priors which map the values between [0,1] on to the domain, and vice versa unit2Domain and domain2Unit.

     u = domain2Unit( d )
     d = unit2Domain( u )

d is a value in the domain of the prior and u is a vlue in [0,1]

The handling of limits is relegated to this Prior class.

  Define
     umin = domain2Unit( lowLimit )
     urange = domain2Unit( highLimit ) - umin

     u = ( domain2Unit( d ) - umin ) / urange
     d = unit2Domain( u * urange + umin )

Symmetric priors can be used in a circular variant; i.e. the low and high limits are folded on each other, provided that the limit values are the same (hence symmetric)

     u = limitedDomain2Unit( d ) + 1 ) / 3
     d = limitedUnit2Domain( ( u * 3 ) % 1 )

The copy method is also necessary.

Attributes

  • lowLimit : float
         low limit on the Prior
  • highLimit : float
         high limit on the Prior
  • deltaP : float
         width of numerical partial derivative calculation
  • circular : bool or float
         whether circular

Hidden Attributes

  • _lowDomain : float
         lower limit of the Priors possible values
  • _highDomain : float
         upper limit of the Priors possible values
  • _umin : float
         umin lowLimit in unit
  • _urng : float
         urange (hi-lo) in unit

Prior( limits=None, circular=False, domain=[-math.inf,math.inf], prior=None ) [source]

Default constructor.

Parameters

  • limits : None or list of 2 floats
         2 limits resp. low and high
  • circular : bool or float
         False not circular
         True circular with period from limits[0] to limits[1]
         period of circularity
  • domain : 2 floats
         over which the prior is defined
  • prior : Prior
         prior to copy (with new limits if applicable)

copy( ) [source]

Return a copy

limitedIntegral( center=0, circular=False, limits=None ) [source]
Calculate the Integral of the prior where tails are cut off due to limits or circularity.

Parameters

  • center : float
         of the prior
  • circular : bool or float
         bool : y|n circular with period from limits[0] to limits[1]
         float :period of circularity
  • limits : None or list of 2 float/None
         None : no limits.
         2 limits, resp low and high

setLimits( limits=None ) [source]
Set limits. It is asserted that lowLimit is smaller than highLimit.

Parameters

  • limits : None or list of any combination of [None, float]
         None : no limit (for both or one)
         float : [low,high] limit

Raises
ValueError when low limit is larger than high limit or out of Domain

setPriorAttributes( limits, circular ) [source]
Set circular attributes.

Parameters

  • limits : None or array of 2 floats
         defining the period
  • circular : bool or float
         False pass
         True Calculate period and center from limits
         float period

isCircular( ) [source]
Whether circular

limitedDomain2Unit( dval ) [source]
Shrink domain to value in [0,1]

limitedUnit2Domain( uval ) [source]
Expand value in [0,1] to domain

circularDomain2Unit( dval ) [source]
Make domain circular in unit by shrinking: domain ==> unit ==> [1/3,2/3]

circularUnit2Domain( uval ) [source]
Unpack circular unit to domain: [1/3,2/3] ==> unit ==> domain

unsetLimits( ) [source]

Remove all limits.

setAttributes( limits=None, scale=None ) [source]
Set possible attributes for a Prior.

Parameters

  • limits : float or None
         [low,high] limit
  • scale : float or None
         scale factor

isOutOfLimits( par ) [source]
True if the parameter is out of limits

Parameters

  • par : float or array_like
         the parameter to check

checkLimit( par ) [source]
Check whether the parameter is within limits.

Parameters

  • par : float
         the parameter to check

Raises
     ValueError when outside limits.

stayInLimits( par ) [source]
Return lower limit or upper limit when parameter is outside.

Parameters

  • par : float
         the parameter to check

hasLowLimit( ) [source]

Return true if the prior has its low limits set.

hasHighLimit( ) [source]

Return true if the prior has its high limits set.

hasLimits( ) [source]

Return true if it has any limits.

getLimits( ) [source]

Return the limits.

getIntegral( ) [source]
Return the integral of the prior over the valid range.

Default: 1.0 (for bound priors)

getRange( ) [source]

Return the range.

domain2Unit( dval ) [source]
Return a value in [0,1] given a value within the valid domain of a parameter for a distribution.

Parameters

  • dval : float
         value within the domain of a parameter

unit2Domain( uval ) [source]
Return a value within the valid domain of the parameter given a value between [0,1] for a distribution.

Parameters

  • uval : float
         value within [0,1]

result( p ) [source]
Return value of the Prior at a given value.

If result is not defined, fall back to numerical derivative of Domain2Unit.

Parameters

  • p : float
         the value

partialDomain2Unit( p ) [source]
Return the derivative of Domain2Unit, aka the result of the distribution at p

Parameters

  • p : float
         the value

logResult( p ) [source]
Return the log of the result; -inf when p == 0.

Parameters

  • p : float
         the value

numPartialDomain2Unit( dval ) [source]
Return a the numeric derivate of the domain2Unit function to dval.

Parameters

  • dval : float
         value within the domain of a parameter

partialLog( p ) [source]
Return partial derivative of log( Prior ) wrt parameter. default numPartialLog

Parameters

  • p : float
         the value

numPartialLog( p ) [source]
Return the numeric partial derivative of log( Prior ) wrt parameter. Parameters
* p : float
     the value

isBound( ) [source]