Exponential Distribution#
- class ExponentialDistribution(amplitude: float = 1.0, scale: float = 1.0, loc: float = 0.0, normalize: bool = False)[source]#
Bases:
BaseDistributionClass for Exponential distribution.
- Parameters:
amplitude (float, optional) – The amplitude of the PDF. Defaults to 1.0. Ignored if normalize is
True.scale (float, optional) – The scale 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 toFalse.
- Raises:
NegativeAmplitudeError – If the provided value of amplitude is negative.
NegativeScaleError – If the provided value of scale is negative.
- Attributes:
Methods
cdf(x)Compute the cumulative density function (CDF) for the distribution.
logcdf(x)Compute the log cumulative density function (logCDF) for the distribution.
logpdf(x)Compute the log probability density function (logPDF) for the distribution.
pdf(x)Compute the probability density function (PDF) for the distribution.
scipy_like([loc, scale])Instantiate ExponentialDistribution with scipy parameterization.
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 expon 6 7from pymultifit.distributions import ExponentialDistribution
Generating a standard Exponential(\(\lambda =1.5\)) distribution with
pyMultiFitandscipy:9x_values = np.linspace(start=0, stop=5, num=500) 10 11y_multifit = ExponentialDistribution(scale=1.5, normalize=True) 12y_scipy = expon
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, scale=1 / 1.5), label='Scipy Exponential') 17ax[0].plot(x_values, y_multifit.pdf(x_values), 'k:', label='pyMultiFit Exponential') 18ax[0].set_ylabel('f(x)') 19 20ax[1].plot(x_values, y_scipy.cdf(x=x_values, scale=1 / 1.5), label='Scipy Exponential') 21ax[1].plot(x_values, y_multifit.cdf(x_values), 'k:', label='pyMultiFit Exponential') 22ax[1].set_ylabel('F(x)') 23 24f.suptitle('Exponential(1.5)') 25 26for i in ax: 27 i.set_xlabel('X') 28 i.legend() 29plt.tight_layout()
Generating a translated Exponential(\(\lambda=1.5\)) distribution with \(\text{loc} = 3\):
32y_multifit = ExponentialDistribution(scale=1.5, 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, scale=1 / 1.5, loc=3), label='Scipy translated Exponential') 37ax[0].plot(x_values, y_multifit.pdf(x_values), 'k:', label='pyMultiFit translated Exponential') 38ax[0].set_ylabel('f(x)') 39 40ax[1].plot(x_values, y_scipy.cdf(x=x_values, scale=1 / 1.5, loc=3), label='Scipy translated Exponential') 41ax[1].plot(x_values, y_multifit.cdf(x_values), 'k:', label='pyMultiFit translated Exponential') 42ax[1].set_ylabel('F(x)') 43 44f.suptitle(r'Exponential(1.5, 3)') 45 46for i in ax: 47 i.set_xlabel('X') 48 i.legend() 49plt.tight_layout()
- cdf(x)[source]#
Compute the cumulative density function (CDF) for the distribution.
- Parameters:
x – Input array at which to evaluate the CDF.
- logcdf(x)[source]#
Compute the log cumulative density function (logCDF) for the distribution.
- Parameters:
x – Input array at which to evaluate the logCDF.
- logpdf(x)[source]#
Compute the log probability density function (logPDF) for the distribution.
- Parameters:
x – Input array at which to evaluate the logPDF.
- pdf(x)[source]#
Compute the probability density function (PDF) for the distribution.
- Parameters:
x – Input array at which to evaluate the PDF.
- classmethod scipy_like(loc: float = 0.0, scale: float = 1.0)[source]#
Instantiate ExponentialDistribution with scipy parameterization.
- Parameters:
- loc: float, optional
The location parameter. Defaults to 0.0.
- scale: float, optional
The rate parameter. Defaults to 1.0.
- Returns:
- ExponentialDistribution
A instance of normalized ExponentialDistribution.
- stats()[source]#
Computes and returns the statistical properties of the distribution, including,
mean,
median,
variance, and
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 ExponentialDistribution is a special case of the GammaDistributionSR,
\(\alpha_\text{gammaSR} = 1\),
\(\lambda_\text{gammaSR} = \lambda_\text{expon}\).
This class internally utilizes the following functions from utilities_d module:
Recommended Import#
from pymultifit.distributions import ExponentialDistribution
Full Import#
from pymultifit.distributions.exponential_d import ExponentialDistribution