From 2c4b9d3920d1f6f8707fdfbbc76cf694916d7583 Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Wed, 1 Nov 2023 21:45:21 -0400 Subject: [PATCH] try fixing LM for banded jacobian --- src/levenberg.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/levenberg.jl b/src/levenberg.jl index f181fcfcc..1462e9510 100644 --- a/src/levenberg.jl +++ b/src/levenberg.jl @@ -260,7 +260,7 @@ function perform_step!(cache::LevenbergMarquardtCache{true, fastls}) where {fast # Usual Levenberg-Marquardt step ("velocity"). # The following lines do: cache.v = -cache.mat_tmp \ cache.u_tmp if fastls - cache.mat_tmp[1:length(fu1), :] .= cache.J + copyto!(@view(cache.mat_tmp[1:length(fu1), :]), cache.J) cache.mat_tmp[(length(fu1) + 1):end, :] .= λ .* cache.DᵀD cache.rhs_tmp[1:length(fu1)] .= _vec(fu1) linres = dolinsolve(alg.precs, linsolve; A = cache.mat_tmp, @@ -299,8 +299,8 @@ function perform_step!(cache::LevenbergMarquardtCache{true, fastls}) where {fast cache.stats.nfactors += 2 # Require acceptable steps to satisfy the following condition. - norm_v = norm(v) - if 2 * norm(cache.a) ≤ α_geodesic * norm_v + norm_v = cache.internalnorm(v) + if 2 * cache.internalnorm(cache.a) ≤ α_geodesic * norm_v _vec(cache.δ) .= _vec(v) .+ _vec(cache.a) ./ 2 @unpack δ, loss_old, norm_v_old, v_old, b_uphill = cache f(cache.fu_tmp, u .+ δ, p) @@ -356,7 +356,7 @@ function perform_step!(cache::LevenbergMarquardtCache{false, fastls}) where {fas # Usual Levenberg-Marquardt step ("velocity"). if fastls - cache.mat_tmp = vcat(J, λ .* cache.DᵀD) + cache.mat_tmp = _vcat(J, λ .* cache.DᵀD) cache.rhs_tmp[1:length(fu1)] .= -_vec(fu1) linres = dolinsolve(alg.precs, linsolve; A = cache.mat_tmp, b = cache.rhs_tmp, linu = _vec(cache.v), p = p, reltol = cache.abstol) @@ -392,8 +392,8 @@ function perform_step!(cache::LevenbergMarquardtCache{false, fastls}) where {fas cache.stats.nfactors += 1 # Require acceptable steps to satisfy the following condition. - norm_v = norm(v) - if 2 * norm(cache.a) ≤ α_geodesic * norm_v + norm_v = cache.internalnorm(v) + if 2 * cache.internalnorm(cache.a) ≤ α_geodesic * norm_v cache.δ = _restructure(cache.δ, _vec(v) .+ _vec(cache.a) ./ 2) @unpack δ, loss_old, norm_v_old, v_old, b_uphill = cache fu_new = f(u .+ δ, p)