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 Poisson Distribution

From Leeroopedia


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

Overview

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

Description

The Poisson struct models the Poisson distribution, denoted X ~ Pois(lambda). This discrete probability distribution expresses the probability of a given number of events occurring in a fixed interval of time or space, given a known constant mean rate.

The struct contains a single field:

  • lambda (f64) -- the rate parameter (expected number of events). Must be positive.

The implementation provides the full Distribution trait interface. The PMF is computed as lambda^k * e^(-lambda) / k!. The CDF uses the lower and upper incomplete gamma functions from the statrs crate. The inverse CDF performs a sequential summation search through the PMF values. The characteristic function is exp(lambda * (e^(it) - 1)).

The entropy method is currently unimplemented (marked with todo!()). The inv_cdf returns f64::NAN for out-of-range inputs and f64::INFINITY when p = 1.0. Random sampling delegates to the rand_distr crate.

Usage

Use this distribution for modeling the count of rare events over a fixed interval, such as the number of trades in a time window, arrival of orders, default events in a credit portfolio, or insurance claims. In quantitative finance, it is commonly used in jump-diffusion models (Merton model) to model the number of jumps.

Code Reference

Source Location

Signature

pub struct Poisson {
    lambda: f64,
}

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

impl Distribution for Poisson {
    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; // todo!()
    fn mgf(&self, t: f64) -> f64;
    fn sample(&self, n: usize) -> Result<Vec<f64>, RustQuantError>;
}

Import

use RustQuant::math::distributions::Poisson;
use RustQuant::math::distributions::Distribution;

I/O Contract

Inputs

Name Type Required Description
lambda f64 Yes The rate parameter (expected events per interval). Must be > 0.

Outputs

Name Type Description
Poisson struct A new Poisson distribution instance.
mean() f64 Returns lambda.
variance() f64 Returns lambda.
skewness() f64 Returns 1 / sqrt(lambda).
kurtosis() f64 Returns 1 / lambda.
sample(n) Result<Vec<f64>, RustQuantError> A vector of n random variates from the Poisson distribution.

Usage Examples

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

// Create a Poisson distribution with lambda = 1.0
let poisson = Poisson::new(1.0);

// Statistical moments
assert_eq!(poisson.mean(), 1.0);
assert_eq!(poisson.variance(), 1.0);
assert_eq!(poisson.mode(), 1.0);
assert_eq!(poisson.median(), 1.0);

// Probability mass function: P(X = 1)
let pmf = poisson.pmf(1.0); // approximately 0.3679

// Cumulative distribution function: P(X <= 1)
let cdf = poisson.cdf(1.0); // approximately 0.6409

// Inverse CDF
let inv = poisson.inv_cdf(0.5); // 1.0

// Moment generating function
let mgf = poisson.mgf(1.0); // approximately 5.5749

// Generate 1000 random samples
let sample = poisson.sample(1000).expect("Poisson sampled");

Related Pages

Page Connections

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