pub struct Gamma { /* private fields */ }Expand description
A continuous distribution over positive real numbers, parameterized by shape and rate.
Commonly used for modeling waiting times and as a conjugate prior for Poisson distributions.
Mathematical Properties:
- Support: (0, +∞)
- PDF: f(x) = (λ^k / Γ(k)) × x^(k-1) × exp(-λx)
- Mean: k / λ
- Variance: k / λ²
Example:
// Shape=1 gives Exponential distribution
let exponential_like = sample(addr!("wait_time"), Gamma::new(1.0, 2.0).unwrap());
// Prior for precision parameter
let precision = sample(addr!("precision"), Gamma::new(2.0, 1.0).unwrap());
// Conjugate prior for Poisson rate
let model = sample(addr!("rate"), Gamma::new(3.0, 2.0).unwrap())
.bind(|lambda| observe(addr!("count"), Poisson::new(lambda).unwrap(), 5u64));
// Scale parameter (rate = 1/scale)
let scale_param = sample(addr!("scale"), Gamma::new(2.0, 0.5).unwrap()); // mean = 4Implementations§
Trait Implementations§
Source§impl Distribution<f64> for Gamma
impl Distribution<f64> for Gamma
Source§fn sample(&self, rng: &mut dyn RngCore) -> f64
fn sample(&self, rng: &mut dyn RngCore) -> f64
Generate a random sample (with its natural type),
T, from the distribution, using the provided random number generator, rng. Read moreimpl Copy for Gamma
Auto Trait Implementations§
impl Freeze for Gamma
impl RefUnwindSafe for Gamma
impl Send for Gamma
impl Sync for Gamma
impl Unpin for Gamma
impl UnwindSafe for Gamma
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more