Skip to content

Fix inflated sigma when using random-phase noise correction#351

Open
felipemunoz8128 wants to merge 1 commit into
SBC-Utrecht:mainfrom
felipemunoz8128:fix-sigma-noise-correction
Open

Fix inflated sigma when using random-phase noise correction#351
felipemunoz8128 wants to merge 1 commit into
SBC-Utrecht:mainfrom
felipemunoz8128:fix-sigma-noise-correction

Conversation

@felipemunoz8128

Copy link
Copy Markdown

Fixes #350.

When --random-phase-correction is enabled, stats["std"] is computed from pre-correction CCC maps but used for cutoff estimation on post-correction scores. The noise correction reduces effective noise, so the pre-correction sigma is inflated, producing a cutoff that misses real particles.

Recompute variance/std from the corrected score map within the ROI after noise correction. The non-corrected path is unchanged.

@sroet

sroet commented Apr 10, 2026

Copy link
Copy Markdown
Collaborator

The problem is is that we have to keep track of the variance per sampled angle as we are looking at maximized scores (so just doing the variance on the final result is an incorrect etimate of the variance). Your fix does not keep that into account for the the noise corrected path.

If I remember my statistics course correctly, the correct fix would be to keep track of the per angle variance on the noise scores and add it to the variance of the real score volume. So this would increase the variance, not decrease it, which also doesn't feel right.

@McHaillet Do you remember why the noise correction does not update the variance? Was this just an oversight or a conscious decision? (our noise substraction is also different than the current STOPGAP implementation)

@felipemunoz8128 felipemunoz8128 force-pushed the fix-sigma-noise-correction branch 3 times, most recently from 36bd32c to 44ce262 Compare April 10, 2026 14:48
@felipemunoz8128

felipemunoz8128 commented Apr 10, 2026

Copy link
Copy Markdown
Author

Hello @sroet. Thank you for reviewing my PR. Yes, I see now that the fix is more complicated than what I proposed originally.

I have asked Claude to generate a document containing a derivation of the correct variance and cutoff formula for the corrected case. I only understand it up to a certain point, so I cannot fully vouch for it's validity. I include it here nevertheless in case it might be useful to you and the other developers as you consider this issue. The commit associated with this PR now contains Claude's implementation of its solution.

logistic_cutoff_derivation.md

@sroet

sroet commented Apr 10, 2026

Copy link
Copy Markdown
Collaborator

hey @felipemunoz8128

Thanks for sharing the document, will discuss it with the other developers. Can't promise on a timeline for this as it requires careful consideration on our statistics in general, (our CCC for example is already scaled with the std of the tomogram in fourier space) and not all relevant developers are in the same lab anymore.

I was a bit sad to see it referencing section 9, without a section 9 being present 😞

In general for commits that were written with the help of AI, please turn on the attribution on the commits: https://code.claude.com/docs/en/settings#attribution-settings

specifically the "co-authored by ..." part. This helps me make a better informed decision on what comments/clarifications to ask when reviewing code (for example, asking about code-design/implementation detail choices is not relevant if the user is using AI, I can then just mention my own preferences instead of needing to "prepare for a discussion").
It also helps me see which parts of the code development were done by AI (just the initial setup, or also any/all of the fixes I ask for, etc)

You can also do it by hand on your commit messages, by adding the 2 newlines followed by Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@felipemunoz8128 felipemunoz8128 force-pushed the fix-sigma-noise-correction branch from 44ce262 to 3312ba4 Compare April 10, 2026 16:34
@felipemunoz8128

Copy link
Copy Markdown
Author

Hi @sroet. Sorry about that! Claude is now properly attributed. And about section 9 -- that was actually my fault 😅 I removed a few sections at the end that I felt were not totally necessary, but I didn't think to remove any references to them. Here's the original doc if you're interested:

derivation_doc_full.md

No worries about the timeline. Looking forward to seeing what you all come up with 👍

When --random-phase-correction is enabled, the automated extraction
cutoff is too high because:
1. sigma is computed from pre-correction CCC values
2. the Gaussian tail formula is applied to scores that follow a
   logistic distribution (difference of two Gumbel-distributed maxima)

Track per-angle noise template variance alongside real template
variance. Store sigma_real and sigma_noise in job stats.

In extract.py, use the logistic tail formula for noise-corrected scores:
  beta_eff = sqrt((sigma_real^2 + sigma_noise^2) / (4 * ln(n_rotations)))
  cutoff = beta_eff * ln(n_voxels / n_false_positives)

n_rotations is read from the job (not stats) to avoid inflation from
volume splitting. The search space collapses from n_voxels * n_angles
to n_voxels for corrected scores. The non-corrected path is unchanged.
Old job JSONs without the new stats fall back to the Gaussian formula.

Co-Authored-By: Claude <noreply@anthropic.com>
@felipemunoz8128 felipemunoz8128 force-pushed the fix-sigma-noise-correction branch from 3312ba4 to 5c70266 Compare April 10, 2026 20:21
@McHaillet

Copy link
Copy Markdown
Collaborator

Nice discussion!

Some unclarities:

  • the claude file suggests we'd need to keep track of the per angle sigma of the noise correlation
  • but looking for gumbel distribution on Wikipedia, it seems to be a distribution of the maximum, so that would imply it describes the distribution of the MIP over the angular search

I agree in general that something should be done about it though. My subtraction of the mean was a quick fix because it didn't know how i could otherwise preserve the cutoff calculation

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.

Automated cutoff too high when using --random-phase-correction

3 participants