diff --git a/Modules/Numerics/Optimizersv4/include/itkLBFGS2Optimizerv4.h b/Modules/Numerics/Optimizersv4/include/itkLBFGS2Optimizerv4.h index 53afacf01ab..640807b80bc 100644 --- a/Modules/Numerics/Optimizersv4/include/itkLBFGS2Optimizerv4.h +++ b/Modules/Numerics/Optimizersv4/include/itkLBFGS2Optimizerv4.h @@ -22,6 +22,8 @@ #include "ITKOptimizersv4Export.h" #include +#include "lbfgs.h" + namespace itk { /*** \class LBFGS2Optimizerv4Enums @@ -504,7 +506,7 @@ class ITK_TEMPLATE_EXPORT LBFGS2Optimizerv4Template private: // Private Implementation (Pimpl), to hide liblbfgs data structures class PrivateImplementationHolder; - std::unique_ptr m_Pimpl; + lbfgs_parameter_t m_Parameters; bool m_EstimateScalesAtEachIteration; double m_CurrentStepSize; diff --git a/Modules/Numerics/Optimizersv4/include/itkLBFGS2Optimizerv4.hxx b/Modules/Numerics/Optimizersv4/include/itkLBFGS2Optimizerv4.hxx index 051faf5dc56..989ead2573e 100644 --- a/Modules/Numerics/Optimizersv4/include/itkLBFGS2Optimizerv4.hxx +++ b/Modules/Numerics/Optimizersv4/include/itkLBFGS2Optimizerv4.hxx @@ -22,25 +22,16 @@ #include "itkMacro.h" #include "itkMath.h" -#include "lbfgs.h" namespace itk { -template -class LBFGS2Optimizerv4Template::PrivateImplementationHolder -{ -public: - lbfgs_parameter_t m_Parameters; -}; - template LBFGS2Optimizerv4Template::LBFGS2Optimizerv4Template() - : m_Pimpl(new PrivateImplementationHolder) { // Initialize to default parameters - lbfgs_parameter_init(&m_Pimpl->m_Parameters); + lbfgs_parameter_init(&m_Parameters); m_StatusCode = 100; this->m_EstimateScalesAtEachIteration = true; @@ -55,22 +46,22 @@ void LBFGS2Optimizerv4Template::PrintSelf(std::ostream & os, Indent indent) const { Superclass::PrintSelf(os, indent); - os << indent << "m: " << m_Pimpl->m_Parameters.m << std::endl; - os << indent << "epsilon: " << m_Pimpl->m_Parameters.epsilon << std::endl; - os << indent << "past: " << m_Pimpl->m_Parameters.past << std::endl; - os << indent << "delta: " << m_Pimpl->m_Parameters.delta << std::endl; - os << indent << "max_iterations: " << m_Pimpl->m_Parameters.max_iterations << std::endl; - os << indent << "linesearch: " << m_Pimpl->m_Parameters.linesearch << std::endl; - os << indent << "max_linesearch: " << m_Pimpl->m_Parameters.max_linesearch << std::endl; - os << indent << "min_step: " << m_Pimpl->m_Parameters.min_step << std::endl; - os << indent << "max_step: " << m_Pimpl->m_Parameters.max_step << std::endl; - os << indent << "ftol: " << m_Pimpl->m_Parameters.ftol << std::endl; - os << indent << "wolfe: " << m_Pimpl->m_Parameters.wolfe << std::endl; - os << indent << "gtol: " << m_Pimpl->m_Parameters.gtol << std::endl; - os << indent << "xtol: " << m_Pimpl->m_Parameters.xtol << std::endl; - os << indent << "orthantwise_c: " << m_Pimpl->m_Parameters.orthantwise_c << std::endl; - os << indent << "orthantwise_start: " << m_Pimpl->m_Parameters.orthantwise_start << std::endl; - os << indent << "orthantwise_end: " << m_Pimpl->m_Parameters.orthantwise_end << std::endl; + os << indent << "m: " << m_Parameters.m << std::endl; + os << indent << "epsilon: " << m_Parameters.epsilon << std::endl; + os << indent << "past: " << m_Parameters.past << std::endl; + os << indent << "delta: " << m_Parameters.delta << std::endl; + os << indent << "max_iterations: " << m_Parameters.max_iterations << std::endl; + os << indent << "linesearch: " << m_Parameters.linesearch << std::endl; + os << indent << "max_linesearch: " << m_Parameters.max_linesearch << std::endl; + os << indent << "min_step: " << m_Parameters.min_step << std::endl; + os << indent << "max_step: " << m_Parameters.max_step << std::endl; + os << indent << "ftol: " << m_Parameters.ftol << std::endl; + os << indent << "wolfe: " << m_Parameters.wolfe << std::endl; + os << indent << "gtol: " << m_Parameters.gtol << std::endl; + os << indent << "xtol: " << m_Parameters.xtol << std::endl; + os << indent << "orthantwise_c: " << m_Parameters.orthantwise_c << std::endl; + os << indent << "orthantwise_start: " << m_Parameters.orthantwise_start << std::endl; + os << indent << "orthantwise_end: " << m_Parameters.orthantwise_end << std::endl; } @@ -114,7 +105,7 @@ LBFGS2Optimizerv4Template::ResumeOptimization() LBFGS2Optimizerv4Template::EvaluateCostCallback, LBFGS2Optimizerv4Template::UpdateProgressCallback, this, - &m_Pimpl->m_Parameters); + &m_Parameters); // Match the behavior of other optimizer setting the current // iteration to the max when iteration limit is reached @@ -309,7 +300,7 @@ template void LBFGS2Optimizerv4Template::SetHessianApproximationAccuracy(int m) { - m_Pimpl->m_Parameters.m = m; + m_Parameters.m = m; this->Modified(); } @@ -317,7 +308,7 @@ template int LBFGS2Optimizerv4Template::GetHessianApproximationAccuracy() const { - return m_Pimpl->m_Parameters.m; + return m_Parameters.m; } template @@ -325,7 +316,7 @@ void LBFGS2Optimizerv4Template::SetSolutionAccuracy( LBFGS2Optimizerv4Template::PrecisionType epsilon) { - m_Pimpl->m_Parameters.epsilon = epsilon; + m_Parameters.epsilon = epsilon; this->Modified(); } @@ -333,14 +324,14 @@ template typename LBFGS2Optimizerv4Template::PrecisionType LBFGS2Optimizerv4Template::GetSolutionAccuracy() const { - return m_Pimpl->m_Parameters.epsilon; + return m_Parameters.epsilon; } template void LBFGS2Optimizerv4Template::SetDeltaConvergenceDistance(int nPast) { - m_Pimpl->m_Parameters.past = nPast; + m_Parameters.past = nPast; this->Modified(); } @@ -348,7 +339,7 @@ template int LBFGS2Optimizerv4Template::GetDeltaConvergenceDistance() const { - return m_Pimpl->m_Parameters.past; + return m_Parameters.past; } template @@ -356,7 +347,7 @@ void LBFGS2Optimizerv4Template::SetDeltaConvergenceTolerance( LBFGS2Optimizerv4Template::PrecisionType tol) { - m_Pimpl->m_Parameters.delta = tol; + m_Parameters.delta = tol; this->Modified(); } @@ -364,14 +355,14 @@ template typename LBFGS2Optimizerv4Template::PrecisionType LBFGS2Optimizerv4Template::GetDeltaConvergenceTolerance() const { - return m_Pimpl->m_Parameters.delta; + return m_Parameters.delta; } template void LBFGS2Optimizerv4Template::SetMaximumIterations(int maxIterations) { - m_Pimpl->m_Parameters.max_iterations = maxIterations; + m_Parameters.max_iterations = maxIterations; this->Modified(); } @@ -380,7 +371,7 @@ template int LBFGS2Optimizerv4Template::GetMaximumIterations() const { - return m_Pimpl->m_Parameters.max_iterations; + return m_Parameters.max_iterations; } // translate to lbfgs.h enum @@ -415,7 +406,7 @@ LBFGS2Optimizerv4Template::SetLineSearch( lbfgsLineSearch = LBFGS_LINESEARCH_MORETHUENTE; } - m_Pimpl->m_Parameters.linesearch = lbfgsLineSearch; + m_Parameters.linesearch = lbfgsLineSearch; this->Modified(); } @@ -424,7 +415,7 @@ typename LBFGS2Optimizerv4Template::LineSearchMet LBFGS2Optimizerv4Template::GetLineSearch() const { LineSearchMethodEnum linesearch = LineSearchMethodEnum::LINESEARCH_DEFAULT; - int lbfgsLineSearch = m_Pimpl->m_Parameters.linesearch; + int lbfgsLineSearch = m_Parameters.linesearch; if (lbfgsLineSearch == LBFGS_LINESEARCH_BACKTRACKING) { linesearch = LineSearchMethodEnum::LINESEARCH_BACKTRACKING; @@ -453,7 +444,7 @@ template void LBFGS2Optimizerv4Template::SetMaximumLineSearchEvaluations(int n) { - m_Pimpl->m_Parameters.max_linesearch = n; + m_Parameters.max_linesearch = n; this->Modified(); } @@ -461,7 +452,7 @@ template int LBFGS2Optimizerv4Template::GetMaximumLineSearchEvaluations() const { - return m_Pimpl->m_Parameters.max_linesearch; + return m_Parameters.max_linesearch; } template @@ -469,7 +460,7 @@ void LBFGS2Optimizerv4Template::SetMinimumLineSearchStep( LBFGS2Optimizerv4Template::PrecisionType step) { - m_Pimpl->m_Parameters.min_step = step; + m_Parameters.min_step = step; this->Modified(); } @@ -477,7 +468,7 @@ template typename LBFGS2Optimizerv4Template::PrecisionType LBFGS2Optimizerv4Template::GetMinimumLineSearchStep() const { - return m_Pimpl->m_Parameters.min_step; + return m_Parameters.min_step; } template @@ -485,7 +476,7 @@ void LBFGS2Optimizerv4Template::SetMaximumLineSearchStep( LBFGS2Optimizerv4Template::PrecisionType step) { - m_Pimpl->m_Parameters.max_step = step; + m_Parameters.max_step = step; this->Modified(); } @@ -494,7 +485,7 @@ template typename LBFGS2Optimizerv4Template::PrecisionType LBFGS2Optimizerv4Template::GetMaximumLineSearchStep() const { - return m_Pimpl->m_Parameters.max_step; + return m_Parameters.max_step; } template @@ -502,7 +493,7 @@ void LBFGS2Optimizerv4Template::SetLineSearchAccuracy( LBFGS2Optimizerv4Template::PrecisionType ftol) { - m_Pimpl->m_Parameters.ftol = ftol; + m_Parameters.ftol = ftol; this->Modified(); } @@ -510,7 +501,7 @@ template typename LBFGS2Optimizerv4Template::PrecisionType LBFGS2Optimizerv4Template::GetLineSearchAccuracy() const { - return m_Pimpl->m_Parameters.ftol; + return m_Parameters.ftol; } template @@ -518,7 +509,7 @@ void LBFGS2Optimizerv4Template::SetWolfeCoefficient( LBFGS2Optimizerv4Template::PrecisionType wc) { - m_Pimpl->m_Parameters.wolfe = wc; + m_Parameters.wolfe = wc; this->Modified(); } @@ -526,7 +517,7 @@ template typename LBFGS2Optimizerv4Template::PrecisionType LBFGS2Optimizerv4Template::GetWolfeCoefficient() const { - return m_Pimpl->m_Parameters.wolfe; + return m_Parameters.wolfe; } template @@ -534,7 +525,7 @@ void LBFGS2Optimizerv4Template::SetLineSearchGradientAccuracy( LBFGS2Optimizerv4Template::PrecisionType gtol) { - m_Pimpl->m_Parameters.gtol = gtol; + m_Parameters.gtol = gtol; this->Modified(); } @@ -542,7 +533,7 @@ template typename LBFGS2Optimizerv4Template::PrecisionType LBFGS2Optimizerv4Template::GetLineSearchGradientAccuracy() const { - return m_Pimpl->m_Parameters.gtol; + return m_Parameters.gtol; } @@ -551,7 +542,7 @@ void LBFGS2Optimizerv4Template::SetMachinePrecisionTolerance( LBFGS2Optimizerv4Template::PrecisionType xtol) { - m_Pimpl->m_Parameters.xtol = xtol; + m_Parameters.xtol = xtol; this->Modified(); } @@ -559,7 +550,7 @@ template typename LBFGS2Optimizerv4Template::PrecisionType LBFGS2Optimizerv4Template::GetMachinePrecisionTolerance() const { - return m_Pimpl->m_Parameters.xtol; + return m_Parameters.xtol; } template @@ -567,7 +558,7 @@ void LBFGS2Optimizerv4Template::SetOrthantwiseCoefficient( LBFGS2Optimizerv4Template::PrecisionType orthant_c) { - m_Pimpl->m_Parameters.orthantwise_c = orthant_c; + m_Parameters.orthantwise_c = orthant_c; this->Modified(); } @@ -575,14 +566,14 @@ template typename LBFGS2Optimizerv4Template::PrecisionType LBFGS2Optimizerv4Template::GetOrthantwiseCoefficient() const { - return m_Pimpl->m_Parameters.orthantwise_c; + return m_Parameters.orthantwise_c; } template void LBFGS2Optimizerv4Template::SetOrthantwiseStart(int start) { - m_Pimpl->m_Parameters.orthantwise_start = start; + m_Parameters.orthantwise_start = start; this->Modified(); } @@ -590,14 +581,14 @@ template int LBFGS2Optimizerv4Template::GetOrthantwiseStart() const { - return m_Pimpl->m_Parameters.orthantwise_start; + return m_Parameters.orthantwise_start; } template void LBFGS2Optimizerv4Template::SetOrthantwiseEnd(int end) { - m_Pimpl->m_Parameters.orthantwise_end = end; + m_Parameters.orthantwise_end = end; this->Modified(); } @@ -605,7 +596,7 @@ template int LBFGS2Optimizerv4Template::GetOrthantwiseEnd() const { - return m_Pimpl->m_Parameters.orthantwise_end; + return m_Parameters.orthantwise_end; } diff --git a/Modules/Numerics/Optimizersv4/src/itkLBFGS2Optimizerv4.cxx b/Modules/Numerics/Optimizersv4/src/itkLBFGS2Optimizerv4.cxx index 8dd1d28c1da..1c2eea9aa0e 100644 --- a/Modules/Numerics/Optimizersv4/src/itkLBFGS2Optimizerv4.cxx +++ b/Modules/Numerics/Optimizersv4/src/itkLBFGS2Optimizerv4.cxx @@ -43,3 +43,5 @@ operator<<(std::ostream & out, const LBFGS2Optimizerv4Enums::LineSearchMethod va } }(); } + +} // end namespace itk