source: XMLIO_V2/external/include/random/exponential.h @ 80

Last change on this file since 80 was 80, checked in by ymipsl, 14 years ago

ajout lib externe

  • Property svn:eol-style set to native
File size: 1.4 KB
Line 
1/*
2 * This generator uses the straightforward transformation
3 *  x = - log(y) * m
4 *
5 * to turn a uniform (0,1) y into an exponentially distributed
6 * variable x.  x has density function
7 *
8 * f(x) = (1/m) exp(-(1/m)x)  (x > 0)
9 *
10 * and mean m.
11 *
12 * NEEDS_WORK: Adapt the method of Ahrens and Dieter.  This will
13 * require extending the precision of the constants.
14 *
15 * Ahrens, J.H. and Dieter, U.  Computer Methods for Sampling From the
16 * Exponential and Normal Distributions. Comm. ACM, 15,10 (Oct. 1972), p. 873.
17 */
18
19#ifndef BZ_RANDOM_EXPONENTIAL
20#define BZ_RANDOM_EXPONENTIAL
21
22#ifndef BZ_RANDOM_UNIFORM
23 #include <random/uniform.h>
24#endif
25
26BZ_NAMESPACE(ranlib)
27
28template<typename T = double, typename IRNG = defaultIRNG, 
29    typename stateTag = defaultState>
30class ExponentialUnit : public UniformOpen<T,IRNG,stateTag>
31{
32public:
33    typedef T T_numtype;
34
35    T random()
36    {
37        return - log(UniformOpen<T,IRNG,stateTag>::random());
38    }
39};
40
41template<typename T = double, typename IRNG = defaultIRNG, 
42    typename stateTag = defaultState>
43class Exponential : public ExponentialUnit<T,IRNG,stateTag> {
44
45public:
46    typedef T T_numtype;
47
48    Exponential(T mean)
49    {
50        mean_ = mean;
51    }
52
53    T random()
54    {
55        return mean_ * ExponentialUnit<T,IRNG,stateTag>::random();
56    }
57
58private:
59    T mean_;
60};
61
62BZ_NAMESPACE_END
63
64#endif // BZ_RANDOM_EXPONENTIAL
Note: See TracBrowser for help on using the repository browser.