Class AliasTable

Nested Relationships

Nested Types

Class Documentation

class AliasTable

the alias method of Walker and Vose: draws i with probability w_i / sum w, in O( 1 ) time from one random word

Public Functions

explicit AliasTable(const std::vector<double> &w)

the table of the weights w, not all zero

Pre:

w not empty, its items finite and >= 0 with a positive sum, and fewer than 2^32 of them

inline std::size_t size(void) const
template<FullWordGenerator G>
std::size_t operator()(G &&g) const

an index drawn with probability proportional to its weight

double probability(std::size_t i) const

the probability of i, as the table gives it

Pre:

i < size()