Skip to content

fix for LSQML joint object and probe step sizes - #112

Merged
mdw771 merged 2 commits into
mainfrom
lsqml_ovj_prb_simultaneous_step_fix
Nov 18, 2026
Merged

mdw771 merged 2 commits into
mainfrom
lsqml_ovj_prb_simultaneous_step_fix

Conversation

@a4894z

@a4894z a4894z commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Features/fixes

The simultaneous step length calculation in LSQML is mathematically incorrect: the matrix element of the 2x2 matrix equation in Eq 22 from the Odstrcil paper can be complex.

See the math in the following notes-to-self, especially Eq 14 for a corrected version of this step length calculation.

I've left the incorrect ptychoshelves version as the default.

lsqml_step_length.pdf

Related issues (optional)

N/A

Mentions

Ming Du

Checklist (Don't skip!)

Have you...

  • Formatted your code properly adhering to PEP-8? Considering using RUFF to format your code automatically (https://docs.astral.sh/ruff/installation/).
  • Cleaned up your code to remove large commented-out blocks?
  • Properly documented any new API knobs and functions with non-trivial signatures?
  • Resolved all merge conflicts with the main branch?
  • Checked the diffs between your branch and the main branch to ensure that your changes are not introducing any regressions or unnecessary/irrelevant changes?
  • Checked the diffs to ensure your PR only includes one feature/fix? Multiple features/fixes/changes should be split into different PRs.
  • Added unit tests for new features if necessary?

@a4894z
a4894z requested a review from mdw771 November 17, 2026 20:00

@mdw771 mdw771 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good to me, thanks! Let's keep the default PTYCHOSHELVES for now. In the next release, we will consider changing the default to REAL_LSQ; if it works well, we might just drop the PTYCHOSHELVES branch.

Attaching a list of changes for future reference.

Old · PTYCHOSHELVES New · REAL_LSQ
Matrix diagonal $A_{11}$ $U + 0.1\bar U$ $U + 0.02\bar U$
Matrix diagonal $A_{22}$ $V + 0.1\bar V$ $V + 0.02\bar V$
Upper off-diagonal $A_{12}$ $c$ $\mbox{Re}(c)$
Lower off-diagonal $A_{21}$ $c^*$ $\mbox{Re}(c)$
Right-hand side $b_1 = \mbox{Re}(\sum u^\chi)$ and $b_2 = \mbox{Re}(\sum v^\chi)$ Same
Solve Solve $Az=b$ as a complex system, then take $\mbox{Re}(z)$. Solve $A\alpha=b$ as a real system.
Damping Add 0.1 times each diagonal’s minibatch mean. Add 0.02 times each diagonal’s minibatch mean.
Zero-direction guard If a damped diagonal is zero, set it to one. The corresponding step comes out zero. Same
Clipping Clip each step independently to $[0,\infty)$. Same
Scope and scaling Solve for one object/probe pair per scan position, then apply the configured step scalers and object normalization. Same

Here $u=P,\Delta O$ and $v=O,\Delta P$ are the object and probe contributions to the linearized exit-wave change, and $\chi$ is the target exit wave minus the current exit wave. The sums $U=\sum u^*u$, $V=\sum v^v$, and $c=\sum uv^$ run over pixels and selected probe modes. The bars in $\bar U$ and $\bar V$ denote minibatch means.

@mdw771
mdw771 merged commit 8b8b563 into main Nov 18, 2026
2 checks passed
@mdw771
mdw771 deleted the lsqml_ovj_prb_simultaneous_step_fix branch November 18, 2026 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants