pybop.parameters.distributions#
Classes#
A base class for defining parameter distributions. |
|
A base class for distributions based on a scipy.stats distribution. |
|
Represents an exponential distribution with a specified scale parameter. |
|
Represents a Gaussian (normal) distribution with a given mean and standard deviation. |
|
Represents a joint distribution composed of multiple distributions. |
|
Represents a log-normal distribution corresponding to a Gaussian distribution for |
|
Represents a log-uniform distribution over a specified interval. |
|
Represents an unbounded distribution with either zero or one finite bound. |
|
Represents a uniform distribution over a specified interval. |
Module Contents#
- class pybop.parameters.distributions.BaseDistribution(properties: dict | None = None, n_parameters: int = 1)[source]#
A base class for defining parameter distributions.
This class provides a foundation for implementing various distributions. It includes methods for calculating the probability density function (PDF), log probability density function (log PDF), and generating random variates from the distribution.
- properties#
A dictionary with distribution keyword argument names as string keys and their values as float values.
- Type:
dict
- n_parameters#
The number of dimensions (default: 1).
- Type:
int
- _dlogpdf_dx(x)[source]#
Evaluates the first derivative of the log distribution at x.
Overwrite this function in a subclass to improve upon this generic finite difference approximation.
- Parameters:
x (float) – The point(s) at which to evaluate the first derivative.
- Returns:
The value(s) of the first derivative at x.
- Return type:
float
- _transform(transform: pybop.transformation.base_transformation.Transformation)[source]#
Get the transformed distribution in the search space.
- abstractmethod cdf(x)[source]#
Calculates the cumulative distribution function (CDF) of the distribution at x.
- Parameters:
x (float) – The point(s) at which to evaluate the CDF.
- Returns:
The cumulative distribution function value at x.
- Return type:
float
- get_transformed_distribution(transform: pybop.transformation.base_transformation.Transformation)[source]#
Get the transformed distribution in the search space.
- abstractmethod icdf(q)[source]#
Calculates the inverse cumulative distribution function (CDF) of the distribution at q.
- Parameters:
q (float) – The point(s) at which to evaluate the inverse CDF.
- Returns:
The inverse cumulative distribution function value at q.
- Return type:
float
- abstractmethod logpdf(x)[source]#
Calculates the logarithm of the probability density function of the distribution at x.
- Parameters:
x (float) – The point(s) at which to evaluate the log pdf.
- Returns:
The logarithm of the probability density function value at x.
- Return type:
float
- logpdfS1(x)[source]#
Evaluates the first derivative of the distribution at x.
- Parameters:
x (float) – The point(s) at which to evaluate the first derivative.
- Returns:
The value(s) of the first derivative at x.
- Return type:
float
- abstractmethod pdf(x)[source]#
Calculates the probability density function (PDF) of the distribution at x.
- Parameters:
x (float) – The point(s) at which to evaluate the pdf.
- Returns:
The probability density function value at x.
- Return type:
float
- abstractmethod rvs(size: int = 1, random_state: int | None = None)[source]#
Generates random variates from the distribution.
- Parameters:
size (int) – The number of random variates to generate.
random_state (int, optional) – The random state seed for reproducibility. Default is None.
- Returns:
An array of random variates from the distribution.
- Return type:
array_like
- Raises:
ValueError – If the size parameter is negative.
- support() tuple[float][source]#
Returns the support of the distribution, to be overwritten by child classes.
- verify(x) numpy.ndarray[source]#
Verifies that the input is a numpy array and converts it if necessary.
- _n_parameters = 1#
- property name#
- properties#
- class pybop.parameters.distributions.Distribution(distribution: scipy.stats.distributions.rv_frozen, properties: dict | None = None, n_parameters: int = 1)[source]#
Bases:
BaseDistributionA base class for distributions based on a scipy.stats distribution.
This class provides a foundation for implementing various distributions. It includes methods for calculating the probability density function (PDF), log probability density function (log PDF), and generating random variates from the distribution.
Additional Attributes#
- distributionscipy.stats.distributions.rv_frozen
The underlying continuous random variable distribution.
- cdf(x)[source]#
Calculates the cumulative distribution function (CDF) of the distribution at x.
- Parameters:
x (float) – The point(s) at which to evaluate the CDF.
- Returns:
The cumulative distribution function value at x.
- Return type:
float
- icdf(q)[source]#
Calculates the inverse cumulative distribution function (CDF) of the distribution at q.
- Parameters:
q (float) – The point(s) at which to evaluate the inverse CDF.
- Returns:
The inverse cumulative distribution function value at q.
- Return type:
float
- logpdf(x)[source]#
Calculates the logarithm of the probability density function of the distribution at x.
- Parameters:
x (float) – The point(s) at which to evaluate the log pdf.
- Returns:
The logarithm of the probability density function value at x.
- Return type:
float
- pdf(x)[source]#
Calculates the probability density function (PDF) of the distribution at x.
- Parameters:
x (float) – The point(s) at which to evaluate the pdf.
- Returns:
The probability density function value at x.
- Return type:
float
- rvs(size: int = 1, random_state: int | None = None)[source]#
Generates random variates from the distribution.
- Parameters:
size (int) – The number of random variates to generate.
random_state (int, optional) – The random state seed for reproducibility. Default is None.
- Returns:
An array of random variates from the distribution.
- Return type:
array_like
- Raises:
ValueError – If the size parameter is negative.
- support() tuple[float][source]#
Returns the support of the distribution, to be overwritten by child classes.
- distribution#
- class pybop.parameters.distributions.Exponential(scale: float, loc: float = 0)[source]#
Bases:
DistributionRepresents an exponential distribution with a specified scale parameter.
- Parameters:
scale (float) – The scale parameter (lambda) of the exponential distribution.
- class pybop.parameters.distributions.Gaussian(mean: float, sigma: float, truncated_at: list[float] | None = None)[source]#
Bases:
DistributionRepresents a Gaussian (normal) distribution with a given mean and standard deviation.
- Parameters:
mean (float) – The mean (mu) of the Gaussian distribution.
sigma (float) – The standard deviation (sigma) of the Gaussian distribution.
truncated_at (list[float], optional) – If provided, the distribution becomes a truncated normal distribution.
- _transform(transform: pybop.transformation.base_transformation.Transformation) BaseDistribution | None[source]#
Get the transformed distribution in the search space.
- class pybop.parameters.distributions.JointDistribution(*distributions: BaseDistribution)[source]#
Bases:
BaseDistributionRepresents a joint distribution composed of multiple distributions.
- Parameters:
distributions (BaseDistribution) – One or more distributions to combine into a joint distribution.
- _transform(transform: pybop.transformation.base_transformation.Transformation) BaseDistribution | None[source]#
Get the transformed distribution in the search space.
- logpdf(x: float | numpy.ndarray) float[source]#
Evaluates the log of the joint distribution at a given point.
- Parameters:
x (float | np.ndarray) – The point(s) at which to evaluate the distribution. The length of x should match the total number of parameters in the joint distribution.
- Returns:
The joint log-probability density of the distribution at x.
- Return type:
float
- logpdfS1(x: float | numpy.ndarray) tuple[float, numpy.ndarray][source]#
Evaluates the first derivative of the log of the joint distribution at a given point.
- Parameters:
x (float | np.ndarray) – The point(s) at which to evaluate the first derivative. The length of x should match the total number of parameters in the joint distribution.
- Returns:
A tuple containing the log-probability density and its first derivative at x.
- Return type:
Tuple[float, np.ndarray]
- rvs(size: int = 1, random_state: int | None = None)[source]#
Sample each distribution individually and then compile.
- support() numpy.ndarray[source]#
Return the support as a numpy array of dimensions (2, n_parameters).
- _distributions_list: list[BaseDistribution] = []#
- _n_parameters = 0#
- class pybop.parameters.distributions.LogNormal(mean_log_x: float, sigma: float)[source]#
Bases:
DistributionRepresents a log-normal distribution corresponding to a Gaussian distribution for log(x) with a given mean and standard deviation.
- Parameters:
mean_log_x (float) – The mean (mu) of the Gaussian distribution of log(x).
sigma (float) – The standard deviation (sigma) of the Gaussian distribution of log(x).
- _transform(transform: pybop.transformation.base_transformation.Transformation) BaseDistribution | None[source]#
Get the transformed distribution in the search space.
- class pybop.parameters.distributions.LogUniform(lower: float, upper: float)[source]#
Bases:
DistributionRepresents a log-uniform distribution over a specified interval.
- Parameters:
lower (float) – The lower bound of the distribution.
upper (float) – The upper bound of the distribution.
- _transform(transform: pybop.transformation.base_transformation.Transformation) BaseDistribution | None[source]#
Get the transformed distribution in the search space.
- class pybop.parameters.distributions.Unbounded(initial_value: float = 1.0, lower: float = -np.inf, upper: float = np.inf)[source]#
Bases:
BaseDistributionRepresents an unbounded distribution with either zero or one finite bound.
- Parameters:
lower (float) – The lower bound of the distribution.
upper (float) – The upper bound of the distribution.
- _transform(transform: pybop.transformation.base_transformation.Transformation) BaseDistribution | None[source]#
Get the transformed distribution in the search space.
- support() tuple[float][source]#
Returns the support of the distribution, to be overwritten by child classes.
- initial_value = None#
- lower#
- upper#
- class pybop.parameters.distributions.Uniform(lower: float, upper: float)[source]#
Bases:
DistributionRepresents a uniform distribution over a specified interval.
- Parameters:
lower (float) – The lower bound of the distribution.
upper (float) – The upper bound of the distribution.
- _transform(transform: pybop.transformation.base_transformation.Transformation) BaseDistribution | None[source]#
Get the transformed distribution in the search space.