Skip to content

Commit

Permalink
do one more newton round even if converged
Browse files Browse the repository at this point in the history
  • Loading branch information
Thore Kockerols authored and Thore Kockerols committed Dec 3, 2024
1 parent fe83522 commit d1ac0f2
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/algorithms/nonlinear_solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ function levenberg_marquardt(f::Function,
# allow for norm increases (in both measures) as this can lead to the solution

if largest_residual <= ftol || largest_step <= xtol || largest_relative_step <= rel_xtol
# println("LM Iteration: $iter; xtol ($xtol): $largest_step; ftol ($ftol): $largest_residual; rel_xtol ($rel_xtol): $largest_relative_step")
break
# else
# println("Iteration: $iter; ftol: $largest_residual; rel_xtol: $largest_relative_step")
# end
end
end
Expand Down Expand Up @@ -273,7 +273,26 @@ function newton(f::Function,
end

if new_residuals_norm < ftol || rel_xtol_reached < rel_xtol || guess_update_norm < xtol # || rel_ftol_reached < rel_ftol
# println("GN worked with $iter iterations - rel_xtol: $rel_xtol_reached; ftol: $new_residuals_norm")# rel_ftol: $rel_ftol_reached")
new_guess_norm =.norm(new_guess)

old_residuals_norm = new_residuals_norm

new_residuals_norm =.norm(new_residuals)

∇̂ =.lu!(∇, check = false)

.ldiv!(∇̂, new_residuals)

guess_update = new_residuals

guess_update_norm =.norm(guess_update)

.axpy!(-1, guess_update, new_guess)

iters[1] += 1
iters[2] += 1

# println("GN worked with $(iter+1) iterations - xtol ($xtol): $guess_update_norm; ftol ($ftol): $new_residuals_norm; rel_xtol ($rel_xtol): $rel_xtol_reached")# rel_ftol: $rel_ftol_reached")
break
end

Expand Down

0 comments on commit d1ac0f2

Please sign in to comment.