blitz  Version 1.0.2
exponential.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // $Id$
3 
4 /*
5  * This generator uses the straightforward transformation
6  * x = - log(y) * m
7  *
8  * to turn a uniform (0,1) y into an exponentially distributed
9  * variable x. x has density function
10  *
11  * f(x) = (1/m) exp(-(1/m)x) (x > 0)
12  *
13  * and mean m.
14  *
15  * NEEDS_WORK: Adapt the method of Ahrens and Dieter. This will
16  * require extending the precision of the constants.
17  *
18  * Ahrens, J.H. and Dieter, U. Computer Methods for Sampling From the
19  * Exponential and Normal Distributions. Comm. ACM, 15,10 (Oct. 1972), p. 873.
20  */
21 
22 #ifndef BZ_RANDOM_EXPONENTIAL
23 #define BZ_RANDOM_EXPONENTIAL
24 
25 #ifndef BZ_RANDOM_UNIFORM
26  #include <random/uniform.h>
27 #endif
28 
29 namespace ranlib {
30 
31 template<typename T = double, typename IRNG = defaultIRNG,
32  typename stateTag = defaultState>
33 class ExponentialUnit : public UniformOpen<T,IRNG,stateTag>
34 {
35 public:
36  typedef T T_numtype;
37 
39 
40  explicit ExponentialUnit(unsigned int i) :
41  UniformOpen<T,IRNG,stateTag>(i) {};
42 
43  T random()
44  {
46  }
47 };
48 
49 template<typename T = double, typename IRNG = defaultIRNG,
50  typename stateTag = defaultState>
51 class Exponential : public ExponentialUnit<T,IRNG,stateTag> {
52 
53 public:
54  typedef T T_numtype;
55 
56  Exponential(T mean)
57  {
58  mean_ = mean;
59  }
60 
61  Exponential(T mean, unsigned int i) :
62  UniformOpen<T,IRNG,stateTag>(i)
63  {
64  mean_ = mean;
65  };
66 
67  T random()
68  {
70  }
71 
72 private:
73  T mean_;
74 };
75 
76 }
77 
78 #endif // BZ_RANDOM_EXPONENTIAL
Definition: exponential.h:33
Definition: beta.h:50
T random()
Definition: exponential.h:67
T T_numtype
Definition: exponential.h:36
Definition: exponential.h:51
T mean_
Definition: exponential.h:73
_bz_global blitz::IndexPlaceholder< 0 > i
Definition: indexexpr.h:256
Exponential(T mean)
Definition: exponential.h:56
T random()
Definition: exponential.h:43
Exponential(T mean, unsigned int i)
Definition: exponential.h:61
T T_numtype
Definition: exponential.h:54
MersenneTwister defaultIRNG
Definition: default.h:120
ExponentialUnit()
Definition: exponential.h:38
Definition: uniform.h:377
ExponentialUnit(unsigned int i)
Definition: exponential.h:40
sharedState defaultState
Definition: default.h:55