Skip to content

Zuko density estimators (#1088) - #1116

Merged
janfb merged 16 commits into
mainfrom
974-zuko-density-estimators-interface
Apr 5, 2024
Merged

janfb merged 16 commits into
mainfrom
974-zuko-density-estimators-interface

Conversation

@anastasiakrouglova

@anastasiakrouglova anastasiakrouglova commented Mar 27, 2024 •

Copy link
Copy Markdown
Collaborator

What does this implement/fix? Explain your changes

Provides Zuko density estimators and resolves comments from previous PR.

Does this close any currently open issues?

Fixes # (issue)

Any relevant code examples, logs, error output, etc?

Up to date with latest comments

Any other comments?

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)

* update zuko to 1.1.0

* test zuko_gmm commit

* build_zuko_nsf added

* add build_zuko_naf, update test

* add license change to pr template.

* CLN pyproject.toml (#1009)

* CLN pyproject.toml

* CLN optional deps comment

* CLN alphabetical order

* fix x_o and broken link tutorial 7 (#1003)

* fix x_o and broken link tutorial 7

* typo in title

* suppress plotting output

---------

Co-authored-by: Matthijs <[email protected]>

* replace prepare_for_sbi in tutorials (#1013)

* add zuko density estimators

* not working gmm

* update tests for PR

* update PR for pyright

* resolve pyright

* add reportArgumentType

* resolve pyright issue

* resolve all issues pyright

* resolve pyright

* add typing and docstring

* add functions from factory to test

* remove comment mdn file

* add docstrings flow file

* add docstring in density_estimator_test.py

* Update sbi/neural_nets/flow.py

Co-authored-by: Sebastian Bischoff <[email protected]>

* Update sbi/neural_nets/flow.py

Co-authored-by: Sebastian Bischoff <[email protected]>

* Update sbi/neural_nets/flow.py

Co-authored-by: Sebastian Bischoff <[email protected]>

* removed pyright

---------

Co-authored-by: bkmi <[email protected]>
Co-authored-by: Nastya Krouglova <[email protected]>
Co-authored-by: Jan Boelts <[email protected]>
Co-authored-by: Thomas Moreau <[email protected]>
Co-authored-by: Matthijs Pals <[email protected]>
Co-authored-by: Matthijs <[email protected]>
Co-authored-by: zinaStef <[email protected]>
Co-authored-by: Sebastian Bischoff <[email protected]>
@Baschdl

Baschdl commented Mar 28, 2024

Copy link
Copy Markdown
Contributor

@anastasiakrouglova Could you resolve the merge conflicts with main? This should also trigger the tests to run.

@janfb janfb 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.

thanks a lot for adding all the flows! 🔥

I added a couple of suggestions, please have a look. Happy to discuss them if needed.

Comment thread sbi/neural_nets/factory.py Resolved
Comment thread sbi/neural_nets/factory.py Resolved
Comment thread sbi/neural_nets/flow.py Resolved
Comment thread sbi/neural_nets/flow.py Resolved
Comment thread tests/neural_nets_factory.py Resolved
@codecov

codecov Bot commented Apr 3, 2024 •

Copy link
Copy Markdown

Codecov Report

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

Project coverage is 77.20%. Comparing base (7be2115) to head (583671d).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1116      +/-   ##
==========================================
- Coverage   85.45%   77.20%   -8.25%     
==========================================
  Files          90       89       -1     
  Lines        6612     6610       -2     
==========================================
- Hits         5650     5103     -547     
- Misses        962     1507     +545     
Flag Coverage Δ
unittests 77.20% <84.04%> (-8.25%) ⬇️

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

Files Coverage Δ
sbi/neural_nets/density_estimators/zuko_flow.py 78.94% <100.00%> (ø)
sbi/neural_nets/factory.py 89.47% <71.42%> (-2.06%) ⬇️
sbi/neural_nets/flow.py 92.97% <84.70%> (-5.65%) ⬇️

... and 23 files with indirect coverage changes

@anastasiakrouglova

Copy link
Copy Markdown
Collaborator Author

Thank you for the feedback. I finally removed the CNF zuko flow, but all the rest is implemented.

@janfb janfb 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, thanks!

I added three last comments.

Comment thread sbi/neural_nets/factory.py Resolved
Comment thread sbi/neural_nets/factory.py Resolved
Comment thread tutorials/05_embedding_net.ipynb Resolved
@janfb janfb self-assigned this Apr 4, 2024
@anastasiakrouglova
anastasiakrouglova requested a review from janfb April 4, 2024 14:17

@janfb janfb 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.

One last issue about the changes in the embedding net tutorial notebook.

Comment thread tutorials/05_embedding_net.ipynb Resolved
@janfb

janfb commented Apr 5, 2024

Copy link
Copy Markdown
Contributor

Indeed, it's quite confusing. These changes to the 05_embedding_net notebook are new, where do they come from?

I can try to fix it by explicitly removing those notebook changes from this PR and move them to a separate branch as a backup.

@anastasiakrouglova

anastasiakrouglova commented Apr 5, 2024 •

Copy link
Copy Markdown
Collaborator Author

Okay that would be awesome, thank you! I'm not sure where the issues come from. At first, I was accidentally merging with the main of the forked bkmi/sbi repository. So maybe it came from this place?

@janfb janfb 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.

Alright, now we are good!
(The notebook changes were duplicates or an older version of that notebook that was merged in on the way, so it was fine to discard them.)

Thanks so much again for adding all the zuko flows - great work! 👏

@janfb
janfb merged commit cbf9dca into main Apr 5, 2024
@janfb
janfb deleted the 974-zuko-density-estimators-interface branch April 5, 2024 09:51
@anastasiakrouglova

Copy link
Copy Markdown
Collaborator Author

Great!! Thank you so much for reviewing it thoroughly!

dgedon added a commit to dgedon/sbi that referenced this pull request Nov 19, 2026
CNF was dropped from the model registry when the Zuko flows were added
in sbi-dev#1116, but its builder stayed. `posterior_nn("zuko_cnf")` raises
`NotImplementedError` when it builds, and nothing in sbi calls the
builder. `build_zuko_flow("CNF", ...)` builds the same network and stays
tested.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
janfb pushed a commit that referenced this pull request Nov 20, 2026
…o_cnf, merge z-score embedding helpers (#2162)

The per-model configs are importable only from sbi.neural_nets. The re-exports from sbi.neural_nets.net_builders never reached a release and are gone.

build_zuko_cnf and the "CNF" option of build_zuko_flow are removed. Nothing in sbi reached them since #1116; for a continuous normalizing flow, use flow matching (FMPE).

The unused build-context types (ZScoreConfig, ZScoreStats, BuildContext, compute_z_score_stats) move to the private module sbi.neural_nets._build_context until the planned z-score pre-pass uses them.

Seven copies of the code that puts a z-scoring layer in front of an embedding net become one helper, build_z_scored_embedding_net in sbi.utils.sbiutils. Every builder builds the same network as before.

transform_to_unconstrained now raises a ValueError for the condition of the build_* functions, for classifier inputs and when a RestrictionEstimator with z_score="transform_to_unconstrained" trains; before, it was silently ignored. The type hints offer it only where it works: the modeled variable of the Zuko flows and the MDN.
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.

3 participants