distributions.Gamma

Gamma distribution implementation with shape (alpha) and scale (beta)

Usage

Source

distributions.Gamma()

parameters.

This class conforms to the Distribution protocol and provides methods to: - Calculate theoretical mean and variance - Derive parameters from specified mean/variance - Generate samples from the distribution

Attributes

Name Description
mean Calculate the theoretical mean of the distribution.
variance Calculate the theoretical variance of the distribution.

mean

Calculate the theoretical mean of the distribution.

mean: float


variance

Calculate the theoretical variance of the distribution.

variance: float

Methods

Name Description
__init__() Initialize a Gamma distribution.
params_from_mean_and_var() Derive shape (α) and scale (β) parameters from mean and variance.
sample() Generate random samples from the Gamma distribution.

__init__()

Initialize a Gamma distribution.

Usage

Source

__init__(alpha, beta, location=0.0, random_seed=None)
Parameters
alpha: float

Shape parameter. Must be > 0.

beta: float

Scale parameter. Must be > 0.

location: float = 0.0

Offset value added to all samples.

random_seed: Optional[Union[int, SeedSequence]] = None
A random seed or SeedSequence to reproduce samples. If None, a unique sample sequence is generated.
Raises
ValueError
If alpha or beta or location are not positive.

params_from_mean_and_var()

Derive shape (α) and scale (β) parameters from mean and variance.

Usage

Source

params_from_mean_and_var(mean, var)
Parameters
mean: float

Target mean value (μ)

var: float
Target variance value (σ²)
Returns
Tuple[float, float]
(alpha, beta) parameters
Notes

Uses formulae: - α = μ²/σ² - β = σ²/μ


sample()

Generate random samples from the Gamma distribution.

Usage

Source

sample(size=None)
Parameters
size: Optional[Union[int, Tuple[int, …]]] = None
Output shape:
  • None returns single sample as float
  • int returns 1D array
  • tuple returns nD array
Returns
Union[float, NDArray[np.float64]]
Samples with specified shape, plus location offset