pyabc.random_variables
Random variables
Random variables are used to define the model prior, proposal distribution, and the model.
- class pyabc.random_variables.Distribution(*args, **kwargs)[source]
Bases:
DistributionBase
,ParameterStructure
Distribution of parameters for a model assuming independence.
Essentially something like a dictionary of random variables or distributions. The variables from which the distribution is initialized are independent.
- copy() Distribution [source]
Copy the distribution.
- Returns:
copied_distribution – A copy of the distribution.
- Return type:
- classmethod from_dictionary_of_dictionaries(dict_of_dicts: dict) Distribution [source]
Create distribution from dictionary of dictionaries.
- Parameters:
dict_of_dicts (dict) – The keys of the dict indicate the parameters names. The values are itself dictionaries representing scipy.stats distribution. I.e. the have the key “name” and at least one of the keys “args” or “kwargs”.
- Returns:
distribution – Created distribution.
- Return type:
- get_parameter_names() list [source]
Get a sorted list of parameter names.
- Returns:
sorted_names – Sorted list of parameter names.
- Return type:
- pdf(x: Parameter | dict)[source]
Get probability density at point x (product of marginals).
Combination of probability density functions (for continuous variables) and probability mass function (for discrete variables).
- class pyabc.random_variables.DistributionBase[source]
Bases:
ABC
Distribution of parameters for a model, abstract base class.
A distribution is a collection of RVs and/or distributions.
This should be used to define a prior.
- class pyabc.random_variables.LowerBoundDecorator(component: RV, lower_bound: float)[source]
Bases:
RVDecorator
Impose a strict lower bound on a random variable. Condition RV X to X > lower bound. In particular P(X = lower_bound) = 0.
Note
Sampling is done via rejection. Up to 10000 samples are taken from the decorated RV. The first sample within the permitted range is then taken. Otherwise None is returned.
- copy()[source]
Copy the random variable.
- Returns:
copied_rv – A copy of the random variable.
- Return type:
- decorator_repr()[source]
Represent the decorator itself.
Template method.
The
__repr__
method useddecorator_repr
and the__repr__
of the decorated RV to build a combined representation.- Returns:
decorator_repr – A string representing the decorator only.
- Return type:
- class pyabc.random_variables.RV(name: str, *args, **kwargs)[source]
Bases:
RVBase
Concrete random variable.
- Parameters:
name (str) – Name of the distribution as in
scipy.stats
args – Arguments as in
scipy.stats
matching the distribution with name “name”.kwargs – Keyword arguments as in
scipy.stats
matching the distribution with name “name”.
- copy()[source]
Copy the random variable.
- Returns:
copied_rv – A copy of the random variable.
- Return type:
- distribution
the scipy.stats. … distribution object
- classmethod from_dictionary(dictionary: dict) RV [source]
Construct random variable from dictionary.
- Parameters:
dictionary (dict) –
A dictionary with the keys
”name” (mandatory)
”args” (optional)
”kwargs” (optional)
as in scipy.stats.
note:: (..) – Either the “args” or the “kwargs” key has to be present.
- class pyabc.random_variables.RVBase[source]
Bases:
ABC
Random variable abstract base class.
Note
Why introduce another random variable class and not just use the one’s provided in
scipy.stats
?This funny construction is done because
scipy.stats
distributions are not pickleable. This class is really a very thin wrapper aroundscipy.stats
distributions to make them pickleable. It is important to be able to pickle them to execute the ABCSMC algorithm in a distributed cluster environment- abstract copy() RVBase [source]
Copy the random variable.
- Returns:
copied_rv – A copy of the random variable.
- Return type:
- class pyabc.random_variables.RVDecorator(component: RVBase)[source]
Bases:
RVBase
Random variable decorator base class.
Implement a decorator pattern.
Further decorators should derive from this class.
It stores the decorated random variable in
self.component
Overwrite the method
decorator_repr
to represent the decorator type. The decorated variable will then be automatically included in the call to__repr__
.- Parameters:
component (RVBase) – The random variable to be decorated.
- component
The decorated random variable
- copy()[source]
Copy the random variable.
- Returns:
copied_rv – A copy of the random variable.
- Return type:
- decorator_repr() str [source]
Represent the decorator itself.
Template method.
The
__repr__
method useddecorator_repr
and the__repr__
of the decorated RV to build a combined representation.- Returns:
decorator_repr – A string representing the decorator only.
- Return type: