Fix inflated sigma when using random-phase noise correction#351
Fix inflated sigma when using random-phase noise correction#351felipemunoz8128 wants to merge 1 commit into
Conversation
d594751 to
fbb34bf
Compare
|
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) |
36bd32c to
44ce262
Compare
|
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. |
|
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"). You can also do it by hand on your commit messages, by adding the 2 newlines followed by |
44ce262 to
3312ba4
Compare
|
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: 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>
3312ba4 to
5c70266
Compare
|
Nice discussion! Some unclarities:
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 |
Fixes #350.
When
--random-phase-correctionis 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.