blitz Version 1.0.2
Loading...
Searching...
No Matches
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
29namespace ranlib {
30
31template<typename T = double, typename IRNG = defaultIRNG,
32 typename stateTag = defaultState>
33class ExponentialUnit : public UniformOpen<T,IRNG,stateTag>
34{
35public:
36 typedef T T_numtype;
37
39
40 explicit ExponentialUnit(unsigned int i) :
41 UniformOpen<T,IRNG,stateTag>(i) {};
42
44 {
46 }
47};
48
49template<typename T = double, typename IRNG = defaultIRNG,
50 typename stateTag = defaultState>
51class Exponential : public ExponentialUnit<T,IRNG,stateTag> {
52
53public:
54 typedef T T_numtype;
55
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
71
72private:
74};
75
76}
77
78#endif // BZ_RANDOM_EXPONENTIAL
Definition exponential.h:34
ExponentialUnit()
Definition exponential.h:38
T T_numtype
Definition exponential.h:36
T random()
Definition exponential.h:43
ExponentialUnit(unsigned int i)
Definition exponential.h:40
Definition exponential.h:51
T mean_
Definition exponential.h:73
T random()
Definition exponential.h:67
Exponential(T mean)
Definition exponential.h:56
Exponential(T mean, unsigned int i)
Definition exponential.h:61
T T_numtype
Definition exponential.h:54
Definition uniform.h:377
Definition beta.h:50
sharedState defaultState
Definition default.h:55
MersenneTwister defaultIRNG
Definition default.h:120