blitz
Version 1.0.2
Toggle main menu visibility
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
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
38
ExponentialUnit
() {}
39
40
explicit
ExponentialUnit
(
unsigned
int
i) :
41
UniformOpen
<T,IRNG,stateTag>(i) {};
42
43
T
random
()
44
{
45
return
- log(
UniformOpen<T,IRNG,stateTag>::random
());
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
{
69
return
mean_
*
ExponentialUnit<T,IRNG,stateTag>::random
();
70
}
71
72
private
:
73
T
mean_
;
74
};
75
76
}
77
78
#endif
// BZ_RANDOM_EXPONENTIAL
ranlib::ExponentialUnit::ExponentialUnit
ExponentialUnit()
Definition
exponential.h:38
ranlib::ExponentialUnit::T_numtype
T T_numtype
Definition
exponential.h:36
ranlib::ExponentialUnit::random
T random()
Definition
exponential.h:43
ranlib::ExponentialUnit::ExponentialUnit
ExponentialUnit(unsigned int i)
Definition
exponential.h:40
ranlib::Exponential::mean_
T mean_
Definition
exponential.h:73
ranlib::Exponential::random
T random()
Definition
exponential.h:67
ranlib::Exponential::Exponential
Exponential(T mean)
Definition
exponential.h:56
ranlib::Exponential::Exponential
Exponential(T mean, unsigned int i)
Definition
exponential.h:61
ranlib::Exponential::T_numtype
T T_numtype
Definition
exponential.h:54
ranlib::UniformOpen
Definition
uniform.h:377
ranlib::UniformOpen< double, defaultIRNG, defaultState >::UniformOpen
UniformOpen()
Definition
uniform.h:381
ranlib::UniformOpen::random
T random()
Definition
uniform.h:385
ranlib
Definition
beta.h:50
ranlib::defaultState
sharedState defaultState
Definition
default.h:55
ranlib::defaultIRNG
MersenneTwister defaultIRNG
Definition
default.h:120
uniform.h
random
exponential.h
Generated by
1.17.0