Skip to content

Commit

Permalink
Actually use backtracking.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendrych committed Oct 26, 2024
1 parent a4365b6 commit d368d73
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/linesearch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -425,15 +425,15 @@ function perform_line_search(
while abs(dot_gdir) > line_search.tol
if i > line_search.limit_num_steps
workspace.last_gamma = best_gamma # Update last_gamma before returning
return best_gamma
break
end

grad!(grad_storage, storage)
dot_gdir_new = fast_dot(grad_storage, d)

if dot_gdir_new dot_gdir
workspace.last_gamma = best_gamma # Update last_gamma before returning
return best_gamma
break
end

gamma_new = gamma - dot_gdir_new * (gamma - gamma_prev) / (dot_gdir_new - dot_gdir)
Expand All @@ -452,6 +452,12 @@ function perform_line_search(
i += 1
end
if abs(dot_gdir) > line_search.tol
# Choose gamma_max to be domain feasible
storage = muladd_memory_mode(memory_mode, storage, x, gamma_max, d)
while !line_search.domain_oracle(storage)
gamma_max /= 2
storage = muladd_memory_mode(memory_mode, storage, x, gamma_max, d)
end
gamma = perform_line_search(
line_search.inner_ls,
0,
Expand All @@ -468,8 +474,9 @@ function perform_line_search(
storage = muladd_memory_mode(memory_mode, storage, x, gamma, d)
new_val = f(storage)

@assert new_val <= best_val
best_gamma = gamma
if new_val <= best_val
best_gamma = gamma
end
end
workspace.last_gamma = best_gamma # Update last_gamma before returning
return best_gamma
Expand Down

0 comments on commit d368d73

Please sign in to comment.