blitz  Version 1.0.2
chisquare.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // $Id$
3 
4 /*
5  * Chi^2 distribution
6  *
7  * This code has been adapted from RANDLIB.C 1.3, by
8  * Barry W. Brown, James Lovato, Kathy Russell, and John Venier.
9  * Code was originally by Ahrens and Dieter (see above).
10  *
11  * Adapter's notes:
12  */
13 
14 #ifndef BZ_RANDOM_CHISQUARE
15 #define BZ_RANDOM_CHISQUARE
16 
17 #ifndef BZ_RANDOM_GAMMA
18  #include <random/gamma.h>
19 #endif
20 
21 namespace ranlib {
22 
23 template<typename T = double, typename IRNG = defaultIRNG,
24  typename stateTag = defaultState>
25 class ChiSquare : public Gamma<T,IRNG,stateTag>
26 {
27 public:
28  typedef T T_numtype;
29 
31  : Gamma<T,IRNG,stateTag>(df/2.0) // isn't this redundant with setDF call?
32  {
33  setDF(df);
34  }
35 
36  ChiSquare(T df, unsigned int i)
37  : Gamma<T,IRNG,stateTag>(df/2.0, i)
38  {
39  setDF(df);
40  }
41 
42  void setDF(T _df)
43  {
44  BZPRECONDITION(_df > 0.0);
45  df = _df;
47  }
48 
49  T random()
50  {
51  return 2.0 * sgamma();
52  }
53 
54 protected:
55  T sgamma()
56  {
58  }
59 
60  T df;
61 };
62 
63 }
64 
65 #endif // BZ_RANDOM_CHISQUARE
Definition: beta.h:50
Definition: gamma.h:45
_bz_global blitz::IndexPlaceholder< 0 > i
Definition: indexexpr.h:256
T random()
Definition: chisquare.h:49
T T_numtype
Definition: chisquare.h:28
T sgamma()
Definition: chisquare.h:55
ChiSquare(T df, unsigned int i)
Definition: chisquare.h:36
MersenneTwister defaultIRNG
Definition: default.h:120
T df
Definition: chisquare.h:60
void setDF(T _df)
Definition: chisquare.h:42
T random()
Definition: gamma.h:113
void setMean(T mean)
Definition: gamma.h:74
sharedState defaultState
Definition: default.h:55
Definition: chisquare.h:25
ChiSquare(T df)
Definition: chisquare.h:30