Functions
core/vnl/vnl_sample.h File Reference

easy ways to sample from various probability distributions More...

Go to the source code of this file.

Functions

void vnl_sample_reseed ()
 re-seed the random number generator.
void vnl_sample_reseed (int seed)
 re-seed the random number generator given a seed.
double vnl_sample_uniform (double a, double b)
 return a random number uniformly drawn on [a, b).
void vnl_sample_normal_2 (double *x, double *y)
 two independent samples from a standard normal distribution.
double vnl_sample_normal (double mean, double sigma)
 Normal distribution with given mean and standard deviation.
int vnl_sample_binomial (int n, double q)
 Return random k, where P(X = k) = [kth term in binomial expansion of (q + (1-q))^n].
int vnl_sample_bernoulli (double q)
 Bernoulli distribution ("coin toss").
template<class I >
void vnl_sample_uniform (I begin, I end, double a, double b)
 handy function to fill a range of values.
template<class I >
void vnl_sample_normal (I begin, I end, double mean, double sigma)
 handy function to fill a range of values.
template<class I >
void vnl_sample_binomial (I begin, I end, int n, double q)
 handy function to fill a range of values.
template<class I >
void vnl_sample_bernoulli (I begin, I end, double q)
 handy function to fill a range of values.
template<class I , class T >
void vnl_sample_uniform (I begin, I end, double a, double b, T)
 handy function to fill a range of values.
template<class I , class T >
void vnl_sample_normal (I begin, I end, double mean, double sigma, T)
 handy function to fill a range of values.

Detailed Description

easy ways to sample from various probability distributions

Author:
fsm
    Modifications
     2005-01-01 Peter Vanroose - use simple (but robust) rng when no DRAND48
     2007-03-26 Peter Vanroose - avoid returning log(0.0) by switching params
     2010-09-12 Peter Vanroose - added implementation for binomial sampling
     2010-09-12 Peter Vanroose - added Bernoulli (unfair coin toss) sampling
   

Definition in file vnl_sample.h.


Function Documentation

int vnl_sample_bernoulli ( double  q)

Bernoulli distribution ("coin toss").

The returned value will be 0 (with probability q) or 1 (with probability 1-q). For a "fair" coin toss, use q=0.5. When q does not lie between 0 and 1, the value -1 is returned.

Definition at line 72 of file vnl_sample.cxx.

template<class I >
void vnl_sample_bernoulli ( begin,
end,
double  q 
) [inline]

handy function to fill a range of values.

Definition at line 72 of file vnl_sample.h.

int vnl_sample_binomial ( int  n,
double  q 
)

Return random k, where P(X = k) = [kth term in binomial expansion of (q + (1-q))^n].

The returned value will lie between 0 and n (but will be -1 when input is nonsense).

Definition at line 83 of file vnl_sample.cxx.

template<class I >
void vnl_sample_binomial ( begin,
end,
int  n,
double  q 
) [inline]

handy function to fill a range of values.

Definition at line 64 of file vnl_sample.h.

double vnl_sample_normal ( double  mean,
double  sigma 
)

Normal distribution with given mean and standard deviation.

Definition at line 64 of file vnl_sample.cxx.

template<class I >
void vnl_sample_normal ( begin,
end,
double  mean,
double  sigma 
) [inline]

handy function to fill a range of values.

Definition at line 56 of file vnl_sample.h.

template<class I , class T >
void vnl_sample_normal ( begin,
end,
double  mean,
double  sigma,
 
) [inline]

handy function to fill a range of values.

Definition at line 88 of file vnl_sample.h.

void vnl_sample_normal_2 ( double *  x,
double *  y 
)

two independent samples from a standard normal distribution.

Definition at line 53 of file vnl_sample.cxx.

void vnl_sample_reseed ( )

re-seed the random number generator.

Definition at line 22 of file vnl_sample.cxx.

void vnl_sample_reseed ( int  seed)

re-seed the random number generator given a seed.

Definition at line 31 of file vnl_sample.cxx.

double vnl_sample_uniform ( double  a,
double  b 
)

return a random number uniformly drawn on [a, b).

Definition at line 40 of file vnl_sample.cxx.

template<class I >
void vnl_sample_uniform ( begin,
end,
double  a,
double  b 
) [inline]

handy function to fill a range of values.

Definition at line 48 of file vnl_sample.h.

template<class I , class T >
void vnl_sample_uniform ( begin,
end,
double  a,
double  b,
 
) [inline]

handy function to fill a range of values.

Definition at line 80 of file vnl_sample.h.