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 randomType >
result_type operator() (randomType &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 52 of file MultiNomialDistribution.h.

Constructor & Destructor Documentation

◆ MultiNomialDistribution() [1/2]

shark::MultiNomialDistribution::MultiNomialDistribution ( )

Definition at line 56 of file MultiNomialDistribution.h.

◆ MultiNomialDistribution() [2/2]

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


[in]probabilitiesProbability vector

Definition at line 60 of file MultiNomialDistribution.h.

References update().

Member Function Documentation

◆ operator()()

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

Samples the distribution.

Definition at line 90 of file MultiNomialDistribution.h.

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

◆ probabilities() [1/2]

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

Accesses the probabilityvector defining the distribution.

Definition at line 76 of file MultiNomialDistribution.h.

◆ probabilities() [2/2]

RealVector& shark::MultiNomialDistribution::probabilities ( )

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 84 of file MultiNomialDistribution.h.

◆ serialize()

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

Stores/Restores the distribution from the supplied archive.

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

Definition at line 69 of file MultiNomialDistribution.h.

◆ update()

void shark::MultiNomialDistribution::update ( )

Definition at line 102 of file MultiNomialDistribution.h.

Referenced by MultiNomialDistribution().

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