random/exponential.h

Go to the documentation of this file.
00001 /*
00002  * This generator uses the straightforward transformation
00003  *  x = - log(y) * m
00004  *
00005  * to turn a uniform (0,1) y into an exponentially distributed
00006  * variable x.  x has density function
00007  * 
00008  * f(x) = (1/m) exp(-(1/m)x)  (x > 0)
00009  *
00010  * and mean m.
00011  *
00012  * NEEDS_WORK: Adapt the method of Ahrens and Dieter.  This will
00013  * require extending the precision of the constants.
00014  *
00015  * Ahrens, J.H. and Dieter, U.  Computer Methods for Sampling From the
00016  * Exponential and Normal Distributions. Comm. ACM, 15,10 (Oct. 1972), p. 873.
00017  */
00018 
00019 #ifndef BZ_RANDOM_EXPONENTIAL
00020 #define BZ_RANDOM_EXPONENTIAL
00021 
00022 #ifndef BZ_RANDOM_UNIFORM
00023  #include <random/uniform.h>
00024 #endif
00025 
00026 BZ_NAMESPACE(ranlib)
00027 
00028 template<typename T = double, typename IRNG = defaultIRNG, 
00029     typename stateTag = defaultState>
00030 class ExponentialUnit : public UniformOpen<T,IRNG,stateTag>
00031 {
00032 public:
00033     typedef T T_numtype;
00034 
00035     T random()
00036     {
00037         return - log(UniformOpen<T,IRNG,stateTag>::random());
00038     }
00039 };
00040 
00041 template<typename T = double, typename IRNG = defaultIRNG, 
00042     typename stateTag = defaultState>
00043 class Exponential : public ExponentialUnit<T,IRNG,stateTag> {
00044 
00045 public:
00046     typedef T T_numtype;
00047 
00048     Exponential(T mean)
00049     {
00050         mean_ = mean;
00051     }
00052 
00053     T random()
00054     {
00055         return mean_ * ExponentialUnit<T,IRNG,stateTag>::random();
00056     }
00057 
00058 private:
00059     T mean_;
00060 };
00061 
00062 BZ_NAMESPACE_END
00063 
00064 #endif // BZ_RANDOM_EXPONENTIAL

Generated on Wed Oct 17 16:27:10 2007 for blitz by  doxygen 1.5.2