GilesStrong / tomopt

TomOpt: Differential Muon Tomography Optimisation
GNU Affero General Public License v3.0
4 stars 0 forks source link

Uncertainties increase with resolution #45

Closed GilesStrong closed 3 years ago

GilesStrong commented 3 years ago

Problem

Whilst investigating #43 I found that the gradient of the scatter-location uncertainties were consistently positive, i.e. as the resolution increases, the uncertainty increases. This feeds into the x0 prediction uncertainties, which tend to have positive gradients (but occasionally can be negative).

I'd have thought that increasing the resolution should always decrease the uncertainty on scatter location.

Checks

In ScatterBatch

# loc uncertainty
dloc_dres = torch.stack([jacobian(self._loc, l.resolution).sum((-1, -2)) for l in dets], dim=1)
self._loc_unc = torch.sqrt((dloc_dres.pow(2) * res2).sum(1))
print('scatter dloc/dres', jacobian(self._loc, dets[0].resolution, create_graph=True, allow_unused=True).sum((-1, -2))[:10])
print('scatter dlocunc/dres', jacobian(self._loc_unc, dets[0].resolution, create_graph=True, allow_unused=True).sum((-1, -2))[:10])

produces:

Screenshot 2021-06-23 at 13 06 02

So resolution can shift the scatter location in either direction of each dimension, but the shift always increases as resolution increases. Similar checks on dtheta, dxy, and theta_in uncertainties all showed that increasing resolution increases uncertainty.

I assume that there is something wrong with the way we calculate the uncertainty: unc_x = sqrt(sum_i [(res_i*dx/dres_i)^2]), where i sums over the 4 detector layers Does this formula appear to be correct?

GilesStrong commented 3 years ago

https://chem.libretexts.org/Bookshelves/Analytical_Chemistry/Supplemental_Modules_(Analytical_Chemistry)/Quantifying_Nature/Significant_Digits/Propagation_of_Error suggests we may be missing some cross-terms.

GilesStrong commented 3 years ago

Location derivatives should be with respect to the hit locations not the resolution. Will take some hacking to get the correct derivatives.

GilesStrong commented 3 years ago

Making progress with this. Now computing (dloc_dhit_i x hit_uncertainty_i)^2, where resolution is [1/resolution_i, 1/resolution_i, 0] for uncertainty in (x,y,z) for detector i. Also I am including cross-terms of the form (dloc_dhit_i x hit_uncertainty_i x dloc_dhit_j x hit_uncertainty_j). These do not cancel to zero. After all this, the location uncertainty shows the correct gradient wrt resolution: as the resolution increases, the location uncertainty decreases.

Screenshot 2021-07-23 at 15 20 23

I'll need to extend this to computing the uncertainties on theta, dtheta, etc.