Skip to main content

Crate tpt_math_prob_dist

Crate tpt_math_prob_dist 

Source
Expand description

Standard probability distributions, bridging rand_distr into the tpt_math_prob_core trait ecosystem.

This crate wraps the rand_distr distributions and makes them sampleable through the minimal tpt_math_prob_core::Rng/Distribution traits used across the tpt-math-prob-* family. Because our Rng is far smaller than rand’s RngCore, we provide CoreRng: a thin adapter that turns any of our RNGs into a rand::RngCore so that every rand_distr distribution can be sampled without pulling in rand’s own generators.

The distributions themselves are not directly re-implemented. Instead the local Dist wrapper (and the small AsU64 helper for counts) adapts a rand_distr distribution to our Distribution trait. Constructor functions (normal, uniform, poisson, …) give ergonomic, documented entry points, and the raw rand_distr module is re-exported so advanced users can reach under the bridge.

The crate is no_std-compatible; all float math is delegated to rand_distr (which uses num-traits’s libm fallback), and std-only conveniences are gated behind the default std feature.

§Examples

use tpt_math_prob_core::{Distribution, Rng, SplitMix64};
use tpt_math_prob_dist::{normal, Dist};

let mut rng = SplitMix64::seed_from_u64(0);
let gauss = normal((0.0, 1.0)).unwrap();
let x: f64 = Dist::new(gauss).sample(&mut rng);
// or, equivalently, with the explicit bridge type:
let y: f64 = Dist::new(normal((2.0, 3.0)).unwrap()).sample(&mut rng);
let _ = x + y;

Re-exports§

pub use rand_distr;

Modules§

density
Densities, probability mass functions, CDFs and quantiles. Needs std (the default) for the special functions in tpt-math-prob-core. Densities, probability mass functions, CDFs and quantiles.
multivariate
The multivariate normal distribution.

Structs§

AsU64
Wrap a float-producing rand_distr distribution and emit integer counts.
CoreRng
Adapter turning one of our Rngs into a rand::RngCore.
Dist
A rand_distr distribution adapted to our Distribution trait.
SplitMix64
SplitMix64: a tiny, fast, deterministic 64-bit PRNG.
Standard
The standard uniform distribution over the type’s natural range.

Traits§

Distribution
A distribution that can produce samples of type T.
Rng
A source of pseudo-random bits.
Sampler
Bulk sampling for any Distribution.

Functions§

beta
Beta distribution with shape parameters alpha, beta.
cauchy
Cauchy distribution with median and scale.
chi_squared
ChiSquared distribution with k degrees of freedom.
exp
Exp (exponential) distribution with rate lambda.
gamma
Gamma distribution with shape and scale.
lognormal
LogNormal distribution.
normal
Normal (Gaussian) distribution, N(mean, std_dev).
poisson
Poisson distribution with rate lambda (samples returned as u64).
student_t
Student’s t distribution with nu degrees of freedom.
uniform
Uniform distribution over an inclusive-exclusive range [low, high).

Type Aliases§

Beta
Beta distribution with shape parameters alpha, beta.
Cauchy
Cauchy distribution with median and scale.
ChiSquared
ChiSquared distribution with k degrees of freedom.
Exp
Exp (exponential) distribution with rate lambda.
Gamma
Gamma distribution with shape and scale.
LogNormal
LogNormal distribution.
Normal
Normal (Gaussian) distribution, N(mean, std_dev).
Poisson
Poisson distribution with rate lambda (samples returned as u64).
StudentT
Student’s t distribution with nu degrees of freedom.