ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkLBFGS2Optimizerv4.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 itkLBFGS2Optimizerv4_h
19 #define itkLBFGS2Optimizerv4_h
20 
21 
23 #include "ITKOptimizersv4Export.h"
24 #include "itkAutoPointer.h"
25 
26 
27 namespace itk
28 {
102 class ITKOptimizersv4_EXPORT LBFGS2Optimizerv4:
104 
105 public:
106 
109  LINESEARCH_DEFAULT = 0,
110 
112  LINESEARCH_MORETHUENTE = 0,
113 
123  LINESEARCH_BACKTRACKING_ARMIJO = 1,
124 
126  LINESEARCH_BACKTRACKING = 2,
127 
138  LINESEARCH_BACKTRACKING_WOLFE = 2,
139 
150  LINESEARCH_BACKTRACKING_STRONG_WOLFE = 3,
151  };
152 
153 
159  typedef double PrecisionType;
160 
161 
167 
168  typedef Superclass::MetricType MetricType;
169  typedef Superclass::ParametersType ParametersType;
170  typedef Superclass::ScalesType ScalesType;
171 
173  itkNewMacro(Self);
174 
176  itkTypeMacro(LBFGS2Optimizerv4, Superclass);
177 
179  virtual void StartOptimization(bool doOnlyInitialization = false) ITK_OVERRIDE;
180 
181  virtual const StopConditionReturnStringType GetStopConditionDescription() const ITK_OVERRIDE;
182 
184  virtual void SetScales(const ScalesType &) ITK_OVERRIDE;
185 
187  virtual void SetWeights(const ScalesType ) ITK_OVERRIDE;
188 
197  void SetHessianApproximationAccuracy(int m);
198  int GetHessianApproximationAccuracy() const;
200 
209  void SetSolutionAccuracy(PrecisionType epsilon);
210  PrecisionType GetSolutionAccuracy() const;
212 
220  void SetDeltaConvergenceDistance(int nPast);
221  int GetDeltaConvergenceDistance() const;
223 
234  void SetDeltaConvergenceTolerance(PrecisionType tol);
235  PrecisionType GetDeltaConvergenceTolerance() const;
237 
238 
247  void SetMaximumIterations(int maxIterations);
248  int GetMaximumIterations() const;
250 
253  virtual SizeValueType GetNumberOfIterations() const ITK_OVERRIDE { return GetMaximumIterations(); }
254  virtual void SetNumberOfIterations( const SizeValueType _arg ) ITK_OVERRIDE { SetMaximumIterations(static_cast<int>(_arg)); }
256 
263  void SetLineSearch(const LineSearchMethod &linesearch);
264  LineSearchMethod GetLineSearch() const;
266 
272  void SetMaximumLineSearchEvaluations(int n);
273  int GetMaximumLineSearchEvaluations() const;
275 
283  void SetMinimumLineSearchStep(PrecisionType step);
284  PrecisionType GetMinimumLineSearchStep() const;
286 
294  void SetMaximumLineSearchStep(PrecisionType step);
295  PrecisionType GetMaximumLineSearchStep() const;
297 
303  void SetLineSearchAccuracy( PrecisionType ftol );
304  PrecisionType GetLineSearchAccuracy() const;
306 
307 
317  void SetWolfeCoefficient( PrecisionType wc );
318  PrecisionType GetWolfeCoefficient() const;
320 
321 
333  void SetLineSearchGradientAccuracy( PrecisionType gtol );
334  PrecisionType GetLineSearchGradientAccuracy() const;
336 
344  void SetMachinePrecisionTolerance(PrecisionType xtol);
345  PrecisionType GetMachinePrecisionTolerance() const;
347 
361  void SetOrthantwiseCoefficient( PrecisionType orthant_c);
362  PrecisionType GetOrthantwiseCoefficient() const;
364 
379  void SetOrthantwiseStart(int start);
380  int GetOrthantwiseStart() const;
382 
390  void SetOrthantwiseEnd(int end);
391  int GetOrthantwiseEnd() const;
393 
395  itkGetConstMacro(CurrentParameterNorm, PrecisionType);
396 
398  itkGetConstMacro(CurrentGradientNorm, PrecisionType);
399  //itkGetConstMacro(CurrentParameter, double* );
400  //itkGetConstMacro(CurrentGradient, double* );
401 
403  itkGetConstMacro(CurrentStepSize, PrecisionType);
404 
406  itkGetConstMacro(CurrentNumberOfEvaluations, PrecisionType);
407 
408 protected:
410  virtual ~LBFGS2Optimizerv4() ITK_OVERRIDE;
411  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
412 
413 
415  static int UpdateProgressCallback( void *Instance,
416  const PrecisionType *x,
417  const PrecisionType *g,
418  const PrecisionType fx,
419  const PrecisionType xnorm,
420  const PrecisionType gnorm,
421  const PrecisionType step,
422  int n,
423  int k,
424  int ls
425  );
426 
428  int UpdateProgress( const PrecisionType *x,
429  const PrecisionType *g,
430  const PrecisionType fx,
431  const PrecisionType xnorm,
432  const PrecisionType gnorm,
433  const PrecisionType step,
434  int n,
435  int k,
436  int ls
437  );
438 
440  static PrecisionType EvaluateCostCallback( void *instance,
441  const PrecisionType *x,
442  PrecisionType *g,
443  const int n,
444  const PrecisionType step
445  );
446 
447  PrecisionType EvaluateCost( const PrecisionType *x,
448  PrecisionType *g,
449  const int n,
450  const PrecisionType step
451  );
452 
453 private:
454  ITK_DISALLOW_COPY_AND_ASSIGN(LBFGS2Optimizerv4);
455 
456  // Private Implementation (Pimpl), to hide liblbfgs data structures
457  class PrivateImplementationHolder;
458 
459  AutoPointer<PrivateImplementationHolder> m_Pimpl;
460 
462  const double *m_CurrentGradient;
463  const double *m_CurrentParameter;
464 
465  double m_CurrentStepSize;
466  double m_CurrentParameterNorm;
467  double m_CurrentGradientNorm;
468  int m_CurrentNumberOfEvaluations;
469 
470  int m_StatusCode;
471 };
472 
473 } // end namespace itk
474 #endif
Light weight base class for most itk classes.
Superclass::ScalesType ScalesType
unsigned long SizeValueType
Definition: itkIntTypes.h:143
Superclass::MetricType MetricType
SmartPointer< const Self > ConstPointer
Superclass::ParametersType ParametersType
virtual void SetNumberOfIterations(const SizeValueType _arg) override
Wrap of the libLBFGS[1] algorithm for use in ITKv4 registration framework. LibLBFGS is a translation ...
Implements an Automatic Pointer to an object.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Abstract base for object-to-object optimizers.
SmartPointer< Self > Pointer
ObjectToObjectOptimizerBaseTemplate< double > Superclass