Honeycomb  0.1
Component-Model Framework
Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
honey::Binomial_< Real > Class Template Reference

Generate a random integer variate from a binomial distribution. More...

#include <Binomial.h>

Inheritance diagram for honey::Binomial_< Real >:
Inheritance graph
[legend]
Collaboration diagram for honey::Binomial_< Real >:
Collaboration graph
[legend]

Public Member Functions

 Binomial_ (RandomGen &gen, Int n, Real p)
 
virtual Real next () const
 Get next randomly distributed variate. Requires a random generator (see ctor or setGen()) More...
 
virtual Real pdf (Real x) const
 Probability Density Function. More...
 
virtual Real cdf (Real x) const
 Cumulative Distribution Function. More...
 
virtual Real cdfInv (Real P) const
 Inverse of the CDF. More...
 
virtual Real mean () const
 Calc mean. More...
 
virtual Real variance () const
 Calc variance. More...
 
- Public Member Functions inherited from honey::RandomDist< Real >
 RandomDist (optional< RandomGen & > gen=optnull)
 Construct with a random generator to use for next() More...
 
virtual ~RandomDist ()
 
virtual Real cdfComp (Real x) const
 Complement of the CDF. More...
 
Real stdDev () const
 Calc standard deviation. More...
 
void setGen (RandomGen &gen)
 Set random generator to use for next() More...
 
RandomGengetGen () const
 Get random generator. More...
 

Static Public Member Functions

static Real trialProb (Int x, Int n, Real P)
 Calculate trial probability given all other values. More...
 

Public Attributes

Int n
 
Real p
 

Friends

template<class >
class Binomial_
 

Additional Inherited Members

- Protected Types inherited from honey::RandomDist< Real >
typedef Numeral< Real >::Real_ Real_
 
typedef Real_::DoubleType Double_
 
typedef Double_::Real Double
 
typedef Alge_< RealAlge
 
typedef Alge_< DoubleAlge_d
 
typedef Uniform_< DoubleUniform
 
- Protected Member Functions inherited from honey::RandomDist< Real >
Real cdfInvFind (Real P, Real min, Real max, bool discrete=false) const
 Generic binary search algorithm to find Cdf. More...
 

Detailed Description

template<class Real>
class honey::Binomial_< Real >

Generate a random integer variate from a binomial distribution.

The result x is the integer number of successes in n independent trials, where each trial has success probability p.

Example: Toss a coin (head p = 0.5) 50 times (n) and count number of heads (x)

Probability density function:

$\displaystyle p(x,n,p) = \binom{n}{x} p^x (1-p)^{n-x} $ where $\displaystyle \binom{n}{k} = \frac{n!}{k!(n-k)!} $ is the choose function.

Parameters
nNumber of trials. Range > 0
pSuccess probability. Range [0,1]
Return values
xNumber of successes. Range [0,n]

Constructor & Destructor Documentation

template<class Real >
honey::Binomial_< Real >::Binomial_ ( RandomGen gen,
Int  n,
Real  p 
)
inline

Member Function Documentation

template<class Real >
Real honey::Binomial_< Real >::cdf ( Real  x) const
virtual

Cumulative Distribution Function.

The integral of the PDF from -inf to x.

Parameters
xvalue, range depends on distribution.
Return values
Pa probability in range [0,1] that a random variate will be <= x.

Reimplemented from honey::RandomDist< Real >.

template<class Real >
Real honey::Binomial_< Real >::cdfInv ( Real  P) const
virtual

Inverse of the CDF.

Parameters
Pcumulative probability
Return values
xA value that has probability P of being >= a random variate X. Also, x satisfies: cdf(x) = P.

Reimplemented from honey::RandomDist< Real >.

template<class Real >
virtual Real honey::Binomial_< Real >::mean ( ) const
inlinevirtual

Calc mean.

Reimplemented from honey::RandomDist< Real >.

template<class Real >
Real honey::Binomial_< Real >::next ( ) const
virtual

Get next randomly distributed variate. Requires a random generator (see ctor or setGen())

Reimplemented from honey::RandomDist< Real >.

template<class Real >
Real honey::Binomial_< Real >::pdf ( Real  x) const
virtual

Probability Density Function.

The PDF integrates to 1 over the entire range of possible values of x.

Parameters
xvalue, range depends on distribution.
Return values
pa relative likelihood in range [0,inf] that a random variate X will equal x.

Reimplemented from honey::RandomDist< Real >.

template<class Real >
Real honey::Binomial_< Real >::trialProb ( Int  x,
Int  n,
Real  P 
)
static

Calculate trial probability given all other values.

Finds the per trial success probability p such that x or fewer number of successes will occur in n trials, with a probability of P

template<class Real >
virtual Real honey::Binomial_< Real >::variance ( ) const
inlinevirtual

Calc variance.

Reimplemented from honey::RandomDist< Real >.

Friends And Related Function Documentation

template<class Real >
template<class >
friend class Binomial_
friend

Member Data Documentation

template<class Real >
Int honey::Binomial_< Real >::n
template<class Real >
Real honey::Binomial_< Real >::p

The documentation for this class was generated from the following files: