Repository navigation
Add MixedDensityEstimatorBuilder for MNLE and MNPE - #1912
Conversation
575564a to
3541dca
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## gsoc-2026 #1912 +/- ##
=============================================
+ Coverage 87.99% 88.03% +0.03%
=============================================
Files 144 144
Lines 13499 13563 +64
=============================================
+ Hits 11879 11940 +61
- Misses 1620 1623 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
|
|
Hi @janfb |
janfb
left a comment
There was a problem hiding this comment.
Looks good! Only one (unlikely) user path is not covered yet, I made a suggestion to fix it, please double check.
Well done! 🚀
| return d | ||
|
|
||
|
|
||
| _VALID_MIXED_CONTINUOUS_MODELS = frozenset({ |
There was a problem hiding this comment.
this is good to have, but it could drift away from the actually supported models we have in the factory. I suggest adding a short tests that fails if they drift, e.g., sth like:
def test_valid_continuous_models_match_builders():
from sbi.neural_nets.net_builders.mixed_nets import model_builders
from sbi.neural_nets.net_builders.estimator_configs import (
_VALID_MIXED_CONTINUOUS_MODELS,
)
assert _VALID_MIXED_CONTINUOUS_MODELS == frozenset(model_builders)|
|
||
| def build( | ||
| self, batch_input: Tensor, batch_condition: Tensor | ||
| ) -> ConditionalDensityEstimator: |
There was a problem hiding this comment.
the return type here should be narrower because the factories will aways return a MixedDensityEstimator.
| mixed-type data. The continuous-component model is selected via | ||
| ``continuous_model``; there is no ``model`` field. | ||
| """ | ||
|
|
There was a problem hiding this comment.
add a comment here: density-estimator model for the continuous variables.
…#1912) * add MixedDensityEstimatorBuilder without build * add build() and changes related to updated plan * integrate new builder to mnle and mnpe * add new tests to existing npe nle test file * make imports single line * some test parametrizations and cleanup * add TypeError to fail fast * add TypeError test * add test to catch drift * narrow down the return type
What does this PR do?
This PR continues the GSoC 2026 Neural Network Builder API refactor by introducing
MixedDensityEstimatorBuilder(a sibling toDensityEstimatorBuilder) and wiring it into the MNLE and MNPE trainers with string deprecation.Our main design choice is introducing the
continuous_modelfield instead of relying onmodelorflow_model. The old string API named the method rather than the estimator, burying the flow model in kwargs. Now, we can explicitly passMixedDensityEstimatorBuilder(continuous_model="nsf"). We chose the namecontinuous_modelbecause the supported architectures include non-flow models like MDN and MADE.Files Changed
estimator_configs.py_VALID_MIXED_CONTINUOUS_MODELSto mirrormixed_nets.model_builders.MixedDensityEstimatorBuilderdataclass, which defaultscontinuous_modelto"nsf"and handles validation in__post_init__.num_categories_per_variableandlog_transform_x) and forwards flow-specific fields to the continuous sub-net.build()method translatescontinuous_modeltoflow_modeland dispatches to_build_mixed_density_estimator.mnpe.pyNotImplementedErrorfor builder instances and updated thedensity_estimatordefault from"mnpe"toNone.MixedDensityEstimatorBuilderto the type union and set up dispatching: passingNonebuilds silently, while passing"mnpe"raises aFutureWarningand falls back toposterior_nn.super().__init__()to assign proper NPE roles (input=θ, condition=x).mnle.pydensity_estimatordefault toNoneand addedMixedDensityEstimatorBuilderto the type union."mnle"triggers aFutureWarningand falls back tolikelihood_nn.super().__init__()to assign the correct NLE roles (input=x, condition=θ).npe_nle_builder_integration_test.pyWe preserved all existing tests and added several new ones for the mixed builder:
Noneor passing a builder instance runs without warnings, while passing old string arguments correctly emits aFutureWarning.ValueErrorcheck for invalidcontinuous_modelinputs.MixedDensityEstimator.test_check_estimator_arg_accepts_valid_inputsto explicitly include the new builder.AI Usage
Does this close any issues?
N/A
Any relevant code examples, logs, or error messages?
N/A