Trait rv::traits::Rv[][src]

pub trait Rv<X> {
    fn ln_f(&self, x: &X) -> f64;
fn draw<R: Rng>(&self, rng: &mut R) -> X; fn f(&self, x: &X) -> f64 { ... }
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<X> { ... } }

Random variable

Contains the minimal functionality that a random object must have to be useful: a function defining the un-normalized density/mass at a point, and functions to draw samples from the distribution.

Required Methods

Probability function

Example

use rv::dist::Gaussian;
use rv::traits::Rv;

let g = Gaussian::standard();
assert!(g.ln_f(&0.0_f64) > g.ln_f(&0.1_f64));
assert!(g.ln_f(&0.0_f64) > g.ln_f(&-0.1_f64));

Single draw from the Rv

Example

Flip a coin

extern crate rand;

use rv::dist::Bernoulli;
use rv::traits::Rv;

let b = Bernoulli::uniform();
let mut rng = rand::thread_rng();
let x: bool = b.draw(&mut rng); // could be true, could be false.

Provided Methods

Probability function

Example

use rv::dist::Gaussian;
use rv::traits::Rv;

let g = Gaussian::standard();
assert!(g.f(&0.0_f64) > g.f(&0.1_f64));
assert!(g.f(&0.0_f64) > g.f(&-0.1_f64));

Multiple draws of the Rv

Example

Flip a lot of coins

extern crate rand;

use rv::dist::Bernoulli;
use rv::traits::Rv;

let b = Bernoulli::uniform();
let mut rng = rand::thread_rng();
let xs: Vec<bool> = b.sample(22, &mut rng);

assert_eq!(xs.len(), 22);

Implementors