GClasses
|
This class is for efficiently drawing random values from a categorical distribution with a large number of categories.
#include <GDistribution.h>
Public Member Functions | |
GCategoricalSampler (size_t categories, const double *pDistribution) | |
categories specifies the number of categories. pDistribution should specify a probability value for each category. They should sum to 1. More... | |
~GCategoricalSampler () | |
size_t | draw (double d) |
d should be a random uniform value from 0 to 1. The corresponding zero-based category index is returned. This method will take log(categories) time. More... | |
Protected Attributes | |
std::map< double, size_t > | m_map |
GClasses::GCategoricalSampler::GCategoricalSampler | ( | size_t | categories, |
const double * | pDistribution | ||
) |
categories specifies the number of categories. pDistribution should specify a probability value for each category. They should sum to 1.
|
inline |
size_t GClasses::GCategoricalSampler::draw | ( | double | d | ) |
d should be a random uniform value from 0 to 1. The corresponding zero-based category index is returned. This method will take log(categories) time.
|
protected |