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

Add wavefield preconditioner #584

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open

Conversation

jfowkes
Copy link
Collaborator

@jfowkes jfowkes commented Sep 12, 2024

The secret sauce of the LSQ-ML algorithm seems to be what they call average update directions:

image

In reality this is just scaling the ML update directions by 1 / Lipschitz constant for the exit wave error as shown by Andy Maiden et al in "Further improvements to the ptychographical iterative engine". Note that 1/L is known to be the optimal step size for gradient descent on convex functions in the math optimization literature:
https://math.stackexchange.com/questions/3587312/the-biggest-step-size-with-guaranteed-convergence-for-constant-step-size-gradien

This PR adds an option to ML called "wavefield_precond" that enables this "average update preconditioner". The following results on Moonflower suggests that this is highly effective at accelerating ML as shown in the images below.

Vanilla ML (all parameters default, 200 iterations):
ML

ML with wavefield_precond=True (all other parameters default, 200 iterations):
ML_precond

ptypy/engines/ML.py Outdated Show resolved Hide resolved
@jfowkes jfowkes marked this pull request as draft September 12, 2024 17:16
@jfowkes jfowkes changed the title Add Lipschitz preconditioner Add Wavefield preconditioner Sep 18, 2024
@jfowkes jfowkes changed the title Add Wavefield preconditioner Add wavefield preconditioner Sep 18, 2024
@pierrethibault
Copy link
Member

You need to take the square root of the sum, not the sum of the square roots.

@jfowkes
Copy link
Collaborator Author

jfowkes commented Sep 18, 2024

You need to take the square root of the sum, not the sum of the square roots.

How stupid of me, thank you! This now works as expected :)

@jfowkes jfowkes marked this pull request as ready for review September 18, 2024 08:02
@jfowkes
Copy link
Collaborator Author

jfowkes commented Nov 14, 2024

Further testing shows that this "wavefield preconditioner" is also highly effective at accelerating ML on real data, as demonstrated below on the small nanogold dataset from the ptypy tutorials:

Vanilla ML (all parameters default, 200 iterations):
ML

ML with wavefield_precond=True (all other parameters default, 200 iterations):
ML_precond

Really impressive to see this level of improvement on ML without any l2-regulariser or smoothing-preconditioner!

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

Successfully merging this pull request may close these issues.

2 participants