ITK  4.8.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 #include "ITKOptimizersExport.h"
24 
25 namespace itk
26 {
44 class ITKOptimizers_EXPORT SPSAOptimizer:
46 {
47 public:
48 
54 
56  itkNewMacro(Self);
57 
60 
62  typedef enum {
66  MetricError
67  } StopConditionType;
68 
70  virtual void AdvanceOneStep();
71 
73  virtual void StartOptimization(void) ITK_OVERRIDE;
74 
77  void ResumeOptimization();
78 
81  void StopOptimization();
82 
84  virtual MeasureType GetValue() const;
85 
87  virtual MeasureType GetValue(const ParametersType & parameters) const;
88 
102  virtual void GuessParameters(
103  SizeValueType numberOfGradientEstimates,
104  double initialStepSize);
105 
107  itkGetConstMacro(CurrentIteration, SizeValueType);
108 
110  itkGetConstMacro(StopCondition, StopConditionType);
111 
113  itkGetConstMacro(LearningRate, double);
114 
116  itkGetConstMacro(GradientMagnitude, double);
117 
119  itkGetConstReferenceMacro(Gradient, DerivativeType);
120 
122  itkSetMacro(Sa, double);
123  itkGetConstMacro(Sa, double);
124  // For backward compatibility
125  void Seta(double a) { SetSa(a); }
126  double Geta() { return GetSa(); }
128 
130  itkSetMacro(Sc, double);
131  itkGetConstMacro(Sc, double);
132  // For backward compatibility
133  void Setc(double c) { SetSc(c); }
134  double Getc() { return GetSc(); }
136 
138  itkSetMacro(A, double);
139  itkGetConstMacro(A, double);
141 
143  itkSetMacro(Alpha, double);
144  itkGetConstMacro(Alpha, double);
146 
148  itkSetMacro(Gamma, double);
149  itkGetConstMacro(Gamma, double);
151 
153  itkGetConstMacro(Maximize, bool);
154  itkSetMacro(Maximize, bool);
155  itkBooleanMacro(Maximize);
156  bool GetMinimize() const
157  { return !m_Maximize; }
158  void SetMinimize(bool v)
159  { this->SetMaximize(!v); }
160  void MinimizeOn()
161  { this->MaximizeOff(); }
162  void MinimizeOff()
163  { this->MaximizeOn(); }
165 
171  itkSetMacro(NumberOfPerturbations, SizeValueType);
172  itkGetConstMacro(NumberOfPerturbations, SizeValueType);
174 
186  itkGetConstMacro(StateOfConvergence, double);
187 
189  itkSetMacro(StateOfConvergenceDecayRate, double);
190  itkGetConstMacro(StateOfConvergenceDecayRate, double);
192 
194  itkSetMacro(MinimumNumberOfIterations, SizeValueType);
195  itkGetConstMacro(MinimumNumberOfIterations, SizeValueType);
197 
199  itkSetMacro(MaximumNumberOfIterations, SizeValueType);
200  itkGetConstMacro(MaximumNumberOfIterations, SizeValueType);
202 
204  itkSetMacro(Tolerance, double);
205  itkGetConstMacro(Tolerance, double);
207 
209  virtual const std::string GetStopConditionDescription() const ITK_OVERRIDE;
210 
211 protected:
212 
213  SPSAOptimizer();
214  virtual ~SPSAOptimizer() {}
215 
217  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
218 
220  DerivativeType m_Gradient;
221 
223 
224  DerivativeType m_Delta;
225 
226  bool m_Stop;
227 
229 
231 
233 
236 
238  virtual double Compute_a(SizeValueType k) const;
239 
244  virtual double Compute_c(SizeValueType k) const;
245 
247  virtual void GenerateDelta(const unsigned int spaceDimension);
248 
253  virtual void ComputeGradient(
254  const ParametersType & parameters,
255  DerivativeType & gradient);
256 
257 private:
258 
259  SPSAOptimizer(const Self &); // purposely not implemented
260  void operator=(const Self &); // purposely not implemented
261 
266  double m_Tolerance;
270 
272  double m_Sa;
273  double m_Sc;
274  double m_A;
275  double m_Alpha;
276  double m_Gamma;
277 }; // end class SPSAOptimizer
278 } // end namespace itk
279 
280 #endif // end #ifndef itkSPSAOptimizer_h
SmartPointer< const Self > ConstPointer
Light weight base class for most itk classes.
void Setc(double c)
SPSAOptimizer Self
void SetMinimize(bool v)
An optimizer based on simultaneous perturbation...
This class is a base for the Optimization methods that optimize a single valued function.
StopConditionType m_StopCondition
DerivativeType m_Delta
unsigned long SizeValueType
Definition: itkIntTypes.h:143
double m_StateOfConvergenceDecayRate
SizeValueType m_CurrentIteration
SmartPointer< Self > Pointer
SizeValueType m_NumberOfPerturbations
DerivativeType m_Gradient
Statistics::MersenneTwisterRandomVariateGenerator::Pointer m_Generator
SizeValueType m_MinimumNumberOfIterations
bool GetMinimize() const
SizeValueType m_MaximumNumberOfIterations
SingleValuedNonLinearOptimizer Superclass
Control indentation during Print() invocation.
Definition: itkIndent.h:49