[][src]Trait statrs::distribution::Continuous

pub trait Continuous<T, K> {
    fn pdf(&self, x: T) -> K;
fn ln_pdf(&self, x: T) -> K; }

The Continuous trait provides an interface for interacting with continuous statistical distributions

Remarks

All methods provided by the Continuous trait are unchecked, meaning they can panic if in an invalid state or encountering invalid input depending on the implementing distribution.

Required methods

fn pdf(&self, x: T) -> K

Returns the probability density function calculated at x for a given distribution. May panic depending on the implementor.

Examples

use statrs::distribution::{Continuous, Uniform};

let n = Uniform::new(0.0, 1.0).unwrap();
assert_eq!(1.0, n.pdf(0.5));

fn ln_pdf(&self, x: T) -> K

Returns the log of the probability density function calculated at x for a given distribution. May panic depending on the implementor.

Examples

use statrs::distribution::{Continuous, Uniform};

let n = Uniform::new(0.0, 1.0).unwrap();
assert_eq!(0.0, n.ln_pdf(0.5));
Loading content...

Implementors

impl Continuous<f64, f64> for Beta[src]

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

Calculates the probability density function for the beta distribution at x.

Formula

This example is not tested
let B(α, β) = Γ(α)Γ(β)/Γ(α + β)

x^(α - 1) * (1 - x)^(β - 1) / B(α, β)

where α is shapeA, β is shapeB, and Γ is the gamma function

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

Calculates the log probability density function for the beta distribution at x.

Formula

This example is not tested
let B(α, β) = Γ(α)Γ(β)/Γ(α + β)

ln(x^(α - 1) * (1 - x)^(β - 1) / B(α, β))

where α is shapeA, β is shapeB, and Γ is the gamma function

impl Continuous<f64, f64> for Cauchy[src]

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

Calculates the probability density function for the cauchy distribution at x

Formula

This example is not tested
1 / (πγ * (1 + ((x - x_0) / γ)^2))

where x_0 is the location and γ is the scale

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

Calculates the log probability density function for the cauchy distribution at x

Formula

This example is not tested
ln(1 / (πγ * (1 + ((x - x_0) / γ)^2)))

where x_0 is the location and γ is the scale

impl Continuous<f64, f64> for Chi[src]

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

Calculates the probability density function for the chi distribution at x

Formula

This example is not tested
(2^(1 - (k / 2)) * x^(k - 1) * e^(-x^2 / 2)) / Γ(k / 2)

where k is the degrees of freedom and Γ is the gamma function

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

Calculates the log probability density function for the chi distribution at x

Formula

This example is not tested
ln((2^(1 - (k / 2)) * x^(k - 1) * e^(-x^2 / 2)) / Γ(k / 2))

impl Continuous<f64, f64> for ChiSquared[src]

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

Calculates the probability density function for the chi-squared distribution at x

Formula

This example is not tested
1 / (2^(k / 2) * Γ(k / 2)) * x^((k / 2) - 1) * e^(-x / 2)

where k is the degrees of freedom and Γ is the gamma function

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

Calculates the log probability density function for the chi-squared distribution at x

Formula

This example is not tested
ln(1 / (2^(k / 2) * Γ(k / 2)) * x^((k / 2) - 1) * e^(-x / 2))

impl Continuous<f64, f64> for Erlang[src]

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

Calculates the probability density function for the erlang distribution at x

Remarks

Returns NAN if any of shape or rate are INF or if x is INF

Formula

This example is not tested
(λ^k / Γ(k)) * x^(k - 1) * e^(-λ * x)

where k is the shape, λ is the rate, and Γ is the gamma function

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

Calculates the log probability density function for the erlang distribution at x

Remarks

Returns NAN if any of shape or rate are INF or if x is INF

Formula

This example is not tested
ln((λ^k / Γ(k)) * x^(k - 1) * e ^(-λ * x))

where k is the shape, λ is the rate, and Γ is the gamma function

impl Continuous<f64, f64> for Exponential[src]

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

Calculates the probability density function for the exponential distribution at x

Formula

This example is not tested
λ * e^(-λ * x)

where λ is the rate

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

Calculates the log probability density function for the exponential distribution at x

Formula

This example is not tested
ln(λ * e^(-λ * x))

where λ is the rate

impl Continuous<f64, f64> for FisherSnedecor[src]

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

Calculates the probability density function for the fisher-snedecor distribution at x

Remarks

Returns NaN if freedom_1, freedom_2 is INF, or x is +INF or -INF

Formula

This example is not tested
sqrt(((d1 * x) ^ d1 * d2 ^ d2) / (d1 * x + d2) ^ (d1 + d2)) / (x * β(d1
/ 2, d2 / 2))

where d1 is the first degree of freedom, d2 is the second degree of freedom, and β is the beta function

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

Calculates the log probability density function for the fisher-snedecor distribution at x

Remarks

Returns NaN if freedom_1, freedom_2 is INF, or x is +INF or -INF

Formula

This example is not tested
ln(sqrt(((d1 * x) ^ d1 * d2 ^ d2) / (d1 * x + d2) ^ (d1 + d2)) / (x *
β(d1 / 2, d2 / 2)))

