pybop.parameters.distributions#

Classes#

Distribution

A base class for defining parameter distributions.

Exponential

Represents an exponential distribution with a specified scale parameter.

Gaussian

Represents a Gaussian (normal) distribution with a given mean and standard deviation.

JointDistribution

Represents a joint distribution composed of multiple distributions.

Uniform

Represents a uniform distribution over a specified interval.

Module Contents#

class pybop.parameters.distributions.Distribution(distribution: scipy.stats.distributions.rv_frozen | None = None)[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.

distribution#

The underlying continuous random variable distribution.

Type:

scipy.stats.distributions.rv_frozen

__repr__()[source]#

Returns a string representation of the object.

_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

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

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

mean()[source]#

Get the mean of the distribution.

Returns:

The mean of the distribution.

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=1, random_state=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.

std()[source]#

Get the standard deviation of the distribution.

Returns:

The standard deviation of the distribution.

Return type:

float

support()[source]#
verify(x)[source]#

Verifies that the input is a numpy array and converts it if necessary.

distribution = None#
class pybop.parameters.distributions.Exponential(scale: float, loc: float = 0)[source]#

Bases: Distribution

Represents an exponential distribution with a specified scale parameter.

This class provides methods to calculate the pdf, the log pdf, and to generate random variates from the distribution.

Parameters:

scale (float) – The scale parameter (lambda) of the exponential distribution.

__repr__()[source]#

Returns a string representation of the object.

_dlogpdf_dx(x)[source]#

Evaluates the first derivative of the log exponential 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

_n_parameters = 1#
loc = 0#
name = 'Exponential'#
scale#
class pybop.parameters.distributions.Gaussian(mean, sigma, truncated_at: list[float] = None)[source]#

Bases: Distribution

Represents a Gaussian (normal) distribution with a given mean and standard deviation.

This class provides methods to calculate the probability density function (pdf), the logarithm of the pdf, and to generate random variates (rvs) from the distribution.

Parameters:
  • mean (float) – The mean (mu) of the Gaussian distribution.

  • sigma (float) – The standard deviation (sigma) of the Gaussian distribution.

_dlogpdf_dx(x)[source]#

Evaluates the first derivative of the log Gaussian 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

_n_parameters = 1#
loc#
name = 'Gaussian'#
scale#
class pybop.parameters.distributions.JointDistribution(*distributions: Distribution | scipy.stats.distributions.rv_frozen)[source]#

Bases: Distribution

Represents a joint distribution composed of multiple distributions.

Parameters:

distributions (Distribution) – One or more distributions to combine into a joint distribution.

__repr__() str[source]#

Returns a string representation of the object.

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=1, random_state=None)[source]#

Sample each distribution individually and then compile.

_distributions_list: list[Distribution]#
_n_parameters = 0#
class pybop.parameters.distributions.Uniform(lower, upper)[source]#

Bases: Distribution

Represents a uniform distribution over a specified interval.

This class provides methods to calculate the pdf, the log pdf, and to generate random variates from the distribution.

Parameters:
  • lower (float) – The lower bound of the distribution.

  • upper (float) – The upper bound of the distribution.

__repr__()[source]#

Returns a string representation of the object.

_dlogpdf_dx(x)[source]#

Evaluates the first derivative of the log uniform 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

mean()[source]#

Returns the mean of the distribution.

_n_parameters = 1#
lower#
name = 'Uniform'#
upper#