bpp-core3  3.0.0
ConjugateGradientMultiDimensions.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_CONJUGATEGRADIENTMULTIDIMENSIONS_H
6 #define BPP_NUMERIC_FUNCTION_CONJUGATEGRADIENTMULTIDIMENSIONS_H
7 
8 
9 #include "AbstractOptimizer.h"
10 #include "BrentOneDimension.h"
11 #include "DirectionFunction.h"
12 
13 namespace bpp
14 {
27  public AbstractOptimizer
28 {
29 protected:
30  BrentOneDimension optimizer_; // One dimensional optimizer.
31  std::vector<double> xi_, h_, g_;
32  std::shared_ptr<DirectionFunction> f1dim_;
33 
34 public:
35  ConjugateGradientMultiDimensions(std::shared_ptr<FirstOrderDerivable> function);
36 
38 
40 
41 public:
47  void doInit(const ParameterList& params);
48 
49  double doStep();
53  {
54  if (function_)
55  {
56  return *dynamic_pointer_cast<const FirstOrderDerivable>(function_);
57  }
58  else
59  {
60  throw NullPointerException("ConjugateGradientMultiDimensions::firstOrderDerivableFunction() : no function associated to this optimizer.");
61  }
62  }
63 
65  {
66  if (function_)
67  {
68  return *dynamic_pointer_cast<FirstOrderDerivable>(function_);
69  }
70  else
71  {
72  throw NullPointerException("ConjugateGradientMultiDimensions::firstOrderDerivableFunction() : no function associated to this optimizer.");
73  }
74  }
75 
76  std::shared_ptr<const FirstOrderDerivable> getFirstOrderDerivableFunction() const
77  {
78  return dynamic_pointer_cast<const FirstOrderDerivable>(function_);
79  }
80 
81  std::shared_ptr<FirstOrderDerivable> getFirstOrderDerivableFunction()
82  {
83  return dynamic_pointer_cast<FirstOrderDerivable>(function_);
84  }
85 
86  void getGradient(std::vector<double>& gradient) const;
87 };
88 } // end of namespace bpp.
89 #endif // BPP_NUMERIC_FUNCTION_CONJUGATEGRADIENTMULTIDIMENSIONS_H
This is the abstract class for first order derivable functions.
Definition: Functions.h:96
std::shared_ptr< FunctionInterface > function_
The function to optimize.
std::shared_ptr< const FirstOrderDerivable > getFirstOrderDerivableFunction() const
double doStep()
This function is called by the step() method and contains all calculations.
The parameter list object.
Definition: ParameterList.h:27
The base class exception for NULL pointer error. This exception may be thrown when an unexpected NULL...
Definition: Exceptions.h:56
ConjugateGradientMultiDimensions(std::shared_ptr< FirstOrderDerivable > function)
void doInit(const ParameterList &params)
This function is called by the init() method and contains all calculations.
Brent&#39;s optimization for one parameter.
Partial implementation of the Optimizer interface.
Conjugate gradient optimization method.
std::shared_ptr< FirstOrderDerivable > getFirstOrderDerivableFunction()
const FirstOrderDerivable & firstOrderDerivableFunction() const
std::shared_ptr< DirectionFunction > f1dim_
ConjugateGradientMultiDimensions * clone() const
Create a copy of this object and send a pointer to it.
void getGradient(std::vector< double > &gradient) const