Gamma#
- class cuqi.distribution.Gamma(shape=None, rate=None, is_symmetric=False, **kwargs)#
Represents a multivariate Gamma distribution characterized by shape and rate parameters of independent random variables x_i. Each is distributed according to the PDF function
\[f(x_i; \alpha, \beta) = \beta^\alpha x_i^{\alpha-1} \exp(-\beta x_i) / \Gamma(\alpha)\]where shape \(\alpha\) and rate \(\beta\) are the parameters of the distribution, and \(\Gamma\) is the Gamma function.
In case shape and/or rate are arrays, the pdf looks like
\[f(x_i; \alpha_i, \beta_i) = \beta_i^{\alpha_i} x_i^{\alpha_i-1} \exp(-\beta_i x_i) / \Gamma(\alpha_i)\]- Parameters:
shape (float or array_like, optional) – The shape parameter of the Gamma distribution. Must be positive.
rate (float or array_like, optional) – The rate parameter of the Gamma distribution. Must be positive.
Examples
import numpy as np import cuqi import matplotlib.pyplot as plt # Create a multivariate Gamma distribution with the same shape and rate parameters shape = 1 rate = 1e-4 gamma_dist = cuqi.distribution.Gamma(shape=shape, rate=rate, geometry=10) # Generate samples samples = gamma_dist.sample(10000) # Plot histogram of samples for index 0 samples.hist_chain(0, bins=70)
import numpy as np import cuqi import matplotlib.pyplot as plt # Create a multivariate Gamma distribution with different shape and rate parameters shape = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] rate = [1e-4, 1e-3, 1e-2, 1e-1, 1, 1e1, 1e2, 1e3, 1e4, 1e5] gamma_dist = cuqi.distribution.Gamma(shape=shape, rate=rate) # Generate samples samples = gamma_dist.sample(10000) # Plot histogram of samples for index 0 samples.hist_chain(0, bins=70)
- __init__(shape=None, rate=None, 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__
([shape, rate, is_symmetric])Initialize the core properties of the distribution.
cdf
(x)Disable finite difference approximation for logd gradient.
enable_FD
([epsilon])Enable finite difference approximation for logd gradient.
Return the conditioning variables of this distribution (if any).
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.
Rate parameter of the Gamma distribution.
Scale parameter of the Gamma distribution.
Shape parameter of the Gamma distribution.