Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Conversation

Deltadahl
Copy link
Contributor

@Deltadahl Deltadahl commented Jan 3, 2023

Implementation of a Klement solver according to https://jatm.com.br/jatm/article/view/373
This implementation is very similar to "broyden.jl".

I did some experiments with this solver compared to the Broyden-solver,
and the Klement-solver was able to solve the problems a lot faster (order of magnitudes).
However, I haven't tried the solvers on particularly "hard" problems yet.

(I also found some improvements I think I can do to the Broyden-solver, but that will come in another PR)

@codecov
Copy link

codecov bot commented Jan 3, 2023

Codecov Report

Merging #18 (4bc4ee7) into main (325547e) will decrease coverage by 57.69%.
The diff coverage is 0.00%.

@@             Coverage Diff             @@
##             main      #18       +/-   ##
===========================================
- Coverage   91.48%   33.79%   -57.70%     
===========================================
  Files           7        8        +1     
  Lines         188      216       +28     
===========================================
- Hits          172       73       -99     
- Misses         16      143      +127     
Impacted Files Coverage Δ
src/SimpleNonlinearSolve.jl 0.00% <ø> (ø)
src/klement.jl 0.00% <0.00%> (ø)
src/broyden.jl 0.00% <0.00%> (-92.60%) ⬇️
src/ad.jl 0.00% <0.00%> (-90.33%) ⬇️
src/bisection.jl 0.00% <0.00%> (-89.19%) ⬇️
src/utils.jl 68.75% <0.00%> (-31.25%) ⬇️
src/raphson.jl 64.51% <0.00%> (-25.81%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Comment on lines +45 to +46
if det(J) ≈ 0
J = ArrayInterfaceCore.zeromatrix(x) + I
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a little hacky. Is it part of the method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah, it's hacky...
I'll have a look at it tomorrow!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge and improve.

@ChrisRackauckas ChrisRackauckas merged commit e681591 into SciML:main Jan 3, 2023
x = float(prob.u0)
fₙ = f(x)
T = eltype(x)
J = ArrayInterfaceCore.zeromatrix(x) + I
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a fallback. If x is mutable, then we could do J = ArrayInterfaceCore.zeromatrix(x); J[diagind(J)] .= one(eltype(x)).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open an issue.

J += (k * Δxₙ' .* J) * J

# Prevent inverting singular matrix
if det(J) ≈ 0
Copy link
Member

@YingboMa YingboMa Jan 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

det(J) ≈ 0 is a bad check for singularity. Consider det(0.1I(1000)).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, by default, x ≈ 0 is true iff x == 0.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was left for a follow-up: #19

xₙ₋₁ = x
fₙ₋₁ = fₙ
for _ in 1:maxiters
xₙ = xₙ₋₁ - inv(J) * fₙ₋₁
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always use the matrix factorization object to solve.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed that. Instead, just \ here.

Copy link
Member

@YingboMa YingboMa Jan 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or F = lu(J), and the singularity check is then abs(F.factors[end, end]) < singular_tol.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants