Beta Distribution#
- class BetaDistribution(amplitude: float = 1.0, alpha: float = 1.0, beta: float = 1.0, loc: float = 0.0, scale: float = 1.0, normalize: bool = False)[source]#
Bases:
BaseDistributionClass for Beta distribution.
- Parameters:
amplitude (float, optional) – The amplitude of the PDF. Defaults to 1.0. Ignored if
normalizeisTrue.alpha (float, optional) – The \(\alpha\) parameter. Defaults to 1.0.
beta (float, optional) – The \(\beta\) parameter. Defaults to 1.0.
loc (float, optional) – float, optional The location parameter, for shifting. Defaults to 0.0.
scale (float, optional) – float, optional The scale parameter, for scaling. Defaults to 1.0.
normalize (bool, optional) – 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.
NegativeAlphaError – If the provided value of \(\alpha\) is negative.
NegativeBetaError – If the provided value of \(\beta\) is negative.
- Attributes:
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, b[, loc, scale])Instantiate BetaDistribution 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 beta 6 7from pymultifit.distributions import BetaDistribution
Generating a standard \(\text{Beta}(2, 30)\) distribution with
pyMultiFitandscipy.9x_values = np.linspace(start=0, stop=1, num=500) 10 11y_multifit = BetaDistribution(alpha=2, beta=30, normalize=True) 12y_scipy = beta
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=2, b=30), label='Scipy Beta') 17ax[0].plot(x_values, y_multifit.pdf(x_values), 'k:', label='pyMultiFit Beta') 18ax[0].set_ylabel('f(x)') 19 20ax[1].plot(x_values, y_scipy.cdf(x=x_values, a=2, b=30), label='Scipy Beta') 21ax[1].plot(x_values, y_multifit.cdf(x_values), 'k:', label='pyMultiFit Beta') 22ax[1].set_ylabel('F(x)') 23 24f.suptitle('Beta(2, 30)') 25 26for i in ax: 27 i.set_xlabel('X') 28 i.legend() 29plt.tight_layout()
Generating a shifted and translated \(\text{Beta}(2, 30)\) distribution.
9x_values = np.linspace(start=0, stop=10, num=500) 10 11y_multifit = BetaDistribution(alpha=2, beta=30, loc=3, scale=5, normalize=True) 12y_scipy = beta
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=2, b=30, loc=3, scale=5), label='Scipy Beta scaled') 17ax[0].plot(x_values, y_multifit.pdf(x_values), 'k:', label='pyMultiFit Beta scaled') 18ax[0].set_ylabel('f(x)') 19 20ax[1].plot(x_values, y_scipy.cdf(x=x_values, a=2, b=30, loc=3, scale=5), label='Scipy Beta scaled') 21ax[1].plot(x_values, y_multifit.cdf(x_values), 'k:', label='pyMultiFit Beta scaled') 22ax[1].set_ylabel('F(x)') 23 24f.suptitle('Beta(2, 30, 5, 3)') 25 26for i in ax: 27 i.set_xlabel('X') 28 i.legend() 29plt.tight_layout()
- cdf(x: ndarray) ndarray[source]#
Compute the cumulative density function (CDF) for the distribution.
- Parameters:
x – Input array at which to evaluate the CDF.
- pdf(x: ndarray) ndarray[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, b: float, loc: float = 0.0, scale: float = 1.0)[source]#
Instantiate BetaDistribution with scipy parameterization.
- Parameters:
- a: float
The shape parameter, \(\alpha\).
- b: float
The shape parameter, \(\beta\).
- loc: float, optional
The location parameter. Defaults to 0.0.
- scale: float, optional
The scale parameter,. Defaults to 1.0.
- Returns:
- BetaDistribution
An instance of normalized BetaDistribution.
- stats() Dict[str, float][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:
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 BetaDistribution encompasses the following specific cases:
ArcSineDistribution:\(\alpha = \beta = 0.5\)
UniformDistribution:\(\alpha = \beta = 1\)
This class internally utilizes the following functions from utilities_d module:
Recommended Import#
from pymultifit.distributions import BetaDistribution
Full Import#
from pymultifit.distributions.beta_d import BetaDistribution