Skip to content

Commit

Permalink
Merge pull request #131 from CCsimon123/master
Browse files Browse the repository at this point in the history
Implementation of a Levenberg–Marquardt algorithm
  • Loading branch information
ChrisRackauckas authored Jan 23, 2023
2 parents c62e922 + 518747a commit e839519
Show file tree
Hide file tree
Showing 5 changed files with 613 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/NonlinearSolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ include("utils.jl")
include("jacobian.jl")
include("raphson.jl")
include("trustRegion.jl")
include("levenberg.jl")
include("ad.jl")

import SnoopPrecompile
Expand All @@ -40,7 +41,7 @@ SnoopPrecompile.@precompile_all_calls begin for T in (Float32, Float64)
prob = NonlinearProblem{false}((u, p) -> u .* u .- p, T(0.1), T(2))

precompile_algs = if VERSION >= v"1.7"
(NewtonRaphson(), TrustRegion())
(NewtonRaphson(), TrustRegion(), LevenbergMarquardt())
else
(NewtonRaphson(),)
end
Expand All @@ -55,6 +56,6 @@ SnoopPrecompile.@precompile_all_calls begin for T in (Float32, Float64)
end
end end

export NewtonRaphson, TrustRegion
export NewtonRaphson, TrustRegion, LevenbergMarquardt

end # module
5 changes: 3 additions & 2 deletions src/ad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ end
function SciMLBase.solve(prob::NonlinearProblem{<:Union{Number, StaticArraysCore.SVector},
iip,
<:Dual{T, V, P}},
alg::Union{NewtonRaphson, TrustRegion},
alg::AbstractNewtonAlgorithm,
args...; kwargs...) where {iip, T, V, P}
sol, partials = scalar_nlsolve_ad(prob, alg, args...; kwargs...)
return SciMLBase.build_solution(prob, alg, Dual{T, V, P}(sol.u, partials), sol.resid;
Expand All @@ -35,7 +35,8 @@ end
function SciMLBase.solve(prob::NonlinearProblem{<:Union{Number, StaticArraysCore.SVector},
iip,
<:AbstractArray{<:Dual{T, V, P}}},
alg::Union{NewtonRaphson, TrustRegion}, args...;
alg::AbstractNewtonAlgorithm,
args...;
kwargs...) where {iip, T, V, P}
sol, partials = scalar_nlsolve_ad(prob, alg, args...; kwargs...)
return SciMLBase.build_solution(prob, alg, Dual{T, V, P}(sol.u, partials), sol.resid;
Expand Down
Loading

0 comments on commit e839519

Please sign in to comment.