bpp-core3  3.0.0
OptimizationStopCondition.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_NUMERIC_FUNCTION_OPTIMIZATIONSTOPCONDITION_H
6 #define BPP_NUMERIC_FUNCTION_OPTIMIZATIONSTOPCONDITION_H
7 
8 
9 #include "../ParameterList.h"
10 
11 using namespace std;
12 
13 namespace bpp
14 {
15 class OptimizerInterface;
16 
17 /******************************************************************************/
18 
33  public virtual Clonable
34 {
35 public:
38 
39  OptimizationStopCondition* clone() const = 0;
40 
41 public:
45  virtual const OptimizerInterface* getOptimizer() const = 0;
51  virtual void setOptimizer(const OptimizerInterface* optimizer) = 0;
52 
56  virtual void init() = 0;
57 
67  virtual bool isToleranceReached() const = 0;
68 
74  virtual void setTolerance(double tolerance) = 0;
75 
81  virtual double getTolerance() const = 0;
82 
91  virtual double getCurrentTolerance() const = 0;
92 };
93 
94 /******************************************************************************/
95 
106  public virtual OptimizationStopCondition
107 {
108 protected:
110  double tolerance_;
111 
116  mutable double callCount_;
117 
118  int burnin_;
119 
120 public:
122  optimizer_(optimizer),
123  tolerance_(0.000001),
124  callCount_(0),
125  burnin_(0) {}
126 
127  AbstractOptimizationStopCondition(const OptimizerInterface* optimizer, double tolerance) :
128  optimizer_(optimizer),
129  tolerance_(tolerance),
130  callCount_(0),
131  burnin_(0) {}
132 
134  optimizer_(optimizer),
135  tolerance_(0.000001),
136  callCount_(0),
137  burnin_(burnin) {}
138 
139  AbstractOptimizationStopCondition(const OptimizerInterface* optimizer, double tolerance, int burnin) :
140  optimizer_(optimizer),
141  tolerance_(tolerance),
142  callCount_(0),
143  burnin_(burnin) {}
144 
146  optimizer_(aosc.optimizer_),
147  tolerance_(aosc.tolerance_),
148  callCount_(aosc.callCount_),
149  burnin_(aosc.burnin_) {}
150 
152  {
153  optimizer_ = aosc.optimizer_;
154  tolerance_ = aosc.tolerance_;
155  callCount_ = aosc.callCount_;
156  burnin_ = aosc.burnin_;
157  return *this;
158  }
159 
161 
162 public:
163  const OptimizerInterface* getOptimizer() const { return optimizer_; }
164 
165  void setOptimizer(const OptimizerInterface* optimizer) { optimizer_ = optimizer; }
166 
167  void setTolerance(double tolerance) { tolerance_ = tolerance; }
168 
169  double getTolerance() const { return tolerance_; }
170 
171  void init() { resetCounter(); }
172 
173  virtual void resetCounter() { callCount_ = 0; }
174 
175  virtual void setBurnin(int burnin) { burnin_ = burnin; }
176 
177  virtual int getBurnin() const { return burnin_; }
178 };
179 
180 /******************************************************************************/
181 
191 {
192 private:
199 
206 
207 public:
209  ParametersStopCondition(const OptimizerInterface* optimizer, double tolerance);
210  ParametersStopCondition(const OptimizerInterface* optimizer, int burnin);
211  ParametersStopCondition(const OptimizerInterface* optimizer, double tolerance, int burnin);
212 
214 
215  ParametersStopCondition* clone() const { return new ParametersStopCondition(*this); }
216 
217 public:
218  void init();
219 
220  bool isToleranceReached() const;
221 
222  double getCurrentTolerance() const;
223 };
224 
225 /******************************************************************************/
226 
236 {
237 private:
243  mutable double lastFunctionValue_;
244 
250  mutable double newFunctionValue_;
251 
252 public:
253  FunctionStopCondition(const OptimizerInterface* optimizer);
254  FunctionStopCondition(const OptimizerInterface* optimizer, double tolerance);
255  FunctionStopCondition(const OptimizerInterface* optimizer, int burnin);
256  FunctionStopCondition(const OptimizerInterface* optimizer, double tolerance, int burnin);
257 
258  virtual ~FunctionStopCondition();
259 
260  FunctionStopCondition* clone() const { return new FunctionStopCondition(*this); }
261 
262 public:
263  void init();
264  bool isToleranceReached() const;
265  double getCurrentTolerance() const;
266 };
267 } // end of namespace bpp.
268 #endif // BPP_NUMERIC_FUNCTION_OPTIMIZATIONSTOPCONDITION_H
ParameterList newParametersEstimates_
The new estimates of the parameters.
AbstractOptimizationStopCondition(const OptimizerInterface *optimizer, double tolerance, int burnin)
double lastFunctionValue_
The last value of the function.
double getTolerance() const
Get the tolerance parameter.
AbstractOptimizationStopCondition(const OptimizerInterface *optimizer, int burnin)
Interface for otimization stop condition objet.
ParameterList lastParametersEstimates_
The last estimates of the parameters.
STL namespace.
Stop condition on function value.
The parameter list object.
Definition: ParameterList.h:27
AbstractOptimizationStopCondition(const OptimizerInterface *optimizer, double tolerance)
void setOptimizer(const OptimizerInterface *optimizer)
Set the optimizer attached to this instance.
void setTolerance(double tolerance)
Set the tolerance parameter.
AbstractOptimizationStopCondition & operator=(const AbstractOptimizationStopCondition &aosc)
double newFunctionValue_
The new value of the function.
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:63
This is the basal interface for all optimization methods.
Definition: Optimizer.h:88
const OptimizerInterface * getOptimizer() const
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.
AbstractOptimizationStopCondition(const OptimizerInterface *optimizer)