JuliaNLSolvers / NLsolve.jl

Julia solvers for systems of nonlinear equations and mixed complementarity problems
Other
324 stars 66 forks source link

only_fj! version requests f and j separately at the same x #240

Closed rleegates closed 4 years ago

rleegates commented 4 years ago

As the title suggests, using method newton, no linesearch. I could search the code for where this occurs, if needed. Since in my case requesting only f and then only j at the same x from fj is less efficient than requesting both simultaneously, this generates significant overhead. With fj! generating some debugging output, I get:

Iter     f(x) inf-norm    Step 2-norm 
------   --------------   --------------
┌ Warning: Requested both stiffness and RHS.
└ @ Solvers ...
     0     3.751768e+03              NaN
┌ Warning: Requested only RHS. norm(x) = 190.759526036454
└ @ Solvers ...
     1     3.523550e+00     6.360172e-02
┌ Warning: Requested only stiffness. norm(x) = 190.759526036454
└ @ Solvers ...
┌ Warning: Requested only RHS. norm(x) = 190.72736454878574
└ @ Solvers ...
     2     2.828951e-02     1.358687e-03
┌ Warning: Requested only stiffness. norm(x) = 190.72736454878574
└ @ Solvers ...
┌ Warning: Requested only RHS. norm(x) = 190.727259268085
└ @ Solvers ...
     3     2.609981e-07     1.455108e-08
┌ Warning: Requested only stiffness. norm(x) = 190.727259268085
└ @ Solvers ...
┌ Warning: Requested only RHS. norm(x) = 190.72726075663638
└ @ Solvers ...
     4     1.096478e-09     2.914448e-12

Is there some reason why this is the intended behavior?

pkofod commented 4 years ago

That's not the intended behavior, no. I can try to look into it.

pkofod commented 4 years ago

But some code to go by would be nice :)

pkofod commented 4 years ago

Okay, I got it.

rleegates commented 4 years ago

...imho, it's the static line-search.

pkofod commented 4 years ago

It's because the value is already checked in the line search, yes. So the cheapest thing is to only calculate the Jacobian next time around (I mean given the current setup). I've changed it here https://github.com/JuliaNLSolvers/NLsolve.jl/pull/243 you can try that branch