bpp-core3  3.0.0
NewtonBacktrackOneDimension.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_NEWTONBACKTRACKONEDIMENSION_H
6 #define BPP_NUMERIC_FUNCTION_NEWTONBACKTRACKONEDIMENSION_H
7 
8 
9 #include "AbstractOptimizer.h"
10 
11 namespace bpp
12 {
33  public AbstractOptimizer
34 {
35 public:
38  {
39 public:
42  virtual ~NBODStopCondition() {}
43 
44  NBODStopCondition* clone() const { return new NBODStopCondition(*this); }
45 
46 public:
47  void init() {}
48  bool isToleranceReached() const { return false; }
49  double getCurrentTolerance() const { return 0; }
50  };
51 
52  friend class NBODStopCondition;
53 
54 public:
61  NewtonBacktrackOneDimension(std::shared_ptr<FunctionInterface> function, double slope, double test);
63 
65 
66 private:
68 
69 public:
70  void doInit(const ParameterList& params);
71 
72  double doStep();
73 
75  {
76  if (function_)
77  {
78  return *dynamic_pointer_cast<const FirstOrderDerivable>(function_);
79  }
80  else
81  {
82  throw NullPointerException("NewtonBacktrackOneDimension::firstOrderDerivableFunction() : no function associated to this optimizer.");
83  }
84  }
85 
87  {
88  if (function_)
89  {
90  return *dynamic_pointer_cast<FirstOrderDerivable>(function_);
91  }
92  else
93  {
94  throw NullPointerException("NewtonBacktrackOneDimension::firstOrderDerivableFunction() : no function associated to this optimizer.");
95  }
96  }
97 
98  std::shared_ptr<const FirstOrderDerivable> getFirstOrderDerivableFunction() const
99  {
100  return dynamic_pointer_cast<const FirstOrderDerivable>(function_);
101  }
102 
103  std::shared_ptr<FirstOrderDerivable> getFirstOrderDerivableFunction()
104  {
105  return dynamic_pointer_cast<FirstOrderDerivable>(function_);
106  }
107 };
108 } // end of namespace bpp.
109 #endif // BPP_NUMERIC_FUNCTION_NEWTONBACKTRACKONEDIMENSION_H
This is the abstract class for first order derivable functions.
Definition: Functions.h:96
double getCurrentTolerance() const
Get the current tolerance.
NewtonBacktrackOneDimension(std::shared_ptr< FunctionInterface > function, double slope, double test)
Constructor.
std::shared_ptr< FirstOrderDerivable > getFirstOrderDerivableFunction()
FirstOrderDerivable & firstOrderDerivableFunction()
void doInit(const ParameterList &params)
This function is called by the init() method and contains all calculations.
std::shared_ptr< FunctionInterface > function_
The function to optimize.
NBODStopCondition * clone() const
Create a copy of this object and send a pointer to it.
The parameter list object.
Definition: ParameterList.h:27
bool isToleranceReached() const
Tell if the we reached the desired tolerance with a given new set of estimates.
double doStep()
This function is called by the step() method and contains all calculations.
NewtonBacktrackOneDimension * clone() const
Create a copy of this object and send a pointer to it.
The base class exception for NULL pointer error. This exception may be thrown when an unexpected NULL...
Definition: Exceptions.h:56
std::shared_ptr< const FirstOrderDerivable > getFirstOrderDerivableFunction() const
Newton&#39;s backtrack nearly optimization for one parameter.
Partial implementation of the Optimizer interface.
Partial implementation of the OptimizationStopCondition interface.
const FirstOrderDerivable & firstOrderDerivableFunction() const