ExponentialSampler.h

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @class  ExponentialSampler
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @author Matthew Jacobs (jacobs.mh@gmail.com)
00005    @date   Fall 2008
00006    
00007    @brief
00008       Represents an exponential distribution:
00009          X ~ Exp(lambda) ; lambda > 0
00010          f(x) = lambda * exp(-lambda * x) ; x >= 0
00011          E(X) = 1 / lambda
00012          Var(X) = 1 / (lambda ^ 2)
00013       
00014       Exponential distributions describe the times (waiting time) between 
00015    events in a Poisson process, i.e., a process in which events occur 
00016    continuously and independently at a constant average rate. An example 
00017    would be the average time you have to wait at a red light before the 
00018    light turns green.
00019    <!-------------------------------------------------------------------->**/
00020 
00021 #ifndef EXPONENTIAL_SAMPLER_H_
00022 #define EXPONENTIAL_SAMPLER_H_
00023 
00024 #include <stats/Sampler.h>
00025 
00026 class ExponentialSampler : public Sampler {
00027    
00028    public:
00029       ///@name Constructors
00030       //@{-----------------------------------------------------------------
00031       
00032       inline explicit ExponentialSampler(const real_t lambda = 1.0)
00033          : Sampler(), 
00034            m_sampler(Random::s_generator, 
00035                      Random::ExponentialDist(lambda)), 
00036            m_lambda(lambda)
00037       { }
00038       
00039       inline ExponentialSampler(const ExponentialSampler &copy)
00040          : Sampler(copy), 
00041            m_sampler(copy.m_sampler), 
00042            m_lambda(copy.m_lambda)
00043       { }
00044       
00045       virtual ~ExponentialSampler()
00046       { }
00047       
00048       
00049       //@}-----------------------------------------------------------------
00050       ///@name Initialization
00051       //@{-----------------------------------------------------------------
00052       
00053       /**
00054        * @brief
00055        *    Should perform any initialization of this random variable which 
00056        * may be necessary to speed or prepare sampling
00057        * 
00058        * @note should be called before calling sample or getPdf
00059        * @note default implementation initialiazes this random variable's 
00060        *    sample space
00061        */
00062       virtual void init();
00063       
00064       
00065       //@}-----------------------------------------------------------------
00066       ///@name Main usage interface
00067       //@{-----------------------------------------------------------------
00068       
00069       /**
00070        * @returns a randomly chosen event x, sampled from this random 
00071        *    variable's sample space
00072        * @note consecutive calls to sample are expected to return 
00073        *    independent, identically distributed (IID) samples
00074        */
00075       virtual Event sample();
00076       
00077       /**
00078        * @returns the probability density with which the given event would be 
00079        *    sampled according to the underlying probability density function
00080        * @note the given event is assumed to lie within this random variable's
00081        *    sample space
00082        */
00083       virtual real_t getPdf(const Event &event) PURE_FUNCTION;
00084       
00085       
00086       //@}-----------------------------------------------------------------
00087       ///@name Accessors/Mutators
00088       //@{-----------------------------------------------------------------
00089       
00090       /**
00091        * @returns the parameter lambda of this distribution, where 
00092        *    lambda is the expected 'rate'
00093        */
00094       inline real_t getLambda() const {
00095          return m_lambda;
00096       }
00097       
00098       
00099       //@}-----------------------------------------------------------------
00100       
00101    protected:
00102       Random::BoostExponentialSampler m_sampler;
00103       
00104       real_t m_lambda;
00105 };
00106 
00107 #endif // EXPONENTIAL_SAMPLER_H_
00108 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6