bpp-core3  3.0.0
DownhillSimplexMethod.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_DOWNHILLSIMPLEXMETHOD_H
6 #define BPP_NUMERIC_FUNCTION_DOWNHILLSIMPLEXMETHOD_H
7 
8 
9 #include "../VectorTools.h"
10 #include "AbstractOptimizer.h"
11 
12 // From the STL:
13 #include <cmath>
14 
15 namespace bpp
16 {
29  public AbstractOptimizer
30 {
31 public:
34  {
35 public:
38  virtual ~DSMStopCondition() {}
39 
40  DSMStopCondition* clone() const { return new DSMStopCondition(*this); }
41 
42 public:
43  bool isToleranceReached() const { return getCurrentTolerance() < tolerance_; }
44  double getCurrentTolerance() const;
45  };
46 
47  friend class DSMStopCondition;
48 
49 private:
50  class Simplex
51  {
52 private:
53  std::vector<ParameterList> parameters_;
54 
55 public:
56  // Class constructor and destructor:
57  Simplex() : parameters_() {}
58  virtual ~Simplex() {}
59 
60 public:
61  // Methods:
62  const ParameterList& operator[](size_t i) const { return parameters_[i]; }
63  ParameterList& operator[](size_t i) { return parameters_[i]; }
64  void resize(size_t size) { parameters_.resize(size); }
65  size_t getDimension() const { return parameters_[0].size(); }
66  };
67 
68 protected:
73 
74 public:
80  DownhillSimplexMethod(std::shared_ptr<FunctionInterface> function);
81 
83 
84  DownhillSimplexMethod* clone() const { return new DownhillSimplexMethod(*this); }
85 
86 public:
97  double optimize();
100  void doInit(const ParameterList& params);
101 
102  double doStep();
103 
104 protected:
115 
123  double tryExtrapolation(double fac);
124 
126 };
127 } // end of namespace bpp.
128 #endif // BPP_NUMERIC_FUNCTION_DOWNHILLSIMPLEXMETHOD_H
std::vector< ParameterList > parameters_
const ParameterList & operator[](size_t i) const
double optimize()
Multidimensional minimization of the function function_ by the downhill simplex method of Nelder and ...
ParameterList getPSum()
Update the pSum_ variable.
void doInit(const ParameterList &params)
This function is called by the init() method and contains all calculations.
double getCurrentTolerance() const
Get the current tolerance.
The parameter list object.
Definition: ParameterList.h:27
double tryExtrapolation(double fac)
Extrapolates by a factor fac through the face of the simplex from the high point. Try the new point a...
double doStep()
This function is called by the step() method and contains all calculations.
bool isToleranceReached() const
Tell if the we reached the desired tolerance with a given new set of estimates.
std::vector< double > Vdouble
Definition: VectorTools.h:34
DownhillSimplexMethod(std::shared_ptr< FunctionInterface > function)
Build a new Downhill Simplex optimizer.
DSMStopCondition * clone() const
Create a copy of this object and send a pointer to it.
Partial implementation of the Optimizer interface.
DownhillSimplexMethod * clone() const
Create a copy of this object and send a pointer to it.
Partial implementation of the OptimizationStopCondition interface.
This implements the Downhill Simplex method in multidimensions.