bpp-core  2.2.0
OptimizationStopCondition.h
Go to the documentation of this file.
1 //
2 // File: OptimizationStopCondition.h
3 // Created by: Julien Dutheil
4 // Created on: Tue Dec 23 11:51:31 2003
5 //
6 
7 /*
8  Copyright or © or Copr. Bio++ Development Team, (November 19, 2004)
9 
10  This software is a computer program whose purpose is to provide classes
11  for numerical calculus.
12 
13  This software is governed by the CeCILL license under French law and
14  abiding by the rules of distribution of free software. You can use,
15  modify and/ or redistribute the software under the terms of the CeCILL
16  license as circulated by CEA, CNRS and INRIA at the following URL
17  "http://www.cecill.info".
18 
19  As a counterpart to the access to the source code and rights to copy,
20  modify and redistribute granted by the license, users are provided only
21  with a limited warranty and the software's author, the holder of the
22  economic rights, and the successive licensors have only limited
23  liability.
24 
25  In this respect, the user's attention is drawn to the risks associated
26  with loading, using, modifying and/or developing or reproducing the
27  software by the user in light of its specific status of free software,
28  that may mean that it is complicated to manipulate, and that also
29  therefore means that it is reserved for developers and experienced
30  professionals having in-depth computer knowledge. Users are therefore
31  encouraged to load and test the software's suitability as regards their
32  requirements in conditions enabling the security of their systems and/or
33  data to be ensured and, more generally, to use and operate it in the
34  same conditions as regards security.
35 
36  The fact that you are presently reading this means that you have had
37  knowledge of the CeCILL license and that you accept its terms.
38 */
39 
40 #ifndef _OPTIMIZATIONSTOPCONDITION_H_
41 #define _OPTIMIZATIONSTOPCONDITION_H_
42 
43 #include "../ParameterList.h"
44 
45 using namespace std;
46 
47 namespace bpp
48 {
49 
50  class Optimizer;
51 
52  /******************************************************************************/
53 
68  public virtual Clonable
69  {
70  public:
73 
74 #ifndef NO_VIRTUAL_COV
76 #else
77  Clonable*
78 #endif
79  clone() const = 0;
80 
81  public:
82 
86  virtual const Optimizer* getOptimizer() const = 0;
92  virtual void setOptimizer(const Optimizer* optimizer) = 0;
93 
97  virtual void init() = 0;
98 
108  virtual bool isToleranceReached() const = 0;
109 
115  virtual void setTolerance(double tolerance) = 0;
116 
122  virtual double getTolerance() const = 0;
123 
132  virtual double getCurrentTolerance() const = 0;
133  };
134 
135  /******************************************************************************/
136 
147  public virtual OptimizationStopCondition
148  {
149  protected:
151  double tolerance_;
152 
157  mutable double callCount_;
158 
159  int burnin_;
160 
161  public:
163  optimizer_(optimizer),
164  tolerance_(0.000001),
165  callCount_(0),
166  burnin_(0) {}
167 
168  AbstractOptimizationStopCondition(const Optimizer* optimizer, double tolerance):
169  optimizer_(optimizer),
170  tolerance_(tolerance),
171  callCount_(0),
172  burnin_(0) {}
173 
174  AbstractOptimizationStopCondition(const Optimizer* optimizer, int burnin):
175  optimizer_(optimizer),
176  tolerance_(0.000001),
177  callCount_(0),
178  burnin_(burnin) {}
179 
180  AbstractOptimizationStopCondition(const Optimizer* optimizer, double tolerance, int burnin):
181  optimizer_(optimizer),
182  tolerance_(tolerance),
183  callCount_(0),
184  burnin_(burnin) {}
185 
187  optimizer_(aosc.optimizer_),
188  tolerance_(aosc.tolerance_),
189  callCount_(aosc.callCount_),
190  burnin_(aosc.burnin_) {}
191 
193  {
194  optimizer_ = aosc.optimizer_;
195  tolerance_ = aosc.tolerance_;
196  callCount_ = aosc.callCount_;
197  burnin_ = aosc.burnin_;
198  return *this;
199  }
200 
202 
203  public:
204  const Optimizer* getOptimizer() const { return optimizer_; }
205  void setOptimizer(const Optimizer* optimizer) { optimizer_ = optimizer; }
206  void setTolerance(double tolerance) { tolerance_ = tolerance; }
207  double getTolerance() const { return tolerance_; }
208  void init() { resetCounter(); }
209  virtual void resetCounter() { callCount_ = 0; }
210  virtual void setBurnin(int burnin) { burnin_ = burnin; }
211  virtual int getBurnin() const { return burnin_; }
212 
213  };
214 
215  /******************************************************************************/
216 
226  {
227  private:
228 
235 
242 
243  public:
244  ParametersStopCondition(const Optimizer* optimizer);
245  ParametersStopCondition(const Optimizer* optimizer, double tolerance);
246  ParametersStopCondition(const Optimizer* optimizer, int burnin);
247  ParametersStopCondition(const Optimizer* optimizer, double tolerance, int burnin);
248 
250 
251  ParametersStopCondition* clone() const { return new ParametersStopCondition(*this); }
252 
253  public:
254  void init();
255 
256  bool isToleranceReached() const;
257 
258  double getCurrentTolerance() const;
259  };
260 
261  /******************************************************************************/
262 
272  {
273  private:
279  mutable double lastFunctionValue_;
280 
286  mutable double newFunctionValue_;
287 
288  public:
289  FunctionStopCondition(const Optimizer* optimizer);
290  FunctionStopCondition(const Optimizer* optimizer, double tolerance);
291  FunctionStopCondition(const Optimizer* optimizer, int burnin);
292  FunctionStopCondition(const Optimizer* optimizer, double tolerance, int burnin);
293 
294  virtual ~FunctionStopCondition();
295 
296 #ifndef NO_VIRTUAL_COV
298 #else
299  Clonable*
300 #endif
301  clone() const { return new FunctionStopCondition(*this); }
302 
303  public:
304  void init();
305  bool isToleranceReached() const;
306  double getCurrentTolerance() const;
307 
308  };
309 
310 } //end of namespace bpp.
311 
312 #endif //_OPTIMIZATIONSTOPCONDITION_H_
313 
ParameterList newParametersEstimates_
The new estimates of the parameters.
AbstractOptimizationStopCondition(const Optimizer *optimizer, double tolerance, int burnin)
double lastFunctionValue_
The last value of the function.
double getTolerance() const
Get the tolerance parameter.
This class allows to perform a correspondence analysis.
Interface for otimization stop condition objet.
ParameterList lastParametersEstimates_
The last estimates of the parameters.
STL namespace.
Stop condition on function value.
AbstractOptimizationStopCondition(const Optimizer *optimizer)
AbstractOptimizationStopCondition(const Optimizer *optimizer, double tolerance)
The parameter list object.
Definition: ParameterList.h:61
void setTolerance(double tolerance)
Set the tolerance parameter.
AbstractOptimizationStopCondition & operator=(const AbstractOptimizationStopCondition &aosc)
double newFunctionValue_
The new value of the function.
AbstractOptimizationStopCondition(const Optimizer *optimizer, int burnin)
ParametersStopCondition * clone() const
Create a copy of this object and send a pointer to it.
AbstractOptimizationStopCondition(const AbstractOptimizationStopCondition &aosc)
The Clonable interface (allow an object to be cloned).
Definition: Clonable.h:99
void setOptimizer(const Optimizer *optimizer)
Set the optimizer attached to this instance.
double callCount_
Count the number of times the isToleranceReached() function has been called.
Stop condition on parameters.
Partial implementation of the OptimizationStopCondition interface.
FunctionStopCondition * clone() const
Create a copy of this object and send a pointer to it.
This is the basal interface for all optimization methods.
Definition: Optimizer.h:125