Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Avhz RustQuant Exponential Distribution

From Leeroopedia
Revision as of 14:31, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Avhz_RustQuant_Exponential_Distribution.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Mathematics, Statistics
Last Updated 2026-02-07 19:00 GMT

Overview

Concrete implementation of the Exponential probability distribution provided by the RustQuant library.

Description

The Exponential struct models the Exponential distribution, denoted X ~ Exp(lambda). This continuous probability distribution describes the time between events in a Poisson point process, where events occur continuously and independently at a constant average rate.

The struct contains a single field:

  • lambda (f64) -- the rate parameter (inverse scale). Must be positive.

The implementation provides the full Distribution trait interface. Key formulas:

  • PDF: lambda * e^(-lambda * x) for x >= 0.
  • CDF: 1 - e^(-lambda * x) for x >= 0.
  • Inverse CDF: -ln(1 - p) / lambda.
  • Characteristic function: 1 / (1 - it/lambda).
  • MGF: lambda / (lambda - t), requires t < lambda.

The pmf method delegates to pdf since the distribution is continuous. The mean is 1/lambda, variance is 1/lambda^2, skewness is always 2.0, and kurtosis is always 6.0. Entropy is 1 - ln(lambda). Random sampling delegates to the rand_distr::Exp distribution.

Usage

Use this distribution for modeling waiting times between events, time-to-failure in reliability analysis, or inter-arrival times. In quantitative finance, it models the time between trades, default times in reduced-form credit models, and durations in ACD (Autoregressive Conditional Duration) models.

Code Reference

Source Location

Signature

pub struct Exponential {
    lambda: f64,
}

impl Exponential {
    pub fn new(lambda: f64) -> Self
}

impl Distribution for Exponential {
    fn cf(&self, t: f64) -> Complex<f64>;
    fn pdf(&self, x: f64) -> f64;
    fn pmf(&self, x: f64) -> f64;
    fn cdf(&self, x: f64) -> f64;
    fn inv_cdf(&self, p: f64) -> f64;
    fn mean(&self) -> f64;
    fn median(&self) -> f64;
    fn mode(&self) -> f64;
    fn variance(&self) -> f64;
    fn skewness(&self) -> f64;
    fn kurtosis(&self) -> f64;
    fn entropy(&self) -> f64;
    fn mgf(&self, t: f64) -> f64;
    fn sample(&self, n: usize) -> Result<Vec<f64>, RustQuantError>;
}

Import

use RustQuant::math::distributions::Exponential;
use RustQuant::math::distributions::Distribution;

I/O Contract

Inputs

Name Type Required Description
lambda f64 Yes The rate parameter (inverse of mean). Must be > 0.

Outputs

Name Type Description
Exponential struct A new Exponential distribution instance.
mean() f64 Returns 1 / lambda.
variance() f64 Returns 1 / lambda^2.
median() f64 Returns ln(2) / lambda.
mode() f64 Always returns 0.0.
sample(n) Result<Vec<f64>, RustQuantError> A vector of n random variates from the Exponential distribution.

Usage Examples

use RustQuant::math::distributions::{Exponential, Distribution};

// Create an Exponential distribution with rate lambda = 1.0
let exp = Exponential::new(1.0);

// Statistical moments
assert_eq!(exp.mean(), 1.0);
assert_eq!(exp.variance(), 1.0);
assert_eq!(exp.mode(), 0.0);
assert_eq!(exp.skewness(), 2.0);
assert_eq!(exp.kurtosis(), 6.0);

// PDF at x = 1
let pdf = exp.pdf(1.0); // approximately 0.3679

// CDF at x = 1
let cdf = exp.cdf(1.0); // approximately 0.6321

// Inverse CDF
let inv = exp.inv_cdf(0.5); // approximately 0.6931 (ln(2))

// MGF (requires t < lambda)
let mgf = exp.mgf(0.5); // 2.0

// Generate random samples
let sample = exp.sample(1000).unwrap();

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment