DiscreteUniformSampler.h

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @class  DiscreteUniformSampler
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @author Matthew Jacobs (jacobs.mh@gmail.com)
00005    @date   Fall 2008
00006    
00007    @brief
00008       Represents a discrete uniform distribution
00009          X ~ U(min, max)
00010          p(x) = 1 / (max - min)
00011    <!-------------------------------------------------------------------->**/
00012 
00013 #ifndef DISCRETE_UNIFORM_SAMPLER_H_
00014 #define DISCRETE_UNIFORM_SAMPLER_H_
00015 
00016 #include <stats/samplers/UniformSampler.h>
00017 
00018 class DiscreteUniformSampler : public UniformSampler<int> {
00019    
00020    public:
00021       ///@name Constructors
00022       //@{-----------------------------------------------------------------
00023       
00024       inline explicit DiscreteUniformSampler(int min = 0, int max = 6)
00025          : UniformSampler<int>(min, max), 
00026            m_sampler(Random::s_generator, 
00027                      Random::DiscreteUniformDist(min, max)), 
00028            m_data(NULL)
00029       { }
00030       
00031       inline explicit DiscreteUniformSampler(const int *data, const unsigned n)
00032          : UniformSampler<int>(0, n), 
00033            m_sampler(Random::s_generator, 
00034                      Random::DiscreteUniformDist(0, n)), 
00035            m_data(data)
00036       { }
00037       
00038       inline DiscreteUniformSampler(const DiscreteUniformSampler &copy)
00039          : UniformSampler<int>(copy), 
00040            m_sampler(copy.m_sampler), 
00041            m_data(copy.m_data)
00042       { }
00043       
00044       virtual ~DiscreteUniformSampler()
00045       { }
00046       
00047       
00048       //@}-----------------------------------------------------------------
00049       ///@name Main usage interface
00050       //@{-----------------------------------------------------------------
00051       
00052       /**
00053        * @returns a randomly chosen event x, sampled from this random 
00054        *    variable's sample space
00055        * @note consecutive calls to sample are expected to return 
00056        *    independent, identically distributed (IID) samples
00057        */
00058       virtual Event sample();
00059       
00060       /**
00061        * @returns the probability density with which the given event would be 
00062        *    sampled according to the underlying probability density function
00063        * @note the given event is assumed to lie within this random variable's
00064        *    sample space
00065        */
00066       virtual real_t getPdf(const Event &event) PURE_FUNCTION;
00067       
00068       
00069       //@}-----------------------------------------------------------------
00070       
00071    protected:
00072       Random::BoostDiscreteUniformSampler m_sampler;
00073       
00074       const int                     *m_data;
00075 };
00076 
00077 #endif // DISCRETE_UNIFORM_SAMPLER_H_
00078 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6