bpp-core  2.2.0
DownhillSimplexMethod.h
Go to the documentation of this file.
1 //
2 // File: DownhillSimplexMethod.h
3 // Created by: Julien Dutheil
4 // Created on: Tue Nov 4 17:10:05 2003
5 //
6 
7 /*
8 Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
9 
10 This software is a computer program whose purpose is to provide classes
11 for phylogenetic data analysis.
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 _DOWNHILLSIMPLEXMETHOD_H_
41 #define _DOWNHILLSIMPLEXMETHOD_H_
42 
43 #include "AbstractOptimizer.h"
44 #include "../VectorTools.h"
45 
46 // From the STL:
47 #include <cmath>
48 
49 namespace bpp
50 {
51 
64  public AbstractOptimizer
65 {
66  public:
69  {
70  public:
73  virtual ~DSMStopCondition() {}
74 
75  DSMStopCondition* clone() const { return new DSMStopCondition(*this); }
76 
77  public:
78  bool isToleranceReached() const { return (getCurrentTolerance() < tolerance_); }
79  double getCurrentTolerance() const;
80  };
81 
82  friend class DSMStopCondition;
83 
84  private:
85  class Simplex
86  {
87  private:
88  std::vector<ParameterList> parameters_;
89 
90  public: // Class constructor and destructor:
92  virtual ~Simplex() {}
93 
94  public: // Methods:
95  const ParameterList& operator[](size_t i) const { return parameters_[i]; }
96  ParameterList& operator[](size_t i) { return parameters_[i]; }
97  void resize(size_t size) { parameters_.resize(size); }
98  size_t getDimension() const { return parameters_[0].size(); }
99  };
100 
101  protected:
106 
107  public:
108 
114  DownhillSimplexMethod(Function * function);
115 
117 
118 #ifndef NO_VIRTUAL_COV
120 #else
121  Clonable*
122 #endif
123  clone() const { return new DownhillSimplexMethod(*this); }
124 
125  public:
136  double optimize() throw (Exception);
139  void doInit(const ParameterList& params) throw (Exception);
140 
141  double doStep() throw (Exception);
142 
143  protected:
144 
155 
163  double tryExtrapolation(double fac);
164 
166 };
167 
168 } //end of namespace bpp.
169 
170 #endif //_DOWNHILLSIMPLEXMETHOD_H_
171 
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 ...
This class allows to perform a correspondence analysis.
ParameterList getPSum()
Update the pSum_ variable.
This is the function abstract class.
Definition: Functions.h:86
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:61
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:67
DownhillSimplexMethod(Function *function)
Build a new Downhill Simplex optimizer.
DSMStopCondition * clone() const
Create a copy of this object and send a pointer to it.
Exception base class.
Definition: Exceptions.h:57
The Clonable interface (allow an object to be cloned).
Definition: Clonable.h:99
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.