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

Methods

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

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

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 Debug for Dirichlet
[src]

Formats the value using the given formatter.

impl Clone for Dirichlet
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl PartialEq for Dirichlet
[src]

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

This method tests for !=.

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

Generate random samples from a dirichlet distribution using r as the source of randomness. Refer here for implementation details

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

Generate random independent samples from a dirichlet distribution using r as the source of randomness. Refer here for implementation details

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

Generate random samples from the dirichlet distribution using r as the source of randomness

Examples

use rand::StdRng;
use statrs::distribution::{Dirichlet, Distribution};

let mut r = rand::StdRng::new().unwrap();
let n = Dirichlet::new(&[1.0, 2.0, 3.0]).unwrap();
print!("{:?}", n.sample::<StdRng>(&mut r));

impl Mean<Vec<f64>> for Dirichlet
[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 Variance<Vec<f64>> for Dirichlet
[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

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

impl Entropy<f64> for Dirichlet
[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<'a> Continuous<&'a [f64], f64> for Dirichlet
[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

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