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"
25 #include "itkAdvancedTransform.h"
26 #include "itkMersenneTwisterRandomVariateGenerator.h"
29 #include "itkPlatformMultiThreader.h"
30 #include "itkImageRandomSampler.h"
31 #include "itkLineSearchOptimizer.h"
33 
34 
35 namespace elastix
36 {
102 template <class TElastix>
105  public OptimizerBase<TElastix>
106 {
107 public:
108 
113  typedef itk::SmartPointer<Self> Pointer;
114  typedef itk::SmartPointer<const Self> ConstPointer;
115 
117  itkNewMacro( Self );
118 
120  itkTypeMacro( AdaptiveStochasticLBFGS,
122 
127  elxClassNameMacro( "AdaptiveStochasticLBFGS" );
128 
131  typedef Superclass1::CostFunctionPointer CostFunctionPointer;
133 
142  typedef itk::SizeValueType SizeValueType;
143 
144 // typedef LineSearchOptimizer LineSearchOptimizerType;
145 
146 // typedef LineSearchOptimizerType::Pointer LineSearchOptimizerPointer;
147 
150 
152 
156 
160  void BeforeRegistration( void ) override;
161  void BeforeEachResolution( void ) override;
162  void AfterEachResolution( void ) override;
163  void AfterEachIteration( void ) override;
164  void AfterRegistration( void ) override;
165 
169  void StartOptimization( void ) override;
170 
172  virtual void LBFGSUpdate( void );
173 
175  void AdvanceOneStep( void ) override;
176 
181  void ResumeOptimization( void ) override;
182 
184  void MetricErrorResponse( itk::ExceptionObject & err ) override;
185 
188  void StopOptimization( void ) override;
189 
199  itkSetMacro( AutomaticParameterEstimation, bool );
200  itkGetConstMacro( AutomaticParameterEstimation, bool );
201 
203  itkSetMacro( AutomaticLBFGSStepsizeEstimation, bool );
204  itkGetConstMacro( AutomaticLBFGSStepsizeEstimation, bool );
205 
207  itkSetMacro( MaximumStepLength, double );
208  itkGetConstMacro( MaximumStepLength, double );
209 
211  itkSetMacro( MaximumNumberOfSamplingAttempts, SizeValueType );
212 
214  itkGetConstReferenceMacro( MaximumNumberOfSamplingAttempts, SizeValueType );
215 
217  typedef unsigned int ThreadIdType;
218 
220  void SetNumberOfWorkUnits( ThreadIdType numberOfThreads )
221  {
222  this->m_Threader->SetNumberOfWorkUnits( numberOfThreads );
223  }
224 
225 protected:
226 
228  typedef typename RegistrationType::FixedImageType FixedImageType;
229  typedef typename RegistrationType::MovingImageType MovingImageType;
230 
231  typedef typename FixedImageType::RegionType FixedImageRegionType;
232  typedef typename FixedImageType::IndexType FixedImageIndexType;
233  typedef typename FixedImageType::PointType FixedImagePointType;
234  typedef typename RegistrationType::ITKBaseType itkRegistrationType;
235  typedef typename itkRegistrationType::TransformType TransformType;
236  typedef typename TransformType::JacobianType JacobianType;
239  typedef typename JacobianType::ValueType JacobianValueType;
240  struct SettingsType { double a, A, alpha, fmax, fmin, omega; };
241  typedef typename std::vector<SettingsType> SettingsVectorType;
242 
245 
250  typedef typename
252  typedef
254  typedef typename
257 
261  typedef typename
263  typedef typename
265 
269  typedef typename
272 
274  typedef itk::Statistics::MersenneTwisterRandomVariateGenerator RandomGeneratorType;
277 
280  itkStaticConstMacro( FixedImageDimension, unsigned int, FixedImageType::ImageDimension );
281  itkStaticConstMacro( MovingImageDimension, unsigned int, MovingImageType::ImageDimension );
282  typedef typename TransformType::ScalarType CoordinateRepresentationType;
283  typedef itk::AdvancedTransform<
285  itkGetStaticConstMacro(FixedImageDimension),
286  itkGetStaticConstMacro(MovingImageDimension) > AdvancedTransformType;
287  typedef typename
289 
291  typedef itk::Array< double > RhoType;
292  typedef std::vector< ParametersType > SType;
293  typedef std::vector< DerivativeType > YType;
294  typedef itk::Array< double > DiagonalMatrixType;
295 
298 
301 
306 
309 
311  typename RandomGeneratorType::Pointer m_RandomGenerator;
312 
314 
316  virtual void CheckForAdvancedTransform( void );
317 
319  virtual void PrintSettingsVector( const SettingsVectorType & settings ) const;
320 
325  virtual void AutomaticParameterEstimation( void );
326 
332 
337 
338  virtual void AutomaticLBFGSStepsizeEstimation( void );
339 
347  virtual void SampleGradients( const ParametersType & mu0,
348  double perturbationSigma, double & gg, double & ee );
349 
354  const ParametersType & parameters, DerivativeType & derivative );
355 
359  virtual void AddRandomPerturbation( ParametersType & parameters, double sigma );
360 
363  virtual void StoreCurrentPoint(
364  const ParametersType & step,
365  const DerivativeType & grad_dif );
370  virtual void ComputeDiagonalMatrix( DiagonalMatrixType & diag_H0 );
371 
379  const DerivativeType & gradient,
380  DerivativeType & searchDir );
381 
389 
391  unsigned int m_CurrentT;
392  unsigned int m_PreviousT;
393  unsigned int m_Bound;
394 
400 
401 private:
402 
403  AdaptiveStochasticLBFGS( const Self& ); // purposely not implemented
404  void operator=( const Self& ); // purposely not implemented
405 
406  // multi-threaded AdvanceOneStep:
408  {
411  };
412 
414  static itk::ITK_THREAD_RETURN_TYPE AdvanceOneStepThreaderCallback( void * arg );
415 
417  inline void ThreadedAdvanceOneStep( ThreadIdType threadId, ParametersType & newPosition );
418 
422 
428 
430 
436 
441 
443 
444 }; // end class AdaptiveStochasticLBFGS
445 
446 
447 } // end namespace elastix
448 
449 #ifndef ITK_MANUAL_INSTANTIATION
450 #include "elxAdaptiveStochasticLBFGS.hxx"
451 #endif
452 
453 #endif // end #ifndef __elxAdaptiveStochasticLBFGS_h
A gradient descent optimizer with an adaptive gain.
virtual void AutomaticLBFGSStepsizeEstimation(void)
Superclass1::ParametersType ParametersType
itk::SmartPointer< const Self > ConstPointer
void StartOptimization(void) override
virtual void StoreCurrentPoint(const ParametersType &step, const DerivativeType &grad_dif)
virtual void ComputeDiagonalMatrix(DiagonalMatrixType &diag_H0)
FixedImageType::IndexType FixedImageIndexType
Superclass2::ConfigurationType ConfigurationType
void SetNumberOfWorkUnits(ThreadIdType numberOfThreads)
LineSearchOptimizerType::Pointer LineSearchOptimizerPointer
itkRegistrationType::TransformType TransformType
itkStaticConstMacro(MovingImageDimension, unsigned int, MovingImageType::ImageDimension)
virtual void PrintSettingsVector(const SettingsVectorType &settings) const
ImageRandomSamplerType::Pointer ImageRandomSamplerPointer
void AfterEachResolution(void) override
virtual void AutomaticParameterEstimationUsingDisplacementDistribution(void)
RegistrationType::FixedImageType FixedImageType
void ThreadedAdvanceOneStep(ThreadIdType threadId, ParametersType &newPosition)
Superclass1::CostFunctionPointer CostFunctionPointer
TransformType::ScalarType CoordinateRepresentationType
ImageRandomSamplerType::ImageSampleContainerType ImageRadomSampleContainerType
void ResumeOptimization(void) override
static itk::ITK_THREAD_RETURN_TYPE AdvanceOneStepThreaderCallback(void *arg)
void StopOptimization(void) override
virtual void ComputeSearchDirection(const DerivativeType &gradient, DerivativeType &searchDir)
ImageRandomSamplerBaseType::Pointer ImageRandomSamplerBasePointer
AdaptiveStochasticLBFGSOptimizer Superclass1
itk::ImageRandomCoordinateSampler< FixedImageType > ImageRandomCoordinateSamplerType
elxClassNameMacro("AdaptiveStochasticLBFGS")
AdvancedTransformType::NonZeroJacobianIndicesType NonZeroJacobianIndicesType
virtual void AutomaticParameterEstimation(void)
virtual void CheckForAdvancedTransform(void)
virtual void LBFGSUpdate(void)
itk::ImageRandomSampler< FixedImageType > ImageRandomSamplerType
Superclass2::RegistrationType RegistrationType
RandomGeneratorType::Pointer m_RandomGenerator
virtual void AddRandomPerturbation(ParametersType &parameters, double sigma)
itk::ImageRandomSamplerBase< FixedImageType > ImageRandomSamplerBaseType
itk::MoreThuenteLineSearchOptimizer LineOptimizerType
itk::Statistics::MersenneTwisterRandomVariateGenerator RandomGeneratorType
itk::ComputeJacobianTerms< FixedImageType, TransformType > ComputeJacobianTermsType
virtual void GetScaledDerivativeWithExceptionHandling(const ParametersType &parameters, DerivativeType &derivative)
std::vector< SettingsType > SettingsVectorType
itkStaticConstMacro(FixedImageDimension, unsigned int, FixedImageType::ImageDimension)
ImageGridSamplerType::ImageSampleContainerType ImageSampleContainerType
itk::ImageGridSampler< FixedImageType > ImageGridSamplerType
virtual void AutomaticParameterEstimationOriginal(void)
TransformType::JacobianType JacobianType
virtual void SampleGradients(const ParametersType &mu0, double perturbationSigma, double &gg, double &ee)
itk::AdvancedTransform< CoordinateRepresentationType, itkGetStaticConstMacro(FixedImageDimension), itkGetStaticConstMacro(MovingImageDimension) > AdvancedTransformType
Superclass1::CostFunctionType CostFunctionType
Superclass1::StopConditionType StopConditionType
LineOptimizerType::Pointer LineOptimizerPointer
ImageSamplerBaseType::Pointer ImageSamplerBasePointer
FixedImageType::RegionType FixedImageRegionType
void BeforeRegistration(void) override
ImageRandomCoordinateSamplerType::Pointer ImageRandomCoordinateSamplerPointer
Superclass2::ElastixPointer ElastixPointer
ProgressCommand::Pointer ProgressCommandPointer
itk::ImageSamplerBase< FixedImageType > ImageSamplerBaseType
ImageGridSamplerType::Pointer ImageGridSamplerPointer
ImageSampleContainerType::Pointer ImageSampleContainerPointer
void AfterEachIteration(void) override
ImageRadomSampleContainerType::Pointer ImageRadomSampleContainerPointer
RegistrationType::MovingImageType MovingImageType
void AdvanceOneStep(void) override
AdvancedTransformType::Pointer m_AdvancedTransform
Superclass2::ConfigurationPointer ConfigurationPointer
RegistrationType::ITKBaseType itkRegistrationType
void BeforeEachResolution(void) override
FixedImageType::PointType FixedImagePointType
void AfterRegistration(void) override
Superclass2::RegistrationPointer RegistrationPointer
void MetricErrorResponse(itk::ExceptionObject &err) override
itk::ComputeDisplacementDistribution< FixedImageType, TransformType > ComputeDisplacementDistributionType
ImageSamplerBaseType::ImageSampleType ImageSampleType
itk::LineSearchOptimizer LineSearchOptimizerType
A class that deals with user given parameters and command line arguments.
This class is the elastix base class for all Optimizers.
Superclass::ConfigurationPointer ConfigurationPointer
itk::Optimizer ITKBaseType
Superclass::ElastixType ElastixType
Superclass::ElastixPointer ElastixPointer
Superclass::RegistrationPointer RegistrationPointer
Superclass::RegistrationType RegistrationType
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.
SmartPointer< Self > Pointer
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.
SmartPointer< Self > Pointer
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.
SmartPointer< Self > Pointer
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.
SmartPointer< Self > Pointer
A base class for LineSearch optimizers.
SmartPointer< Self > Pointer
ITK version of the MoreThuente line search algorithm.
Define a front-end to the STL "vector" container that conforms to the IndexedContainerInterface.
SmartPointer< Self > Pointer


Generated on 1667476801 for elastix by doxygen 1.9.1 elastix logo