diff --git a/src/levenberg.jl b/src/levenberg.jl index c71c9016c..d4eb23a3f 100644 --- a/src/levenberg.jl +++ b/src/levenberg.jl @@ -274,18 +274,19 @@ function perform_step!(cache::LevenbergMarquardtCache{false}) end @unpack u, p, λ, JᵀJ, DᵀD, J = cache + cache.mat_tmp = JᵀJ + λ * DᵀD # Usual Levenberg-Marquardt step ("velocity"). - cache.v = -(JᵀJ + λ * DᵀD) \ (J' * fu1) + cache.v = -cache.mat_tmp \ (J' * fu1) @unpack v, h, α_geodesic = cache # Geodesic acceleration (step_size = v + a / 2). - cache.a = -J \ ((2 / h) .* ((f(u .+ h .* v, p) .- fu1) ./ h .- J * v)) + cache.a = -cache.mat_tmp \ ((2 / h) .* ((f(u .+ h .* v, p) .- fu1) ./ h .- J * v)) cache.stats.nsolve += 1 cache.stats.nfactors += 1 # Require acceptable steps to satisfy the following condition. norm_v = norm(v) - if (2 * norm(cache.a) / norm_v) < α_geodesic + if @fastmath((1 + log2(norm(cache.a)) - log2(norm_v))≤log2(α_geodesic)) cache.δ = v .+ cache.a ./ 2 @unpack δ, loss_old, norm_v_old, v_old, b_uphill = cache fu_new = f(u .+ δ, p)