NormalSampler.h

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @class  NormalSampler
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 normal distribution:
00009          X ~ N(u, sigma^2)
00010          f(x) = 1/(sqrt(2*pi*sigma^2)*exp(-(x-u)^2/(2*sigma^2)))
00011       The normal distribution (aka Gaussian) is parameterized by its mean 
00012    and variance and is referred to as the standard normal distribution when 
00013    when it has mean zero and variance one. The normal distribution is 
00014    probably the single most important distribution in all of probability 
00015    because of its ubiquity in describing natural phenomena and because of the 
00016    Central Limit Theorem, which says that the sum of a sufficiently large 
00017    number of iid random variables, each with finite mean and varirance, will 
00018    be approximately normally distributed.  This allows one to study almost 
00019    any distribution in terms of one, standard normal, distribution, simplifying
00020    many computations and proofs all over both applied and theoretical 
00021    statistics.
00022    <!-------------------------------------------------------------------->**/
00023 
00024 #ifndef NORMAL_SAMPLER_H_
00025 #define NORMAL_SAMPLER_H_
00026 
00027 #include <stats/Sampler.h>
00028 
00029 class NormalSampler : public Sampler {
00030    
00031    public:
00032       ///@name Constructors
00033       //@{-----------------------------------------------------------------
00034       
00035       inline explicit NormalSampler(real_t mean = 0, real_t variance = 1)
00036          : Sampler(), 
00037            m_sampler(Random::s_generator, 
00038                      Random::NormalDist(mean, sqrt(variance))), 
00039            m_mean(mean), m_variance(variance)
00040       { }
00041       
00042       inline NormalSampler(const NormalSampler &copy)
00043          : Sampler(copy), 
00044            m_sampler(copy.m_sampler), 
00045            m_mean(copy.getMean()), m_variance(copy.getVariance())
00046       { }
00047       
00048       virtual ~NormalSampler()
00049       { }
00050       
00051       
00052       //@}-----------------------------------------------------------------
00053       ///@name Initialization
00054       //@{-----------------------------------------------------------------
00055       
00056       /**
00057        * @brief
00058        *    Should perform any initialization of this random variable which 
00059        * may be necessary to speed or prepare sampling
00060        * 
00061        * @note should be called before calling sample or getPdf
00062        * @note default implementation initialiazes this random variable's 
00063        *    sample space
00064        */
00065       virtual void init();
00066       
00067       
00068       //@}-----------------------------------------------------------------
00069       ///@name Main usage interface
00070       //@{-----------------------------------------------------------------
00071       
00072       /**
00073        * @returns a randomly chosen event x, sampled from this random 
00074        *    variable's sample space
00075        * @note consecutive calls to sample are expected to return 
00076        *    independent, identically distributed (IID) samples
00077        */
00078       virtual Event sample();
00079       
00080       /**
00081        * @returns the probability density with which the given event would be 
00082        *    sampled according to the underlying probability density function
00083        * @note the given event is assumed to lie within this random variable's
00084        *    sample space
00085        */
00086       virtual real_t getPdf(const Event &event) PURE_FUNCTION;
00087       
00088       
00089       //@}-----------------------------------------------------------------
00090       ///@name Accessors/Mutators
00091       //@{-----------------------------------------------------------------
00092       
00093       /**
00094        * @returns the mean 'mu' of this normal random variable
00095        */
00096       inline real_t getMean() const {
00097          return m_mean;
00098       }
00099       
00100       /**
00101        * @returns the variance 'sigma squared' of this normal random variable
00102        */
00103       inline real_t getVariance() const {
00104          return m_variance;
00105       }
00106       
00107       /**
00108        * @returns the standard deviation 'sigma' of this normal random variable
00109        */
00110       inline real_t getStdDev() const {
00111          return m_sampler.distribution().sigma();
00112       }
00113       
00114       /**
00115        * @returns whether or not this normal distribution is approximately 
00116        *    standard with mean 0 and variance 1 (within EPSILON)
00117        */
00118       inline bool isStandardNormal() const {
00119          return (EQ(m_mean, 0) && EQ(m_variance, 1));
00120       }
00121       
00122       //@}-----------------------------------------------------------------
00123       
00124    protected:
00125       Random::BoostNormalSampler m_sampler;
00126       
00127       real_t m_mean;
00128       real_t m_variance;
00129 };
00130 
00131 #endif // NORMAL_SAMPLER_H_
00132 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6