UserDefinedDistribution#
- class cuqi.distribution.UserDefinedDistribution(dim=None, logpdf_func=None, gradient_func=None, sample_func=None, **kwargs)#
Class to wrap user-defined logpdf, gradient, and/or sampling callable into CUQIpy Distribution.
- Parameters:
logpdf_func (Function evaluating log probability density function. Callable.)
gradient_func (Function evaluating the gradient of the logpdf. Callable.)
sample_func (Function drawing samples from distribution. Callable.)
Example
# Generate an i.i.d. n-dim Gaussian with zero mean and 2 variance. mu1 = -1.0 std1 = 4.0 X = cuqi.distribution.Normal(mean=mu1, std=std1) dim1 = 1 logpdf_func = lambda xx: -np.log(std1*np.sqrt(2*np.pi))-0.5*((xx-mu1)/std1)**2 sample_func = lambda : mu1 + std1*np.random.randn(dim1,1) XU = cuqi.distribution.UserDefinedDistribution(dim=dim1, logpdf_func=logpdf_func, sample_func=sample_func)
- __init__(dim=None, logpdf_func=None, gradient_func=None, sample_func=None, **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__
([dim, logpdf_func, gradient_func, ...])Initialize the core properties of the distribution.
Disable finite difference approximation for logd gradient.
enable_FD
([epsilon])Enable finite difference approximation for logd gradient.
Returns the conditioning variables of the distribution.
Return any public variable that is mutable (attribute or property) except those in the ignore_vars list
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)Evaluate the log probability density function of the distribution.
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
Returns True if finite difference approximation of the logd gradient is enabled.
Spacing for the finite difference approximation of the logd gradient.
Return the dimension of the distribution based on the geometry.
Return the geometry of the distribution.
Returns True if instance (self) is a conditional distribution.
Name of the random variable associated with the density.