Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/levenberg_marquardt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ function levenberg_marquardt(
lower::AbstractVector{T}=Array{T}(undef, 0),
upper::AbstractVector{T}=Array{T}(undef, 0),
avv!::Union{Function,Nothing,Avv}=nothing,
callback::Function=x -> false,
) where {T}

# First evaluation
Expand Down Expand Up @@ -158,7 +159,7 @@ function levenberg_marquardt(
# Maintain a trace of the system.
tr = LMTrace{LevenbergMarquardt}()
if show_trace || store_trace
d = Dict("lambda" => lambda)
d = Dict("lambda" => lambda, "x" => copy(x))
os = LMState{LevenbergMarquardt}(iterCt, sum(abs2, value(df)), NaN, d)
push!(tr, os)
if show_trace
Expand All @@ -168,7 +169,7 @@ function levenberg_marquardt(

startTime = time()

while (~converged && iterCt < maxIter && maxTime > time() - startTime)
while (~converged && iterCt < maxIter && maxTime > time() - startTime && !callback(tr))
# jacobian! will check if x is new or not, so it is only actually
# evaluated if x was updated last iteration.
jacobian!(df, x) # has alias J
Expand Down Expand Up @@ -271,7 +272,7 @@ function levenberg_marquardt(
# show state
if show_trace || store_trace
g_norm = norm(J' * value(df), Inf)
d = Dict("g(x)" => g_norm, "dx" => copy(delta_x), "lambda" => lambda)
d = Dict("g(x)" => g_norm, "dx" => copy(delta_x), "lambda" => lambda, "x" => copy(x))
os = LMState{LevenbergMarquardt}(iterCt, sum(abs2, value(df)), g_norm, d)
push!(tr, os)
if show_trace
Expand Down