pybop.parameters.multivariate_distributions#

Classes#

BaseMultivariateDistribution

A base class for defining multivariate parameter distributions.

MarginalDistribution

Represents a univariate marginal distribution of a pybop.BaseMultivariateDistribution.

MultivariateGaussian

Represents a multivariate Gaussian (normal) distribution with a

MultivariateLogNormal

Represents a multivariate log-normal distribution with a

MultivariateNonparametric

Represents a "freeform" distribution, i.e., one that is defined from

MultivariateUniform

Represents a multivariate uniform distribution.

Module Contents#

class pybop.parameters.multivariate_distributions.BaseMultivariateDistribution(distribution: scipy.stats.distributions.rv_frozen | None = None)[source]#

Bases: pybop.parameters.distributions.Distribution

A base class for defining multivariate parameter distributions.

This class extends pybop.Distribution with methods that reduce the output of a multivariate distribution to its individual dimensions.

Note that, unlike in pybop.Distribution, distribution attributes are stored in a dictionary, as multivariate distributions in SciPy do not follow the loc/scale convention.

distribution#

The underlying continuous random variable distribution.

Type:

scipy.stats.rv_continuous

properties#

A dictionary with distribution keyword argument names as string keys and their values as float values.

Type:

dict

__repr__()[source]#

Returns a string representation of the object.

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

cdf_marginal(x, dim)[source]#

Takes the marginal cumulative distribution function (CDF) at x in dim.

Parameters:
  • x (numpy.ndarray) – The point(s) at which to evaluate the CDF.

  • dim (int) – The dimension to which to reduce the CDF to.

Returns:

The marginal cumulative distribution function value at x in dim.

Return type:

float

abstractmethod icdf_marginal(q, dim)[source]#
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

abstractmethod marginal(position)[source]#

Return univariate marginal distribution of parameter with index ‘position’

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.

abstractmethod transformed_properties(transformation)[source]#

Return distribution properties in search space

abstract property compatible_transformations#
icdf = None#

Multivariate distributions have no invertible CDF.

abstract property mean#

Get the mean of the distribution.

Returns:

The mean of the distribution.

Return type:

float

abstract property sigma#
class pybop.parameters.multivariate_distributions.MarginalDistribution(parent_distribution: BaseMultivariateDistribution, position: int)[source]#

Bases: pybop.parameters.distributions.Distribution

Represents a univariate marginal distribution of a pybop.BaseMultivariateDistribution. Relies on the “marginal” method of the multivariate distribution.

Sub-class of pybop.Distribution with the additional properties “parent_distribution” and “position”

Parameters:
  • parent_distribution (pybop.BaseMultivariateDistribution) – A multivariate distribution

  • position (int) – position of the parameter for which to create the marginal distribution

mean()[source]#

Get the mean of the distribution.

Returns:

The mean of the distribution.

Return type:

float

std()[source]#

Get the standard deviation of the distribution.

Returns:

The standard deviation of the distribution.

Return type:

float

_position#
parent_distribution#
property position#
class pybop.parameters.multivariate_distributions.MultivariateGaussian(mean=None, covariance=None, bounds=None, random_state=None)[source]#

Bases: BaseMultivariateDistribution

Represents a multivariate Gaussian (normal) distribution with a given mean and covariance.

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 (numpy.ndarray) – The mean (µ) of the multivariate Gaussian distribution.

  • covariance (numpy.ndarray) – The covariance matrix (Σ) of the multivariate Gaussian distribution. Note that what is called σ in 1D would be the square root of Σ here.

  • bounds (numpy.ndarray) – Lower and upper bounds (2nd dim) of the parameters (1st dim).

marginal(position)[source]#

Return univariate marginal distribution of parameter with index ‘position’

transformed_properties(transformation)[source]#

Return distribution properties in search space

_n_parameters#
property compatible_transformations#
property mean#

Get the mean of the distribution.

Returns:

The mean of the distribution.

Return type:

float

name = 'MultivariateGaussian'#
properties#
property sigma#
sigma2 = None#
class pybop.parameters.multivariate_distributions.MultivariateLogNormal(mean_log_x=None, covariance_log_x=None)[source]#

Bases: BaseMultivariateDistribution

Represents a multivariate log-normal distribution with a given mean and covariance of the normally distributed log(x).

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_log_x (numpy.ndarray) – The mean (µ) of the multivariate Gaussian distribution of log(x).

  • covariance_log_x (numpy.ndarray) – The covariance matrix (Σ) of the multivariate Gaussian distribution of log(x). Note that what is called σ in 1D would be the square root of Σ here.

_get_covariance_and_mean()[source]#

Method to compute the covariance and mean in the model space based on the covariance and mean of log(x) (i.e. in the search space)

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

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

marginal(position)[source]#

Return univariate marginal distribution of parameter with index ‘position’

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.

transformed_properties(transformation)[source]#

Return distribution properties in search space

_n_parameters#
property compatible_transformations#
distribution_log_x#
name = 'MultivariateLogNormal'#
properties#
properties_log_x#
sigma2#
class pybop.parameters.multivariate_distributions.MultivariateNonparametric(samples, random_state=None)[source]#

Bases: BaseMultivariateDistribution

Represents a “freeform” distribution, i.e., one that is defined from a random sampling and a kernel density estimate on that sampling.

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:

samples (numpy.ndarray) – The random variates to base the distribution on.

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

marginal(position)[source]#

Return univariate marginal distribution of parameter with index ‘position’

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.

transformed_properties(transformation)[source]#

Return distribution properties in search space

_n_parameters#
property compatible_transformations#
name = 'MultivariateNonparametric'#
properties#
class pybop.parameters.multivariate_distributions.MultivariateUniform(bounds, random_state=None)[source]#

Bases: BaseMultivariateDistribution

Represents a multivariate uniform distribution.

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

Parameters:

bounds (numpy.ndarray) – The lower and upper bounds for the uniform distribution.

marginal(position)[source]#

Return univariate marginal distribution of parameter with index ‘position’

_n_parameters#
property compatible_transformations#
name = 'MultivariateUniform'#
properties#