NormalDistribution Class
- class Stats_Analysis.Base_Dist.NormalDistribution_Class.NormalDistribution(mu, sigma, lower_bound=None, upper_bound=None)[source]
Bases:
objectNormal distribution probability distribution.
This class supports computation of the PDF and CDF for scalar and array inputs, with optional truncation. Uses scipy.stats.norm for the underlying normal distribution.
- Parameters:
mu (float) – The mean of the normal distribution.
sigma (float) – The standard deviation of the normal distribution. Must be sigma > 0.
lower_bound (float, optional) – The lower bound. Default is None, meaning no lower bound is applied.
upper_bound (float, optional) – The upper bound. Default is None, meaning no upper bound is applied.
- Raises:
ValueError – If sigma (standard deviation) is not positive. If lower_bound >= upper_bound.
- __init__(mu, sigma, lower_bound=None, upper_bound=None)[source]
Initialize the normal distribution with optional truncation.
- _calc_trunc_fact()[source]
Calculate the normalisation factor if the distribution has been truncated. ie limits applied
- cdf(X)[source]
Calculate the Cumulative Distribution Function (CDF).
- Parameters:
X (float or np.ndarray) – The value(s) at which to evaluate the truncated CDF.
- Returns:
The truncated CDF value(s).
- Return type:
float or np.ndarray
Notes
For values less than lower_bound, the CDF equals 0.
For values greater than upper_bound, the CDF equals 1
Within the bounds, the CDF is scaled by the truncation factor.
- cdf_fitting(X, mu, sigma)[source]
Calculate the Cumulative Distribution Function (CDF) with no set parameters, automatically including truncation if bounds are set, for use in Binned MLE fitting.
- Parameters:
X (float or np.ndarray) – The value(s) at which to evaluate the truncated CDF.
- Returns:
The truncated CDF value(s).
- Return type:
float or np.ndarray
Notes
For values less than lower_bound, the CDF equals 0.
For values greater than upper_bound, the CDF equals 1
Within the bounds, the CDF is scaled by the truncation factor.
- normalisation_check()[source]
Perform a numerical integration using scipy.integrate.quad to check the normalization of the PDF.
If the PDF has been truncated: It is first performed over the region the PDF is defined [lower_bound, upper_bound]
It is then performed over the entire real line (-infinity to infinity).
Prints the results of the numerical integrations.
- pdf(X)[source]
Calculate the Probability Density Function (PDF), automatically including truncation if bounds are set.
- Parameters:
X (float or np.ndarray) – The value(s) at which to evaluate the PDF.
- Returns:
The normalized PDF value(s), accounting for optional truncation.
- Return type:
float or np.ndarray
Notes
For Z > -beta, the PDF is defined by lower_bound Gaussian core.
For Z <= -beta, the PDF transitions to a power-law tail.
If truncation bounds are provided, the PDF is zero outside the truncation range.