aGrUM  0.14.1
approximationScheme.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN et Christophe GONZALES *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
33 #ifndef GUM_APPROXIMATION_SCHEME_H
34 #define GUM_APPROXIMATION_SCHEME_H
35 
36 #include <agrum/agrum.h>
37 #include <agrum/core/math/math.h>
40 #include <agrum/core/timer.h>
41 
42 namespace gum {
43 
106  public:
107  // ========================================================================
109  // ========================================================================
111 
112  ApproximationScheme(bool v = false);
113 
114  virtual ~ApproximationScheme();
115 
117  // ========================================================================
119  // ========================================================================
121 
131  void setEpsilon(double eps);
132 
137  double epsilon() const;
138 
142  void disableEpsilon();
143 
147  void enableEpsilon();
148 
155  bool isEnabledEpsilon() const;
156 
166  void setMinEpsilonRate(double rate);
167 
172  double minEpsilonRate() const;
173 
177  void disableMinEpsilonRate();
178 
182  void enableMinEpsilonRate();
183 
190  bool isEnabledMinEpsilonRate() const;
191 
200  void setMaxIter(Size max);
201 
206  Size maxIter() const;
207 
211  void disableMaxIter();
212 
216  void enableMaxIter();
217 
224  bool isEnabledMaxIter() const;
225 
234  void setMaxTime(double timeout);
235 
240  double maxTime() const;
241 
246  double currentTime() const;
247 
252  void disableMaxTime();
253 
257  void enableMaxTime();
258 
265  bool isEnabledMaxTime() const;
266 
272  void setPeriodSize(Size p);
273 
278  Size periodSize() const;
279 
284  void setVerbosity(bool v);
285 
290  bool verbosity() const;
291 
297 
303  Size nbrIterations() const;
304 
311  const std::vector< double >& history() const;
312 
317 
324  bool startOfPeriod();
325 
330  void updateApproximationScheme(unsigned int incr = 1);
331 
337 
342 
353  bool continueApproximationScheme(double error);
354 
355 
357 
358  private:
363  void _stopScheme(ApproximationSchemeSTATE new_state);
364 
365  protected:
368 
371 
374 
377 
380 
383 
385  std::vector< double > _history;
386 
388  double _eps;
389 
392 
395 
398 
400  double _max_time;
401 
404 
407 
410 
413 
416 
419  };
420 } // namespace gum
421 
422 #ifndef GUM_NO_INLINE
424 #endif
425 
426 #endif // GUM_APPROXIMATION_SCHEME_H
Useful macros for maths.
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). ...
This file contains getters and setters defintion for ApproximationSchem settings. ...
void initApproximationScheme()
Initialise the scheme.
Class used to compute response times for benchmark purposes.
gum is the global namespace for all aGrUM entities
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).
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.
Classes of signaler.
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. ...
Inline implementatioh of gum::ApproximationSettings.
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:48
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
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.