npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
SobolGenerator.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_SOBOLGENERATOR_HH_
2 #define NPSTAT_SOBOLGENERATOR_HH_
3 
4 /*!
5 // \file SobolGenerator.hh
6 //
7 // \brief Generator of Sobol low-discrepancy sequences
8 //
9 // Author: I. Volobouev
10 //
11 // October 2010
12 */
13 
15 
16 namespace npstat {
17  /**
18  // Generator of Sobol sequences. Based on the "i8_sobol" function
19  // written by John Burkardt:
20  // http://people.sc.fsu.edu/~jburkardt/cpp_src/sobol/sobol.html
21  */
23  {
24  public:
25  /**
26  // Maximum number of dimensions and maximum number of points which
27  // can be generated by this code (the latter equals pow(2,LOG_MAX))
28  */
29  enum {
30  DIM_MAX = 1111,
31  LOG_MAX = 62
32  };
33 
34  /**
35  // Constructor arguments are as follows:
36  //
37  // dim -- dimensionality of the point set
38  //
39  // maxPowerOfTwo -- maximum number of points which can be made
40  // by this generator will be 2^maxPowerOfTwo.
41  // maxPowerOfTwo must not be less than 2 and
42  // must not exceed LOG_MAX.
43  //
44  // nSkip -- number of events to skip at the beginning
45  // in order to "warm up" the generator.
46  // Reasonable values of this argument are
47  // 2^(maxPowerOfTwo-k), with some small k > 0.
48  */
49  explicit SobolGenerator(unsigned dim, unsigned maxPowerOfTwo=LOG_MAX,
50  unsigned nSkip=0U);
51  inline virtual ~SobolGenerator() {}
52 
53  inline virtual unsigned dim() const {return dim_num;}
54  virtual void run(double* buf, unsigned bufSize, unsigned nPoints);
55 
56  double operator()();
57  inline unsigned long long maxPoints() const {return 1ULL << maxcol;}
58 
59  protected:
60  void nextBitSet(long long* buf, unsigned bufSize);
61  inline unsigned maxPowerOfTwo() const {return maxcol;}
62 
63  private:
64  void update();
65 
66  double recipd_;
67  long long count;
68  long long lastq[DIM_MAX];
69  long long v[DIM_MAX][LOG_MAX];
70  unsigned dim_num;
71  unsigned maxcol;
72  };
73 }
74 
75 #endif // NPSTAT_SOBOLGENERATOR_HH_
Interface definition for pseudo- and quasi-random number generators.
Definition: SobolGenerator.hh:23
virtual void run(double *buf, unsigned bufSize, unsigned nPoints)
virtual unsigned dim() const
Definition: SobolGenerator.hh:53
unsigned long long maxPoints() const
Definition: SobolGenerator.hh:57
SobolGenerator(unsigned dim, unsigned maxPowerOfTwo=LOG_MAX, unsigned nSkip=0U)
Definition: AbsArrayProjector.hh:14
Definition: AbsRandomGenerator.hh:27