-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CR: Update iterate on first iteration for negative curvature with line search and when zero curvature is detected #958
Conversation
Update cr.jl Update cr.jl
A unit test would be good. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #958 +/- ##
==========================================
- Coverage 94.68% 93.55% -1.13%
==========================================
Files 45 47 +2
Lines 8027 9177 +1150
==========================================
+ Hits 7600 8586 +986
- Misses 427 591 +164 ☔ View full report in Codecov by Sentry. |
@dpo added couple tests and added some function to create the needed systems. |
Co-authored-by: Dominique <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. How about you @amontoison ?
I think we need to replace We could have a wrong solution if linesearch is combined with warm-start ( |
@amontoison Thanks for pointing it out. However, I don’t think we should do that. if ρ == 0
stats.niter = 0
stats.solved, stats.inconsistent = true, false
stats.timer = start_time |> ktimer
stats.status = "p is a zero-curvature direction"
history && push!(ArNorms, zero(T))
solver.warm_start = false
linesearch && kcopy!(n, x, p) # x ← p
return solver
end I assume that when we use a warm start, the probability of The original code was written this way. If we set What do you think? |
|
@farhadrclass This is not a question of probability; I just want to ensure that It’s quite complex to test all the options together (like linesearch, preconditioner, warm-start, etc.). linesearch && kcopy!(n, x, p) # x ← p
warm_start && kaxpy!(n, one(FC), Δx, x) @dpo I think I made a mistake in all the Krylov methods where I implemented warm start... For historical reasons, we checked whether the initial residual was zero or not. It should be fixed by #961. linesearch && kcopy!(n, x, b) # x ← b by linesearch && kcopy!(n, x, p) # x ← p |
I think the There is something special about the rhs If we supplied a "better" initial guess If we encounter negative curvature at iteration At least for the time being, I think we should make sure that The same goes for Maybe |
Thanks for the explanation @dpo! You can merge the PR and I will take care to return errors if some options like |
Thanks @farhadrclass ! |
thanks @amontoison for help and working on the follow-up |
Sure. This is a bug fix. |
Can I trigger the V0.9.10? |
This PR fixes an issue in the Conjugate Residual (CR) implementation (in
$$b = -\nabla f(x_k) \neq 0.$$
src/cr.jl
) where, on the first iteration (iter == 0
), if the computed curvature is non-positive (i.e. either zero or negative), the algorithm may return without updating the iterate—even though we haveTo address this, when line search is enabled and a non-positive curvature (zero or negative) is detected at iteration 0, we now explicitly update the iterate by performing
x .= b
This change guarantees that the method behaves consistently by setting
x
appropriately when curvature information is either zero or negative during the first iteration.Changes Made:
First Iteration Check (iter == 0):
s <= 0
), andlinesearch
is enabled, updatex
tob
before returning.Zero Curvature Check (general case):
x
tob
iflinesearch
is enabled.