CompositeDistribution#

class hmclab.Distributions.CompositeDistribution(*args, **kwargs)[source]#

Bases: hmclab.Distributions.base._AbstractDistribution

Distribution distribution combined from multiple unconditional distributions.

Parameters
  • dimensions (int) – Combined dimension of all the separate distributions

  • list_of_distributions (List[_AbstractDistribution]) – List of all separate distributions.

Raises

ValueError – Raised if the passed dimensions do not correspond to the sum of the separate dimensions of each distribution.

This class can be used when two or more sets of coordinates should be described by different distributions, e.g. when one set requires a Normal distribution and another a uniform distribution.

__init__(list_of_distributions: Optional[List[hmclab.Distributions.base._AbstractDistribution]] = None, lower_bounds: Optional[numpy.ndarray] = None, upper_bounds: Optional[numpy.ndarray] = None)[source]#

Methods

__init__

collapse_bounds

Method to restructure all composite bounds into top level object.

corrector

Override method to correct an HMC particle for composite distribution, which is called after every time integration step.

create_default

dimensions

Dimensionality of misfit space.

generate

gradient

misfit

misfit_bounds

Compute misfit of bounded distribution.

normalize

Normalize distribution.

update_bounds

Update bounded distribution.

Attributes

lower_bounds

Lower bounds for every parameter.

name

Name of the distribution.

normalized

Boolean describing if the distribution is normalized.

upper_bounds

Upper bounds for every parameter.

enumerated_dimensions

This object describes how many dimensions each distribution has, ordered according to CompositeDistribution.separate_distributions.

enumerated_dimensions_cumulative

This object describes each separate distribution index in combined model space.

enumerated_dimensions: numpy.ndarray#

This object describes how many dimensions each distribution has, ordered according to CompositeDistribution.separate_distributions. Sums to CompositeDistribution.dimesions.

dimensions() int#

Dimensionality of misfit space.

This is an abstract parameter. If it is not defined either in your class directly or in its constructor (the __init__ function) then attempting to use the class will raise a NotImplementedError.

Access it like a parameter, not a function: distribution.dimensions.

enumerated_dimensions_cumulative: numpy.ndarray#

This object describes each separate distribution index in combined model space. Invoking numpy.split(m, CompositeDistribution.enumerated_dimensions_cumulative)[:-1]) splits a vector appropriately for all separate distributions.

collapse_bounds()[source]#

Method to restructure all composite bounds into top level object.

corrector(coordinates: numpy.ndarray, momentum: numpy.ndarray)[source]#

Override method to correct an HMC particle for composite distribution, which is called after every time integration step. Calls all sub-correctors only if the object does not have bounds itself.

Parameters
  • coordinates (numpy.ndarray) – Numpy array shaped as (dimensions, 1) representing a column vector containing the coordinates \(\mathbf{m}\) upon which to operate by reference.

  • momentum (numpy.ndarray) – Numpy array shaped as (dimensions, 1) representing a column vector containing the momenta \(\mathbf{p}\) upon which to operate by reference.

misfit_bounds(coordinates: numpy.ndarray) float#

Compute misfit of bounded distribution.

Method to compute the misfit associated with the truncated part of the distribution. Used internally.

normalize()#

Normalize distribution.

Method to compute the normalization constant of a distribution. As this might take significant time, it is not done in initialization.

Raises

AttributeError – An AttributeError is raised if the distribution provides no way to be normalized, e.g. when the normalization constant is intractable.

update_bounds(lower: Optional[numpy.ndarray] = None, upper: Optional[numpy.ndarray] = None)#

Update bounded distribution.

This method updates the bounds of a distribution. Note that invocating it, does not require both bounds to be passed.

If both vectors are passed, ensure that all upper bounds are above the corresponding lower bounds.

Parameters
  • lower (numpy.ndarray or None) – Either an array shaped as (dimensions, 1) with floats for the lower bounds, or None for no bounds. If some dimensions should be bounded, while others should not, use -numpy.inf within the vector as needed.

  • upper (numpy.ndarray or None) – Either an array shaped as (dimensions, 1) with floats for the upper bounds, or None for no bounds. If some dimensions should be bounded, while others should not, use numpy.inf within the vector as needed.

Raises

ValueError – A ValueError is raised if the supplied upper and lower bounds are incompatible.