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 () |
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.
|
inline |
Definition at line 57 of file MultiNomialDistribution.h.
|
inline |
Constructor.
[in] | probabilities | Probability vector |
Definition at line 61 of file MultiNomialDistribution.h.
References update().
|
inline |
Samples the distribution.
Definition at line 91 of file MultiNomialDistribution.h.
References shark::coinToss(), and shark::discrete().
|
inline |
Accesses the probabilityvector defining the distribution.
Definition at line 77 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 85 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 70 of file MultiNomialDistribution.h.
|
inline |
Definition at line 103 of file MultiNomialDistribution.h.
References shark::blas::min(), shark::blas::vector< T >::resize(), and shark::blas::sum().
Referenced by MultiNomialDistribution().