Skip to main content

Poisson

Struct Poisson 

Source
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>

Source

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}
Source§

impl<T: FloatScalar> Poisson<T>

Source

pub fn sample(&self, rng: &mut Rng) -> u64

Draw a random sample from this distribution.

For small lambda (< 30), uses Knuth’s algorithm. For large lambda, uses a normal approximation.

Source

pub fn sample_array<const K: usize>(&self, rng: &mut Rng) -> [u64; K]

Fill a fixed-size array with independent samples.

Trait Implementations§

Source§

impl<T: Clone> Clone for Poisson<T>

Source§

fn clone(&self) -> Poisson<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Poisson<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: FloatScalar> DiscreteDistribution<T> for Poisson<T>

Source§

fn pmf(&self, k: u64) -> T

Probability mass function P(X = k).
Source§

fn ln_pmf(&self, k: u64) -> T

Natural log of the probability mass function.
Source§

fn cdf(&self, k: u64) -> T

Cumulative distribution function P(X ≤ k).
Source§

fn quantile(&self, p: T) -> u64

Quantile function (inverse CDF). Returns the smallest k such that P(X ≤ k) ≥ p.
Source§

fn mean(&self) -> T

Expected value E[X].
Source§

fn variance(&self) -> T

Variance Var(X).
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.