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 () |
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.
|
inline |
Definition at line 56 of file MultiNomialDistribution.h.
|
inline |
Constructor.
[in] | probabilities | Probability vector |
Definition at line 60 of file MultiNomialDistribution.h.
References update().
|
inline |
Samples the distribution.
Definition at line 90 of file MultiNomialDistribution.h.
References shark::random::coinToss(), and shark::random::discrete().
|
inline |
Accesses the probabilityvector defining the distribution.
Definition at line 76 of file MultiNomialDistribution.h.
|
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 84 of file MultiNomialDistribution.h.
|
inline |
Stores/Restores the distribution from the supplied archive.
[in,out] | ar | The archive to read from/write to. |
[in] | version | Currently unused. |
Definition at line 69 of file MultiNomialDistribution.h.
|
inline |
Definition at line 102 of file MultiNomialDistribution.h.
Referenced by MultiNomialDistribution().