Skip to content

Commit

Permalink
Only compute Jacobian in RLM if last step success
Browse files Browse the repository at this point in the history
  • Loading branch information
Affie committed Oct 12, 2023
1 parent c4bc49d commit 6d29ba4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/plans/nonlinear_least_squares_plan.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ mutable struct LevenbergMarquardtState{
damping_term_min::Tparams
β::Tparams
expect_zero_residual::Bool
last_step_successful::Bool
function LevenbergMarquardtState(
M::AbstractManifold,
p::P,
Expand Down Expand Up @@ -244,6 +245,7 @@ mutable struct LevenbergMarquardtState{
damping_term_min,
β,
expect_zero_residual,
true,
)
end
end
Expand Down
7 changes: 6 additions & 1 deletion src/solvers/LevenbergMarquardt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@ function step_solver!(
M = get_manifold(dmp)
nlso = get_objective(dmp)
basis_ox = _maybe_get_basis(M, lms.p, nlso.jacobian_tangent_basis)
get_jacobian!(dmp, lms.jacF, lms.p, basis_ox)
# a new Jacobian is only needed if the last step was successful
if lms.last_step_successful
get_jacobian!(dmp, lms.jacF, lms.p, basis_ox)
end
λk = lms.damping_term * norm(lms.residual_values)^2

JJ = transpose(lms.jacF) * lms.jacF + λk * I
Expand Down Expand Up @@ -291,8 +294,10 @@ function step_solver!(
if lms.expect_zero_residual
lms.damping_term = max(lms.damping_term_min, lms.damping_term / lms.β)
end
lms.last_step_successful = true
else
lms.damping_term *= lms.β
lms.last_step_successful = false
end
return lms
end
Expand Down

0 comments on commit 6d29ba4

Please sign in to comment.