ANIMA  4.0
animaBoundedLevenbergMarquardtOptimizer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <itkMultipleValuedNonLinearOptimizer.h>
5 #include "AnimaOptimizersExport.h"
6 
7 namespace anima
8 {
9 
21 class ANIMAOPTIMIZERS_EXPORT BoundedLevenbergMarquardtOptimizer:
22  public itk::MultipleValuedNonLinearOptimizer
23 {
24 public:
27  typedef itk::MultipleValuedNonLinearOptimizer Superclass;
28  typedef itk::SmartPointer <Self> Pointer;
29  typedef itk::SmartPointer <const Self> ConstPointer;
30 
32  itkNewMacro(Self)
33 
34  typedef Superclass::CostFunctionType CostFunctionType;
35  typedef Superclass::MeasureType MeasureType;
36 
38  itkTypeMacro(BoundedLevenbergMarquardtOptimizer, MultipleValuedNonLinearOptimizer)
39 
41  void StartOptimization() ITK_OVERRIDE;
42 
43  itkSetMacro(NumberOfIterations, unsigned int)
44  itkSetMacro(ValueTolerance, double)
45  itkSetMacro(CostTolerance, double)
46 
47  itkGetMacro(CurrentValue, double)
48 
49  itkSetMacro(LowerBounds, ParametersType)
50  itkSetMacro(UpperBounds, ParametersType)
51 
52 protected:
53  BoundedLevenbergMarquardtOptimizer()
54  {
55  m_NumberOfIterations = 2000;
56  m_ValueTolerance = 1e-8;
57  m_CostTolerance = 1e-5;
58  m_LambdaParameter = 1.0e-8;
59  m_DeltaParameter = 0.0;
60 
61  m_CurrentValue = 0.0;
62  m_LambdaCostFunction = anima::BLMLambdaCostFunction::New();
63  }
64 
65  virtual ~BoundedLevenbergMarquardtOptimizer() ITK_OVERRIDE {}
66 
67  double EvaluateCostFunctionAtParameters(ParametersType &parameters, MeasureType &residualValues);
68 
69  bool CheckSolutionIsInBounds(ParametersType &solutionVector, ParametersType &lowerBounds,
70  ParametersType &upperBounds, unsigned int rank);
71 
72  void UpdateLambdaParameter(DerivativeType &derivative, ParametersType &dValues,
73  std::vector <unsigned int> &pivotVector,
74  ParametersType &qtResiduals, unsigned int rank);
75 
76  bool CheckConditions(unsigned int numIterations, ParametersType &newParams,
77  ParametersType &oldParams, ParametersType &dValues, double newCostValue);
78 
79 private:
80  ITK_DISALLOW_COPY_AND_ASSIGN(BoundedLevenbergMarquardtOptimizer);
81 
82  unsigned int m_NumberOfIterations;
83  double m_ValueTolerance;
84  double m_CostTolerance;
85 
86  double m_LambdaParameter;
87  double m_DeltaParameter;
88  double m_CurrentValue;
89 
90  anima::BLMLambdaCostFunction::Pointer m_LambdaCostFunction;
91  ParametersType m_LowerBounds, m_UpperBounds;
92  ParametersType m_CurrentAddonVector;
93  MeasureType m_ResidualValues;
94 };
95 
96 } // end namespace anima
Levenberg-Marquardt optimizer with lower and upper bounds on parameters Implementation of the origina...