KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | List of all members
kjb::Gsl_ran_discrete Class Reference

Randomly sample discrete events with an empirical distribution. More...

#include <gsl_randist.h>

Public Member Functions

 Gsl_ran_discrete (size_t event_count, const double *event_probs)
 build the sampler from an array of event weights or probabilities More...
 
 Gsl_ran_discrete (const Vector &event_probs)
 build the sampler from a Vector event weights or probabilities More...
 
 Gsl_ran_discrete (const std::vector< double > &event_probs)
 build the sampler from a std::vector< double > of event weights More...
 
double sample (const gsl_rng *rng)
 sample from the discrete distribution More...
 
double pdf (size_t k)
 Recompute the probability mass (or density) for event k. More...
 
void swap (Gsl_ran_discrete &that)
 swap the internal state of two of these objects More...
 

Detailed Description

Randomly sample discrete events with an empirical distribution.

This is an RAII wrapper on the GNU GSL code to support sampling from an empirically-defined distribution of discrete events.

Exceptions
Missing_dependencyif compiled with NO_LIBS.
See Also
http://www.gnu.org/software/gsl/manual/html_node/General-Discrete-Distributions.html

Constructor & Destructor Documentation

kjb::Gsl_ran_discrete::Gsl_ran_discrete ( size_t  event_count,
const double *  event_probs 
)
inline

build the sampler from an array of event weights or probabilities

Event weights do not need to be normalized to sum to 1.

kjb::Gsl_ran_discrete::Gsl_ran_discrete ( const Vector event_probs)
inline

build the sampler from a Vector event weights or probabilities

Event weights do not need to be normalized to sum to 1.

kjb::Gsl_ran_discrete::Gsl_ran_discrete ( const std::vector< double > &  event_probs)
inline

build the sampler from a std::vector< double > of event weights

Event weights do not need to be normalized to sum to 1.

Member Function Documentation

double kjb::Gsl_ran_discrete::pdf ( size_t  k)
inline

Recompute the probability mass (or density) for event k.

Warning
this is sort of an expensive operation: if you can save the original array of probabilities (or densities) that were used in the ctor, that would be quicker.
double kjb::Gsl_ran_discrete::sample ( const gsl_rng rng)
inline

sample from the discrete distribution

Parameters
rngThis is a GSL random number generator pointer. I recommend that you instantiate a class such as Gsl_rng_mt19937 and pass in that object, which will be transparently converted to the correct type. To prevent correlations, you should not instantiate a new RNG object each time you sample or even each time you instantiate this class. You should minimize the number of instantiations of random number generators.
void kjb::Gsl_ran_discrete::swap ( Gsl_ran_discrete that)
inline

swap the internal state of two of these objects


The documentation for this class was generated from the following file: