NormalSampler.cpp

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @file   NormalSampler.h
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 #include "NormalSampler.h"
00025 
00026 void NormalSampler::init() {
00027    Sampler::init();
00028    
00029    ASSERT(m_variance >= 0);
00030 }
00031 
00032 Event NormalSampler::sample() {
00033    return Event(m_sampler(), this);
00034 }
00035 
00036 real_t NormalSampler::getPdf(const Event &event) {
00037    const real_t &x = event.getValue<real_t>();
00038    const real_t xShift = (x - m_mean);
00039    
00040    return 1.0 / (sqrt(2 * M_PI * m_variance) * exp(xShift * xShift / (-2 * m_variance)));
00041 }
00042 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6