ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkSPSAOptimizer.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
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 * https://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
25namespace itk
26{
45// Define how to print enumeration
46extern ITKOptimizers_EXPORT std::ostream &
47 operator<<(std::ostream & out, const SPSAOptimizerEnums::StopConditionSPSAOptimizer value);
59
60class ITKOptimizers_EXPORT SPSAOptimizer : public SingleValuedNonLinearOptimizer
61{
62public:
63 ITK_DISALLOW_COPY_AND_MOVE(SPSAOptimizer);
64
70
72 itkNewMacro(Self);
73
75 itkOverrideGetNameOfClassMacro(SPSAOptimizer);
76
78#if !defined(ITK_LEGACY_REMOVE)
79 // We need to expose the enum values at the class level
80 // for backwards compatibility
81 static constexpr StopConditionSPSAOptimizerEnum Unknown = StopConditionSPSAOptimizerEnum::Unknown;
82 static constexpr StopConditionSPSAOptimizerEnum MaximumNumberOfIterations =
83 StopConditionSPSAOptimizerEnum::MaximumNumberOfIterations;
84 static constexpr StopConditionSPSAOptimizerEnum BelowTolerance = StopConditionSPSAOptimizerEnum::BelowTolerance;
85 static constexpr StopConditionSPSAOptimizerEnum MetricError = StopConditionSPSAOptimizerEnum::MetricError;
86#endif
88 virtual void
90
92 void
94
97 void
99
102 void
104
106 virtual MeasureType
107 GetValue() const;
108
110 virtual MeasureType
111 GetValue(const ParametersType & parameters) const;
112
123 virtual void
124 GuessParameters(SizeValueType numberOfGradientEstimates, double initialStepSize);
125
127 itkGetConstMacro(CurrentIteration, SizeValueType);
128
131
133 itkGetConstMacro(LearningRate, double);
134
136 itkGetConstMacro(GradientMagnitude, double);
137
139 itkGetConstReferenceMacro(Gradient, DerivativeType);
140
143 itkSetMacro(Sa, double);
144 itkGetConstMacro(Sa, double);
145 // For backward compatibility
146 void
147 Seta(double a)
148 {
149 SetSa(a);
150 }
151 double
152 Geta() const
153 {
154 return GetSa();
155 }
156
159 itkSetMacro(Sc, double);
160 itkGetConstMacro(Sc, double);
161 // For backward compatibility
162 void
163 Setc(double c)
164 {
165 SetSc(c);
166 }
167 double
168 Getc() const
169 {
170 return GetSc();
171 }
172
175 itkSetMacro(A, double);
176 itkGetConstMacro(A, double);
180 itkSetMacro(Alpha, double);
181 itkGetConstMacro(Alpha, double);
185 itkSetMacro(Gamma, double);
186 itkGetConstMacro(Gamma, double);
190 itkGetConstMacro(Maximize, bool);
191 itkSetMacro(Maximize, bool);
192 itkBooleanMacro(Maximize);
193 bool
195 {
196 return !m_Maximize;
197 }
198 void
200 {
201 this->SetMaximize(!v);
202 }
203 void
205 {
206 this->MaximizeOff();
207 }
208 void
210 {
211 this->MaximizeOn();
212 }
213
220 itkSetMacro(NumberOfPerturbations, SizeValueType);
221 itkGetConstMacro(NumberOfPerturbations, SizeValueType);
234 itkGetConstMacro(StateOfConvergence, double);
235
238 itkSetMacro(StateOfConvergenceDecayRate, double);
239 itkGetConstMacro(StateOfConvergenceDecayRate, double);
243 itkSetMacro(MinimumNumberOfIterations, SizeValueType);
244 itkGetConstMacro(MinimumNumberOfIterations, SizeValueType);
248 itkSetMacro(MaximumNumberOfIterations, SizeValueType);
249 itkGetConstMacro(MaximumNumberOfIterations, SizeValueType);
253 itkSetMacro(Tolerance, double);
254 itkGetConstMacro(Tolerance, double);
257 std::string
259
260protected:
262 ~SPSAOptimizer() override = default;
263
265 void
266 PrintSelf(std::ostream & os, Indent indent) const override;
267
270
272
274
275 bool m_Stop{ false };
276
278
280
282
285
287 virtual double
289
294 virtual double
296
303 virtual void
304 GenerateDelta(const unsigned int spaceDimension);
305
310 virtual void
311 ComputeGradient(const ParametersType & parameters, DerivativeType & gradient);
312
313private:
318 double m_Tolerance{};
322
324 double m_Sa{};
325 double m_Sc{};
326 double m_A{};
327 double m_Alpha{};
328 double m_Gamma{};
329}; // end class SPSAOptimizer
330
331// Define how to print enumeration
332extern ITKOptimizers_EXPORT std::ostream &
333 operator<<(std::ostream & out, const SPSAOptimizer::StopConditionSPSAOptimizerEnum value);
334
335} // end namespace itk
336
337#endif // end #ifndef itkSPSAOptimizer_h
Control indentation during Print() invocation.
Definition itkIndent.h:50
Contains all enum classes used by SPSAOptimizer class.
virtual void SetMaximize(bool _arg)
Statistics::MersenneTwisterRandomVariateGenerator::Pointer m_Generator
virtual void SetSc(double _arg)
SmartPointer< const Self > ConstPointer
void StartOptimization() override
SPSAOptimizerEnums::StopConditionSPSAOptimizer StopConditionSPSAOptimizerEnum
void PrintSelf(std::ostream &os, Indent indent) const override
SizeValueType m_NumberOfPerturbations
virtual void MaximizeOff()
virtual void GenerateDelta(const unsigned int spaceDimension)
virtual double Compute_a(SizeValueType k) const
SingleValuedNonLinearOptimizer Superclass
SizeValueType m_MaximumNumberOfIterations
~SPSAOptimizer() override=default
StopConditionSPSAOptimizerEnum m_StopCondition
DerivativeType m_Gradient
virtual void SetSa(double _arg)
DerivativeType m_Delta
virtual void AdvanceOneStep()
virtual void ComputeGradient(const ParametersType &parameters, DerivativeType &gradient)
virtual double Compute_c(SizeValueType k) const
virtual double GetSc() const
SizeValueType m_CurrentIteration
std::string GetStopConditionDescription() const override
virtual double GetSa() const
virtual void MaximizeOn()
virtual void GuessParameters(SizeValueType numberOfGradientEstimates, double initialStepSize)
virtual MeasureType GetValue() const
virtual MeasureType GetValue(const ParametersType &parameters) const
SizeValueType m_MinimumNumberOfIterations
SmartPointer< Self > Pointer
Implements transparent reference counting.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition itkIntTypes.h:86
ITKCommon_EXPORT std::ostream & operator<<(std::ostream &out, typename AnatomicalOrientation::CoordinateEnum value)