Skip to content

Commit

Permalink
Update MoreThuente.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinebou12 authored Dec 19, 2024
1 parent 19bec68 commit 113bbb2
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/polysolve/nonlinear/line_search/MoreThuente.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ namespace polysolve::nonlinear::line_search
wolfe_c1 = params.at("line_search").at("MoreThuente").value("c1", 1e-4);
wolfe_c2 = params.at("line_search").at("MoreThuente").value("c2", 0.9);
max_iterations = params.at("line_search").at("MoreThuente").value("max_iterations", 20);
max_step_size = params.at("line_search").at("MoreThuente").value("max_step_size", 10.0);

// Optionally, log the initialized parameters for debugging
m_logger.debug("More-Thuente parameters: c1={}, c2={}, max_iterations={}, max_step_size={}",
wolfe_c1, wolfe_c2, max_iterations, max_step_size);
}

double MoreThuente::compute_descent_step_size(
Expand All @@ -23,7 +28,7 @@ namespace polysolve::nonlinear::line_search
{
double step_size = starting_step_size;
double low = 0.0;
double high = std::numeric_limits<double>::infinity();
double high = max_step_size;
double energy;
TVector grad;

Expand All @@ -49,21 +54,27 @@ namespace polysolve::nonlinear::line_search
}
}

if (high < std::numeric_limits<double>::infinity())
if (high < max_step_size)
{
step_size = 0.5 * (low + high);
}
else
{
step_size *= 2.0; // Expand step size
// Ensure that step_size does not exceed max_step_size
if (step_size > max_step_size)
{
step_size = max_step_size;
}
}

m_logger.debug("Iteration {}: step_size = {}, energy = {}", i, step_size, energy);
}

if (step_size <= current_min_step_size() || step_size >= high)
{
m_logger.warn("More-Thuente line search failed to find a valid step size.");
m_logger.warn("More-Thuente line search failed to find a valid step size. step_size={}, high={}",
step_size, high);
return NaN;
}

Expand Down

0 comments on commit 113bbb2

Please sign in to comment.