Gamma Distribution (SR)#

class GammaDistributionSR(amplitude: float = 1.0, shape: float = 1.0, rate: float = 1.0, loc: float = 0.0, normalize: bool = False)[source]#

Bases: BaseDistribution

Class for Gamma distribution with shape and rate parameters.

Parameters:
  • amplitude (float, optional) – The amplitude of the PDF. Default is 1.0. Ignored if normalize is True.

  • shape (float, optional) – The shape parameter, \(\alpha\). Defaults to 1.0.

  • rate (float, optional) – The rate parameter, \(\lambda\). Defaults to 1.0.

  • loc (float, optional) – The location parameter, for shifting. Defaults to 0.0.

  • normalize (bool, optional) – If True, the distribution is normalized so that the total area under the PDF equals 1. Defaults to False.

Raises:
Attributes:
mean

The mean of the distribution.

median

The median of the distribution.

mode

The mode of the distribution.

stddev

The standard deviation of the distribution.

variance

The variance of the distribution.

Methods

cdf(x)

Compute the cumulative density function (CDF) for the distribution.

pdf(x)

Compute the probability density function (PDF) for the distribution.

scipy_like(a[, loc, scale])

Instantiate GammaDistributionSR with scipy parametrization.

stats()

Computes and returns the statistical properties of the distribution, including,

Examples

Importing libraries:

3import matplotlib.pyplot as plt
4import numpy as np
5from scipy.stats import gamma
6
7from pymultifit.distributions import GammaDistributionSR

Generating a standard GammaSR(\(\alpha =1.5, \lambda = 1\)) distribution with pyMultiFit and scipy:

 9x_values = np.linspace(start=0, stop=5, num=500)
10
11y_multifit = GammaDistributionSR(shape=1.5, normalize=True)
12y_scipy = gamma

Plotting PDF and CDF:

14f, ax = plt.subplots(1, 2, figsize=(12, 5))
15
16ax[0].plot(x_values, y_scipy.pdf(x=x_values, a=1.5), label='Scipy Gamma SR')
17ax[0].plot(x_values, y_multifit.pdf(x_values), 'k:', label='pyMultiFit Gamma SR')
18ax[0].set_ylabel('f(x)')
19
20ax[1].plot(x_values, y_scipy.cdf(x=x_values, a=1.5), label='Scipy Gamma SR')
21ax[1].plot(x_values, y_multifit.cdf(x_values), 'k:', label='pyMultiFit Gamma SR')
22ax[1].set_ylabel('F(x)')
23
24f.suptitle('GammaSR(1.5)')
25
26for i in ax:
27    i.set_xlabel('X')
28    i.legend()
29plt.tight_layout()
GammaSR(1.5, 1)

Generating a translated Gamma(\(\alpha=1.5, \lambda=0.2\)) distribution with \(\text{loc} = 3\):

32y_multifit = GammaDistributionSR(shape=1.5, rate=0.2, loc=3, normalize=True)

Plotting PDF and CDF:

34f, ax = plt.subplots(1, 2, figsize=(12, 5))
35
36ax[0].plot(x_values, y_scipy.pdf(x=x_values, a=1.5, scale=1 / 0.2, loc=3), label='Scipy translated Gamma SR')
37ax[0].plot(x_values, y_multifit.pdf(x_values), 'k:', label='pyMultiFit translated Gamma SR')
38ax[0].set_ylabel('f(x)')
39
40ax[1].plot(x_values, y_scipy.cdf(x=x_values, a=1.5, scale=1 / 0.2, loc=3), label='Scipy translated Gamma SR')
41ax[1].plot(x_values, y_multifit.cdf(x_values), 'k:', label='pyMultiFit translated Gamma SR')
42ax[1].set_ylabel('F(x)')
43
44f.suptitle(r'Gamma SR(1.5, 0.2, 3)')
45
46for i in ax:
47    i.set_xlabel('X')
48    i.legend()
49plt.tight_layout()
GammaSR(1.5, 0.2, 3)
cdf(x: array) array[source]#

Compute the cumulative density function (CDF) for the distribution.

Parameters:

x – Input array at which to evaluate the CDF.

pdf(x: array) array[source]#

Compute the probability density function (PDF) for the distribution.

Parameters:

x – Input array at which to evaluate the PDF.

classmethod scipy_like(a: float, loc: float = 0.0, scale: float = 1.0)[source]#

Instantiate GammaDistributionSR with scipy parametrization.

Parameters:
a: float

The shape parameter.

loc: float, optional

The location parameter, for shifting. Defaults to 0.0.

scale: float, optional

The scaling parameter, for scaling. Defaults to 1.0.

Returns:
“GammaDistributionSR”

An instance of normalized GammaDistributionSR.

stats() Dict[str, float][source]#

Computes and returns the statistical properties of the distribution, including,

  1. mean,

  2. median,

  3. variance, and

  4. standard deviation.

Returns:

A dictionary containing statistical properties such as mean, variance, etc.

Return type:

Dict[str, float]

Notes

If any of the parameter is not computable for a distribution, this method returns None.

property mean#

The mean of the distribution.

property median#

The median of the distribution.

property mode#

The mode of the distribution.

property stddev#

The standard deviation of the distribution.

property variance#

The variance of the distribution.

Note

The GammaDistributionSR encompasses the following specific cases:

  1. ExponentialDistribution:
    • \(\alpha = 1\), and

    • \(\lambda_\text{gammaSR} = \lambda_\text{expon}\).

  2. GammaDistributionSS:
    • \(\alpha_\text{gammaSR} = \alpha_\text{gammaSS}\)

    • \(\lambda = \theta^{-1}\).

  3. UniformDistribution:
    • \(\alpha = 1\), and

    • \(\lambda = 1\).

This class internally utilizes the following functions from utilities_d module:

Full Import#

from pymultifit.distributions.gamma_d import GammaDistributionSR