Skip to content

Give all DensityEstimators an input_shape - #1138

Merged
michaeldeistler merged 1 commit into
mainfrom
xshapeestimator
Apr 23, 2024
Merged

michaeldeistler merged 1 commit into
mainfrom
xshapeestimator

Conversation

@michaeldeistler

@michaeldeistler michaeldeistler commented Apr 9, 2024 •

Copy link
Copy Markdown
Contributor

What does this implement/fix? Explain your changes

Closes #1135

Does the following things:

  • introduce input_shape to the DensityEstimator
  • the inference classes uses the input_shape and condition_shape of the DensityEstimator to infer ._x_shape. inference._x_shape no longer contains a batch dimension.
  • the posterior no longer performs checks for x_shape. These checks should be fully handled by the DensityEstimator.

Checklist

Put an x in the boxes that apply. You can also fill these out after creating
the PR. If you're unsure about any of them, don't hesitate to ask. We're here to
help! This is simply a reminder of what we are going to look for before merging
your code.

  • I have read and understood the contribution
    guidelines
  • I agree with re-licensing my contribution from AGPLv3 to Apache-2.0.
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have reported how long the new tests run and potentially marked them
    with pytest.mark.slow.
  • New and existing unit tests pass locally with my changes
  • I performed linting and formatting as described in the contribution
    guidelines
  • I rebased on main (or there are no conflicts with main)
  • For reviewer: The continuous deployment (CD) workflow are passing.

@michaeldeistler michaeldeistler mentioned this pull request Apr 9, 2024
8 tasks done
@michaeldeistler
michaeldeistler marked this pull request as ready for review April 22, 2024 15:55
@michaeldeistler michaeldeistler changed the title [WIP] Give all DensityEstimators an input_shape Give all DensityEstimators an input_shape Apr 22, 2024
@codecov

codecov Bot commented Apr 22, 2024 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 69.38776% with 15 lines in your changes are missing coverage. Please review.

Project coverage is 77.04%. Comparing base (0f0ee6e) to head (48bfc15).
Report is 5 commits behind head on main.

❗ Current head 48bfc15 differs from pull request most recent head 1c6f621. Consider uploading reports for the commit 1c6f621 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1138      +/-   ##
==========================================
- Coverage   85.13%   77.04%   -8.10%     
==========================================
  Files          90       90              
  Lines        6652     6647       -5     
==========================================
- Hits         5663     5121     -542     
- Misses        989     1526     +537     
Flag Coverage Δ
unittests 77.04% <69.38%> (-8.10%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
sbi/inference/posteriors/direct_posterior.py 98.36% <100.00%> (-0.08%) ⬇️
sbi/inference/posteriors/importance_posterior.py 55.55% <ø> (ø)
sbi/inference/posteriors/mcmc_posterior.py 85.02% <ø> (-0.97%) ⬇️
sbi/inference/posteriors/rejection_posterior.py 82.50% <ø> (-12.50%) ⬇️
sbi/inference/posteriors/vi_posterior.py 81.25% <ø> (-10.00%) ⬇️
sbi/inference/snle/mnle.py 86.95% <100.00%> (-6.53%) ⬇️
sbi/inference/snle/snle_base.py 93.61% <100.00%> (-0.07%) ⬇️
sbi/inference/snpe/snpe_base.py 89.02% <100.00%> (-0.07%) ⬇️
sbi/inference/snre/snre_base.py 94.28% <ø> (ø)
.../neural_nets/density_estimators/categorical_net.py 98.03% <100.00%> (ø)
... and 15 more

... and 14 files with indirect coverage changes

@manuelgloeckler manuelgloeckler self-assigned this Apr 23, 2024
Comment thread sbi/utils/user_input_checks.py Resolved

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great looks good :) I added a few comments.

@michaeldeistler
michaeldeistler merged commit f0aa0f9 into main Apr 23, 2024
@michaeldeistler
michaeldeistler deleted the xshapeestimator branch April 23, 2024 07:29

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! thanks for unifying all the shape handling 👏
I see that it's already merged, but I have one question about a dropped process_x.

self._x = process_x(
x, x_shape=self._x_shape, allow_iid_x=self.potential_fn.allow_iid_x
).to(self._device)
self._x = x.to(self._device)

ghost Apr 23, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need the allow_iid check anymore?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Only the DensityEstimators should be carrying x_shape

3 participants