Value#

class Value(value=None, lower=0, upper=1, prior=None, args=None, **kwargs)[source]#

Bases: object

The Value class is a wrapper around a float value, with additional details such as the prior distribution, lower and upper bounds. It supports all basic mathematical operations and can be used as a regular float with the parameter value as operand.

Parameters:
valuefloat

The value of the parameter.

lowerfloat, optional

The lower bound of the parameter.

upperfloat, optional

The upper bound of the parameter.

priorstr or object, optional

If a string, it should be one of continuous distributions from scipy.stats. See the scipy documentation for more details. The default is None. If an object, it should be or contain a callable function representing the prior distribution of the parameter with methods similar to scipy.stats distributions. See Notes for more details.

argsdict, optional

A dictionary of arguments for the prior distribution function.

Returns:
Value

A Value object, where each attribute is one of the arguments provided for the function. It support all basic mathematical operations and can be used as a regular float with the parameter value as operand.

Notes

We currently implement the following continuous distributions from scipy.stats corresponding to the prior argument:

  • ‘uniform’

  • ‘truncated_normal’

  • ‘beta’

  • ‘gamma’

  • ‘truncated_exponential’

  • ‘norm’

Because these distributions are inherited from scipy.stats, see the scipy documentation for more details on how to update variables of the distribution.

copy()[source]#

Return a copy of the parameter.

Returns:
Value

A copy of the parameter.

fill(value)[source]#

Replace the value of the parameter with a new value.

Parameters:
valuefloat or array_like

The new value of the parameter.

Notes

If the parameter is an array, it should be a list of values. If the parameter is an array, and the new value is a single value, it will be broadcasted to the shape of the array.

PDF(log=False)[source]#

Return the prior distribution of the parameter.

Returns:
float

The probability of the parameter value under the prior distribution. If log is True, the log probability is returned.

sample(size=1, jump=False)[source]#

Sample and update the parameter value from its prior distribution.

Returns:
samplefloat

A sample from the prior distribution of the parameter.

update_prior(**kwargs)[source]#

Update the prior distribution of the parameter. Currently it is only implemented for truncated normal distributions.

Parameters:
**kwargsdict

Keyword arguments representing the parameters of the prior distribution. If you are unsure what the names are for the parameters of the prior distribution, you can check the scipy.stats documentation or the prior.kwds attribute.