From 2530e2fa5008b54cd2cd08812167b278b35e89f7 Mon Sep 17 00:00:00 2001 From: Arvi Date: Tue, 5 Dec 2023 08:50:13 -0500 Subject: [PATCH 1/4] Add a function for analysis after LS --- src/polysolve/nonlinear/Problem.hpp | 2 ++ src/polysolve/nonlinear/Solver.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/polysolve/nonlinear/Problem.hpp b/src/polysolve/nonlinear/Problem.hpp index 6cb15a3..67864e8 100644 --- a/src/polysolve/nonlinear/Problem.hpp +++ b/src/polysolve/nonlinear/Problem.hpp @@ -39,6 +39,8 @@ namespace polysolve::nonlinear virtual void solution_changed(const TVector &new_x) {} + virtual void step_accepted(const TVector &new_x) {} + virtual bool stop(const TVector &x) { return false; } void sample_along_direction( diff --git a/src/polysolve/nonlinear/Solver.cpp b/src/polysolve/nonlinear/Solver.cpp index daf8811..8bb425f 100644 --- a/src/polysolve/nonlinear/Solver.cpp +++ b/src/polysolve/nonlinear/Solver.cpp @@ -195,6 +195,7 @@ namespace polysolve::nonlinear this->m_stop.fDelta, this->m_stop.gradNorm, this->m_stop.xDelta); update_solver_info(objFunc.value(x)); + objFunc.step_accepted(x); int f_delta_step_cnt = 0; double f_delta = 0; @@ -373,6 +374,7 @@ namespace polysolve::nonlinear this->m_status = cppoptlib::Status::IterationLimit; update_solver_info(energy); + objFunc.step_accepted(x); // reset the tolerance, since in the first iter it might be smaller this->m_stop.gradNorm = g_norm_tol; From ab7091d20ae52795117c959958506a38305921fe Mon Sep 17 00:00:00 2001 From: Arvi Date: Tue, 5 Dec 2023 09:03:23 -0500 Subject: [PATCH 2/4] add iter number to step accepted --- src/polysolve/nonlinear/Problem.hpp | 2 +- src/polysolve/nonlinear/Solver.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/polysolve/nonlinear/Problem.hpp b/src/polysolve/nonlinear/Problem.hpp index 67864e8..f436081 100644 --- a/src/polysolve/nonlinear/Problem.hpp +++ b/src/polysolve/nonlinear/Problem.hpp @@ -39,7 +39,7 @@ namespace polysolve::nonlinear virtual void solution_changed(const TVector &new_x) {} - virtual void step_accepted(const TVector &new_x) {} + virtual void step_accepted(const int iter_num, const TVector &new_x) {} virtual bool stop(const TVector &x) { return false; } diff --git a/src/polysolve/nonlinear/Solver.cpp b/src/polysolve/nonlinear/Solver.cpp index 8bb425f..32df004 100644 --- a/src/polysolve/nonlinear/Solver.cpp +++ b/src/polysolve/nonlinear/Solver.cpp @@ -195,7 +195,7 @@ namespace polysolve::nonlinear this->m_stop.fDelta, this->m_stop.gradNorm, this->m_stop.xDelta); update_solver_info(objFunc.value(x)); - objFunc.step_accepted(x); + objFunc.step_accepted(this->m_current.iterations, x); int f_delta_step_cnt = 0; double f_delta = 0; @@ -374,7 +374,7 @@ namespace polysolve::nonlinear this->m_status = cppoptlib::Status::IterationLimit; update_solver_info(energy); - objFunc.step_accepted(x); + objFunc.step_accepted(this->m_current.iterations, x); // reset the tolerance, since in the first iter it might be smaller this->m_stop.gradNorm = g_norm_tol; From 148752ffaf2c36ee2f972ff8c668c3f1f053a223 Mon Sep 17 00:00:00 2001 From: Arvi Date: Wed, 6 Dec 2023 14:38:00 -0500 Subject: [PATCH 3/4] Add post step call instead of solution_accepted --- src/polysolve/nonlinear/Solver.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/polysolve/nonlinear/Solver.cpp b/src/polysolve/nonlinear/Solver.cpp index 32df004..cc5f585 100644 --- a/src/polysolve/nonlinear/Solver.cpp +++ b/src/polysolve/nonlinear/Solver.cpp @@ -181,6 +181,8 @@ namespace polysolve::nonlinear objFunc.solution_changed(x); } + objFunc.post_step(this->m_current.iterations, x); + const auto g_norm_tol = this->m_stop.gradNorm; this->m_stop.gradNorm = first_grad_norm_tol; @@ -195,7 +197,6 @@ namespace polysolve::nonlinear this->m_stop.fDelta, this->m_stop.gradNorm, this->m_stop.xDelta); update_solver_info(objFunc.value(x)); - objFunc.step_accepted(this->m_current.iterations, x); int f_delta_step_cnt = 0; double f_delta = 0; @@ -374,7 +375,6 @@ namespace polysolve::nonlinear this->m_status = cppoptlib::Status::IterationLimit; update_solver_info(energy); - objFunc.step_accepted(this->m_current.iterations, x); // reset the tolerance, since in the first iter it might be smaller this->m_stop.gradNorm = g_norm_tol; From 5468520ba470f18e210c415ffdaa85ee1872a8e8 Mon Sep 17 00:00:00 2001 From: Arvi Date: Wed, 6 Dec 2023 14:41:50 -0500 Subject: [PATCH 4/4] remove step accepted --- src/polysolve/nonlinear/Problem.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/polysolve/nonlinear/Problem.hpp b/src/polysolve/nonlinear/Problem.hpp index f436081..6cb15a3 100644 --- a/src/polysolve/nonlinear/Problem.hpp +++ b/src/polysolve/nonlinear/Problem.hpp @@ -39,8 +39,6 @@ namespace polysolve::nonlinear virtual void solution_changed(const TVector &new_x) {} - virtual void step_accepted(const int iter_num, const TVector &new_x) {} - virtual bool stop(const TVector &x) { return false; } void sample_along_direction(