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