Struct statrs::distribution::Dirichlet[][src]

pub struct Dirichlet { /* fields omitted */ }

Implements the Dirichlet distribution

Examples

use statrs::distribution::{Dirichlet, Continuous};
use statrs::statistics::Mean;

let n = Dirichlet::new(&[1.0, 2.0, 3.0]).unwrap();
assert_eq!(n.mean(), [1.0 / 6.0, 1.0 / 3.0, 0.5]);
assert_eq!(n.pdf(&[0.33333, 0.33333, 0.33333]), 2.222155556222205);

Implementations

impl Dirichlet[src]

pub fn new(alpha: &[f64]) -> Result<Dirichlet>[src]

Constructs a new dirichlet distribution with the given concenctration parameters (alpha)

Errors

Returns an error if any element x in alpha exist such that x < = 0.0 or x is NaN, or if the length of alpha is less than 2

Examples

use statrs::distribution::Dirichlet;

let alpha_ok = [1.0, 2.0, 3.0];
let mut result = Dirichlet::new(&alpha_ok);
assert!(result.is_ok());

let alpha_err = [0.0];
result = Dirichlet::new(&alpha_err);
assert!(result.is_err());

pub fn new_with_param(alpha: f64, n: usize) -> Result<Dirichlet>[src]

Constructs a new dirichlet distribution with the given concenctration parameter (alpha) repeated n times

Errors

Returns an error if alpha < = 0.0 or alpha is NaN, or if n < 2

Examples

use statrs::distribution::Dirichlet;

let mut result = Dirichlet::new_with_param(1.0, 3);
assert!(result.is_ok());

result = Dirichlet::new_with_param(0.0, 1);
assert!(result.is_err());

pub fn alpha(&self) -> &[f64][src]

Returns the concentration parameters of the dirichlet distribution as a slice

Examples

use statrs::distribution::Dirichlet;

let n = Dirichlet::new(&[1.0, 2.0, 3.0]).unwrap();
assert_eq!(n.alpha(), [1.0, 2.0, 3.0]);

Trait Implementations

impl<'a> CheckedContinuous<&'a [f64], f64> for Dirichlet[src]

fn checked_pdf(&self, x: &[f64]) -> Result<f64>[src]

Calculates the probabiliy density function for the dirichlet distribution with given x’s corresponding to the concentration parameters for this distribution

Errors

If any element in x is not in (0, 1), the elements in x do not sum to 1 with a tolerance of 1e-4, or if x is not the same length as the vector of concentration parameters for this distribution

Formula

(1 / B(α)) * Π(x_i^(α_i - 1))

where

B(α) = Π(Γ(α_i)) / Γ(Σ(α_i))

α is the vector of concentration parameters, α_i is the ith concentration parameter, x_i is the ith argument corresponding to the ith concentration parameter, Γ is the gamma function, Π is the product from 1 to K, Σ is the sum from 1 to K, and K is the number of concentration parameters

fn checked_ln_pdf(&self, x: &[f64]) -> Result<f64>[src]

Calculates the log probabiliy density function for the dirichlet distribution with given x’s corresponding to the concentration parameters for this distribution

Errors

If any element in x is not in (0, 1), the elements in x do not sum to 1 with a tolerance of 1e-4, or if x is not the same length as the vector of concentration parameters for this distribution

Formula

ln((1 / B(α)) * Π(x_i^(α_i - 1)))

where

B(α) = Π(Γ(α_i)) / Γ(Σ(α_i))

α is the vector of concentration parameters, α_i is the ith concentration parameter, x_i is the ith argument corresponding to the ith concentration parameter, Γ is the gamma function, Π is the product from 1 to K, Σ is the sum from 1 to K, and K is the number of concentration parameters

impl Clone for Dirichlet[src]

impl<'a> Continuous<&'a [f64], f64> for Dirichlet[src]

fn pdf(&self, x: &[f64]) -> f64[src]

Calculates the probabiliy density function for the dirichlet distribution with given x’s corresponding to the concentration parameters for this distribution

Panics

If any element in x is not in (0, 1), the elements in x do not sum to 1 with a tolerance of 1e-4, or if x is not the same length as the vector of concentration parameters for this distribution

Formula

(1 / B(α)) * Π(x_i^(α_i - 1))

where

B(α) = Π(Γ(α_i)) / Γ(Σ(α_i))

α is the vector of concentration parameters, α_i is the ith concentration parameter, x_i is the ith argument corresponding to the ith concentration parameter, Γ is the gamma function, Π is the product from 1 to K, Σ is the sum from 1 to K, and K is the number of concentration parameters

fn ln_pdf(&self, x: &[f64]) -> f64[src]

Calculates the log probabiliy density function for the dirichlet distribution with given x’s corresponding to the concentration parameters for this distribution

Panics

If any element in x is not in (0, 1), the elements in x do not sum to 1 with a tolerance of 1e-4, or if x is not the same length as the vector of concentration parameters for this distribution

Formula

ln((1 / B(α)) * Π(x_i^(α_i - 1)))

where

B(α) = Π(Γ(α_i)) / Γ(Σ(α_i))

α is the vector of concentration parameters, α_i is the ith concentration parameter, x_i is the ith argument corresponding to the ith concentration parameter, Γ is the gamma function, Π is the product from 1 to K, Σ is the sum from 1 to K, and K is the number of concentration parameters

impl Debug for Dirichlet[src]

impl Distribution<Vec<f64, Global>> for Dirichlet[src]

impl Entropy<f64> for Dirichlet[src]

fn entropy(&self) -> f64[src]

Returns the entropy of the dirichlet distribution

Formula

ln(B(α)) - (K - α_0)ψ(α_0) - Σ((α_i - 1)ψ(α_i))

where

B(α) = Π(Γ(α_i)) / Γ(Σ(α_i))

α_0 is the sum of all concentration parameters, K is the number of concentration parameters, ψ is the digamma function, α_i is the ith concentration parameter, and Σ is the sum from 1 to K

impl Mean<Vec<f64, Global>> for Dirichlet[src]

fn mean(&self) -> Vec<f64>[src]

Returns the means of the dirichlet distribution

Formula

α_i / α_0

for the ith element where α_i is the ith concentration parameter and α_0 is the sum of all concentration parameters

impl PartialEq<Dirichlet> for Dirichlet[src]

impl StructuralPartialEq for Dirichlet[src]

impl Variance<Vec<f64, Global>> for Dirichlet[src]

fn variance(&self) -> Vec<f64>[src]

Returns the variances of the dirichlet distribution

Formula

(α_i * (α_0 - α_i)) / (α_0^2 * (α_0 + 1))

for the ith element where α_i is the ith concentration parameter and α_0 is the sum of all concentration parameters

fn std_dev(&self) -> Vec<f64>[src]

Returns the standard deviation of the dirichlet distribution

Formula

sqrt((α_i * (α_0 - α_i)) / (α_0^2 * (α_0 + 1)))

for the ith element where α_i is the ith concentration parameter and α_0 is the sum of all concentration parameters

Auto Trait Implementations

impl RefUnwindSafe for Dirichlet

impl Send for Dirichlet

impl Sync for Dirichlet

impl Unpin for Dirichlet

impl UnwindSafe for Dirichlet

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 
[src]