[−][src]Trait statrs::distribution::Distribution
The Distribution
trait is used to specify an interface
for sampling statistical distributions
Required methods
fn sample<R: Rng>(&self, r: &mut R) -> T
Draws a random sample using the supplied random number generator
Examples
A trivial implementation that just samples from the supplied random number generator
use rand::Rng; use statrs::distribution::Distribution; struct Foo; impl Distribution<f64> for Foo { fn sample<R: Rng>(&self, r: &mut R) -> f64 { r.next_f64() } }
Implementors
impl Distribution<f64> for Bernoulli
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
[src]
Generate a random sample from the
bernoulli distribution using r
as the source
of randomness where the generated
values are 1
with probability p
and 0
with probability 1-p
.
Examples
use rand::StdRng; use statrs::distribution::{Bernoulli, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = Bernoulli::new(0.5).unwrap(); print!("{}", n.sample::<StdRng>(&mut r));
impl Distribution<f64> for Beta
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
[src]
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 Distribution<f64> for Binomial
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
[src]
Generate a random sample from the binomial distribution
using r
as the source of randomness where the range of
values is [0.0, n]
.
Examples
use rand::StdRng; use statrs::distribution::{Binomial, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = Binomial::new(0.5, 5).unwrap(); print!("{}", n.sample::<StdRng>(&mut r));
impl Distribution<f64> for Categorical
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
[src]
Generate a random sample from the categorical distribution
using r
as the source of randomness
Examples
use rand::StdRng; use statrs::distribution::{Categorical, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = Categorical::new(&[1.0, 2.0, 3.0]).unwrap(); print!("{}", n.sample::<StdRng>(&mut r));
impl Distribution<f64> for Cauchy
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
[src]
Generate a random sample from the cauchy distribution
using r
as the source of randomness
Examples
use rand::StdRng; use statrs::distribution::{Cauchy, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = Cauchy::new(0.0, 1.0).unwrap(); print!("{}", n.sample::<StdRng>(&mut r));
impl Distribution<f64> for Chi
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
[src]
Generate a random sample from the chi distribution
using r
as the source of randomness
Examples
use rand::StdRng; use statrs::distribution::{Chi, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = Chi::new(2.0).unwrap(); print!("{}", n.sample::<StdRng>(&mut r));
impl Distribution<f64> for ChiSquared
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
[src]
Generate a random sample from the chi-squared distribution
using r
as the source of randomness
Examples
use rand::StdRng; use statrs::distribution::{ChiSquared, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = ChiSquared::new(3.0).unwrap(); print!("{}", n.sample::<StdRng>(&mut r));
impl Distribution<f64> for DiscreteUniform
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
[src]
Generate a random sample from the discrete uniform distribution
using r
as the source of randomness in the range [min, max]
Examples
use rand::StdRng; use statrs::distribution::{DiscreteUniform, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = DiscreteUniform::new(0, 5).unwrap(); print!("{}", n.sample::<StdRng>(&mut r));
impl Distribution<f64> for Erlang
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
[src]
Generate a random sample from a erlang distribution using
r
as the source of randomness.
Examples
use rand::StdRng; use statrs::distribution::{Erlang, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = Erlang::new(3, 1.0).unwrap(); print!("{}", n.sample::<StdRng>(&mut r));
impl Distribution<f64> for Exponential
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
[src]
Generate a random sample from the exponential distribution
using r
as the source of randomness
Examples
use rand::StdRng; use statrs::distribution::{Exponential, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = Exponential::new(1.0).unwrap(); print!("{}", n.sample::<StdRng>(&mut r));
impl Distribution<f64> for FisherSnedecor
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
[src]
Generate a random sample from a fisher-snedecor distribution using
r
as the source of randomness.
Examples
use rand::StdRng; use statrs::distribution::{FisherSnedecor, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = FisherSnedecor::new(2.0, 2.0).unwrap(); print!("{}", n.sample::<StdRng>(&mut r));
impl Distribution<f64> for Gamma
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
[src]
Generate a random sample from a gamma distribution using
r
as the source of randomness. The implementation is based
on:
Examples
use rand::StdRng; use statrs::distribution::{Gamma, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = Gamma::new(3.0, 1.0).unwrap(); print!("{}", n.sample::<StdRng>(&mut r));
impl Distribution<f64> for Geometric
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
[src]
Generates a random sample from the geometric distribution
using r
as the source of randomness
Examples
use rand::StdRng; use statrs::distribution::{Geometric, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = Geometric::new(0.5).unwrap(); print!("{}", n.sample::<StdRng>(&mut r));
impl Distribution<f64> for Hypergeometric
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
[src]
Generates a random sample from the hypergeometric distribution
using r
as the source of randomness
Examples
use rand::StdRng; use statrs::distribution::{Hypergeometric, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = Hypergeometric::new(10, 5, 3).unwrap(); print!("{}", n.sample::<StdRng>(&mut r));
impl Distribution<f64> for InverseGamma
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
[src]
Generate a random sample from an inverse gamma distribution
using r
as the source of randomness.
Examples
use rand::StdRng; use statrs::distribution::{InverseGamma, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = InverseGamma::new(3.0, 1.0).unwrap(); print!("{}", n.sample::<StdRng>(&mut r));
impl Distribution<f64> for LogNormal
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
[src]
Generate a random sample from the log-normal distribution
using r
as the source of randomness. Uses the Box-Muller
algorithm
Examples
use rand::StdRng; use statrs::distribution::{LogNormal, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = LogNormal::new(0.0, 1.0).unwrap(); print!("{}", n.sample::<StdRng>(&mut r));
impl Distribution<f64> for Normal
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
[src]
Generate a random sample from the normal distribution
using r
as the source of randomness. Uses the Box-Muller
algorithm
Examples
use rand::StdRng; use statrs::distribution::{Normal, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = Normal::new(0.0, 1.0).unwrap(); print!("{}", n.sample::<StdRng>(&mut r));
impl Distribution<f64> for Pareto
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
[src]
Generate a random sample from a Pareto distribution using
r
as the source of randomness. The implementation uses inverse
transform sampling.
Examples
use rand::StdRng; use statrs::distribution::{Pareto, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = Pareto::new(1.0, 2.0).unwrap(); print!("{}", n.sample::<StdRng>(&mut r));
impl Distribution<f64> for Poisson
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
[src]
Generate a random sample from a poisson distribution using
r
as the source of randomness. The implementation is based
on Knuth's method if lambda < 30.0
or Rejection method PA by
A. C. Atkinson from the Journal of the Royal Statistical Society
Series C (Applied Statistics) Vol. 28 No. 1. (1979) pp. 29 - 35
Examples
use rand::StdRng; use statrs::distribution::{Poisson, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = Poisson::new(1.0).unwrap(); print!("{}", n.sample::<StdRng>(&mut r));
impl Distribution<f64> for StudentsT
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
[src]
Generate a random sample from a student's t-distribution using
r
as the source of randomness. The implementation is based
on method 2, section 5 in chapter 9 of L. Devroye's
"Non-Uniform Random Variate Generation"
Examples
use rand::StdRng; use statrs::distribution::{StudentsT, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = StudentsT::new(0.0, 1.0, 2.0).unwrap(); print!("{}", n.sample::<StdRng>(&mut r));
impl Distribution<f64> for Triangular
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
[src]
Generate a random sample from a triangular distribution using
r
as the source of randomness.
Examples
use rand::StdRng; use statrs::distribution::{Triangular, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = Triangular::new(0.0, 5.0, 2.5).unwrap(); print!("{}", n.sample::<StdRng>(&mut r));
impl Distribution<f64> for Uniform
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
[src]
Generate a random sample from the continuous uniform distribution
using r
as the source of randomness in the range [min, max]
Examples
use rand::StdRng; use statrs::distribution::{Uniform, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = Uniform::new(0.0, 5.0).unwrap(); print!("{}", n.sample::<StdRng>(&mut r));
impl Distribution<f64> for Weibull
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
[src]
Generate a random sample from the weibull distribution
using r
as the source of randomness
Examples
use rand::StdRng; use statrs::distribution::{Weibull, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = Weibull::new(10.0, 1.0).unwrap(); print!("{}", n.sample::<StdRng>(&mut r));
impl Distribution<Vec<f64>> for Dirichlet
[src]
fn sample<R: Rng>(&self, r: &mut R) -> Vec<f64>
[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 Distribution<Vec<f64>> for Multinomial
[src]
fn sample<R: Rng>(&self, r: &mut R) -> Vec<f64>
[src]
Generate random samples from the multinomial distribution
using r
as the source of randomness
Examples
use rand::StdRng; use statrs::distribution::{Multinomial, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = Multinomial::new(&[0.0, 1.0, 2.0], 4).unwrap(); print!("{:?}", n.sample::<StdRng>(&mut r));