Struct distimate::Pert

source ·
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

source

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 distribution
  • likely - The most likely value (mode) of the distribution
  • max - 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:

  • min is greater than or equal to max
  • likely is less than min or greater than max
§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);
source

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 distribution
  • likely - The most likely value (mode) of the distribution
  • max - The maximum value of the distribution
  • shape - 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:

  • min is greater than or equal to max
  • likely is less than min or greater than max
  • shape is 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);
source

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);
source

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);
source

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);
source

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 Clone for Pert

source§

fn clone(&self) -> Pert

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

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

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 range
source§

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 range
source§

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

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

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§

fn sf(&self, x: K) -> T

Returns the survival function calculated at x for a given distribution. May panic depending on the implementor. Read more
source§

impl Debug for Pert

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

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>

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>

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>

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>

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§

fn std_dev(&self) -> Option<T>

Returns the standard deviation, if it exists. Read more
source§

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

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 the rand::Rng trait
§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>
where R: Rng, Self: Sized,

Create an iterator that generates random values of T, using rng as the source of randomness. Read more
source§

fn map<F, S>(self, func: F) -> DistMap<Self, F, T, S>
where F: Fn(T) -> S, Self: Sized,

Create a distribution of values of ‘S’ by mapping the output of Self through the closure F Read more
source§

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 EstimationDistribution
source§

fn percentile_estimate(&self, p: f64) -> Result<f64>

Returns the estimate at a given percentile. Read more
source§

fn optimistic_estimate(&self) -> f64

Returns the optimistic (best-case) estimate, typically the 5th percentile. Read more
source§

fn pessimistic_estimate(&self) -> f64

Returns the pessimistic (worst-case) estimate, typically the 95th percentile. Read more
source§

fn most_likely_estimate(&self) -> f64

Returns the most likely estimate (mode). Read more
source§

fn expected_value(&self) -> f64

Returns the expected value (mean) of the distribution. Read more
source§

fn uncertainty(&self) -> f64

Returns the standard deviation of the distribution. Read more
source§

fn probability_of_completion(&self, estimate: f64) -> f64

Calculates the probability of completing a task or project by a given estimate. Read more
source§

fn risk_of_overrun(&self, estimate: f64) -> f64

Calculates the risk of exceeding a given estimate. Read more
source§

fn confidence_interval(&self, confidence_level: f64) -> (f64, f64)

Returns a confidence interval for the estimate. Read more
source§

fn evaluate_fit_quality(&self, data: &[f64]) -> Result<EstimationFitQuality>

Evaluates how well the distribution fits a given dataset in the context of estimation. Read more
source§

fn calculate_within_interval( &self, data: &[f64], lower_percentile: f64, upper_percentile: f64, ) -> Result<f64>

Helper method to calculate the proportion of data within a given interval. Read more
source§

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

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

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

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

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

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

Implementation of the Mode trait for the PERT distribution.

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V