pub struct Poisson<T> { /* private fields */ }Expand description
Poisson distribution with rate λ.
P(X = k) = λ^k e^{−λ} / k! for k = 0, 1, 2, …
§Example
use numeris::stats::{Poisson, DiscreteDistribution};
let p = Poisson::new(3.0_f64).unwrap();
assert!((p.mean() - 3.0).abs() < 1e-14);
assert!((p.variance() - 3.0).abs() < 1e-14);Implementations§
Source§impl<T: FloatScalar> Poisson<T>
impl<T: FloatScalar> Poisson<T>
Sourcepub fn new(lambda: T) -> Result<Self, StatsError>
pub fn new(lambda: T) -> Result<Self, StatsError>
Create a Poisson distribution with rate lambda. Requires lambda > 0.
Examples found in repository?
docs/examples/gen_plots.rs (line 632)
630fn make_poisson_pmf_plot() -> String {
631 let dists: Vec<(Poisson<f64>, &str)> = vec![
632 (Poisson::new(1.0).unwrap(), "λ = 1"),
633 (Poisson::new(4.0).unwrap(), "λ = 4"),
634 (Poisson::new(10.0).unwrap(), "λ = 10"),
635 ];
636
637 let k_max = 20u64;
638 let kv: Vec<f64> = (0..=k_max).map(|k| k as f64).collect();
639
640 let traces: Vec<String> = dists
641 .iter()
642 .map(|(d, name)| {
643 let yv: Vec<f64> = (0..=k_max).map(|k| d.pmf(k)).collect();
644 bar_trace(name, &kv, &yv)
645 })
646 .collect();
647
648 let layout = decorate_layout_ex(
649 "Poisson Distribution — PMF",
650 "k",
651 "",
652 "P(X = k)",
653 "",
654 ",\"barmode\":\"group\"",
655 );
656 plotly_snippet("plot-poisson-pmf", &format!("[{}]", traces.join(",")), &layout, 400)
657}Trait Implementations§
Source§impl<T: FloatScalar> DiscreteDistribution<T> for Poisson<T>
impl<T: FloatScalar> DiscreteDistribution<T> for Poisson<T>
impl<T: Copy> Copy for Poisson<T>
Auto Trait Implementations§
impl<T> Freeze for Poisson<T>where
T: Freeze,
impl<T> RefUnwindSafe for Poisson<T>where
T: RefUnwindSafe,
impl<T> Send for Poisson<T>where
T: Send,
impl<T> Sync for Poisson<T>where
T: Sync,
impl<T> Unpin for Poisson<T>where
T: Unpin,
impl<T> UnsafeUnpin for Poisson<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Poisson<T>where
T: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.