| Crates.io | distimate |
| lib.rs | distimate |
| version | 0.2.1 |
| created_at | 2024-08-27 18:57:55.232413+00 |
| updated_at | 2024-08-28 22:30:06.540873+00 |
| description | A crate providing probability distributions for estimation and risk analysis |
| homepage | |
| repository | https://github.com/swaits/distimate |
| max_upload_size | |
| id | 1353738 |
| size | 105,826 |
distimate is a Rust crate that provides probability distributions specifically
designed for estimation and risk analysis scenarios. It offers implementations
of various distributions that are commonly used in project management, cost
estimation, and other fields where uncertainty needs to be modeled.
Add this to your Cargo.toml:
[dependencies]
distimate = "<desired version>"
Here's a quick example of how to use the PERT distribution:
use distimate::prelude::*;
use distimate::Pert;
fn main() {
// Create a PERT distribution for a task estimated to take
// between 1 and 3 days, most likely 2 days
let task_duration = Pert::new(1.0, 2.0, 3.0).unwrap();
println!("Expected duration: {:.2} days", task_duration.expected_value());
println!("Optimistic estimate (P5): {:.2} days", task_duration.optimistic_estimate());
println!("Pessimistic estimate (P95): {:.2} days", task_duration.pessimistic_estimate());
println!("Probability of completing within 2.5 days: {:.2}%",
task_duration.probability_of_completion(2.5) * 100.0);
println!("Risk of exceeding 2.5 days: {:.2}%",
task_duration.risk_of_overrun(2.5) * 100.0);
let (lower, upper) = task_duration.confidence_interval(0.9);
println!("90% Confidence Interval: {:.2} to {:.2} days", lower, upper);
}
The PERT (Program Evaluation and Review Technique) distribution is commonly used in project management and risk analysis. It's defined by minimum, most likely (mode), and maximum values.
let pert = Pert::new(1.0, 2.0, 3.0).unwrap();
The Triangular distribution is often used when limited sample data is available. It's also defined by minimum, most likely (mode), and maximum values.
let triangular = Triangular::new(1.0, 2.0, 3.0).unwrap();
The Normal (Gaussian) distribution is implemented with modifications to respect a given range. It's suitable for natural phenomena and when values are expected to be symmetrically distributed around a mean.
let normal = Normal::new(1.0, 2.0, 3.0).unwrap();
All distributions implement common traits for statistical operations:
Distribution: Provides mean(), variance(), skewness(), and entropy()Median: Provides median()Mode: Provides mode()Continuous: Provides pdf() and ln_pdf()ContinuousCDF: Provides cdf() and inverse_cdf()Min and Max: Provide min() and max()Additionally, all distributions can be sampled using the sample() method,
which is useful for Monte Carlo simulations.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.