diff --git a/src/optimizer/levenberg_marquardt.jl b/src/optimizer/levenberg_marquardt.jl index 6b21bf4..77dee1e 100644 --- a/src/optimizer/levenberg_marquardt.jl +++ b/src/optimizer/levenberg_marquardt.jl @@ -85,7 +85,9 @@ function optimize!( need_jacobian = false end colsumabs2!(dtd, J) - clamp!(dtd, MIN_DIAGONAL, MAX_DIAGONAL) + # this ensures that the operation in clamp! is scaling irrelevant + dtd_mean = sum(dtd) / length(dtd) + clamp!(dtd, MIN_DIAGONAL * dtd_mean, MAX_DIAGONAL * dtd_mean) rmul!(dtd, 1/Δ) δx, lmiter = ldiv!(δx, J, fcur, dtd, anls.solver) # apply box constraints