GClasses
GClasses::GCategoricalSampler Class Reference

Detailed Description

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
 

Constructor & Destructor Documentation

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.

GClasses::GCategoricalSampler::~GCategoricalSampler ( )
inline

Member Function Documentation

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.

Member Data Documentation

std::map<double,size_t> GClasses::GCategoricalSampler::m_map
protected