Parameters#
- class Parameters(**kwargs)[source]#
Bases:
objectA class representing a set of parameters. It takes keyword arguments representing the parameters with their values and wraps them into a python object.
- Parameters:
- **kwargs
dict Keyword arguments representing the parameters.
- **kwargs
- Returns:
ParametersA Parameters object, where each attributes is one of the keyword arguments provided for the function wrapped by the Value class.
Examples
>>> from cpm.generators import Parameters >>> parameters = Parameters(a=0.5, b=0.5, c=0.5) >>> parameters['a'] 0.1 >>> parameters.a 0.1 >>> parameters() {'a': 0.1, 'b': 0.2, 'c': 0.5}
The Parameters class can also provide a prior.
>>> x = Parameters( >>> a=Value(value=0.1, lower=0, upper=1, prior="normal", args={"mean": 0.5, "sd": 0.1}), >>> b=0.5, >>> weights=Value(value=[0.1, 0.2, 0.3], lower=0, upper=1, prior=None), >>> )
>>> x.prior(log=True) -6.5854290732499186
We can also sample new parameter values from the prior distributions. >>> x.sample() {‘a’: 0.4670755733417274, ‘b’: 0.30116207009111917}
- update(**kwargs)[source]#
Update the parameters with new values.
- Parameters:
- **kwargs
dict Keyword arguments representing the parameters.
- **kwargs
- keys()[source]#
Return a list of all the keys in the parameters dictionary.
- Returns:
- keys
list A list of all the keys in the parameters dictionary.
- keys
- bounds()[source]#
Returns a tuple with lower (first element) and upper (second element) bounds for parameters with defined priors.
- Returns:
- lower, upper: tuples
A tuple of lower and upper parameter bounds
- PDF(log=False)[source]#
Return the prior probability density of the parameter values.
- Returns:
floatThe summed probability density of the parameter set under the prior distribution for each parameter. If
logis True, the log probability is returned. When the PDF is 0, it returns the smallest positive float value. Iflogis True and the log probability is negative infinity, it returns the most negative float value.
- update_prior(**kwargs)[source]#
Update the prior distribution of all parameters.
- Parameters:
- **kwargs
dict Keyword arguments representing the parameters of the prior distribution. For each parameter, the keyword should be the name of the parameter and the value should be a dictionary of 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
- sample(size=1, jump=False)[source]#
Sample and update parameter values from their prior distribution.
- Returns:
- sample
dict A dictionary of the sampled parameters.
- sample
- free()[source]#
Return a dictionary of all parameters with a prior distribution.
- Returns:
- free
dict A dictionary of all parameters with a prior distribution.
- free
- export()[source]#
Return all freely-varying parameters and their accompanying lower and upper bounds, and prior distributions.
- Returns:
- pandas.DataFrame
A table of all freely-varying parameters and their accompanying lower and upper bounds, and prior distributions. Each row is a parameter, and the columns are the lower bound, upper bound, prior distribution, and the parameters of the prior distribution.