CosmoStat / autometacal

Metacalibration and shape measurement by automatic differentiation
MIT License
4 stars 1 forks source link

Comparison of finite and automatic differentiation procedures. #18

Closed andrevitorelli closed 2 years ago

andrevitorelli commented 3 years ago

This is an investigation of the difference between doing automatic differentiation and finite differences for computing the response matrix. We will have plots like this below, from Yahia-Cherif et al 2021.

...where in x we will look at different finite step sizes, and y the resulting relative difference between methods.

andrevitorelli commented 3 years ago

Comparing finite vs automatic differentiation for simple 2 points in each direction (1p,1m,2p,2m) - and on a single image - we get this: autofinite1624917908 1275868

andrevitorelli commented 3 years ago

Nb is here: https://github.com/CosmoStat/autometacal/blob/e5a43752ebc5ca05d4c1d2e8aa2db6d5de5a00a9/notebooks/metacal_compare_auto_finite.ipynb

EiffL commented 3 years ago

Fantastic, very nice! Yes this is what we want :-) But I was thinking about a plot of the R matrix than ellipticity. This plot is still very interesting, and if I understand correctly, you apply the inverse R matrix obtained with either form of metacal and you compare the "calibrated" ellipticities. So it's nice because it tells us how an error on the response matrix might translate into a calibration error.

So, two things:

andrevitorelli commented 3 years ago

Here: autofinite_response1624956019 4873207

andrevitorelli commented 3 years ago

Nothing changes with a slightly sheared 'galaxy' (g1=0.05): autofinite1624959558 9800317 autofinite_response_log (neither with a highly sheared one (either g1 or g2 = 0.5), not depicted)

andrevitorelli commented 3 years ago

With additional noise, off-diagonal elements rise. autofinite_response_log

EiffL commented 3 years ago

So that's pretty interesting! We see a non-zero bias at 1e-2 in this case with noise for the diagonal terms of the response matrix :-)

Alright, so I would suggest the following to make plots for the paper:

In any case, I think we can start by adding a section on this comparison in the paper @andrevitorelli :-)

andrevitorelli commented 3 years ago

I'm not sure on plotting relative residuals at the moment, because there are important differences in magnitudes between diagonal and off diagonal elements in different scenarios that are washed away in relative residuals. I think this is actually due to implementation problems, and after these are resolved, a final plot with relative residuals would make sense, as we're only interested in overall behaviour.

andrevitorelli commented 3 years ago

I am still trying to understand why the derivative differences are so stable between different images. This was created from the median, and CL68 and 95 regions of absolute differences between auto and finite differentiation over 100 galaxy images. median_response

andrevitorelli commented 3 years ago

Next tasks down the road to close this issue:

Bonus mission?

andrevitorelli commented 3 years ago

Some results with decreasing noise levels (by 1 order of magnitude each row) median_response_100x_noise median_response_10x_noise median_response

andrevitorelli commented 3 years ago
andrevitorelli commented 3 years ago
EiffL commented 3 years ago

ok, so, what happens with float 64 and cpu vs gpu?

andrevitorelli commented 3 years ago

@EiffL with even number of pixels, the autodiff vs finite differences go on getting closer and up to the step size of 1e-5 - instead of rising back again (the relative differences between methods become as low as 1e-7). With odd number of pixels nothing changes, the plateau is there.