Value#
- class Value(value=None, lower=0, upper=1, prior=None, args=None, **kwargs)[source]#
Bases:
objectThe
Valueclass 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:
- value
float The value of the parameter.
- lower
float, optional The lower bound of the parameter.
- upper
float, optional The upper bound of the parameter.
- prior
stror 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 toscipy.statsdistributions. See Notes for more details.- args
dict, optional A dictionary of arguments for the prior distribution function.
- value
- 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.statscorresponding to thepriorargument:‘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.- fill(value)[source]#
Replace the value of the parameter with a new value.
- Parameters:
- value
floator array_like The new value of the parameter.
- value
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:
floatThe probability of the parameter value under the prior distribution. If
logis True, the log probability is returned.
- sample(size=1, jump=False)[source]#
Sample and update the parameter value from its prior distribution.
- Returns:
- sample
float A sample from the prior distribution of the parameter.
- sample
- update_prior(**kwargs)[source]#
Update the prior distribution of the parameter. Currently it is only implemented for truncated normal distributions.
- Parameters:
- **kwargs
dict 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.statsdocumentation or theprior.kwdsattribute.
- **kwargs
See also