shark::MultiNomialDistribution Class Reference

Implements a multinomial distribution. More...

#include <shark/Statistics/Distributions/MultiNomialDistribution.h>

Public Member Functions

 MultiNomialDistribution ()
 
 MultiNomialDistribution (RealVector const &probabilities)
 Constructor. More...
 
template<typename Archive >
void serialize (Archive &ar, const unsigned int version)
 Stores/Restores the distribution from the supplied archive. More...
 
RealVector const & probabilities () const
 Accesses the probabilityvector defining the distribution. More...
 
RealVector & probabilities ()
 Accesses a mutable reference to the probability vector defining the distribution. Allows for l-value semantics. More...
 
template<class RngType >
result_type operator() (RngType &rng) const
 Samples the distribution. More...
 
void update ()
 

Detailed Description

Implements a multinomial distribution.

A multinomial distribution is a discrete distribution with states 0,...,N-1 and probabilities p_i for state i with sum_i p_i = 1. This implementation uses the fast alias method (Kronmal and Peterson,1979) to draw the numbers in constant time. Setup is O(N) and also quite fast. It is advisable to use this method to draw many numbers in succession.

The idea of the alias method is to pair a state with high probability with a state with low probability. A high probability state can in this case be included in several pairs. To draw, first one of the states is selected and afterwards a coin toss decides which element of the pair is taken.

Definition at line 53 of file MultiNomialDistribution.h.

Constructor & Destructor Documentation

§ MultiNomialDistribution() [1/2]

shark::MultiNomialDistribution::MultiNomialDistribution ( )
inline

Definition at line 57 of file MultiNomialDistribution.h.

§ MultiNomialDistribution() [2/2]

shark::MultiNomialDistribution::MultiNomialDistribution ( RealVector const &  probabilities)
inline

Constructor.

Parameters
[in]probabilitiesProbability vector

Definition at line 61 of file MultiNomialDistribution.h.

References update().

Member Function Documentation

§ operator()()

template<class RngType >
result_type shark::MultiNomialDistribution::operator() ( RngType &  rng) const
inline

Samples the distribution.

Definition at line 91 of file MultiNomialDistribution.h.

References shark::coinToss(), and shark::discrete().

§ probabilities() [1/2]

RealVector const& shark::MultiNomialDistribution::probabilities ( ) const
inline

Accesses the probabilityvector defining the distribution.

Definition at line 77 of file MultiNomialDistribution.h.

§ probabilities() [2/2]

RealVector& shark::MultiNomialDistribution::probabilities ( )
inline

Accesses a mutable reference to the probability vector defining the distribution. Allows for l-value semantics.

ATTENTION: If the reference is altered, update needs to be called manually.

Definition at line 85 of file MultiNomialDistribution.h.

§ serialize()

template<typename Archive >
void shark::MultiNomialDistribution::serialize ( Archive &  ar,
const unsigned int  version 
)
inline

Stores/Restores the distribution from the supplied archive.

Parameters
[in,out]arThe archive to read from/write to.
[in]versionCurrently unused.

Definition at line 70 of file MultiNomialDistribution.h.

§ update()

void shark::MultiNomialDistribution::update ( )
inline

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