Struct statrs::distribution::Beta
[−]
[src]
pub struct Beta { /* fields omitted */ }
Implements the Beta distribution
Examples
use statrs::distribution::{Beta, Continuous}; use statrs::statistics::Mean; use statrs::prec; let n = Beta::new(2.0, 2.0).unwrap(); assert_eq!(n.mean(), 0.5); assert!(prec::almost_eq(n.pdf(0.5), 1.5, 1e-14));
Methods
impl Beta
[src]
fn new(shape_a: f64, shape_b: f64) -> Result<Beta>
Constructs a new beta distribution with shapeA (α) of shape_a
and shapeB (β) of shape_b
Errors
Returns an error if shape_a
or shape_b
are NaN
.
Also returns an error if shape_a <= 0.0
or shape_b <= 0.0
Examples
use statrs::distribution::Beta; let mut result = Beta::new(2.0, 2.0); assert!(result.is_ok()); result = Beta::new(0.0, 0.0); assert!(result.is_err());
fn shape_a(&self) -> f64
Returns the shapeA (α) of the beta distribution
Examples
use statrs::distribution::Beta; let n = Beta::new(2.0, 2.0).unwrap(); assert_eq!(n.shape_a(), 2.0);
fn shape_b(&self) -> f64
Returns the shapeB (β) of the beta distributionβ
Examples
use statrs::distribution::Beta; let n = Beta::new(2.0, 2.0).unwrap(); assert_eq!(n.shape_b(), 2.0);
Trait Implementations
impl Debug for Beta
[src]
impl Copy for Beta
[src]
impl Clone for Beta
[src]
fn clone(&self) -> Beta
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl PartialEq for Beta
[src]
fn eq(&self, __arg_0: &Beta) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Beta) -> bool
This method tests for !=
.
impl Sample<f64> for Beta
[src]
fn sample<R: Rng>(&mut self, r: &mut R) -> f64
Generate a random sample from a beta distribution
using r
as the source of randomness.
Refer here for implementation details.
impl IndependentSample<f64> for Beta
[src]
fn ind_sample<R: Rng>(&self, r: &mut R) -> f64
Generate a random independent sample from a beta distribution
using r
as the source of randomness.
Refer here for implementation details.
impl Distribution<f64> for Beta
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
Generate a random sample from a beta distribution using
r
as the source of randomness. Generated by sampling
two gamma distributions and normalizing.
Examples
use rand::StdRng; use statrs::distribution::{Beta, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = Beta::new(2.0, 2.0).unwrap(); print!("{}", n.sample::<StdRng>(&mut r));
impl Univariate<f64, f64> for Beta
[src]
impl Min<f64> for Beta
[src]
fn min(&self) -> f64
Returns the minimum value in the domain of the beta distribution representable by a double precision float
Formula
0
impl Max<f64> for Beta
[src]
fn max(&self) -> f64
Returns the maximum value in the domain of the beta distribution representable by a double precision float
Formula
1
impl Mean<f64> for Beta
[src]
impl Variance<f64> for Beta
[src]
fn variance(&self) -> f64
Returns the variance of the beta distribution
Remarks
Returns f64::NAN
if either shape_a
or shape_b
are
positive infinity
Formula
(α * β) / ((α + β)^2 * (α + β + 1))
where α
is shapeA and β
is shapeB
fn std_dev(&self) -> f64
impl Entropy<f64> for Beta
[src]
fn entropy(&self) -> f64
Returns the entropy of the beta distribution
Formula
ln(B(α, β)) - (α - 1)ψ(α) - (β - 1)ψ(β) + (α + β - 2)ψ(α + β)
where α
is shapeA, β
is shapeB and ψ
is the digamma function
impl Skewness<f64> for Beta
[src]
fn skewness(&self) -> f64
Returns the skewness of the Beta distribution
Formula
2(β - α) * sqrt(α + β + 1) / ((α + β + 2) * sqrt(αβ))
where α
is shapeA and β
is shapeB
impl Mode<f64> for Beta
[src]
impl Continuous<f64, f64> for Beta
[src]
fn pdf(&self, x: f64) -> f64
Calculates the probability density function for the beta distribution at x
.
Panics
If x < 0.0
or x > 1.0
Formula
let B(α, β) = Γ(α)Γ(β)/Γ(α + β) x^(α - 1) * (1 - x)^(β - 1) / B(α, β)
where α
is shapeA, β
is shapeB, and Γ
is the gamma function