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

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);

Methods

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

This example is not tested
(1 / B(α)) * Π(x_i^(α_i - 1))

where

This example is not tested
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

This example is not tested
ln((1 / B(α)) * Π(x_i^(α_i - 1)))

where

This example is not tested
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<'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

This example is not tested
(1 / B(α)) * Π(x_i^(α_i - 1))

where

This example is not tested
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

This example is not tested
ln((1 / B(α)) * Π(x_i^(α_i - 1)))

where

This example is not tested
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 Mean<Vec<f64>> for Dirichlet[src]

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

Returns the means of the dirichlet distribution

Formula

This example is not tested
α_i / α_0

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

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

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

Returns the variances of the dirichlet distribution

Formula

This example is not tested
(α_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

This example is not tested
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

impl Entropy<f64> for Dirichlet[src]

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

Returns the entropy of the dirichlet distribution

Formula

This example is not tested
ln(B(α)) - (K - α_0)ψ(α_0) - Σ((α_i - 1)ψ(α_i))

where

This example is not tested
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 PartialEq<Dirichlet> for Dirichlet[src]

impl Clone for Dirichlet[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for Dirichlet[src]

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

fn sample_iter<R>(&'a self, rng: &'a mut R) -> DistIter<'a, Self, R, T> where
    R: Rng
[src]

Create an iterator that generates random values of T, using rng as the source of randomness. Read more

Auto Trait Implementations

impl Send for Dirichlet

impl Sync for Dirichlet

Blanket Implementations

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

type Owned = T

The resulting type after obtaining ownership.

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

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

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<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

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