maho3 / ltu-ili

Robust ML in Astro
https://ltu-ili.readthedocs.io/en/latest/
45 stars 9 forks source link

111 make custom iliutilsdistributions #112

Closed maho3 closed 10 months ago

maho3 commented 11 months ago

This adds two new files, ili.utils.distributions_pt.py and ili.utils.distributions_tf.py, which wrap pytorch and pydelfi distributions, respectively, to make them more amenable to our configurations.

Now, users can simply go:

prior = ili.utils.Uniform(low=[0, 0, 0], high=[1, 1, 1], device=device)  # Uniform distribution
## OR
prior = ili.utils.IndependentNormal(loc=[0,0,0], scale=[1,1,1])  # Standard normal distribution

to get an appropriate prior distribution. The change is the same in the yaml configs.

Features:

codecov-commenter commented 11 months ago

Codecov Report

Attention: 31 lines in your changes are missing coverage. Please review.

Comparison is base (8b8b3e8) 85.26% compared to head (d2bb43a) 84.86%. Report is 2 commits behind head on main.

:exclamation: Current head d2bb43a differs from pull request most recent head 1e437c6. Consider uploading reports for the commit 1e437c6 to get more accurate results

Files Patch % Lines
ili/utils/distributions_pt.py 80.79% 29 Missing :warning:
ili/inference/runner_sbi.py 50.00% 1 Missing :warning:
ili/utils/distributions_tf.py 96.96% 1 Missing :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #112 +/- ## ========================================== - Coverage 85.26% 84.86% -0.40% ========================================== Files 16 18 +2 Lines 821 1057 +236 ========================================== + Hits 700 897 +197 - Misses 121 160 +39 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

maho3 commented 10 months ago

Added designated prior tests in both pydelfi and sbi. Also, I added a custom TruncatedNormal distribution in sbi, to mirror that of pydelfi and to show how one can make a custom pytorch distribution.

DeaglanBartlett commented 10 months ago

Thank you for adding these. Perhaps I missed it last time, but given that you've added Dirichlet and LowRankMultivariateNormal to ili.utils.distributions_pt, these should also be included in the unit tests. It would also be good to see unit tests for all the methods of the classes introduced in ili.utils.distributions_pt and ili.utils.distributions_tf

maho3 commented 10 months ago

Ready for review again!