Skip to content
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

Levenberg-Marquart + SLSQP for Proximity #394

Merged
merged 42 commits into from
May 7, 2024
Merged

Levenberg-Marquart + SLSQP for Proximity #394

merged 42 commits into from
May 7, 2024

Conversation

jzwar
Copy link
Collaborator

@jzwar jzwar commented Mar 11, 2024

Overview

Adds Levenberg-Marquart and SLSQP for proximity. Current implementation wouldn't work for some situations (see #389). Source for SLSQP is from current scipy's fortran version. To avoid difficulties of fortran-compiler-setup in CI systems, the source is translated to c using f2c. Then, removed some static variables and add const keywords.

Now, the search looks like this:

Initial guess
|
Newton
|
Converged? -- yes -- return
|
No
|
Reset initial guess, max_iterations *= 5
|
SLSQP
|
Converged? -- yes -- return
|
No
|
Reset initial guess, max_iterations *= 5
|
LM

Also, SLSQP can incorporate bounds. Nice.

Addressed Issues

  • fixes Issues with Proximity #389
  • Sometimes, newton iterations does not converge
  • Sometimes, we needed to sample a lot of points for k-d tree
  • Sometimes, we really want to get correct values at any cost.

Checklists

  • Documentations are up-to-date.
  • Added example(s)
  • Added test(s)

@j042
Copy link
Member

j042 commented Mar 11, 2024

super cool!

@j042 j042 force-pushed the ft-LM-test branch 2 times, most recently from adf8c3a to 5fed186 Compare April 16, 2024 06:47
@j042
Copy link
Member

j042 commented Apr 26, 2024

Do you have scripts/notes of the origin of this implementation?

@j042
Copy link
Member

j042 commented Apr 26, 2024

never mind, found it in #389

@j042
Copy link
Member

j042 commented Apr 26, 2024

one thing to note in general is that we probably had to call system.ResetRowOrder(); at each iteration.

@j042
Copy link
Member

j042 commented Apr 26, 2024

one thing to note in general is that we probably had to call system.ResetRowOrder(); at each iteration.

On the other hand, it would have iterated through this order and reordered it, so maybe it is irrelevant

Copy link
Member

@j042 j042 left a comment

Choose a reason for hiding this comment

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

Awesome addition! I think we can set Newton max_iter a bit lower than LM. I've added some discussion points.

if (modified_marquart) {
lhs(i, i) = 2 * spline_gradient_AAt(i, i) * (1 + lambda);
} else {
lhs(i, i) = 2 * (spline_gradient_AAt(i, i) + lambda);
Copy link
Member

Choose a reason for hiding this comment

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

@jzwar current J removes this 2 *, but can you double check this? With 2*, I thought it should be:

Suggested change
lhs(i, i) = 2 * (spline_gradient_AAt(i, i) + lambda);
lhs(i, i) = (2 * (spline_gradient_AAt(i, i)) + lambda;


// compute || F(x + dX) ||^2 then rho
ComputeCostAndDerivatives(data, 0); // computes J and everything on the way
const double rho =
Copy link
Member

Choose a reason for hiding this comment

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

@jzwar you think it is crucial to keep both neu and alt metrics?

@j042 j042 marked this pull request as ready for review April 26, 2024 16:16
j042 added a commit that referenced this pull request Apr 26, 2024
@j042 j042 mentioned this pull request Apr 26, 2024
@j042 j042 added the cibuildwheel-test Ask ci to test all wheel builds label May 3, 2024
@j042 j042 changed the title Levenberg-Marquart cool? Levenberg-Marquart + SLSQP for Proximity May 3, 2024
@j042
Copy link
Member

j042 commented May 3, 2024

If you get a chance, I'd appreciate if you can take a look at proximity.hpp / proximity.cpp @danielwolff1 :)

@j042 j042 removed the request for review from clemens-fricke May 3, 2024 10:33
@j042 j042 added the enhancement New feature or request label May 3, 2024
Copy link
Member

@danielwolff1 danielwolff1 left a comment

Choose a reason for hiding this comment

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

I took a look at it and have some minor comments.

I have to admit that I did not check every single line of code in detail, but I took a few hours to check closely and to me it looks good, I didn't spot anything that seems completely wrong. Therefore, I approve! 🚀

j042 and others added 4 commits May 4, 2024 11:18
main return first, then additional ones.
This applies to
GuessMinusQuery, J, dJdu, d2Jdu2
@danielwolff1
Copy link
Member

Thanks for incorporating the changes, from my point of view this can be merged! 🚀

j042 added 3 commits May 6, 2024 09:26
Queries outside of the spline sometimes does not return
0.0 convergence_norm.
However, slsqp exits with 0 if J itself converges.
@j042
Copy link
Member

j042 commented May 6, 2024

Thanks for the review @danielwolff1 !

@j042 j042 merged commit 5e39cfb into main May 7, 2024
21 checks passed
@j042 j042 deleted the ft-LM-test branch May 7, 2024 13:37
markriegler pushed a commit that referenced this pull request Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cibuildwheel-test Ask ci to test all wheel builds enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issues with Proximity
3 participants