bpp-core3  3.0.0
NewtonOneDimension.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_NEWTONONEDIMENSION_H
6 #define BPP_NUMERIC_FUNCTION_NEWTONONEDIMENSION_H
7 
8 
9 #include "AbstractOptimizer.h"
10 
11 namespace bpp
12 {
17  public AbstractOptimizer
18 {
19 private:
20  std::string _param;
21  unsigned int _maxCorrection;
22 
23 public:
24  NewtonOneDimension(std::shared_ptr<SecondOrderDerivable> function = nullptr);
25  virtual ~NewtonOneDimension() {}
26 
27  NewtonOneDimension* clone() const { return new NewtonOneDimension(*this); }
28 
29 public:
30  void doInit(const ParameterList& params);
31 
32  double doStep();
33 
34  void setMaximumNumberOfCorrections(unsigned int mx) { _maxCorrection = mx; }
35 
37  {
38  if (function_)
39  {
40  return *dynamic_pointer_cast<const FirstOrderDerivable>(function_);
41  }
42  else
43  {
44  throw NullPointerException("NewtonOneDimension::firstOrderDerivableFunction() : no function associated to this optimizer.");
45  }
46  }
47 
49  {
50  if (function_)
51  {
52  return *dynamic_pointer_cast<FirstOrderDerivable>(function_);
53  }
54  else
55  {
56  throw NullPointerException("NewtonOneDimension::firstOrderDerivableFunction() : no function associated to this optimizer.");
57  }
58  }
59 
60  std::shared_ptr<const FirstOrderDerivable> getFirstOrderDerivableFunction() const
61  {
62  return dynamic_pointer_cast<const FirstOrderDerivable>(function_);
63  }
64 
65  std::shared_ptr<FirstOrderDerivable> getFirstOrderDerivableFunction()
66  {
67  return dynamic_pointer_cast<FirstOrderDerivable>(function_);
68  }
69 
71  {
72  if (function_)
73  {
74  return *dynamic_pointer_cast<const SecondOrderDerivable>(function_);
75  }
76  else
77  {
78  throw NullPointerException("NewtonOneDimension::secondOrderDerivableFunction() : no function associated to this optimizer.");
79  }
80  }
81 
83  {
84  if (function_)
85  {
86  return *dynamic_pointer_cast<SecondOrderDerivable>(function_);
87  }
88  else
89  {
90  throw NullPointerException("NewtonOneDimension::secondOrderDerivableFunction() : no function associated to this optimizer.");
91  }
92  }
93 
94  std::shared_ptr<const SecondOrderDerivable> getSecondOrderDerivableFunction() const
95  {
96  return dynamic_pointer_cast<const SecondOrderDerivable>(function_);
97  }
98 
99  std::shared_ptr<SecondOrderDerivable> getSecondOrderDerivableFunction()
100  {
101  return dynamic_pointer_cast<SecondOrderDerivable>(function_);
102  }
103 };
104 } // end of namespace bpp.
105 #endif // BPP_NUMERIC_FUNCTION_NEWTONONEDIMENSION_H
std::shared_ptr< SecondOrderDerivable > getSecondOrderDerivableFunction()
This is the abstract class for first order derivable functions.
Definition: Functions.h:96
void doInit(const ParameterList &params)
This function is called by the init() method and contains all calculations.
void setMaximumNumberOfCorrections(unsigned int mx)
std::shared_ptr< FunctionInterface > function_
The function to optimize.
std::shared_ptr< const SecondOrderDerivable > getSecondOrderDerivableFunction() const
The parameter list object.
Definition: ParameterList.h:27
NewtonOneDimension(std::shared_ptr< SecondOrderDerivable > function=nullptr)
std::shared_ptr< FirstOrderDerivable > getFirstOrderDerivableFunction()
std::shared_ptr< const FirstOrderDerivable > getFirstOrderDerivableFunction() const
SecondOrderDerivable & secondOrderDerivableFunction()
The base class exception for NULL pointer error. This exception may be thrown when an unexpected NULL...
Definition: Exceptions.h:56
const SecondOrderDerivable & secondOrderDerivableFunction() const
double doStep()
This function is called by the step() method and contains all calculations.
Partial implementation of the Optimizer interface.
FirstOrderDerivable & firstOrderDerivableFunction()
NewtonOneDimension * clone() const
Create a copy of this object and send a pointer to it.
const FirstOrderDerivable & firstOrderDerivableFunction() const
Newton&#39;s optimization for one parameter.
This is the abstract class for second order derivable functions.
Definition: Functions.h:151