pub struct Pert { /* private fields */ }Expand description
Represents a PERT (Program Evaluation and Review Technique) distribution.
The PERT distribution is defined by its minimum, most likely (mode), and maximum values, along with an optional shape parameter.
§Examples
use distimate::prelude::*;
use distimate::Pert;
use approx::assert_relative_eq;
let pert = Pert::new(1.0, 2.0, 3.0).unwrap();
assert_eq!(pert.min(), 1.0);
assert_eq!(pert.mode(), 2.0);
assert_eq!(pert.max(), 3.0);
assert_relative_eq!(pert.mean().unwrap(), 2.0, epsilon = 1e-6);Implementations§
source§impl Pert
impl Pert
sourcepub fn new(min: f64, likely: f64, max: f64) -> Result<Self>
pub fn new(min: f64, likely: f64, max: f64) -> Result<Self>
Creates a new PERT distribution with the given minimum, likely, and maximum values.
This method uses the default shape parameter of 4.0.
§Arguments
min- The minimum value of the distributionlikely- The most likely value (mode) of the distributionmax- The maximum value of the distribution
§Returns
Returns a Result containing the new Pert instance if the parameters are valid,
or an Error if the parameters are invalid.
§Errors
Returns an error if:
minis greater than or equal tomaxlikelyis less thanminor greater thanmax
§Examples
use distimate::prelude::*;
use distimate::Pert;
let pert = Pert::new(1.0, 2.0, 3.0).unwrap();
assert_eq!(pert.min(), 1.0);
assert_eq!(pert.mode(), 2.0);
assert_eq!(pert.max(), 3.0);sourcepub fn new_with_shape(
min: f64,
likely: f64,
max: f64,
shape: f64,
) -> Result<Self>
pub fn new_with_shape( min: f64, likely: f64, max: f64, shape: f64, ) -> Result<Self>
Creates a new PERT distribution with the given minimum, likely, maximum, and shape values.
§Arguments
min- The minimum value of the distributionlikely- The most likely value (mode) of the distributionmax- The maximum value of the distributionshape- The shape parameter of the distribution (must be between 2.0 and 6.0, inclusive)
§Returns
Returns a Result containing the new Pert instance if the parameters are valid,
or an Error if the parameters are invalid.
§Errors
Returns an error if:
minis greater than or equal tomaxlikelyis less thanminor greater thanmaxshapeis not between 2.0 and 6.0 (inclusive)
§Examples
use distimate::prelude::*;
use distimate::Pert;
let pert = Pert::new_with_shape(1.0, 2.0, 3.0, 5.0).unwrap();
assert_eq!(pert.min(), 1.0);
assert_eq!(pert.mode(), 2.0);
assert_eq!(pert.max(), 3.0);sourcepub fn alpha(&self) -> f64
pub fn alpha(&self) -> f64
Returns the alpha parameter of the underlying Beta distribution.
The alpha parameter is calculated based on the minimum, mode, maximum, and shape parameters of the PERT distribution.
§Returns
The alpha parameter as an f64 value.
§Examples
use distimate::prelude::*;
use distimate::Pert;
use approx::assert_relative_eq;
let pert = Pert::new(1.0, 2.0, 3.0).unwrap();
assert_relative_eq!(pert.alpha(), 3.0, epsilon = 1e-6);sourcepub fn beta(&self) -> f64
pub fn beta(&self) -> f64
Returns the beta parameter of the underlying Beta distribution.
The beta parameter is calculated based on the minimum, mode, maximum, and shape parameters of the PERT distribution.
§Returns
The beta parameter as an f64 value.
§Examples
use distimate::prelude::*;
use distimate::Pert;
use approx::assert_relative_eq;
let pert = Pert::new(1.0, 2.0, 3.0).unwrap();
assert_relative_eq!(pert.beta(), 3.0, epsilon = 1e-6);sourcepub fn shape(&self) -> f64
pub fn shape(&self) -> f64
Returns the shape parameter of the PERT distribution.
The shape parameter influences the peakedness of the distribution. A higher value results in a more peaked distribution around the mode.
§Returns
The shape parameter as an f64 value.
§Examples
use distimate::prelude::*;
use distimate::Pert;
let pert = Pert::new_with_shape(1.0, 2.0, 3.0, 5.0).unwrap();
assert_eq!(pert.shape(), 5.0);sourcepub fn kurtosis(&self) -> f64
pub fn kurtosis(&self) -> f64
Calculates the excess kurtosis of the PERT distribution.
Excess kurtosis is a measure of the “tailedness” of the probability distribution compared to a normal distribution. A positive excess kurtosis indicates heavier tails and a higher, sharper peak, while a negative excess kurtosis indicates lighter tails and a lower, more rounded peak.
§Returns
The excess kurtosis as an f64 value.
§Examples
use distimate::prelude::*;
use distimate::Pert;
use approx::assert_relative_eq;
let pert = Pert::new(1.0, 2.0, 3.0).unwrap();
assert_relative_eq!(pert.kurtosis(), -0.6666667, epsilon = 1e-6);Trait Implementations§
source§impl Continuous<f64, f64> for Pert
impl Continuous<f64, f64> for Pert
Implementation of the Continuous trait for the PERT distribution.
This implementation provides methods to calculate the probability density function (PDF) and its natural logarithm for the PERT distribution. These functions are crucial for understanding the likelihood of different outcomes within the distribution’s range.
The PERT distribution is continuous over its defined range (minimum to maximum), with the PDF representing the relative likelihood of each possible value.
source§fn pdf(&self, x: f64) -> f64
fn pdf(&self, x: f64) -> f64
Calculates the probability density function (PDF) of the PERT distribution at a given point.
The PDF represents the relative likelihood of the distribution taking on a specific value. For the PERT distribution, the PDF is non-zero only within the range [min, max] and reaches its peak at the mode.
§Arguments
x- The point at which to calculate the PDF
§Returns
The value of the PDF at the given point as an f64.
§Examples
use distimate::prelude::*;
use distimate::Pert;
use approx::assert_relative_eq;
let pert = Pert::new(1.0, 2.0, 3.0).unwrap();
assert_relative_eq!(pert.pdf(2.0), 0.9375, epsilon = 1e-6);
assert_eq!(pert.pdf(0.0), 0.0); // Outside the distribution's rangesource§fn ln_pdf(&self, x: f64) -> f64
fn ln_pdf(&self, x: f64) -> f64
Calculates the natural logarithm of the probability density function (PDF) of the PERT distribution at a given point.
This method is particularly useful for numerical stability in calculations involving very small probability densities. It’s often used in statistical inference and machine learning algorithms.
§Arguments
x- The point at which to calculate the log PDF
§Returns
The natural logarithm of the PDF at the given point as an f64.
§Examples
use distimate::prelude::*;
use distimate::Pert;
use approx::assert_relative_eq;
let pert = Pert::new(1.0, 2.0, 3.0).unwrap();
assert_relative_eq!(pert.ln_pdf(2.0), -0.064538, epsilon = 1e-6);
assert_eq!(pert.ln_pdf(0.0), f64::NEG_INFINITY); // Outside the distribution's rangesource§impl ContinuousCDF<f64, f64> for Pert
impl ContinuousCDF<f64, f64> for Pert
Implementation of the ContinuousCDF trait for the PERT distribution.
This implementation provides methods to calculate the cumulative distribution function (CDF) and its inverse for the PERT distribution. These functions are essential for understanding the probability of the distribution taking on a value less than or equal to a given point, and for generating random variates from the distribution.
source§fn cdf(&self, x: f64) -> f64
fn cdf(&self, x: f64) -> f64
Calculates the cumulative distribution function (CDF) of the PERT distribution at a given point.
The CDF represents the probability that a random variable from this distribution will be less than or equal to the given value.
§Arguments
x- The point at which to calculate the CDF
§Returns
The value of the CDF at the given point as an f64, in the range [0, 1].
§Examples
use distimate::prelude::*;
use distimate::Pert;
use approx::assert_relative_eq;
let pert = Pert::new(1.0, 2.0, 3.0).unwrap();
assert_relative_eq!(pert.cdf(2.0), 0.5, epsilon = 1e-6);
assert_eq!(pert.cdf(1.0), 0.0);
assert_eq!(pert.cdf(3.0), 1.0);source§fn inverse_cdf(&self, p: f64) -> f64
fn inverse_cdf(&self, p: f64) -> f64
Calculates the inverse of the cumulative distribution function (inverse CDF) of the PERT distribution for a given probability.
This function is also known as the quantile function. It returns the value x for which P(X ≤ x) = p, where p is the given probability.
§Arguments
p- The probability for which to calculate the inverse CDF, must be in the range [0, 1]
§Returns
The value x for which the CDF of the distribution equals the given probability.
§Examples
use distimate::prelude::*;
use distimate::Pert;
use approx::assert_relative_eq;
let pert = Pert::new(1.0, 2.0, 3.0).unwrap();
assert_relative_eq!(pert.inverse_cdf(0.5), 2.0, epsilon = 1e-4);
assert_relative_eq!(pert.inverse_cdf(0.0), 1.0, epsilon = 1e-4);
assert_relative_eq!(pert.inverse_cdf(1.0), 3.0, epsilon = 1e-4);source§impl Distribution<f64> for Pert
impl Distribution<f64> for Pert
Implementation of the Distribution trait for the PERT distribution.
This implementation provides methods to calculate various statistical properties of the PERT distribution.
source§fn mean(&self) -> Option<f64>
fn mean(&self) -> Option<f64>
Calculates the mean of the PERT distribution.
§Returns
The mean of the distribution as an Option<f64>. Always returns Some(value)
as the PERT distribution always has a defined mean.
§Examples
use distimate::prelude::*;
use distimate::Pert;
use approx::assert_relative_eq;
let pert = Pert::new(1.0, 2.0, 3.0).unwrap();
assert_relative_eq!(pert.mean().unwrap(), 2.0, epsilon = 1e-6);source§fn variance(&self) -> Option<f64>
fn variance(&self) -> Option<f64>
Calculates the variance of the PERT distribution.
§Returns
The variance of the distribution as an Option<f64>. Always returns Some(value)
as the PERT distribution always has a defined variance.
§Examples
use distimate::prelude::*;
use distimate::Pert;
use approx::assert_relative_eq;
let pert = Pert::new(1.0, 2.0, 3.0).unwrap();
assert_relative_eq!(pert.variance().unwrap(), 1.0 / 7.0, epsilon = 1e-6);source§fn skewness(&self) -> Option<f64>
fn skewness(&self) -> Option<f64>
Calculates the skewness of the PERT distribution.
§Returns
The skewness of the distribution as an Option<f64>. Always returns Some(value)
as the PERT distribution always has a defined skewness.
§Examples
use distimate::prelude::*;
use distimate::Pert;
use approx::assert_relative_eq;
let pert = Pert::new(1.0, 2.0, 3.0).unwrap();
assert_relative_eq!(pert.skewness().unwrap(), 0.0, epsilon = 1e-6);source§fn entropy(&self) -> Option<f64>
fn entropy(&self) -> Option<f64>
Calculates the entropy of the Pert distribution.
The entropy is a measure of the average amount of information contained in the distribution.
§Returns
The entropy of the distribution as an Option<f64>. Always returns Some(value)
as the Pert distribution always has a defined entropy.
§Examples
use distimate::prelude::*;
use distimate::Pert;
use approx::assert_relative_eq;
let pert = Pert::new(1.0, 2.0, 3.0).unwrap();
assert_relative_eq!(pert.entropy().unwrap(), -0.267864, epsilon = 1e-6);source§impl Distribution<f64> for Pert
impl Distribution<f64> for Pert
Implementation of the rand::distributions::Distribution trait for the PERT distribution.
This implementation allows for random sampling from the PERT distribution using
any random number generator that implements the rand::Rng trait.
source§fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> f64
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> f64
Generates a random sample from the PERT distribution.
This method uses the inverse transform sampling technique: it generates a uniform random number between 0 and 1, then applies the inverse CDF to this number to produce a sample from the PERT distribution.
§Arguments
rng- A random number generator that implements therand::Rngtrait
§Returns
A random sample from the PERT distribution as an f64.
§Examples
use distimate::prelude::*;
use distimate::Pert;
use rand::prelude::*;
let pert = Pert::new(1.0, 2.0, 3.0).unwrap();
let mut rng = StdRng::seed_from_u64(42); // For reproducibility
let sample = pert.sample(&mut rng);
assert!(sample >= 1.0 && sample <= 3.0);source§fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>
fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>
T, using rng as
the source of randomness. Read moresource§impl EstimationDistribution for Pert
impl EstimationDistribution for Pert
Implementation of the EstimationDistribution trait for the PERT distribution.
This trait marks the PERT distribution as suitable for use in estimation contexts. It doesn’t add any new methods, but signals that this distribution is appropriate for modeling uncertain estimates or durations.
§Examples
use distimate::prelude::*;
use distimate::Pert;
let pert = Pert::new(1.0, 2.0, 3.0).unwrap();
// The fact that we can create a Pert instance demonstrates
// that it implements EstimationDistributionsource§fn percentile_estimate(&self, p: f64) -> Result<f64>
fn percentile_estimate(&self, p: f64) -> Result<f64>
source§fn optimistic_estimate(&self) -> f64
fn optimistic_estimate(&self) -> f64
source§fn pessimistic_estimate(&self) -> f64
fn pessimistic_estimate(&self) -> f64
source§fn most_likely_estimate(&self) -> f64
fn most_likely_estimate(&self) -> f64
source§fn expected_value(&self) -> f64
fn expected_value(&self) -> f64
source§fn uncertainty(&self) -> f64
fn uncertainty(&self) -> f64
source§fn probability_of_completion(&self, estimate: f64) -> f64
fn probability_of_completion(&self, estimate: f64) -> f64
source§fn risk_of_overrun(&self, estimate: f64) -> f64
fn risk_of_overrun(&self, estimate: f64) -> f64
source§fn confidence_interval(&self, confidence_level: f64) -> (f64, f64)
fn confidence_interval(&self, confidence_level: f64) -> (f64, f64)
source§fn evaluate_fit_quality(&self, data: &[f64]) -> Result<EstimationFitQuality>
fn evaluate_fit_quality(&self, data: &[f64]) -> Result<EstimationFitQuality>
source§impl Max<f64> for Pert
impl Max<f64> for Pert
Implementation of the Max trait for the PERT distribution.
This implementation provides a method to retrieve the maximum value of the PERT distribution, which is one of its defining parameters.
source§fn max(&self) -> f64
fn max(&self) -> f64
Returns the maximum value of the PERT distribution.
The maximum value represents the highest possible outcome in the distribution.
§Returns
The maximum value of the distribution as an f64.
§Examples
use distimate::prelude::*;
use distimate::Pert;
let pert = Pert::new(1.0, 2.0, 3.0).unwrap();
assert_eq!(pert.max(), 3.0);source§impl Median<f64> for Pert
impl Median<f64> for Pert
Implementation of the Median trait for the PERT distribution.
The median of a PERT distribution is the value that separates the lower and upper halves of the probability distribution. For a PERT distribution, this is calculated using the inverse cumulative distribution function (inverse CDF) at probability 0.5.
source§fn median(&self) -> f64
fn median(&self) -> f64
Calculates the median of the PERT distribution.
The median is the value separating the higher half from the lower half of the distribution.
§Returns
The median of the distribution as an f64 value.
§Examples
use distimate::prelude::*;
use distimate::Pert;
use approx::assert_relative_eq;
let pert = Pert::new(1.0, 2.0, 3.0).unwrap();
assert_relative_eq!(pert.median(), 2.0, epsilon = 1e-4);source§impl Min<f64> for Pert
impl Min<f64> for Pert
Implementation of the Min trait for the PERT distribution.
This implementation provides a method to retrieve the minimum value of the PERT distribution, which is one of its defining parameters.
source§fn min(&self) -> f64
fn min(&self) -> f64
Returns the minimum value of the PERT distribution.
The minimum value represents the lowest possible outcome in the distribution.
§Returns
The minimum value of the distribution as an f64.
§Examples
use distimate::prelude::*;
use distimate::Pert;
let pert = Pert::new(1.0, 2.0, 3.0).unwrap();
assert_eq!(pert.min(), 1.0);source§impl Mode<f64> for Pert
impl Mode<f64> for Pert
Implementation of the Mode trait for the PERT distribution.
source§fn mode(&self) -> f64
fn mode(&self) -> f64
Returns the mode of the PERT distribution.
The mode is the most likely value of the distribution, which is one of the defining parameters of the PERT distribution.
§Returns
The mode of the distribution as an f64 value.
§Examples
use distimate::prelude::*;
use distimate::Pert;
let pert = Pert::new(1.0, 2.0, 3.0).unwrap();
assert_eq!(pert.mode(), 2.0);Auto Trait Implementations§
impl Freeze for Pert
impl RefUnwindSafe for Pert
impl Send for Pert
impl Sync for Pert
impl Unpin for Pert
impl UnwindSafe for Pert
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moresource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.