bpp-phyl  2.2.0
PseudoNewtonOptimizer.h
Go to the documentation of this file.
1 //
2 // File: PseudoNewtonOptimizer.h
3 // Created by; Julien Dutheil
4 // Created on: Tue Nov 16 11:52 2004
5 //
6 
7 /*
8  Copyright or © or Copr. Bio++ Development Team, (November 16, 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 _PSEUDONEWTONOPTIMIZER_H_
41 #define _PSEUDONEWTONOPTIMIZER_H_
42 
43 #include <Bpp/Numeric/Function/AbstractOptimizer.h>
44 
45 namespace bpp
46 {
47 
59  public AbstractOptimizer
60  {
61  public:
63  public AbstractOptimizationStopCondition
64  {
65  public:
67  AbstractOptimizationStopCondition(pno) {}
68  virtual ~PNStopCondition() {}
69 
70  PNStopCondition* clone() const { return new PNStopCondition(*this); }
71 
72  public:
73  bool isToleranceReached() const;
74  double getCurrentTolerance() const;
75  };
76 
77  friend class PNStopCondition;
78 
79  private:
80 
81  ParameterList previousPoint_; // Current point is in parameters_
82 
84 
85  size_t n_; // Number of parameters
86 
87  std::vector<std::string> params_; // All parameter names
88 
89  unsigned int maxCorrection_;
90 
91  bool useCG_;
92 
93  public:
94 
95  PseudoNewtonOptimizer(DerivableSecondOrder* function);
96 
98 
99  PseudoNewtonOptimizer* clone() const { return new PseudoNewtonOptimizer(*this); }
100 
101  public:
102  const DerivableSecondOrder* getFunction() const
103  {
104  return dynamic_cast<const DerivableSecondOrder*>(AbstractOptimizer::getFunction());
105  }
106  DerivableSecondOrder* getFunction()
107  {
108  return dynamic_cast<DerivableSecondOrder*>(AbstractOptimizer::getFunction());
109  }
110 
116  double getFunctionValue() const throw (NullPointerException) { return currentValue_; }
119  void doInit(const ParameterList& params) throw (Exception);
120 
121  double doStep() throw (Exception);
122 
123  void setMaximumNumberOfCorrections(unsigned int mx) { maxCorrection_ = mx; }
124 
125  void disableCG() { useCG_ = false; }
126 
127  protected:
128  DerivableSecondOrder* getFunction_()
129  {
130  return dynamic_cast<DerivableSecondOrder*>(AbstractOptimizer::getFunction_());
131  }
132 
133 
134  };
135 
136 } //end of namespace bpp.
137 
138 #endif //_PSEUDONEWTONOPTIMIZER_H_
139 
DerivableSecondOrder * getFunction_()
PseudoNewtonOptimizer(DerivableSecondOrder *function)
void setMaximumNumberOfCorrections(unsigned int mx)
std::vector< std::string > params_
PseudoNewtonOptimizer * clone() const
void doInit(const ParameterList &params)
This Optimizer implements Newton&#39;s algorithm for finding a minimum of a function. This is in fact a m...
DerivableSecondOrder * getFunction()
const DerivableSecondOrder * getFunction() const