pub struct Pert { /* private fields */ }Expand description
PERT distribution (Program Evaluation and Review Technique).
A modified Beta distribution defined by three points: optimistic (min), most likely (mode), and pessimistic (max).
§Mathematical Definition
Shape parameters (with λ = 4):
α = 1 + λ · (mode − min) / (max − min)
β = 1 + λ · (max − mode) / (max − min)The underlying variable Y = (X − min)/(max − min) follows Beta(α, β).
- Mean: (min + λ·mode + max) / (λ + 2) = (min + 4·mode + max) / 6
- Std Dev (simplified): (max − min) / (λ + 2) = (max − min) / 6
§Exact vs Simplified Variance
The simplified variance ((max−min)/6)² is an approximation. The exact
variance uses the Beta distribution formula:
Var = α·β / ((α+β)²·(α+β+1)) × (max−min)²The simplified formula is exact when the distribution is symmetric (mode = midpoint) and becomes less accurate as skewness increases.
Reference: Malcolm et al. (1959), “Application of a Technique for Research and Development Program Evaluation”, Operations Research 7(5).
Implementations§
Source§impl Pert
impl Pert
Sourcepub fn new(min: f64, mode: f64, max: f64) -> Result<Self, DistributionError>
pub fn new(min: f64, mode: f64, max: f64) -> Result<Self, DistributionError>
Creates a standard PERT distribution (λ = 4).
§Errors
Returns Err if min >= max or mode is outside [min, max].
Sourcepub fn with_shape(
min: f64,
mode: f64,
max: f64,
lambda: f64,
) -> Result<Self, DistributionError>
pub fn with_shape( min: f64, mode: f64, max: f64, lambda: f64, ) -> Result<Self, DistributionError>
Creates a modified PERT distribution with custom shape parameter λ.
λ controls the weight of the mode:
- λ = 4: standard PERT
- λ > 4: tighter distribution (more peaked)
- λ < 4: flatter distribution (less peaked)
§Errors
Returns Err if parameters are invalid.
pub fn min(&self) -> f64
pub fn mode(&self) -> f64
pub fn max(&self) -> f64
pub fn alpha(&self) -> f64
pub fn beta_param(&self) -> f64
Sourcepub fn mean(&self) -> f64
pub fn mean(&self) -> f64
Mean = (min + 4·mode + max) / 6 for standard PERT (λ=4).
General: (min + λ·mode + max) / (λ + 2).
Sourcepub fn variance(&self) -> f64
pub fn variance(&self) -> f64
Exact variance using Beta distribution formula.
Var = α·β / ((α+β)²·(α+β+1)) × (max−min)²Sourcepub fn cdf(&self, x: f64) -> f64
pub fn cdf(&self, x: f64) -> f64
CDF via regularized incomplete beta function approximation.
Uses a numerical approximation of the regularized incomplete beta function I_x(α, β).
Sourcepub fn quantile(&self, p: f64) -> Option<f64>
pub fn quantile(&self, p: f64) -> Option<f64>
Evaluates the quantile (inverse CDF) at probability p ∈ [0, 1].
A PERT is a Beta(α, β) stretched over [min, max], so its quantile is
min + (max − min)·B⁻¹(p; α, β) – exact to the tolerance of the Beta
quantile, and inside [min, max] by construction. (A normal
approximation μ + σ·Φ⁻¹(p) is off for any skewed estimate and can land
outside the support.)
Returns None if p is outside [0, 1].
§Examples
use u_numflow::distributions::Pert;
let pert = Pert::new(0.0, 1.0, 10.0).unwrap();
let q = pert.quantile(0.9).unwrap();
assert!((pert.cdf(q) - 0.9).abs() < 1e-9);