ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkSPSAOptimizer.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkSPSAOptimizer_h
19 #define __itkSPSAOptimizer_h
20 
23 
24 namespace itk
25 {
43 class ITK_EXPORT SPSAOptimizer:
45 {
46 public:
47 
53 
55  itkNewMacro(Self);
56 
59 
61  typedef enum {
65  MetricError
66  } StopConditionType;
67 
69  virtual void AdvanceOneStep(void);
70 
72  void StartOptimization(void);
73 
76  void ResumeOptimization(void);
77 
80  void StopOptimization(void);
81 
83  virtual MeasureType GetValue(void) const;
84 
86  virtual MeasureType GetValue(const ParametersType & parameters) const;
87 
101  virtual void GuessParameters(
102  SizeValueType numberOfGradientEstimates,
103  double initialStepSize);
104 
106  itkGetConstMacro(CurrentIteration, SizeValueType);
107 
109  itkGetConstMacro(StopCondition, StopConditionType);
110 
112  itkGetConstMacro(LearningRate, double);
113 
115  itkGetConstMacro(GradientMagnitude, double);
116 
118  itkGetConstReferenceMacro(Gradient, DerivativeType);
119 
121  itkSetMacro(Sa, double);
122  itkGetConstMacro(Sa, double);
123  // For backward compatibility
124  void Seta(double a) { SetSa(a); }
125  double Geta() { return GetSa(); }
127 
129  itkSetMacro(Sc, double);
130  itkGetConstMacro(Sc, double);
131  // For backward compatibility
132  void Setc(double c) { SetSc(c); }
133  double Getc() { return GetSc(); }
135 
137  itkSetMacro(A, double);
138  itkGetConstMacro(A, double);
140 
142  itkSetMacro(Alpha, double);
143  itkGetConstMacro(Alpha, double);
145 
147  itkSetMacro(Gamma, double);
148  itkGetConstMacro(Gamma, double);
150 
152  itkGetConstMacro(Maximize, bool);
153  itkSetMacro(Maximize, bool);
154  itkBooleanMacro(Maximize);
155  bool GetMinimize() const
156  { return !m_Maximize; }
157  void SetMinimize(bool v)
158  { this->SetMaximize(!v); }
159  void MinimizeOn()
160  { this->MaximizeOff(); }
161  void MinimizeOff()
162  { this->MaximizeOn(); }
164 
170  itkSetMacro(NumberOfPerturbations, SizeValueType);
171  itkGetConstMacro(NumberOfPerturbations, SizeValueType);
173 
185  itkGetConstMacro(StateOfConvergence, double);
186 
188  itkSetMacro(StateOfConvergenceDecayRate, double);
189  itkGetConstMacro(StateOfConvergenceDecayRate, double);
191 
193  itkSetMacro(MinimumNumberOfIterations, SizeValueType);
194  itkGetConstMacro(MinimumNumberOfIterations, SizeValueType);
196 
198  itkSetMacro(MaximumNumberOfIterations, SizeValueType);
199  itkGetConstMacro(MaximumNumberOfIterations, SizeValueType);
201 
203  itkSetMacro(Tolerance, double);
204  itkGetConstMacro(Tolerance, double);
206 
208  const std::string GetStopConditionDescription() const;
209 
210 protected:
211 
212  SPSAOptimizer();
213  virtual ~SPSAOptimizer() {}
214 
216  void PrintSelf(std::ostream & os, Indent indent) const;
217 
220 
222 
224 
225  bool m_Stop;
226 
228 
230 
232 
235 
237  virtual double Compute_a(SizeValueType k) const;
238 
243  virtual double Compute_c(SizeValueType k) const;
244 
246  virtual void GenerateDelta(const unsigned int spaceDimension);
247 
252  virtual void ComputeGradient(
253  const ParametersType & parameters,
254  DerivativeType & gradient);
255 
256 private:
257 
258  SPSAOptimizer(const Self &); // purposely not implemented
259  void operator=(const Self &); // purposely not implemented
260 
265  double m_Tolerance;
269 
271  double m_Sa;
272  double m_Sc;
273  double m_A;
274  double m_Alpha;
275  double m_Gamma;
276 }; // end class SPSAOptimizer
277 } // end namespace itk
278 
279 #endif // end #ifndef __itkSPSAOptimizer_h
280