aGrUM  0.13.2
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 <cmath>
37 
38 #include <agrum/agrum.h>
41 #include <agrum/core/timer.h>
42 
43 namespace gum {
44 
107  public:
108  // ========================================================================
110  // ========================================================================
112 
113  ApproximationScheme(bool v = false);
114 
115  virtual ~ApproximationScheme();
116 
118  // ========================================================================
120  // ========================================================================
122 
132  void setEpsilon(double eps);
133 
138  double epsilon() const;
139 
143  void disableEpsilon();
144 
148  void enableEpsilon();
149 
156  bool isEnabledEpsilon() const;
157 
167  void setMinEpsilonRate(double rate);
168 
173  double minEpsilonRate() const;
174 
178  void disableMinEpsilonRate();
179 
183  void enableMinEpsilonRate();
184 
191  bool isEnabledMinEpsilonRate() const;
192 
201  void setMaxIter(Size max);
202 
207  Size maxIter() const;
208 
212  void disableMaxIter();
213 
217  void enableMaxIter();
218 
225  bool isEnabledMaxIter() const;
226 
235  void setMaxTime(double timeout);
236 
241  double maxTime() const;
242 
247  double currentTime() const;
248 
253  void disableMaxTime();
254 
258  void enableMaxTime();
259 
266  bool isEnabledMaxTime() const;
267 
273  void setPeriodSize(Size p);
274 
279  Size periodSize() const;
280 
285  void setVerbosity(bool v);
286 
291  bool verbosity() const;
292 
298 
304  Size nbrIterations() const;
305 
312  const std::vector< double >& history() const;
313 
318 
325  bool startOfPeriod();
326 
331  void updateApproximationScheme(unsigned int incr = 1);
332 
338 
343 
354  bool continueApproximationScheme(double error);
355 
356 
358 
359  private:
364  void _stopScheme(ApproximationSchemeSTATE new_state);
365 
366  protected:
369 
372 
375 
378 
381 
384 
386  std::vector< double > _history;
387 
389  double _eps;
390 
393 
396 
399 
401  double _max_time;
402 
405 
408 
411 
414 
417 
420  };
421 } // namespace gum
422 
423 #ifndef GUM_NO_INLINE
425 #endif
426 
427 #endif // GUM_APPROXIMATION_SCHEME_H
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
ApproximationSchemeSTATE stateApproximationScheme() const
Returns the approximation scheme state.
bool isEnabledMinEpsilonRate() const
Returns true if stopping criterion on epsilon rate is enabled, false otherwise.
bool verbosity() const
Returns true if verbosity is enabled.
void disableMinEpsilonRate()
Disable stopping criterion on epsilon rate.
bool _enabled_max_iter
If true, the maximum iterations stopping criterion is enabled.
bool _enabled_eps
If true, the threshold convergence is enabled.
double minEpsilonRate() const
Returns the value of the minimal epsilon rate.
Approximation Scheme.
void enableMinEpsilonRate()
Enable stopping criterion on epsilon rate.
double currentTime() const
Returns the current running time in second.
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 isEnabledMaxTime() const
Returns true if stopping criterion on timeout is enabled, false otherwise.
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)|).
const std::vector< double > & history() const
Returns the scheme history.
void setVerbosity(bool v)
Set the verbosity on (true) or off (false).
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.
double _eps
Threshold for convergence.
double _current_rate
Current rate.
bool continueApproximationScheme(double error)
Update the scheme w.r.t the new error.
double maxTime() const
Returns the timeout (in seconds).
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.
Size periodSize() const
Returns the period size.
void stopApproximationScheme()
Stop the approximation scheme.
Size _current_step
The current step.
std::vector< double > _history
The scheme history, used only if verbosity == true.
Size _period_size
Checking criteria frequency.
bool isEnabledEpsilon() const
Returns true if stopping criterion on epsilon is enabled, false otherwise.
double _min_rate_eps
Threshold for the epsilon rate.
bool isEnabledMaxIter() const
Returns true if stopping criterion on max iterations is enabled, false otherwise. ...
double epsilon() const
Returns the value of epsilon.
void setMaxIter(Size max)
Stopping criterion on number of iterations.
Inline implementatioh of gum::ApproximationSettings.
bool _verbosity
If true, verbosity is enabled.
double _last_epsilon
Last epsilon value.
void setEpsilon(double eps)
Given that we approximate f(t), stopping criterion on |f(t+1)-f(t)|.
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
Size maxIter() const
Returns the criterion on number of iterations.
ApproximationSchemeSTATE
The different state of an approximation scheme.
Size nbrIterations() const
Returns the number of iterations.
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.