ITK  5.2.0
Insight Toolkit
itkLBFGS2Optimizerv4.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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 {
29 /*** \class LBFGS2Optimizerv4Enums
30  * \brief Scoped Enum classes for LBFGS2Optimizerv4 class
31  * \ingroup ITKOptimizersv4
32  */
34 {
35 public:
36  /***\class LineSearchMethod
37  * \ingroup ITKOptimizersv4
38  * Line search method enum
39  */
41  {
44 
47 
58 
61 
73 
85  };
86 };
87 // Define how to print enumeration
88 extern ITKOptimizersv4_EXPORT std::ostream &
89  operator<<(std::ostream & out, LBFGS2Optimizerv4Enums::LineSearchMethod value);
91 
165 
166 
167 class ITKOptimizersv4_EXPORT LBFGS2Optimizerv4 : public ObjectToObjectOptimizerBaseTemplate<double>
168 {
169 
170 public:
171  ITK_DISALLOW_COPY_AND_MOVE(LBFGS2Optimizerv4);
172 
174 #if !defined(ITK_LEGACY_REMOVE)
175 
176  static constexpr LineSearchMethodEnum LINESEARCH_DEFAULT = LineSearchMethodEnum::LINESEARCH_DEFAULT;
177  static constexpr LineSearchMethodEnum LINESEARCH_MORETHUENTE = LineSearchMethodEnum::LINESEARCH_MORETHUENTE;
178  static constexpr LineSearchMethodEnum LINESEARCH_BACKTRACKING_ARMIJO =
179  LineSearchMethodEnum::LINESEARCH_BACKTRACKING_ARMIJO;
180  static constexpr LineSearchMethodEnum LINESEARCH_BACKTRACKING = LineSearchMethodEnum::LINESEARCH_BACKTRACKING;
181  static constexpr LineSearchMethodEnum LINESEARCH_BACKTRACKING_WOLFE =
182  LineSearchMethodEnum::LINESEARCH_BACKTRACKING_WOLFE;
183  static constexpr LineSearchMethodEnum LINESEARCH_BACKTRACKING_STRONG_WOLFE =
184  LineSearchMethodEnum::LINESEARCH_BACKTRACKING_STRONG_WOLFE;
185 #endif
186 
192  using PrecisionType = double;
193 
194 
200 
201  using MetricType = Superclass::MetricType;
202  using ParametersType = Superclass::ParametersType;
203  using ScalesType = Superclass::ScalesType;
204 
206  itkNewMacro(Self);
207 
209  itkTypeMacro(LBFGS2Optimizerv4, Superclass);
210 
212  void
213  StartOptimization(bool doOnlyInitialization = false) override;
214 
216  GetStopConditionDescription() const override;
217 
219  void
220  SetScales(const ScalesType &) override;
221 
223  void
224  SetWeights(const ScalesType) override;
225 
234  void
235  SetHessianApproximationAccuracy(int m);
236  int
237  GetHessianApproximationAccuracy() const;
239 
248  void
249  SetSolutionAccuracy(PrecisionType epsilon);
251  GetSolutionAccuracy() const;
253 
261  void
262  SetDeltaConvergenceDistance(int nPast);
263  int
264  GetDeltaConvergenceDistance() const;
266 
277  void
278  SetDeltaConvergenceTolerance(PrecisionType tol);
280  GetDeltaConvergenceTolerance() const;
282 
283 
292  void
293  SetMaximumIterations(int maxIterations);
294  int
295  GetMaximumIterations() const;
297 
301  GetNumberOfIterations() const override
302  {
303  return GetMaximumIterations();
304  }
305  void
307  {
308  SetMaximumIterations(static_cast<int>(_arg));
309  }
311 
318  void
319  SetLineSearch(const LineSearchMethodEnum & linesearch);
320  LineSearchMethodEnum
321  GetLineSearch() const;
323 
329  void
330  SetMaximumLineSearchEvaluations(int n);
331  int
332  GetMaximumLineSearchEvaluations() const;
334 
342  void
343  SetMinimumLineSearchStep(PrecisionType step);
344  PrecisionType
345  GetMinimumLineSearchStep() const;
347 
355  void
356  SetMaximumLineSearchStep(PrecisionType step);
357  PrecisionType
358  GetMaximumLineSearchStep() const;
360 
366  void
367  SetLineSearchAccuracy(PrecisionType ftol);
368  PrecisionType
369  GetLineSearchAccuracy() const;
371 
372 
382  void
383  SetWolfeCoefficient(PrecisionType wc);
384  PrecisionType
385  GetWolfeCoefficient() const;
387 
388 
400  void
401  SetLineSearchGradientAccuracy(PrecisionType gtol);
402  PrecisionType
403  GetLineSearchGradientAccuracy() const;
405 
413  void
414  SetMachinePrecisionTolerance(PrecisionType xtol);
415  PrecisionType
416  GetMachinePrecisionTolerance() const;
418 
432  void
433  SetOrthantwiseCoefficient(PrecisionType orthant_c);
434  PrecisionType
435  GetOrthantwiseCoefficient() const;
437 
452  void
453  SetOrthantwiseStart(int start);
454  int
455  GetOrthantwiseStart() const;
457 
465  void
466  SetOrthantwiseEnd(int end);
467  int
468  GetOrthantwiseEnd() const;
470 
472  itkGetConstMacro(CurrentParameterNorm, PrecisionType);
473 
475  itkGetConstMacro(CurrentGradientNorm, PrecisionType);
476  // itkGetConstMacro(CurrentParameter, double* );
477  // itkGetConstMacro(CurrentGradient, double* );
478 
480  itkGetConstMacro(CurrentStepSize, PrecisionType);
481 
483  itkGetConstMacro(CurrentNumberOfEvaluations, PrecisionType);
484 
485 protected:
487  ~LBFGS2Optimizerv4() override;
488  void
489  PrintSelf(std::ostream & os, Indent indent) const override;
490 
491 
493  static int
494  UpdateProgressCallback(void * instance,
495  const PrecisionType * x,
496  const PrecisionType * g,
497  const PrecisionType fx,
498  const PrecisionType xnorm,
499  const PrecisionType gnorm,
500  const PrecisionType step,
501  int n,
502  int k,
503  int ls);
504 
506  int
507  UpdateProgress(const PrecisionType * x,
508  const PrecisionType * g,
509  const PrecisionType fx,
510  const PrecisionType xnorm,
511  const PrecisionType gnorm,
512  const PrecisionType step,
513  int n,
514  int k,
515  int ls);
516 
518  static PrecisionType
519  EvaluateCostCallback(void * instance,
520  const PrecisionType * x,
521  PrecisionType * g,
522  const int n,
523  const PrecisionType step);
524 
525  PrecisionType
526  EvaluateCost(const PrecisionType * x, PrecisionType * g, const int n, const PrecisionType step);
527 
528 private:
529  // Private Implementation (Pimpl), to hide liblbfgs data structures
530  class PrivateImplementationHolder;
531 
532  std::unique_ptr<PrivateImplementationHolder> m_Pimpl;
533 
535  const double * m_CurrentGradient;
536  const double * m_CurrentParameter;
537 
542 
544 };
545 } // end namespace itk
546 #endif
itk::LBFGS2Optimizerv4::m_CurrentGradient
const double * m_CurrentGradient
Definition: itkLBFGS2Optimizerv4.h:535
itk::uint8_t
::uint8_t uint8_t
Definition: itkIntTypes.h:29
itk::LBFGS2Optimizerv4::m_CurrentParameter
const double * m_CurrentParameter
Definition: itkLBFGS2Optimizerv4.h:536
itk::LBFGS2Optimizerv4::m_StatusCode
int m_StatusCode
Definition: itkLBFGS2Optimizerv4.h:543
itk::LBFGS2Optimizerv4Enums::LineSearchMethod::LINESEARCH_BACKTRACKING_STRONG_WOLFE
itk::LBFGS2Optimizerv4Enums::LineSearchMethod::LINESEARCH_BACKTRACKING_WOLFE
itk::operator<<
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:218
itk::LBFGS2Optimizerv4Enums::LineSearchMethod::LINESEARCH_MORETHUENTE
itk::LBFGS2Optimizerv4Enums
Definition: itkLBFGS2Optimizerv4.h:33
itk::ObjectToObjectOptimizerBaseTemplate< double >::StopConditionReturnStringType
std::string StopConditionReturnStringType
Definition: itkObjectToObjectOptimizerBase.h:148
itk::LBFGS2Optimizerv4Enums::LineSearchMethod::LINESEARCH_DEFAULT
itk::LBFGS2Optimizerv4Enums::LineSearchMethod::LINESEARCH_BACKTRACKING_ARMIJO
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::LBFGS2Optimizerv4Enums::LineSearchMethod::LINESEARCH_BACKTRACKING
itk::LBFGS2Optimizerv4::ScalesType
Superclass::ScalesType ScalesType
Definition: itkLBFGS2Optimizerv4.h:203
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::LBFGS2Optimizerv4::m_CurrentStepSize
double m_CurrentStepSize
Definition: itkLBFGS2Optimizerv4.h:538
itk::LBFGS2Optimizerv4::ParametersType
Superclass::ParametersType ParametersType
Definition: itkLBFGS2Optimizerv4.h:202
itk::LBFGS2Optimizerv4::MetricType
Superclass::MetricType MetricType
Definition: itkLBFGS2Optimizerv4.h:201
itk::LBFGS2Optimizerv4Enums::LineSearchMethod
LineSearchMethod
Definition: itkLBFGS2Optimizerv4.h:40
itk::LBFGS2Optimizerv4::GetNumberOfIterations
SizeValueType GetNumberOfIterations() const override
Definition: itkLBFGS2Optimizerv4.h:301
itk::LBFGS2Optimizerv4::m_Pimpl
std::unique_ptr< PrivateImplementationHolder > m_Pimpl
Definition: itkLBFGS2Optimizerv4.h:530
itk::LBFGS2Optimizerv4::SetNumberOfIterations
void SetNumberOfIterations(const SizeValueType _arg) override
Definition: itkLBFGS2Optimizerv4.h:306
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itkObjectToObjectOptimizerBase.h
itk::ObjectToObjectOptimizerBaseTemplate
Abstract base for object-to-object optimizers.
Definition: itkObjectToObjectOptimizerBase.h:113
itk::LBFGS2Optimizerv4::m_CurrentParameterNorm
double m_CurrentParameterNorm
Definition: itkLBFGS2Optimizerv4.h:539
itk::LBFGS2Optimizerv4
Wrap of the libLBFGS[1] algorithm for use in ITKv4 registration framework. LibLBFGS is a translation ...
Definition: itkLBFGS2Optimizerv4.h:167
itk::LBFGS2Optimizerv4::m_CurrentNumberOfEvaluations
int m_CurrentNumberOfEvaluations
Definition: itkLBFGS2Optimizerv4.h:541
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itk::LBFGS2Optimizerv4::m_CurrentGradientNorm
double m_CurrentGradientNorm
Definition: itkLBFGS2Optimizerv4.h:540
itk::LBFGS2Optimizerv4::PrecisionType
double PrecisionType
Definition: itkLBFGS2Optimizerv4.h:192