ITK  5.0.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 <memory>
25 
26 
27 namespace itk
28 {
102 class ITKOptimizersv4_EXPORT LBFGS2Optimizerv4:
104 
105 public:
106  ITK_DISALLOW_COPY_AND_ASSIGN(LBFGS2Optimizerv4);
107 
110  LINESEARCH_DEFAULT = 0,
111 
113  LINESEARCH_MORETHUENTE = 0,
114 
124  LINESEARCH_BACKTRACKING_ARMIJO = 1,
125 
127  LINESEARCH_BACKTRACKING = 2,
128 
139  LINESEARCH_BACKTRACKING_WOLFE = 2,
140 
151  LINESEARCH_BACKTRACKING_STRONG_WOLFE = 3,
152  };
153 
154 
160  using PrecisionType = double;
161 
162 
168 
169  using MetricType = Superclass::MetricType;
170  using ParametersType = Superclass::ParametersType;
171  using ScalesType = Superclass::ScalesType;
172 
174  itkNewMacro(Self);
175 
177  itkTypeMacro(LBFGS2Optimizerv4, Superclass);
178 
180  void StartOptimization(bool doOnlyInitialization = false) override;
181 
182  const StopConditionReturnStringType GetStopConditionDescription() const override;
183 
185  void SetScales(const ScalesType &) override;
186 
188  void SetWeights(const ScalesType ) override;
189 
198  void SetHessianApproximationAccuracy(int m);
199  int GetHessianApproximationAccuracy() const;
201 
210  void SetSolutionAccuracy(PrecisionType epsilon);
211  PrecisionType GetSolutionAccuracy() const;
213 
221  void SetDeltaConvergenceDistance(int nPast);
222  int GetDeltaConvergenceDistance() const;
224 
235  void SetDeltaConvergenceTolerance(PrecisionType tol);
236  PrecisionType GetDeltaConvergenceTolerance() const;
238 
239 
248  void SetMaximumIterations(int maxIterations);
249  int GetMaximumIterations() const;
251 
254  SizeValueType GetNumberOfIterations() const override { return GetMaximumIterations(); }
255  void SetNumberOfIterations( const SizeValueType _arg ) override { SetMaximumIterations(static_cast<int>(_arg)); }
257 
264  void SetLineSearch(const LineSearchMethod &linesearch);
265  LineSearchMethod GetLineSearch() const;
267 
273  void SetMaximumLineSearchEvaluations(int n);
274  int GetMaximumLineSearchEvaluations() const;
276 
284  void SetMinimumLineSearchStep(PrecisionType step);
285  PrecisionType GetMinimumLineSearchStep() const;
287 
295  void SetMaximumLineSearchStep(PrecisionType step);
296  PrecisionType GetMaximumLineSearchStep() const;
298 
304  void SetLineSearchAccuracy( PrecisionType ftol );
305  PrecisionType GetLineSearchAccuracy() const;
307 
308 
318  void SetWolfeCoefficient( PrecisionType wc );
319  PrecisionType GetWolfeCoefficient() const;
321 
322 
334  void SetLineSearchGradientAccuracy( PrecisionType gtol );
335  PrecisionType GetLineSearchGradientAccuracy() const;
337 
345  void SetMachinePrecisionTolerance(PrecisionType xtol);
346  PrecisionType GetMachinePrecisionTolerance() const;
348 
362  void SetOrthantwiseCoefficient( PrecisionType orthant_c);
363  PrecisionType GetOrthantwiseCoefficient() const;
365 
380  void SetOrthantwiseStart(int start);
381  int GetOrthantwiseStart() const;
383 
391  void SetOrthantwiseEnd(int end);
392  int GetOrthantwiseEnd() const;
394 
396  itkGetConstMacro(CurrentParameterNorm, PrecisionType);
397 
399  itkGetConstMacro(CurrentGradientNorm, PrecisionType);
400  //itkGetConstMacro(CurrentParameter, double* );
401  //itkGetConstMacro(CurrentGradient, double* );
402 
404  itkGetConstMacro(CurrentStepSize, PrecisionType);
405 
407  itkGetConstMacro(CurrentNumberOfEvaluations, PrecisionType);
408 
409 protected:
411  ~LBFGS2Optimizerv4() override;
412  void PrintSelf(std::ostream & os, Indent indent) const override;
413 
414 
416  static int UpdateProgressCallback( void *Instance,
417  const PrecisionType *x,
418  const PrecisionType *g,
419  const PrecisionType fx,
420  const PrecisionType xnorm,
421  const PrecisionType gnorm,
422  const PrecisionType step,
423  int n,
424  int k,
425  int ls
426  );
427 
429  int UpdateProgress( const PrecisionType *x,
430  const PrecisionType *g,
431  const PrecisionType fx,
432  const PrecisionType xnorm,
433  const PrecisionType gnorm,
434  const PrecisionType step,
435  int n,
436  int k,
437  int ls
438  );
439 
441  static PrecisionType EvaluateCostCallback( void *instance,
442  const PrecisionType *x,
443  PrecisionType *g,
444  const int n,
445  const PrecisionType step
446  );
447 
448  PrecisionType EvaluateCost( const PrecisionType *x,
449  PrecisionType *g,
450  const int n,
451  const PrecisionType step
452  );
453 
454 private:
455  // Private Implementation (Pimpl), to hide liblbfgs data structures
456  class PrivateImplementationHolder;
457 
458  std::unique_ptr<PrivateImplementationHolder> m_Pimpl;
459 
461  const double *m_CurrentGradient;
462  const double *m_CurrentParameter;
463 
468 
470 };
471 
472 } // end namespace itk
473 #endif
Light weight base class for most itk classes.
unsigned long SizeValueType
Definition: itkIntTypes.h:83
void SetNumberOfIterations(const SizeValueType _arg) override
SizeValueType GetNumberOfIterations() const override
std::unique_ptr< PrivateImplementationHolder > m_Pimpl
Wrap of the libLBFGS[1] algorithm for use in ITKv4 registration framework. LibLBFGS is a translation ...
Superclass::ScalesType ScalesType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Superclass::MetricType MetricType
Superclass::ParametersType ParametersType
Abstract base for object-to-object optimizers.