Seg3D  2.4
Seg3D is a free volume segmentation and processing tool developed by the NIH Center for Integrative Biomedical Computing at the University of Utah Scientific Computing and Imaging (SCI) Institute.
itkRegularStepGradientDescentOptimizer2.h
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2016 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 // File : itkRegularStepGradientDescentOptimizer2.h
30 // Author : Pavel A. Koshevoy, Tolga Tasdizen
31 // Created : 2005/11/11 14:54
32 // Copyright : (C) 2004-2008 University of Utah
33 // Description : An enhanced version of the
34 // itk::RegularStepGradientDescentOptimizer
35 // fixing a bug with relaxation and adding support for
36 // step size increase (pick up pace), back tracking and
37 // keeping track of the best metric value
38 // and associated parameters.
39 
40 #ifndef __itkRegularStepGradientDescentOptimizer2_h
41 #define __itkRegularStepGradientDescentOptimizer2_h
42 
43 // ITK includes:
44 #include <itkSingleValuedNonLinearOptimizer.h>
45 
46 namespace itk
47 {
48 
49 //----------------------------------------------------------------
50 // RegularStepGradientDescentOptimizer2
51 //
53  public SingleValuedNonLinearOptimizer
54 {
55 public:
58  typedef SingleValuedNonLinearOptimizer Superclass;
59  typedef SmartPointer<Self> Pointer;
60  typedef SmartPointer<const Self> ConstPointer;
61 
63  itkNewMacro(Self);
64 
67  SingleValuedNonLinearOptimizer);
68 
69  //----------------------------------------------------------------
70  // StopConditionType
71  //
72  // Codes of stopping conditions:
73  //
74  typedef enum {
75  GradientMagnitudeTolerance = 1,
76  StepTooSmall = 2,
77  ImageNotAvailable = 3,
78  SamplesNotAvailable = 4,
79  MaximumNumberOfIterations = 5
80  } StopConditionType;
81 
83  itkSetMacro(Maximize, bool);
84  itkGetConstReferenceMacro(Maximize, bool);
85  itkBooleanMacro(Maximize);
86 
87  inline bool GetMinimize() const { return !m_Maximize; }
88  inline void SetMinimize(bool v) { this->SetMaximize(!v); }
89  inline void MinimizeOn() { SetMaximize(false); }
90  inline void MinimizeOff() { SetMaximize(true); }
91 
92  // virtual:
93  void StartOptimization();
94 
95  // virtual:
96  void ResumeOptimization();
97 
98  // virtual:
99  void StopOptimization();
100 
101  // Set/Get parameters to control the optimization process:
102  itkSetMacro(MaximumStepLength, double);
103  itkSetMacro(MinimumStepLength, double);
104  itkGetConstReferenceMacro(MaximumStepLength, double);
105  itkGetConstReferenceMacro(MinimumStepLength, double);
106 
107  itkSetMacro(RelaxationFactor, double);
108  itkGetConstReferenceMacro(RelaxationFactor, double);
109 
110  itkSetMacro(NumberOfIterations, unsigned long);
111  itkGetConstReferenceMacro(NumberOfIterations, unsigned long);
112 
113  itkSetMacro(GradientMagnitudeTolerance, double);
114  itkGetConstReferenceMacro(GradientMagnitudeTolerance, double);
115 
116  itkSetMacro(BackTracking, bool);
117  itkGetConstReferenceMacro(BackTracking, bool);
118 
119  itkSetMacro(PickUpPaceSteps, unsigned int);
120  itkGetConstReferenceMacro(PickUpPaceSteps, unsigned int);
121 
122  itkGetConstReferenceMacro(CurrentStepLength, double);
123  itkGetConstMacro(CurrentIteration, unsigned int);
124  itkGetConstReferenceMacro(StopCondition, StopConditionType);
125  itkGetConstReferenceMacro(Value, MeasureType);
126  itkGetConstReferenceMacro(Gradient, DerivativeType);
127  itkGetConstReferenceMacro(BestParams, ParametersType);
128  itkGetConstReferenceMacro(BestValue, MeasureType);
129 
130 protected:
131  RegularStepGradientDescentOptimizer2();
132  virtual ~RegularStepGradientDescentOptimizer2() {}
133 
134  // advance one step following the gradient direction:
135  virtual void AdvanceOneStep();
136 
137  // advance one step along the given direction vector
138  // scaled by the step length scale; this method is
139  // called by AdvanceOneStep:
140  virtual void StepAlongGradient(double step_length_scale,
141  const DerivativeType & step_direction);
142 
143  // virtual:
144  void PrintSelf(std::ostream& os, Indent indent) const;
145 
146  // data members:
147  DerivativeType m_Gradient;
148  DerivativeType m_PreviousGradient;
149 
150  bool m_Stop;
151  bool m_Maximize;
152  MeasureType m_Value;
153  MeasureType m_PreviousValue;
154  double m_GradientMagnitudeTolerance;
155  double m_MaximumStepLength;
156  double m_MinimumStepLength;
157  double m_CurrentStepLength;
158  double m_RelaxationFactor;
159  StopConditionType m_StopCondition;
160  unsigned long m_NumberOfIterations;
161  unsigned long m_CurrentIteration;
162 
163  // this keeps track of the best function value and corresponding parameters:
164  MeasureType m_BestValue;
165  ParametersType m_BestParams;
166 
167  // this flag controls whether the algorithm will step back
168  // to a previous position as well as relax every time it
169  // detects a worsening of the metric;
170  // default is false:
171  bool m_BackTracking;
172 
173  // this is the number of successful iterations that must occur
174  // after which the algorithm will increase the step size;
175  // default is 1000000:
176  unsigned int m_PickUpPaceSteps;
177 
178 private:
179  // disable the copy constructor and assignment operator:
180  RegularStepGradientDescentOptimizer2(const Self &);
181  void operator = (const Self &);
182 };
183 
184 } // end namespace itk
185 
186 
187 #endif // __itkRegularStepGradientDescentOptimizer2_h
Definition: itkNormalizeImageFilterWithMask.h:48
RegularStepGradientDescentOptimizer2 Self
Definition: itkRegularStepGradientDescentOptimizer2.h:57
Definition: itkRegularStepGradientDescentOptimizer2.h:52