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 "itkMultiThreaderBase.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;
246 using typename Superclass2::SettingsType;
247 using typename Superclass2::SettingsVectorType;
249
258
263 using ImageRadomSampleContainerPointer = typename ImageRadomSampleContainerType::Pointer;
264
269 using ImageSampleContainerPointer = typename ImageSampleContainerType::Pointer;
270
272 using RandomGeneratorType = itk::Statistics::MersenneTwisterRandomVariateGenerator;
273
276 itkStaticConstMacro(FixedImageDimension, unsigned int, FixedImageType::ImageDimension);
277 itkStaticConstMacro(MovingImageDimension, unsigned int, MovingImageType::ImageDimension);
278 using CoordinateRepresentationType = typename TransformType::ScalarType;
282
284 using RhoType = itk::Array<double>;
285 using SType = std::vector<ParametersType>;
286 using YType = std::vector<DerivativeType>;
287 using DiagonalMatrixType = itk::Array<double>;
288
290 ~AdaptiveStochasticLBFGS() override = default;
291
294
299
302
304 typename RandomGeneratorType::Pointer m_RandomGenerator;
305
307
312 virtual void
314
319 virtual void
321
325 virtual void
327
328 virtual void
330
338 virtual void
339 SampleGradients(const ParametersType & mu0, double perturbationSigma, double & gg, double & ee);
340
344 virtual void
345 GetScaledDerivativeWithExceptionHandling(const ParametersType & parameters, DerivativeType & derivative);
346
350 virtual void
351 AddRandomPerturbation(ParametersType & parameters, double sigma);
352
355 virtual void
356 StoreCurrentPoint(const ParametersType & step, const DerivativeType & grad_dif);
361 virtual void
363
370 virtual void
371 ComputeSearchDirection(const DerivativeType & gradient, DerivativeType & searchDir);
372
380
382 unsigned int m_CurrentT;
383 unsigned int m_PreviousT;
384 unsigned int m_Bound;
385
391
392private:
394
395 // multi-threaded AdvanceOneStep:
401
403 static itk::ITK_THREAD_RETURN_TYPE
405
407 inline void
409
413
419
421
427
432
434
435}; // end class AdaptiveStochasticLBFGS
436
437
438} // end namespace elastix
439
440#ifndef ITK_MANUAL_INSTANTIATION
441# include "elxAdaptiveStochasticLBFGS.hxx"
442#endif
443
444#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
typename JacobianType::ValueType JacobianValueType
typename AdvancedTransformType::NonZeroJacobianIndicesType NonZeroJacobianIndicesType
virtual void AutomaticParameterEstimation()
typename ImageSampleContainerType::Pointer ImageSampleContainerPointer
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
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
typename std::vector< SettingsType > SettingsVectorType
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
typename std::vector< SettingsType > SettingsVectorType
typename ITKBaseType::ParametersType ParametersType
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 2024-07-17 for elastix by doxygen 1.11.0 (9b424b03c9833626cd435af22a444888fbbb192d) elastix logo