go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
elxAdaptiveStochasticLBFGS.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright UMC Utrecht and contributors
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 elxAdaptiveStochasticLBFGS_h
19#define elxAdaptiveStochasticLBFGS_h
20
21#include "elxIncludes.h" // include first to avoid MSVS warning
23
24#include "elxProgressCommand.h"
26#include "itkMersenneTwisterRandomVariateGenerator.h"
29#include "itkPlatformMultiThreader.h"
33
34
35namespace elastix
36{
102template <class TElastix>
103class ITK_TEMPLATE_EXPORT AdaptiveStochasticLBFGS
105 , public OptimizerBase<TElastix>
106{
107public:
109
114 using Pointer = itk::SmartPointer<Self>;
115 using ConstPointer = itk::SmartPointer<const Self>;
116
118 itkNewMacro(Self);
119
122
127 elxClassNameMacro("AdaptiveStochasticLBFGS");
128
130 using Superclass1::CostFunctionType;
131 using Superclass1::CostFunctionPointer;
133
135 using typename Superclass2::ElastixType;
136 using typename Superclass2::RegistrationType;
138 using SizeValueType = itk::SizeValueType;
139
140 // using LineSearchOptimizerType = LineSearchOptimizer ;
141
142 // using LineSearchOptimizerPointer = LineSearchOptimizerType::Pointer;
143
145 using typename Superclass1::ParametersType;
146
148
152
156 void
158 void
160 void
162 void
164 void
166
170 void
172
174 virtual void
176
178 void
179 AdvanceOneStep() override;
180
185 void
187
189 void
190 MetricErrorResponse(itk::ExceptionObject & err) override;
191
194 void
196
206 itkSetMacro(AutomaticParameterEstimation, bool);
207 itkGetConstMacro(AutomaticParameterEstimation, bool);
208
210 itkSetMacro(AutomaticLBFGSStepsizeEstimation, bool);
211 itkGetConstMacro(AutomaticLBFGSStepsizeEstimation, bool);
212
214 itkSetMacro(MaximumStepLength, double);
215 itkGetConstMacro(MaximumStepLength, double);
216
218 itkSetMacro(MaximumNumberOfSamplingAttempts, SizeValueType);
219
221 itkGetConstReferenceMacro(MaximumNumberOfSamplingAttempts, SizeValueType);
222
224 using ThreadIdType = unsigned int;
225
227 void
229 {
230 this->m_Threader->SetNumberOfWorkUnits(numberOfThreads);
231 }
232
233protected:
235 using FixedImageType = typename RegistrationType::FixedImageType;
236 using MovingImageType = typename RegistrationType::MovingImageType;
237
238 using FixedImageRegionType = typename FixedImageType::RegionType;
239 using FixedImageIndexType = typename FixedImageType::IndexType;
240 using FixedImagePointType = typename FixedImageType::PointType;
241 using itkRegistrationType = typename RegistrationType::ITKBaseType;
242 using TransformType = typename itkRegistrationType::TransformType;
243 using JacobianType = typename TransformType::JacobianType;
245 using JacobianValueType = typename JacobianType::ValueType;
247 {
248 double a, A, alpha, fmax, fmin, omega;
249 };
250 using SettingsVectorType = typename std::vector<SettingsType>;
251
253
262
267 using ImageRadomSampleContainerPointer = typename ImageRadomSampleContainerType::Pointer;
268
273 using ImageSampleContainerPointer = typename ImageSampleContainerType::Pointer;
274
276 using RandomGeneratorType = itk::Statistics::MersenneTwisterRandomVariateGenerator;
279
282 itkStaticConstMacro(FixedImageDimension, unsigned int, FixedImageType::ImageDimension);
283 itkStaticConstMacro(MovingImageDimension, unsigned int, MovingImageType::ImageDimension);
284 using CoordinateRepresentationType = typename TransformType::ScalarType;
288
290 using RhoType = itk::Array<double>;
291 using SType = std::vector<ParametersType>;
292 using YType = std::vector<DerivativeType>;
293 using DiagonalMatrixType = itk::Array<double>;
294
296 ~AdaptiveStochasticLBFGS() override = default;
297
300
305
308
310 typename RandomGeneratorType::Pointer m_RandomGenerator;
311
313
315 virtual void
317
322 virtual void
324
329 virtual void
331
335 virtual void
337
338 virtual void
340
348 virtual void
349 SampleGradients(const ParametersType & mu0, double perturbationSigma, double & gg, double & ee);
350
354 virtual void
355 GetScaledDerivativeWithExceptionHandling(const ParametersType & parameters, DerivativeType & derivative);
356
360 virtual void
361 AddRandomPerturbation(ParametersType & parameters, double sigma);
362
365 virtual void
366 StoreCurrentPoint(const ParametersType & step, const DerivativeType & grad_dif);
371 virtual void
373
380 virtual void
381 ComputeSearchDirection(const DerivativeType & gradient, DerivativeType & searchDir);
382
390
392 unsigned int m_CurrentT;
393 unsigned int m_PreviousT;
394 unsigned int m_Bound;
395
401
402private:
404
405 // multi-threaded AdvanceOneStep:
407 {
410 };
411
413 static itk::ITK_THREAD_RETURN_TYPE
415
417 inline void
419
423
429
431
437
442
444
445}; // end class AdaptiveStochasticLBFGS
446
447
448} // end namespace elastix
449
450#ifndef ITK_MANUAL_INSTANTIATION
451# include "elxAdaptiveStochasticLBFGS.hxx"
452#endif
453
454#endif // end #ifndef elxAdaptiveStochasticLBFGS_h
A gradient descent optimizer with an adaptive gain.
typename RegistrationType::ITKBaseType itkRegistrationType
typename TransformType::JacobianType JacobianType
typename TransformType::ScalarType CoordinateRepresentationType
virtual void StoreCurrentPoint(const ParametersType &step, const DerivativeType &grad_dif)
virtual void ComputeDiagonalMatrix(DiagonalMatrixType &diag_H0)
typename ImageRandomSamplerType::Pointer ImageRandomSamplerPointer
void SetNumberOfWorkUnits(ThreadIdType numberOfThreads)
ITK_DISALLOW_COPY_AND_MOVE(AdaptiveStochasticLBFGS)
itkStaticConstMacro(MovingImageDimension, unsigned int, MovingImageType::ImageDimension)
typename Superclass2::ITKBaseType ITKBaseType
virtual void PrintSettingsVector(const SettingsVectorType &settings) const
typename JacobianType::ValueType JacobianValueType
typename AdvancedTransformType::NonZeroJacobianIndicesType NonZeroJacobianIndicesType
virtual void AutomaticParameterEstimation()
typename ImageSampleContainerType::Pointer ImageSampleContainerPointer
typename std::vector< SettingsType > SettingsVectorType
void ThreadedAdvanceOneStep(ThreadIdType threadId, ParametersType &newPosition)
typename ImageGridSamplerType::ImageSampleContainerType ImageSampleContainerType
static itk::ITK_THREAD_RETURN_TYPE AdvanceOneStepThreaderCallback(void *arg)
virtual void ComputeSearchDirection(const DerivativeType &gradient, DerivativeType &searchDir)
virtual void AutomaticLBFGSStepsizeEstimation()
elxClassNameMacro("AdaptiveStochasticLBFGS")
RandomGeneratorType::Pointer m_RandomGenerator
virtual void AddRandomPerturbation(ParametersType &parameters, double sigma)
typename FixedImageType::PointType FixedImagePointType
typename itkRegistrationType::TransformType TransformType
typename ImageGridSamplerType::Pointer ImageGridSamplerPointer
typename FixedImageType::RegionType FixedImageRegionType
virtual void GetScaledDerivativeWithExceptionHandling(const ParametersType &parameters, DerivativeType &derivative)
void BeforeEachResolution() override
typename ProgressCommand::Pointer ProgressCommandPointer
itkStaticConstMacro(FixedImageDimension, unsigned int, FixedImageType::ImageDimension)
virtual void AutomaticParameterEstimationOriginal()
typename ImageSamplerBaseType::ImageSampleType ImageSampleType
typename ImageRadomSampleContainerType::Pointer ImageRadomSampleContainerPointer
typename RegistrationType::MovingImageType MovingImageType
virtual void SampleGradients(const ParametersType &mu0, double perturbationSigma, double &gg, double &ee)
typename ImageSamplerBaseType::Pointer ImageSamplerBasePointer
typename ImageRandomCoordinateSamplerType::Pointer ImageRandomCoordinateSamplerPointer
virtual void AutomaticParameterEstimationUsingDisplacementDistribution()
typename ImageRandomSamplerType::ImageSampleContainerType ImageRadomSampleContainerType
itk::SmartPointer< const Self > ConstPointer
typename RegistrationType::FixedImageType FixedImageType
typename ImageRandomSamplerBaseType::Pointer ImageRandomSamplerBasePointer
AdvancedTransformType::Pointer m_AdvancedTransform
itk::Statistics::MersenneTwisterRandomVariateGenerator RandomGeneratorType
typename FixedImageType::IndexType FixedImageIndexType
~AdaptiveStochasticLBFGS() override=default
void MetricErrorResponse(itk::ExceptionObject &err) override
This class is the elastix base class for all Optimizers.
typename ElastixType::RegistrationBaseType RegistrationType
itk::Optimizer ITKBaseType
typename ITKBaseType::ParametersType ParametersType
A specialized Command object for updating the progress of a filter.
itk::SmartPointer< Self > Pointer
Transform maps points, vectors and covariant vectors from an input space to an output space.
std::vector< unsigned long > NonZeroJacobianIndicesType
This is a helper class for the automatic parameter estimation of the ASGD optimizer.
This is a helper class for the automatic parameter estimation of the ASGD optimizer.
Samples image voxels on a regular grid.
Samples an image by randomly composing a set of physical coordinates.
This class is a base class for any image sampler that randomly picks samples.
Samples randomly some voxels of an image.
A class that defines an image sample, which is the coordinates of a point and its value.
This class is a base class for any image sampler.
A base class for LineSearch optimizers.
ITK version of the MoreThuente line search algorithm.
Define a front-end to the STL "vector" container that conforms to the IndexedContainerInterface.


Generated on 2023-01-13 for elastix by doxygen 1.9.6 elastix logo