aGrUM  0.16.0
approximationScheme.h
Go to the documentation of this file.
1 
35 #ifndef GUM_APPROXIMATION_SCHEME_H
36 #define GUM_APPROXIMATION_SCHEME_H
37 
38 #include <agrum/agrum.h>
39 #include <agrum/core/math/math.h>
42 #include <agrum/core/timer.h>
43 
44 namespace gum {
45 
108  public:
109  // ========================================================================
111  // ========================================================================
113 
114  ApproximationScheme(bool verbosity = false);
115 
116  virtual ~ApproximationScheme();
117 
119  // ========================================================================
121  // ========================================================================
123 
133  void setEpsilon(double eps);
134 
139  double epsilon() const;
140 
144  void disableEpsilon();
145 
149  void enableEpsilon();
150 
157  bool isEnabledEpsilon() const;
158 
168  void setMinEpsilonRate(double rate);
169 
174  double minEpsilonRate() const;
175 
179  void disableMinEpsilonRate();
180 
184  void enableMinEpsilonRate();
185 
192  bool isEnabledMinEpsilonRate() const;
193 
202  void setMaxIter(Size max);
203 
208  Size maxIter() const;
209 
213  void disableMaxIter();
214 
218  void enableMaxIter();
219 
226  bool isEnabledMaxIter() const;
227 
236  void setMaxTime(double timeout);
237 
242  double maxTime() const;
243 
248  double currentTime() const;
249 
254  void disableMaxTime();
255 
259  void enableMaxTime();
260 
267  bool isEnabledMaxTime() const;
268 
274  void setPeriodSize(Size p);
275 
280  Size periodSize() const;
281 
286  void setVerbosity(bool v);
287 
292  bool verbosity() const;
293 
299 
305  Size nbrIterations() const;
306 
313  const std::vector< double >& history() const;
314 
319 
326  bool startOfPeriod();
327 
332  void updateApproximationScheme(unsigned int incr = 1);
333 
339 
344 
355  bool continueApproximationScheme(double error);
356 
357 
359 
360  private:
365  void _stopScheme(ApproximationSchemeSTATE new_state);
366 
367  protected:
370 
373 
376 
379 
382 
385 
387  std::vector< double > _history;
388 
390  double _eps;
391 
394 
397 
400 
402  double _max_time;
403 
406 
409 
412 
415 
418 
421  };
422 } // namespace gum
423 
424 #ifndef GUM_NO_INLINE
426 #endif
427 
428 #endif // GUM_APPROXIMATION_SCHEME_H
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
double minEpsilonRate() const
Returns the value of the minimal epsilon rate.
void disableMinEpsilonRate()
Disable stopping criterion on epsilon rate.
bool _enabled_max_iter
If true, the maximum iterations stopping criterion is enabled.
double maxTime() const
Returns the timeout (in seconds).
bool _enabled_eps
If true, the threshold convergence is enabled.
Approximation Scheme.
void enableMinEpsilonRate()
Enable stopping criterion on epsilon rate.
void _stopScheme(ApproximationSchemeSTATE new_state)
Stop the scheme given a new state.
void setPeriodSize(Size p)
How many samples between two stopping is enable.
Size remainingBurnIn()
Returns the remaining burn in.
double _current_epsilon
Current epsilon.
bool _enabled_min_rate_eps
If true, the minimal threshold for epsilon rate is enabled.
bool startOfPeriod()
Returns true if we are at the beginning of a period (compute error is mandatory). ...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void initApproximationScheme()
Initialise the scheme.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
void setMinEpsilonRate(double rate)
Given that we approximate f(t), stopping criterion on d/dt(|f(t+1)-f(t)|).
void setVerbosity(bool v)
Set the verbosity on (true) or off (false).
ApproximationScheme(bool verbosity=false)
Size periodSize() const
Returns the period size.
void setMaxTime(double timeout)
Stopping criterion on timeout.
Size _burn_in
Number of iterations before checking stopping criteria.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void disableEpsilon()
Disable stopping criterion on epsilon.
Size nbrIterations() const
Returns the number of iterations.
double _eps
Threshold for convergence.
double _current_rate
Current rate.
bool continueApproximationScheme(double error)
Update the scheme w.r.t the new error.
bool isEnabledMinEpsilonRate() const
Returns true if stopping criterion on epsilon rate is enabled, false otherwise.
bool _enabled_max_time
If true, the timeout is enabled.
void disableMaxTime()
Disable stopping criterion on timeout.
void enableMaxIter()
Enable stopping criterion on max iterations.
void stopApproximationScheme()
Stop the approximation scheme.
Size maxIter() const
Returns the criterion on number of iterations.
Size _current_step
The current step.
std::vector< double > _history
The scheme history, used only if verbosity == true.
Size _period_size
Checking criteria frequency.
double _min_rate_eps
Threshold for the epsilon rate.
const std::vector< double > & history() const
Returns the scheme history.
ApproximationSchemeSTATE stateApproximationScheme() const
Returns the approximation scheme state.
void setMaxIter(Size max)
Stopping criterion on number of iterations.
bool isEnabledMaxIter() const
Returns true if stopping criterion on max iterations is enabled, false otherwise. ...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
bool _verbosity
If true, verbosity is enabled.
bool verbosity() const
Returns true if verbosity is enabled.
double epsilon() const
Returns the value of epsilon.
double _last_epsilon
Last epsilon value.
bool isEnabledEpsilon() const
Returns true if stopping criterion on epsilon is enabled, false otherwise.
bool isEnabledMaxTime() const
Returns true if stopping criterion on timeout is enabled, false otherwise.
void setEpsilon(double eps)
Given that we approximate f(t), stopping criterion on |f(t+1)-f(t)|.
double currentTime() const
Returns the current running time in second.
void disableMaxIter()
Disable stopping criterion on max iterations.
Class used to compute response times for benchmark purposesThis class represents a classic timer...
Definition: timer.h:51
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
ApproximationSchemeSTATE
The different state of an approximation scheme.
Size _max_iter
The maximum iterations.
ApproximationSchemeSTATE _current_state
The current state.
double _max_time
The timeout.
void enableMaxTime()
Enable stopping criterion on timeout.
void updateApproximationScheme(unsigned int incr=1)
Update the scheme w.r.t the new error and increment steps.
void enableEpsilon()
Enable stopping criterion on epsilon.