Pakman
ABCSMCController.h
1 #ifndef ABCSMCCONTROLLER_H
2 #define ABCSMCCONTROLLER_H
3 
4 #include <string>
5 #include <vector>
6 #include <queue>
7 #include <memory>
8 #include <random>
9 #include <chrono>
10 
11 #include "core/Command.h"
12 
13 #include "AbstractController.h"
14 
15 class LongOptions;
16 class Arguments;
17 
36 {
37  public:
38 
39  // Forward declaration of Input
40  struct Input;
41 
50  ABCSMCController(const Input &input_obj);
51 
53  virtual ~ABCSMCController() override = default;
54 
56  virtual void iterate() override;
57 
59  virtual Command getSimulator() const override;
60 
62  static std::string help();
63 
69  static void addLongOptions(LongOptions& lopts);
70 
77  static ABCSMCController* makeController(const Arguments& args);
78 
81  struct Input
82  {
89  static Input makeInput(const Arguments& args);
90 
93 
95  std::vector<Epsilon> epsilons;
96 
99 
101  std::vector<ParameterName> parameter_names;
102 
105 
108 
111 
116 
118  unsigned long seed =
119  std::chrono::system_clock::now().time_since_epoch().count();
120  };
121 
122  private:
123 
125  // Sample parameter
126  Parameter sampleParameter();
127 
129  // Epsilons
130  std::vector<Epsilon> m_epsilons;
131 
132  // Iteration counter
133  int m_t = 0;
134 
135  // Perturbation pdf for weights calculation
136  Command m_perturbation_pdf;
137 
138  // Parameter names
139  std::vector<ParameterName> m_parameter_names;
140 
141  // Population size
142  int m_population_size;
143 
144  // New accepted parameters
145  std::vector<Parameter> m_prmtr_accepted_new;
146 
147  // New weights
148  std::vector<double> m_weights_new;
149 
150  // Number of parameters simulated
151  int m_number_simulated = 0;
152 
153  // Simulator command
154  Command m_simulator;
155 
156  // Prior pdf values for accepted parameters
157  std::vector<double> m_prior_pdf_accepted;
158 
159  // Uniform distribution for sampling from population
160  std::uniform_real_distribution<double> m_distribution;
161 
162  // Random number generator
163  std::mt19937_64 m_generator;
164 
165  // Prior pdf values of pending parameters
166  std::queue<double> m_prior_pdf_pending;
167 
168  // Parameters accepted in previous generation
169  std::vector<Parameter> m_prmtr_accepted_old;
170 
171  // Weights of parameters accepted in previous generation
172  std::vector<double> m_weights_old;
173 
174  // Cumulative sum of weights
175  std::vector<double> m_weights_cumsum;
176 
177  // Prior sampler command
178  Command m_prior_sampler;
179 
180  // Perturber command
181  Command m_perturber;
182 
183  // Prior_pdf command
184  Command m_prior_pdf;
185 
186  // First iteration
187  bool m_first = true;
188 
189  // Entered iterate()
190  bool m_entered = false;
191 };
192 
193 #endif // ABCSMCCONTROLLER_H
virtual Command getSimulator() const override
static ABCSMCController * makeController(const Arguments &args)
ABCSMCController(const Input &input_obj)
std::vector< ParameterName > parameter_names
static void addLongOptions(LongOptions &lopts)
std::vector< Epsilon > epsilons
virtual void iterate() override
static Input makeInput(const Arguments &args)
virtual ~ABCSMCController() override=default
static std::string help()