bpp-phyl3  3.0.0
PseudoNewtonOptimizer.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_PHYL_PSEUDONEWTONOPTIMIZER_H
6 #define BPP_PHYL_PSEUDONEWTONOPTIMIZER_H
7 
9 
10 
11 namespace bpp
12 {
24  public AbstractOptimizer
25 {
26 public:
29  {
30 public:
33  virtual ~PNStopCondition() {}
34 
35  PNStopCondition* clone() const { return new PNStopCondition(*this); }
36 
37 public:
38  bool isToleranceReached() const;
39  double getCurrentTolerance() const;
40  };
41 
42  friend class PNStopCondition;
43 
44 private:
45  ParameterList previousPoint_; // Current point is in parameters_
46 
48 
49  size_t n_; // Number of parameters
50 
51  std::vector<std::string> params_; // All parameter names
52 
53  unsigned int maxCorrection_;
54 
55  bool useCG_;
56 
57 public:
58  PseudoNewtonOptimizer(std::shared_ptr<SecondOrderDerivable> function);
59 
61 
62  PseudoNewtonOptimizer* clone() const { return new PseudoNewtonOptimizer(*this); }
63 
64 public:
66  {
67  return *dynamic_pointer_cast<const SecondOrderDerivable>(function_);
68  }
69 
71  {
72  return *dynamic_pointer_cast<SecondOrderDerivable>(function_);
73  }
74 
75  std::shared_ptr<const SecondOrderDerivable> getSecondOrderDerivableFunction() const
76  {
77  return dynamic_pointer_cast<const SecondOrderDerivable>(function_);
78  }
79 
80  std::shared_ptr<SecondOrderDerivable> getSecondOrderDerivableFunction()
81  {
82  return dynamic_pointer_cast<SecondOrderDerivable>(function_);
83  }
84 
90  double getFunctionValue() const { return currentValue_; }
93  void doInit(const ParameterList& params);
94 
95  double doStep();
96 
97  void setMaximumNumberOfCorrections(unsigned int mx) { maxCorrection_ = mx; }
98 
99  void disableCG() { useCG_ = false; }
100 };
101 } // end of namespace bpp.
102 #endif // BPP_PHYL_PSEUDONEWTONOPTIMIZER_H
std::shared_ptr< FunctionInterface > function_
This Optimizer implements Newton's algorithm for finding a minimum of a function. This is in fact a m...
PseudoNewtonOptimizer * clone() const
std::shared_ptr< SecondOrderDerivable > getSecondOrderDerivableFunction()
PseudoNewtonOptimizer(std::shared_ptr< SecondOrderDerivable > function)
void setMaximumNumberOfCorrections(unsigned int mx)
std::vector< std::string > params_
const SecondOrderDerivable & secondOrderDerivableFunction() const
SecondOrderDerivable & secondOrderDerivableFunction()
void doInit(const ParameterList &params)
std::shared_ptr< const SecondOrderDerivable > getSecondOrderDerivableFunction() const
Defines the basic types of data flow nodes.