Gamma

Data Type: float

The gamma distribution is a generalization of the exponential distribution. The distribution has support on the positive real line. The probability density function is given by

\[f\left(x | k, \theta \right) = \frac{1}{\Gamma(k)\theta^k}x^{k-1}e^{-\frac{1}{\theta}x}, \; x \geq 0.\]

The above is the scale parametarization of the gamma distribution. For more info see Gamma Distribution.

GammaDistribution

class dmx.stats.gamma.GammaDistribution(k, theta, name=None, keys=None)

Gamma distribution with shape k and scale theta.

k

Positive real-valued shape parameter.

Type:

float

theta

Positive real-valued scale parameter.

Type:

float

name

Name for the GammaDistribution instance.

Type:

Optional[str]

log_const

Normalizing constant of gamma distribution.

Type:

float

keys

Key for parameters of distribution.

Type:

Optional[str]

__init__(k, theta, name=None, keys=None)

Initialize GammaDistribution.

Parameters:
  • k (float) – Positive real-valued shape parameter.

  • theta (float) – Positive real-valued scale parameter.

  • name (Optional[str], optional) – Name for the GammaDistribution instance.

  • keys (Optional[str], optional) – Key for parameters of distribution.

density(x)

Evaluate the density of the gamma distribution at x.

Parameters:

x (float) – Positive real-valued number.

Returns:

Density evaluated at x.

Return type:

float

dist_to_encoder()

Return a GammaDataEncoder for this distribution.

Returns:

Encoder object.

Return type:

GammaDataEncoder

estimator(pseudo_count=None)

Return a GammaEstimator for this distribution.

Parameters:

pseudo_count (Optional[float], optional) – Pseudo-count for regularization.

Returns:

Estimator object.

Return type:

GammaEstimator

log_density(x)

Evaluate the log-density of the gamma distribution at x.

Parameters:

x (float) – Positive real-valued number.

Returns:

Log-density evaluated at x.

Return type:

float

sampler(seed=None)

Return a GammaSampler for this distribution.

Parameters:

seed (Optional[int], optional) – Seed for random number generator.

Returns:

Sampler object.

Return type:

GammaSampler

seq_log_density(x)

Vectorized log-density for encoded data.

Parameters:

x (GammaEncodedDataSequence) – Encoded data sequence.

Returns:

Log-density values.

Return type:

np.ndarray

GammaEstimator

class dmx.stats.gamma.GammaEstimator(pseudo_count=(0.0, 0.0), suff_stat=(1.0, 0.0), threshold=1e-08, name=None, keys=None)

Estimator for the gamma distribution from aggregated sufficient statistics.

pseudo_count

Values used to re-weight sufficient statistics.

Type:

Tuple[float, float]

suff_stat

Prior shape ‘k’ and scale ‘theta’.

Type:

Tuple[float, float]

threshold

Threshold for estimating the shape of gamma.

Type:

float

name

Name for the estimator.

Type:

Optional[str]

keys

Key for combining sufficient statistics.

Type:

Optional[str]

__init__(pseudo_count=(0.0, 0.0), suff_stat=(1.0, 0.0), threshold=1e-08, name=None, keys=None)

Initialize GammaEstimator.

Parameters:
  • pseudo_count (Tuple[float, float], optional) – Values used to re-weight sufficient statistics.

  • suff_stat (Tuple[float, float], optional) – Prior shape ‘k’ and scale ‘theta’.

  • threshold (float, optional) – Threshold for estimating the shape of gamma.

  • name (Optional[str], optional) – Name for the estimator.

  • keys (Optional[str], optional) – Key for combining sufficient statistics.

Raises:

TypeError – If keys is not a string or None.

accumulator_factory()

Return a GammaAccumulatorFactory for this estimator.

Returns:

Factory object.

Return type:

GammaAccumulatorFactory

estimate(nobs, suff_stat)

Estimate a GammaDistribution from sufficient statistics.

Parameters:
  • nobs (Optional[float]) – Number of observations (not used).

  • suff_stat (Tuple[float, float, float]) – (nobs, sum, sum_of_logs) sufficient statistics.

Returns:

Estimated distribution.

Return type:

GammaDistribution

static estimate_shape(avg_sum, avg_sum_of_logs, threshold)

Estimate the shape parameter of the GammaDistribution.

Parameters:
  • avg_sum (float) – Weighted mean of gamma observations.

  • avg_sum_of_logs (float) – Weighted mean of log gamma observations.

  • threshold (float) – Threshold for convergence of shape estimation.

Returns:

Estimate of shape parameter ‘k’.

Return type:

float

GammaSampler

class dmx.stats.gamma.GammaSampler(dist, seed=None)

Sampler for the gamma distribution.

rng

Random number generator.

Type:

RandomState

dist

GammaDistribution to sample from.

Type:

GammaDistribution

seed

Seed for random number generator.

Type:

Optional[int]

sample(size=None)

Draw iid samples from the gamma distribution.

Parameters:

size (Optional[int], optional) – Number of iid samples to draw. If None, returns a single sample.

Returns:

Single sample (float) if size is None, else a list of samples.

Return type:

Union[float, List[float]]