bpp-core3  3.0.0
OptimizationStopCondition.h
Go to the documentation of this file.
1 //
2 // File: OptimizationStopCondition.h
3 // Authors:
4 // Julien Dutheil
5 // Created: 2003-12-23 11:51:31
6 //
7 
8 /*
9  Copyright or © or Copr. Bio++ Development Team, (November 19, 2004)
10 
11  This software is a computer program whose purpose is to provide classes
12  for numerical calculus.
13 
14  This software is governed by the CeCILL license under French law and
15  abiding by the rules of distribution of free software. You can use,
16  modify and/ or redistribute the software under the terms of the CeCILL
17  license as circulated by CEA, CNRS and INRIA at the following URL
18  "http://www.cecill.info".
19 
20  As a counterpart to the access to the source code and rights to copy,
21  modify and redistribute granted by the license, users are provided only
22  with a limited warranty and the software's author, the holder of the
23  economic rights, and the successive licensors have only limited
24  liability.
25 
26  In this respect, the user's attention is drawn to the risks associated
27  with loading, using, modifying and/or developing or reproducing the
28  software by the user in light of its specific status of free software,
29  that may mean that it is complicated to manipulate, and that also
30  therefore means that it is reserved for developers and experienced
31  professionals having in-depth computer knowledge. Users are therefore
32  encouraged to load and test the software's suitability as regards their
33  requirements in conditions enabling the security of their systems and/or
34  data to be ensured and, more generally, to use and operate it in the
35  same conditions as regards security.
36 
37  The fact that you are presently reading this means that you have had
38  knowledge of the CeCILL license and that you accept its terms.
39 */
40 
41 #ifndef BPP_NUMERIC_FUNCTION_OPTIMIZATIONSTOPCONDITION_H
42 #define BPP_NUMERIC_FUNCTION_OPTIMIZATIONSTOPCONDITION_H
43 
44 
45 #include "../ParameterList.h"
46 
47 using namespace std;
48 
49 namespace bpp
50 {
51 class Optimizer;
52 
53 /******************************************************************************/
54 
69  public virtual Clonable
70 {
71 public:
74 
76 
77 public:
81  virtual const Optimizer* getOptimizer() const = 0;
87  virtual void setOptimizer(const Optimizer* optimizer) = 0;
88 
92  virtual void init() = 0;
93 
103  virtual bool isToleranceReached() const = 0;
104 
110  virtual void setTolerance(double tolerance) = 0;
111 
117  virtual double getTolerance() const = 0;
118 
127  virtual double getCurrentTolerance() const = 0;
128 };
129 
130 /******************************************************************************/
131 
142  public virtual OptimizationStopCondition
143 {
144 protected:
146  double tolerance_;
147 
152  mutable double callCount_;
153 
154  int burnin_;
155 
156 public:
158  optimizer_(optimizer),
159  tolerance_(0.000001),
160  callCount_(0),
161  burnin_(0) {}
162 
163  AbstractOptimizationStopCondition(const Optimizer* optimizer, double tolerance) :
164  optimizer_(optimizer),
165  tolerance_(tolerance),
166  callCount_(0),
167  burnin_(0) {}
168 
169  AbstractOptimizationStopCondition(const Optimizer* optimizer, int burnin) :
170  optimizer_(optimizer),
171  tolerance_(0.000001),
172  callCount_(0),
173  burnin_(burnin) {}
174 
175  AbstractOptimizationStopCondition(const Optimizer* optimizer, double tolerance, int burnin) :
176  optimizer_(optimizer),
177  tolerance_(tolerance),
178  callCount_(0),
179  burnin_(burnin) {}
180 
182  optimizer_(aosc.optimizer_),
183  tolerance_(aosc.tolerance_),
184  callCount_(aosc.callCount_),
185  burnin_(aosc.burnin_) {}
186 
188  {
189  optimizer_ = aosc.optimizer_;
190  tolerance_ = aosc.tolerance_;
191  callCount_ = aosc.callCount_;
192  burnin_ = aosc.burnin_;
193  return *this;
194  }
195 
197 
198 public:
199  const Optimizer* getOptimizer() const { return optimizer_; }
200  void setOptimizer(const Optimizer* optimizer) { optimizer_ = optimizer; }
201  void setTolerance(double tolerance) { tolerance_ = tolerance; }
202  double getTolerance() const { return tolerance_; }
203  void init() { resetCounter(); }
204  virtual void resetCounter() { callCount_ = 0; }
205  virtual void setBurnin(int burnin) { burnin_ = burnin; }
206  virtual int getBurnin() const { return burnin_; }
207 };
208 
209 /******************************************************************************/
210 
220 {
221 private:
228 
235 
236 public:
237  ParametersStopCondition(const Optimizer* optimizer);
238  ParametersStopCondition(const Optimizer* optimizer, double tolerance);
239  ParametersStopCondition(const Optimizer* optimizer, int burnin);
240  ParametersStopCondition(const Optimizer* optimizer, double tolerance, int burnin);
241 
243 
244  ParametersStopCondition* clone() const { return new ParametersStopCondition(*this); }
245 
246 public:
247  void init();
248 
249  bool isToleranceReached() const;
250 
251  double getCurrentTolerance() const;
252 };
253 
254 /******************************************************************************/
255 
265 {
266 private:
272  mutable double lastFunctionValue_;
273 
279  mutable double newFunctionValue_;
280 
281 public:
282  FunctionStopCondition(const Optimizer* optimizer);
283  FunctionStopCondition(const Optimizer* optimizer, double tolerance);
284  FunctionStopCondition(const Optimizer* optimizer, int burnin);
285  FunctionStopCondition(const Optimizer* optimizer, double tolerance, int burnin);
286 
287  virtual ~FunctionStopCondition();
288 
289  FunctionStopCondition* clone() const { return new FunctionStopCondition(*this); }
290 
291 public:
292  void init();
293  bool isToleranceReached() const;
294  double getCurrentTolerance() const;
295 };
296 } // end of namespace bpp.
297 #endif // BPP_NUMERIC_FUNCTION_OPTIMIZATIONSTOPCONDITION_H
Partial implementation of the OptimizationStopCondition interface.
AbstractOptimizationStopCondition(const Optimizer *optimizer)
double callCount_
Count the number of times the isToleranceReached() function has been called.
AbstractOptimizationStopCondition(const AbstractOptimizationStopCondition &aosc)
AbstractOptimizationStopCondition & operator=(const AbstractOptimizationStopCondition &aosc)
AbstractOptimizationStopCondition(const Optimizer *optimizer, double tolerance, int burnin)
void setTolerance(double tolerance)
Set the tolerance parameter.
double getTolerance() const
Get the tolerance parameter.
AbstractOptimizationStopCondition(const Optimizer *optimizer, int burnin)
AbstractOptimizationStopCondition(const Optimizer *optimizer, double tolerance)
void setOptimizer(const Optimizer *optimizer)
Set the optimizer attached to this instance.
The Clonable interface (allow an object to be cloned).
Definition: Clonable.h:103
Stop condition on function value.
FunctionStopCondition * clone() const
Create a copy of this object and send a pointer to it.
double lastFunctionValue_
The last value of the function.
double newFunctionValue_
The new value of the function.
Interface for otimization stop condition objet.
virtual double getCurrentTolerance() const =0
Get the current tolerance.
OptimizationStopCondition * clone() const =0
Create a copy of this object and send a pointer to it.
virtual bool isToleranceReached() const =0
Tell if the we reached the desired tolerance with a given new set of estimates.
virtual void setOptimizer(const Optimizer *optimizer)=0
Set the optimizer attached to this instance.
virtual void setTolerance(double tolerance)=0
Set the tolerance parameter.
virtual double getTolerance() const =0
Get the tolerance parameter.
virtual void init()=0
Initialize the condition.
virtual const Optimizer * getOptimizer() const =0
This is the basal interface for all optimization methods.
Definition: Optimizer.h:119
The parameter list object.
Definition: ParameterList.h:65
Stop condition on parameters.
ParameterList lastParametersEstimates_
The last estimates of the parameters.
ParametersStopCondition * clone() const
Create a copy of this object and send a pointer to it.
ParameterList newParametersEstimates_
The new estimates of the parameters.