TruncatedNormal#

class cuqi.distribution.TruncatedNormal(mean=None, std=None, low=-inf, high=inf, is_symmetric=False, **kwargs)#

Truncated Normal probability distribution.

Generates instance of cuqi.distribution.TruncatedNormal. It allows the user to specify upper and lower bounds on random variables represented by a Normal distribution. This distribution is suitable for a small dimension setup (e.g. `dim`=3 or 4). Using TruncatedNormal Distribution with a larger dimension can lead to a high rejection rate when used within MCMC samplers.

The variables of this distribution are iid.

Parameters:
  • mean (float or array_like of floats) – mean of distribution

  • std (float or array_like of floats) – standard deviation

  • low (float or array_like of floats) – lower bound of the distribution

  • high (float or array_like of floats) – upper bound of the distribution

Example

#Generate Normal with mean 0, standard deviation 1 and bounds [-2,2]
p = cuqi.distribution.TruncatedNormal(mean=0, std=1, low=-2, high=2)
samples = p.sample(5000)
__init__(mean=None, std=None, low=-inf, high=inf, is_symmetric=False, **kwargs)#

Initialize the core properties of the distribution.

Parameters:
  • name (str, default None) – Name of distribution.

  • geometry (Geometry, default _DefaultGeometry (or None)) – Geometry of distribution.

  • is_symmetric (bool, default None) – Indicator if distribution is symmetric.

Methods

__init__([mean, std, low, high, is_symmetric])

Initialize the core properties of the distribution.

disable_FD()

Disable finite difference approximation for logd gradient.

enable_FD([epsilon])

Enable finite difference approximation for logd gradient.

get_conditioning_variables()

Return the conditioning variables of this distribution (if any).

get_mutable_variables()

Return any public variable that is mutable (attribute or property) except those in the ignore_vars list

get_parameter_names()

Returns the names of the parameters that the density can be evaluated at or conditioned on.

gradient(*args, **kwargs)

Returns the gradient of the log density at x.

logd(*args, **kwargs)

Evaluate the un-normalized log density function of the distribution.

logpdf(x)

Computes the unnormalized logpdf at the given values of x.

pdf(x)

Evaluate the log probability density function of the distribution.

sample([N])

Sample from the distribution.

to_likelihood(data)

Convert conditional distribution to a likelihood function given observed data

Attributes

FD_enabled

Returns True if finite difference approximation of the logd gradient is enabled.

FD_epsilon

Spacing for the finite difference approximation of the logd gradient.

dim

Return the dimension of the distribution based on the geometry.

geometry

Return the geometry of the distribution.

high

Higher bound of the distribution

is_cond

Returns True if instance (self) is a conditional distribution.

low

Lower bound of the distribution

mean

Mean of the distribution

name

Name of the random variable associated with the density.

std

Std of the distribution