ANIMA  4.0
animaBobyqaOptimizer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <itkVector.h>
4 #include <itkMatrix.h>
5 #include <itkSingleValuedNonLinearOptimizer.h>
6 #include "AnimaOptimizersExport.h"
7 
8 namespace anima
9 {
15 class ANIMAOPTIMIZERS_EXPORT BobyqaOptimizer : public itk::SingleValuedNonLinearOptimizer
16 {
17 public:
20  typedef itk::Object Superclass;
21  typedef itk::SmartPointer<Self> Pointer;
22  typedef itk::SmartPointer<const Self> ConstPointer;
23 
24  typedef itk::SingleValuedNonLinearOptimizer::ParametersType ParametersType;
25  typedef itk::SingleValuedNonLinearOptimizer::ScalesType ScalesType;
26 
28  itkNewMacro(Self)
29 
30 
31  itkTypeMacro(BobyqaOptimizer, SingleValuedNonLinearOptimizer)
32 
33 
34  typedef itk::SingleValuedCostFunction CostFunctionType;
35  typedef CostFunctionType::Pointer CostFunctionPointer;
36 
38  itkSetMacro(Maximize, bool)
39  itkBooleanMacro(Maximize)
40  itkGetConstReferenceMacro(Maximize, bool)
41 
43  itkSetMacro(MaximumIteration, unsigned int)
44  itkGetConstReferenceMacro(MaximumIteration, unsigned int)
45 
46  itkSetMacro(SpaceDimension, unsigned int)
47  itkGetConstReferenceMacro(SpaceDimension, unsigned int)
48 
50  itkSetMacro(NumberSamplingPoints, unsigned int)
51  itkGetConstReferenceMacro(NumberSamplingPoints, unsigned int)
52 
55  itkSetMacro(RhoBegin, double)
56  itkGetConstReferenceMacro(RhoBegin, double)
57 
60  itkSetMacro(RhoEnd, double)
61  itkGetConstReferenceMacro(RhoEnd, double)
62 
64  itkGetConstReferenceMacro(CurrentCost, MeasureType)
65  MeasureType GetValue() const
66  {
67  if (this->GetMaximize())
68  return -this->GetCurrentCost();
69  else
70  return this->GetCurrentCost();
71  }
72 
74  itkGetConstReferenceMacro( CurrentIteration, unsigned int)
75 
76 
77  void StartOptimization() ITK_OVERRIDE;
78 
82  void StopOptimization() {m_Stop = true;}
83 
84  itkGetConstReferenceMacro(CatchGetValueException, bool)
85  itkSetMacro(CatchGetValueException, bool)
86 
87  itkGetConstReferenceMacro(MetricWorstPossibleValue, double)
88  itkSetMacro(MetricWorstPossibleValue, double)
89 
90  itkSetMacro(LowerBounds, ScalesType)
91  itkSetMacro(UpperBounds, ScalesType)
92 
93  const std::string GetStopConditionDescription() const ITK_OVERRIDE;
94 
95 protected:
98  virtual ~BobyqaOptimizer();
99  void PrintSelf(std::ostream& os, itk::Indent indent) const ITK_OVERRIDE;
100 
103 
104  unsigned int m_SpaceDimension;
105 
106  unsigned int m_MaximumIteration;
107  unsigned int m_CurrentIteration;
108 
111 
113  double m_RhoBegin, m_RhoEnd;
114 
115  // int Parameters;
117  ScalesType m_LowerBounds, m_UpperBounds;
118 
119  itkSetMacro(CurrentCost, double);
120 
122  MeasureType m_CurrentCost;
123 
128  bool m_Stop;
129 
130  std::ostringstream m_StopConditionDescription;
131 
132 protected: // From f2c...
133  int optimize(long int &npt, double *x, double *xl, double *xu, double &rhobeg, double &rhoend,
134  long int &maxfun, double *w);
135  int bobyqb_(long int &npt, double *x, double *xl, double *xu, double &rhobeg, double &rhoend,
136  long int &maxfun, double *xbase, double *xpt, double *fval, double *xopt,
137  double *gopt, double *hq, double *pq, double *bmat, double *zmat,
138  long int &ndim, double *sl, double *su, double *xnew, double *xalt, double *d__,
139  double *vlag, double *w);
140  int altmov_(long int &npt, double *xpt, double *xopt, double *bmat, double *zmat, long int &ndim,
141  double *sl, double *su, long int &kopt, long int &knew, double *adelt, double *xnew,
142  double *xalt, double *alpha, double *cauchy, double *glag, double *hcol, double *w);
143  int prelim_(long int &npt, double *x, double *xl, double *xu, double &rhobeg, long int &maxfun,
144  double *xbase, double *xpt, double *fval, double *gopt, double *hq, double *pq,
145  double *bmat, double *zmat, long int &ndim, double *sl, double *su, long int &nf,
146  long int &kopt);
147  int rescue_(long int &npt, double *xl, double *xu, long int &maxfun, double *xbase, double *xpt,
148  double *fval, double *xopt, double *gopt, double *hq, double *pq, double *bmat,
149  double *zmat, long int &ndim, double *sl, double *su, long int &nf, double *delta,
150  long int &kopt, double *vlag, double *ptsaux, double *ptsid, double *w);
151  int trsbox_(long int &npt, double *xpt, double *xopt, double *gopt, double *hq, double *pq,
152  double *sl, double *su, double *delta, double *xnew, double *d__, double *gnew,
153  double *xbdi, double *s, double *hs, double *hred, double *dsq, double *crvmin);
154  int update_(long int &npt, double *bmat, double *zmat, long int &ndim, double *vlag,
155  double *beta, double *denom, long int &knew, double *w);
156 };
157 
158 } // end of namespace anima
159 
160 
161 
itk::SingleValuedNonLinearOptimizer::ParametersType ParametersType
itk::SingleValuedNonLinearOptimizer::ScalesType ScalesType
BobyqaOptimizer::ParametersType px
itk::SingleValuedCostFunction CostFunctionType
itk::SmartPointer< Self > Pointer
itk::SmartPointer< const Self > ConstPointer
std::ostringstream m_StopConditionDescription
CostFunctionType::Pointer CostFunctionPointer