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

pub struct Dirichlet { /* fields omitted */ }
Expand description

Implements the Dirichlet distribution

Examples

use statrs::distribution::{Dirichlet, Continuous};
use statrs::statistics::Distribution;
use nalgebra::DVector;
use statrs::statistics::MeanN;

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

Implementations

impl Dirichlet[src]

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

Constructs a new dirichlet distribution with the given concentration 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;
use nalgebra::DVector;

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

let alpha_err = vec![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 concentration 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) -> &DVector<f64>[src]

Returns the concentration parameters of the dirichlet distribution as a slice

Examples

use statrs::distribution::Dirichlet;
use nalgebra::DVector;

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

pub fn entropy(&self) -> Option<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

Trait Implementations

impl Clone for Dirichlet[src]

fn clone(&self) -> Dirichlet[src]

Returns a copy of the value. Read more

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

Performs copy-assignment from source. Read more

impl<'a> Continuous<&'a Matrix<f64, Dynamic, Const<1_usize>, VecStorage<f64, Dynamic, Const<1_usize>>>, f64> for Dirichlet[src]

fn pdf(&self, x: &DVector<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: &DVector<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]

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

Formats the value using the given formatter. Read more

impl Distribution<Matrix<f64, Dynamic, Const<1_usize>, VecStorage<f64, Dynamic, Const<1_usize>>>> for Dirichlet[src]

fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> DVector<f64>[src]

Generate a random value of T, using rng as the source of randomness.

fn sample_iter<R>(self, rng: R) -> DistIter<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

impl MeanN<Matrix<f64, Dynamic, Const<1_usize>, VecStorage<f64, Dynamic, Const<1_usize>>>> for Dirichlet[src]

fn mean(&self) -> Option<DVector<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]

fn eq(&self, other: &Dirichlet) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &Dirichlet) -> bool[src]

This method tests for !=.

impl VarianceN<Matrix<f64, Dynamic, Dynamic, VecStorage<f64, Dynamic, Dynamic>>> for Dirichlet[src]

fn variance(&self) -> Option<DMatrix<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

impl StructuralPartialEq for Dirichlet[src]

Auto Trait Implementations

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Same<T> for T

type Output = T

Should always be Self

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

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

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

pub fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).

pub fn to_subset_unchecked(&self) -> SS

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

pub fn from_subset(element: &SS) -> SP

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

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

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

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.

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

Performs the conversion.

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.

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

Performs the conversion.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

pub fn vzip(self) -> V