-
Notifications
You must be signed in to change notification settings - Fork 46
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
Integrating detector background model variance #1692
Conversation
Perhaps what is meant by the variance of the background model here is actually the square of the standard error of the mean? In that case the value requires division by an additional factor of |
NB an additional division by |
Thinking about this some more, I think the further division by N makes sense. It implies that the |
@phyy-nx this change affects anyone working with integrating detectors, when the |
Thanks, I've been following the thread loosely today. dials.stills_process overrides the background algorithm to simple, but enforces the |
Right, I haven't touched linear2d. I'll look through the other methods though to see that all are consistent. |
Surprisingly the new calculation makes absolutely no difference to the integration results. This implies that the variance calculation made here is not actually used. Investigating further... |
Hi David So the variance in the case is as you suspected, the expected variance on the mean so it looks like what you have implemented is correct.
That's right, the original implementation was basically done as described in the Leslie 1999 paper.
So the variance calculation should have an effect on the variance of the integrated intensities, is this not the case? |
Actually taking a closer look at the integration code, the variance on the integrated intensities is calculated without reference to this variance (so I guess I just implemented this here to give a value for the variance in the absence of integration results). See for example https://github.com/dials/dials/blob/main/algorithms/integration/sum/summation.h line 84. In that implementation, the variance of the integrated intensity is gives by |I_signal| + |I_background| * (1 + N_sigma / N_background) so this should never be negative at least. I think I used the absolute values precisely because of the problem with negative backgrounds in ED data. I was never 100% happy with this but it was the best solution I could think of at the time. |
Use Welford variance calculation rather than the naive algorithm, which suffers from loss of precision. Use Bessel's correction for the sample variance. This leads to a small positive increase in values of refl["background.dispersion"]
Thanks @jmp1985 for the information. I'm developing a fuller understanding of what's going on in this code now. The calculation I changed previously was the estimation of variances of the background model parameters, not variances of the background model values, however as these models are for constant background these concepts coincided within a scale factor of the number of pixels. I added some explanatory comments and then moved on to dealing with another variance calculation. This time, it is the variance of background values that is being calculated, but only as an intermediate step to setting the This change still has no effect on integrated intensity error estimation, because as you point out that is done separately in |
After a bit more testing, it appears that moderately negative background values are already tolerated by I would like to continue to make changes to the intensity error estimates for integrating detectors, but in a separate PR as that would no longer be down to simply changing the background model variance. I believe the changes here are worth merging as they constitute improvements to the calculation of background model parameter variance, and in the calculation of |
The variance calculation for the
"simple"
background model, with aConstant3dModel
or aConstant2dModel
appeared incorrect. This was being calculated byvar[k] = mean[k] / (count - 1);
, which means that if the background mean value is negative (which can happen with integrating detectors), then the variance could be set negative, which is clearly wrong.This PR sets the variance to the actual sample variance of the background pixels using a standard one-pass variance algorithm. Two tests fail:
I might need help from @jmp1985 in figuring out what these tests are supposed to show and why they fail.