random_utils.h
Go to the documentation of this file.
1 #ifndef SLAM_CTOR_CORE_RANDOM_UTILS_H
2 #define SLAM_CTOR_CORE_RANDOM_UTILS_H
3 
4 #include <random>
5 
6 // Random variables
7 
8 template<typename T>
10 public:
11  virtual double sample(T& rnd_engine) = 0;
12  virtual std::unique_ptr<RandomVariable1D<T>> clone() const = 0;
13  virtual ~RandomVariable1D() {}
14 };
15 
16 template <typename Engine>
17 class GaussianRV1D : public RandomVariable1D<Engine> {
18 public:
19  GaussianRV1D(double mean, double stddev)
20  : _mean{mean}, _stddev{stddev}, _distr{_mean, _stddev} {}
21 
22  double sample(Engine &rnd_engine) override {
23  return _distr(rnd_engine);
24  }
25 
26  std::unique_ptr<RandomVariable1D<Engine>> clone() const override {
27  return std::make_unique<GaussianRV1D<Engine>>(_mean, _stddev);
28  }
29 
30 private:
31  double _mean;
32  double _stddev;
33  std::normal_distribution<> _distr;
34 };
35 
36 template <typename Engine>
37 class UniformRV1D : public RandomVariable1D<Engine> {
38 public:
39  UniformRV1D(double from, double to)
40  : _from{from}, _to{to}, _distr{_from, _to} {}
41 
42  double sample(Engine &rnd_engine) override {
43  return _distr(rnd_engine);
44  }
45 
46  std::unique_ptr<RandomVariable1D<Engine>> clone() const override {
47  return std::make_unique<UniformRV1D<Engine>>(_from, _to);
48  }
49 
50 private:
51  double _from;
52  double _to;
53  std::uniform_real_distribution<> _distr;
54 };
55 
56 #endif
double _from
Definition: random_utils.h:51
std::unique_ptr< RandomVariable1D< Engine > > clone() const override
Definition: random_utils.h:26
std::uniform_real_distribution _distr
Definition: random_utils.h:53
double _mean
Definition: random_utils.h:31
GaussianRV1D(double mean, double stddev)
Definition: random_utils.h:19
UniformRV1D(double from, double to)
Definition: random_utils.h:39
std::unique_ptr< RandomVariable1D< Engine > > clone() const override
Definition: random_utils.h:46
virtual std::unique_ptr< RandomVariable1D< T > > clone() const =0
double sample(Engine &rnd_engine) override
Definition: random_utils.h:42
std::normal_distribution _distr
Definition: random_utils.h:33
virtual double sample(T &rnd_engine)=0
double _stddev
Definition: random_utils.h:32
double _to
Definition: random_utils.h:52
virtual ~RandomVariable1D()
Definition: random_utils.h:13
double sample(Engine &rnd_engine) override
Definition: random_utils.h:22


slam_constructor
Author(s): JetBrains Research, OSLL team
autogenerated on Mon Jun 10 2019 15:08:25