MUQ  0.4.3
RandomGenerator.h
Go to the documentation of this file.
1 
2 #ifndef _RandomGenerator_h
3 #define _RandomGenerator_h
4 
5 #include <random>
6 
7 #include <Eigen/Core>
8 #include <array>
9 #include <mutex>
10 
11 
12 namespace muq {
13 namespace Utilities {
14 
20 {
21 public:
23 
25 private:
26  std::mt19937 oldGenerator;
27 };
28 
29 
30 
35 public:
36 
37  typedef std::mt19937 GeneratorType;
38 
40  static double GetNormal();
41  static Eigen::MatrixXd GetNormal(int rows){return GetNormal(rows,1);};
42  static Eigen::MatrixXd GetNormal(int rows, int cols);
43 
45  static double GetUniform();
46  static Eigen::MatrixXd GetUniform(int rows){return GetUniform(rows,1);};
47  static Eigen::MatrixXd GetUniform(int rows, int cols);
48 
49  static double GetGamma(double const alpha, double const beta);
50  static Eigen::MatrixXd GetGamma(double const alpha, double const beta, int rows){return GetGamma(alpha, beta, rows, 1);};
51  static Eigen::MatrixXd GetGamma(double const alpha, double const beta, int rows, int cols);
52 
54  static int GetUniformInt(int lb, int ub);
55  static Eigen::MatrixXi GetUniformInt(int lb, int ub, int rows){return GetUniformInt(lb, ub, rows, 1, true);};
56  static Eigen::MatrixXi GetUniformInt(int lb, int ub, int rows, bool unique){return GetUniformInt(lb, ub, rows, 1, unique);};
57  static Eigen::MatrixXi GetUniformInt(int lb, int ub, int rows, int cols){return GetUniformInt(lb, ub, rows, cols, true);};
58  static Eigen::MatrixXi GetUniformInt(int lb, int ub, int rows, int cols, bool unique);
59 
60 
62  static int GetDiscrete(std::vector<double> const& discProbs);
63  static int GetDiscrete(Eigen::Ref<const Eigen::VectorXd> const& discProbs);
64 
65  static Eigen::MatrixXi GetDiscrete(std::vector<double> const& discProbs, int rows, int cols=1);
66  static Eigen::MatrixXi GetDiscrete(Eigen::Ref<const Eigen::VectorXd> const& discProbs, int rows, int cols=1);
67 
69  static void SetSeed(int seedval);
70 
73 
75  static void SetGenerator(GeneratorType);
76 
77 private:
78 
80  static GeneratorType & GetGenerator();
81 };
82 
83 
85 public:
86 
87  SeedGenerator();
88  SeedGenerator(const std::array<std::seed_seq::result_type, RandomGenerator::GeneratorType::state_size> &seed_data);
89  //draw a seed for the entire state, as per: http://stackoverflow.com/questions/15509270/does-stdmt19937-require-warmup
90  std::seed_seq seed_seq;
91  //virtual ~SeedGenerator() = default;
92 };
93 
94 
95 
96 } // namespace GeneralUtilties
97 } //namespace muq
98 
99 #endif // ifndef _RandomGenerator_h
static Eigen::MatrixXd GetUniform(int rows)
static int GetDiscrete(std::vector< double > const &discProbs)
static Eigen::MatrixXi GetUniformInt(int lb, int ub, int rows, bool unique)
static Eigen::MatrixXi GetUniformInt(int lb, int ub, int rows, int cols)
static Eigen::MatrixXd GetNormal(int rows)
static void SetGenerator(GeneratorType)
Set the state of the generator, designed for use with CopyGenerator. Be very careful in using this,...
static GeneratorType & GetGenerator()
static GeneratorType CopyGenerator()
Store a copy of the generator, designed for use with SetGenerator. Be very careful in using this,...
static void SetSeed(int seedval)
Set the seed for the random number generator. This is a fairly low quality way to do this,...
static double GetGamma(double const alpha, double const beta)
static int GetUniformInt(int lb, int ub)
static Eigen::MatrixXd GetGamma(double const alpha, double const beta, int rows)
static Eigen::MatrixXi GetUniformInt(int lb, int ub, int rows)
SeedGenerator(const std::array< std::seed_seq::result_type, RandomGenerator::GeneratorType::state_size > &seed_data)