ITK  5.0.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  ITK_DISALLOW_COPY_AND_ASSIGN(SPSAOptimizer);
49 
55 
57  itkNewMacro(Self);
58 
61 
63  typedef enum {
67  MetricError
68  } StopConditionType;
69 
71  virtual void AdvanceOneStep();
72 
74  void StartOptimization() override;
75 
78  void ResumeOptimization();
79 
82  void StopOptimization();
83 
85  virtual MeasureType GetValue() const;
86 
88  virtual MeasureType GetValue(const ParametersType & parameters) const;
89 
103  virtual void GuessParameters(
104  SizeValueType numberOfGradientEstimates,
105  double initialStepSize);
106 
108  itkGetConstMacro(CurrentIteration, SizeValueType);
109 
111  itkGetConstMacro(StopCondition, StopConditionType);
112 
114  itkGetConstMacro(LearningRate, double);
115 
117  itkGetConstMacro(GradientMagnitude, double);
118 
120  itkGetConstReferenceMacro(Gradient, DerivativeType);
121 
123  itkSetMacro(Sa, double);
124  itkGetConstMacro(Sa, double);
125  // For backward compatibility
126  void Seta(double a) { SetSa(a); }
127  double Geta() { return GetSa(); }
129 
131  itkSetMacro(Sc, double);
132  itkGetConstMacro(Sc, double);
133  // For backward compatibility
134  void Setc(double c) { SetSc(c); }
135  double Getc() { return GetSc(); }
137 
139  itkSetMacro(A, double);
140  itkGetConstMacro(A, double);
142 
144  itkSetMacro(Alpha, double);
145  itkGetConstMacro(Alpha, double);
147 
149  itkSetMacro(Gamma, double);
150  itkGetConstMacro(Gamma, double);
152 
154  itkGetConstMacro(Maximize, bool);
155  itkSetMacro(Maximize, bool);
156  itkBooleanMacro(Maximize);
157  bool GetMinimize() const
158  { return !m_Maximize; }
159  void SetMinimize(bool v)
160  { this->SetMaximize(!v); }
161  void MinimizeOn()
162  { this->MaximizeOff(); }
163  void MinimizeOff()
164  { this->MaximizeOn(); }
166 
172  itkSetMacro(NumberOfPerturbations, SizeValueType);
173  itkGetConstMacro(NumberOfPerturbations, SizeValueType);
175 
187  itkGetConstMacro(StateOfConvergence, double);
188 
190  itkSetMacro(StateOfConvergenceDecayRate, double);
191  itkGetConstMacro(StateOfConvergenceDecayRate, double);
193 
195  itkSetMacro(MinimumNumberOfIterations, SizeValueType);
196  itkGetConstMacro(MinimumNumberOfIterations, SizeValueType);
198 
200  itkSetMacro(MaximumNumberOfIterations, SizeValueType);
201  itkGetConstMacro(MaximumNumberOfIterations, SizeValueType);
203 
205  itkSetMacro(Tolerance, double);
206  itkGetConstMacro(Tolerance, double);
208 
210  const std::string GetStopConditionDescription() const override;
211 
212 protected:
213 
214  SPSAOptimizer();
215  ~SPSAOptimizer() override = default;
216 
218  void PrintSelf(std::ostream & os, Indent indent) const override;
219 
221  DerivativeType m_Gradient;
222 
224 
225  DerivativeType m_Delta;
226 
227  bool m_Stop{false};
228 
230 
232 
234 
237 
239  virtual double Compute_a(SizeValueType k) const;
240 
245  virtual double Compute_c(SizeValueType k) const;
246 
248  virtual void GenerateDelta(const unsigned int spaceDimension);
249 
254  virtual void ComputeGradient(
255  const ParametersType & parameters,
256  DerivativeType & gradient);
257 
258 private:
259 
264  double m_Tolerance;
268 
270  double m_Sa;
271  double m_Sc;
272  double m_A;
273  double m_Alpha;
274  double m_Gamma;
275 }; // end class SPSAOptimizer
276 } // end namespace itk
277 
278 #endif // end #ifndef itkSPSAOptimizer_h
Light weight base class for most itk classes.
void Setc(double c)
unsigned long SizeValueType
Definition: itkIntTypes.h:83
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
void Seta(double a)
double m_StateOfConvergenceDecayRate
SizeValueType m_CurrentIteration
SizeValueType m_NumberOfPerturbations
DerivativeType m_Gradient
Statistics::MersenneTwisterRandomVariateGenerator::Pointer m_Generator
SizeValueType m_MinimumNumberOfIterations
bool GetMinimize() const
SizeValueType m_MaximumNumberOfIterations
Control indentation during Print() invocation.
Definition: itkIndent.h:49