ANIMA  4.0
animaBaseRootFindingAlgorithm.h
Go to the documentation of this file.
1 #pragma once
2 #include "AnimaOptimizersExport.h"
3 #include <itkSingleValuedCostFunction.h>
4 
5 #include <limits>
6 #include <cmath>
7 
8 namespace anima
9 {
10 
12 {
13 public:
15  {
16  m_RootRelativeTolerance = std::sqrt(std::numeric_limits<double>::epsilon());
17  }
18 
19  void SetRootRelativeTolerance(const double &tol) {m_RootRelativeTolerance = tol;}
20  bool operator()(const double &a, const double &b);
21 
22 private:
23  double m_RootRelativeTolerance;
24 };
25 
27 {
28 public:
29  using BaseCostFunctionType = itk::SingleValuedCostFunction;
30  using BaseCostFunctionPointer = BaseCostFunctionType::Pointer;
31  using ParametersType = BaseCostFunctionType::ParametersType;
32 
33  double operator()(const double &x);
34 
35  void SetRootFindingFunction(BaseCostFunctionType *f) {m_RootFindingFunction = f;}
36 
38  {
39  m_ParametersVector.set_size(1);
40  }
41 
42 private:
43  BaseCostFunctionPointer m_RootFindingFunction;
44  ParametersType m_ParametersVector;
45 };
46 
47 class ANIMAOPTIMIZERS_EXPORT BaseRootFindingAlgorithm
48 {
49 public:
50  using BaseCostFunctionType = itk::SingleValuedCostFunction;
51  using BaseCostFunctionPointer = BaseCostFunctionType::Pointer;
52  using ParametersType = BaseCostFunctionType::ParametersType;
53 
54  void SetRootRelativeTolerance(const double &val) {m_RootRelativeTolerance = val;}
55  void SetCostFunctionTolerance(const double &val) {m_CostFunctionTolerance = val;}
56  void SetMaximumNumberOfIterations(const unsigned int &val) {m_MaximumNumberOfIterations = val;}
57  void SetRootFindingFunction(BaseCostFunctionType *f) {m_RootFindingFunction = f;}
58  void SetLowerBound(const double &val) {m_LowerBound = val;}
59  void SetUpperBound(const double &val) {m_UpperBound = val;}
60  void SetFunctionValueAtInitialLowerBound(const double &val);
61  void SetFunctionValueAtInitialUpperBound(const double &val);
62 
63  bool GetProvidedFunctionValueAtInitialLowerBound() {return m_ProvidedFunctionValueAtInitialLowerBound;}
64  bool GetProvidedFunctionValueAtInitialUpperBound() {return m_ProvidedFunctionValueAtInitialUpperBound;}
65  double GetFunctionValueAtInitialLowerBound() {return m_FunctionValueAtInitialLowerBound;}
66  double GetFunctionValueAtInitialUpperBound() {return m_FunctionValueAtInitialUpperBound;}
67  double GetLowerBound() {return m_LowerBound;}
68  double GetUpperBound() {return m_UpperBound;}
69  unsigned int GetMaximumNumberOfIterations() {return m_MaximumNumberOfIterations;}
70  double GetRootRelativeTolerance() {return m_RootRelativeTolerance;}
71  double GetCostFunctionTolerance() {return m_CostFunctionTolerance;}
72  BaseCostFunctionType *GetRootFindingFunction() {return m_RootFindingFunction;}
73 
74  virtual double Optimize() = 0;
75 
77  {
78  m_RootRelativeTolerance = std::sqrt(std::numeric_limits<double>::epsilon());
79  m_CostFunctionTolerance = std::sqrt(std::numeric_limits<double>::epsilon());
80  m_MaximumNumberOfIterations = 50;
81  m_ProvidedFunctionValueAtInitialLowerBound = false;
82  m_ProvidedFunctionValueAtInitialUpperBound = false;
83  m_FunctionValueAtInitialLowerBound = 0.0;
84  m_FunctionValueAtInitialUpperBound = 0.0;
85  }
86 
88 
89 private:
91  double m_RootRelativeTolerance;
93  double m_CostFunctionTolerance;
94  unsigned int m_MaximumNumberOfIterations;
95  double m_LowerBound;
96  double m_UpperBound;
97  bool m_ProvidedFunctionValueAtInitialLowerBound;
98  bool m_ProvidedFunctionValueAtInitialUpperBound;
99  double m_FunctionValueAtInitialLowerBound;
100  double m_FunctionValueAtInitialUpperBound;
101  BaseCostFunctionPointer m_RootFindingFunction;
102 };
103 
104 } // end of namespace anima
BaseCostFunctionType::Pointer BaseCostFunctionPointer
void SetRootFindingFunction(BaseCostFunctionType *f)
BaseCostFunctionType::Pointer BaseCostFunctionPointer
BaseCostFunctionType::ParametersType ParametersType
BaseCostFunctionType::ParametersType ParametersType
bool operator()(const double &a, const double &b)
itk::SingleValuedCostFunction BaseCostFunctionType
itk::SingleValuedCostFunction BaseCostFunctionType
void SetMaximumNumberOfIterations(const unsigned int &val)
void SetRootFindingFunction(BaseCostFunctionType *f)