/usr/include/random/F.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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | // -*- C++ -*-
// $Id$
/*
* F distribution
*
* This code has been adapted from RANDLIB.C 1.3, by
* Barry W. Brown, James Lovato, Kathy Russell, and John Venier.
* Code was originally by Ahrens and Dieter (see above).
*
* Adapter's notes:
* BZ_NEEDS_WORK: how to handle seeding for the two gamma RNGs if
* independentState is used?
* BZ_NEEDS_WORK: code for handling possible overflow when xden
* is tiny seems a bit flaky.
*/
#ifndef BZ_RANDOM_F
#define BZ_RANDOM_F
#ifndef BZ_RANDOM_GAMMA
#include <random/gamma.h>
#endif
BZ_NAMESPACE(ranlib)
template<typename T = double, typename IRNG = defaultIRNG,
typename stateTag = defaultState>
class F {
public:
typedef T T_numtype;
F(T numeratorDF, T denominatorDF)
{
setDF(numeratorDF, denominatorDF);
mindenom = 0.085 * blitz::tiny(T());
}
F(T numeratorDF, T denominatorDF, unsigned int i) :
ngamma(i), dgamma(i)
{
setDF(numeratorDF, denominatorDF);
mindenom = 0.085 * blitz::tiny(T());
}
void setDF(T _dfn, T _dfd)
{
BZPRECONDITION(_dfn > 0.0);
BZPRECONDITION(_dfd > 0.0);
dfn = _dfn;
dfd = _dfd;
ngamma.setMean(dfn/2.0);
dgamma.setMean(dfd/2.0);
}
T random()
{
T xnum = 2.0 * ngamma.random() / dfn;
T xden = 2.0 * ngamma.random() / dfd;
// Rare event: Will an overflow probably occur?
if (xden <= mindenom)
{
// Yes, just return huge(T())
return blitz::huge(T());
}
return xnum / xden;
}
void seed(IRNG_int s, IRNG_int r)
{
// This is such a bad idea if independentState is used. Ugh.
// If sharedState is used, it is merely inefficient (the
// same RNG is seeded twice).
// yes it's unacceptable -- changed to using two seeds / Patrik
// in fact should probably be two uncorrelated IRNGs...
ngamma.seed(s);
dgamma.seed(r);
}
protected:
Gamma<T,IRNG,stateTag> ngamma, dgamma;
T dfn, dfd, mindenom;
};
BZ_NAMESPACE_END
#endif // BZ_RANDOM_F
|