where d1 is the first degree of freedom, d2 is the second degree of freedom, and β is the beta function

impl Continuous<f64, f64> for Gamma[src]

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

Calculates the probability density function for the gamma distribution at x

Remarks

Returns NAN if any of shape or rate are INF or if x is INF

Formula

This example is not tested
(β^α / Γ(α)) * x^(α - 1) * e^(-β * x)

where α is the shape, β is the rate, and Γ is the gamma function

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

Calculates the log probability density function for the gamma distribution at x

Remarks

Returns NAN if any of shape or rate are INF or if x is INF

Formula

This example is not tested
ln((β^α / Γ(α)) * x^(α - 1) * e ^(-β * x))

where α is the shape, β is the rate, and Γ is the gamma function

impl Continuous<f64, f64> for InverseGamma[src]

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

Calculates the probability density function for the inverse gamma distribution at x

Formula

This example is not tested
(β^α / Γ(α)) * x^(-α - 1) * e^(-β / x)

where α is the shape, β is the rate, and Γ is the gamma function

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

Calculates the probability density function for the inverse gamma distribution at x

Formula

This example is not tested
ln((β^α / Γ(α)) * x^(-α - 1) * e^(-β / x))

where α is the shape, β is the rate, and Γ is the gamma function

impl Continuous<f64, f64> for LogNormal[src]

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

Calculates the probability density function for the log-normal distribution at x

Formula

This example is not tested
(1 /  * sqrt()) * e^(-((ln(x) - μ)^2) / ^2)

where μ is the location and σ is the scale

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

Calculates the log probability density function for the log-normal distribution at x

Formula

This example is not tested
ln((1 /  * sqrt()) * e^(-((ln(x) - μ)^2) / ^2))

where μ is the location and σ is the scale

impl Continuous<f64, f64> for Normal[src]

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

Calculates the probability density function for the normal distribution at x

Formula

This example is not tested
(1 / sqrt(^2 * π)) * e^(-(x - μ)^2 / ^2)

where μ is the mean and σ is the standard deviation

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

Calculates the log probability density function for the normal distribution at x

Formula

This example is not tested
ln((1 / sqrt(^2 * π)) * e^(-(x - μ)^2 / ^2))

where μ is the mean and σ is the standard deviation

impl Continuous<f64, f64> for Pareto[src]

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

Calculates the probability density function for the Pareto distribution at x

Formula

This example is not tested
if x < x_m {
    0
} else {
    (α * x_m^α)/(x^(α + 1))
}

where x_m is the scale and α is the shape

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

Calculates the log probability density function for the Pareto distribution at x

Formula

This example is not tested
if x < x_m {
    -INF
} else {
    ln(α) + α*ln(x_m) - (α + 1)*ln(x)
}

where x_m is the scale and α is the shape

impl Continuous<f64, f64> for StudentsT[src]

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

Calculates the probability density function for the student's t-distribution at x

Formula

This example is not tested
Γ((v + 1) / 2) / (sqrt() * Γ(v / 2) * σ) * (1 + k^2 / v)^(-1 / 2 * (v
+ 1))

where k = (x - μ) / σ, μ is the location, σ is the scale, v is the freedom, and Γ is the gamma function

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

Calculates the log probability density function for the student's t-distribution at x

Formula

This example is not tested
ln(Γ((v + 1) / 2) / (sqrt() * Γ(v / 2) * σ) * (1 + k^2 / v)^(-1 / 2 *
(v + 1)))

where k = (x - μ) / σ, μ is the location, σ is the scale, v is the freedom, and Γ is the gamma function

impl Continuous<f64, f64> for Triangular[src]

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

Calculates the probability density function for the triangular distribution at x

Formula

This example is not tested
if x < min {
    0
} else if min <= x <= mode {
    2 * (x - min) / ((max - min) * (mode - min))
} else if mode < x <= max {
    2 * (max - x) / ((max - min) * (max - mode))
} else {
    0
}

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

Calculates the log probability density function for the triangular distribution at x

Formula

This example is not tested
ln( if x < min {
    0
} else if min <= x <= mode {
    2 * (x - min) / ((max - min) * (mode - min))
} else if mode < x <= max {
    2 * (max - x) / ((max - min) * (max - mode))
} else {
    0
} )

impl Continuous<f64, f64> for Uniform[src]

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

Calculates the probability density function for the continuous uniform distribution at x

Remarks

Returns 0.0 if x is not in [min, max]

Formula

This example is not tested
1 / (max - min)

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

Calculates the log probability density function for the continuous uniform distribution at x

Remarks

Returns f64::NEG_INFINITY if x is not in [min, max]

Formula

This example is not tested
ln(1 / (max - min))

impl Continuous<f64, f64> for Weibull[src]

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

Calculates the probability density function for the weibull distribution at x

Formula

This example is not tested
(k / λ) * (x / λ)^(k - 1) * e^(-(x / λ)^k)

where k is the shape and λ is the scale

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

Calculates the log probability density function for the weibull distribution at x

Formula

This example is not tested
ln((k / λ) * (x / λ)^(k - 1) * e^(-(x / λ)^k))

where k is the shape and λ is the scale

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

Loading content...