Repository navigation
Adding interface for unconditional flow training - #1470
Conversation
janfb
left a comment
There was a problem hiding this comment.
I left some comments but I think it makes sense / is more efficient to discuss this in person. how about later today, 4pm?
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1470 +/- ##
===========================================
- Coverage 89.60% 79.14% -10.46%
===========================================
Files 121 123 +2
Lines 9357 9572 +215
===========================================
- Hits 8384 7576 -808
- Misses 973 1996 +1023
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
OK, now following @janfb suggestion for reorganization, we can have a script for testing the marginal pdf estimation as per: |
|
cool @plcrodrigues I tested this locally and it works like a charm. my suggestions:
(see also comments in PR review). |
janfb
left a comment
There was a problem hiding this comment.
great stuff! added a couple of comments.
janfb
left a comment
There was a problem hiding this comment.
Looks great now, thanks a lot for adding this @plcrodrigues 🙏
We now can perform unconditional flow training for learning priors or p(x)! 🎉
…d and unconditional estimator defaults (#2158) * fix(estimators): keep nflows sample_and_log_prob samples with their condition nflows returns samples and log probs as (batch, sample). `sample_and_log_prob` reshaped them without the transpose that `sample()` got in #1155, so with several conditions it filed half of the samples and their log probs under the wrong condition. The #1155 test now also checks `sample_and_log_prob` against `log_prob`. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(estimators): use self.net in the unconditional density estimator base `UnconditionalDensityEstimator.log_prob` and `sample` used `self._neural_net`, which is never set, so subclasses that keep these methods raised an AttributeError. They now use `self.net` and keep the `eval()` call from #1470. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(samplers): thin serial slice_np chains once `SliceSamplerSerial.run(n)` built each chain's `SliceSampler` with `thin`, which already takes `thin` steps per kept sample, and then thinned the result again. With `thin > 1` this cost `thin` times more potential evaluations and kept every `thin**2`-th step. The chain sampler now uses `thin=1`, so `run(n)` takes `n` steps and thins once, as `SliceSamplerVectorized` does. Seeded `slice_np` results with `thin > 1` change. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(posteriors): make mcmc_method and set_mcmc_method set the sampling method `MCMCPosterior.mcmc_method` read `self._mcmc_method`, which `__init__` never sets, and `set_mcmc_method` wrote that attribute while sampling reads `self.method`. So the getter raised, and after setting a method the posterior reported it but kept sampling with the old one. Both now use `self.method`, and `set_mcmc_method` raises for unknown methods, as `__init__` does. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(estimators): leave train/eval mode to the caller in unconditional log_prob `UnconditionalDensityEstimator.log_prob` called `self.net.eval()`, so a subclass whose `loss` uses `log_prob` was trained with Dropout and BatchNorm in eval mode. The trainer sets the mode, as for the other estimators. Co-Authored-By: Claude Opus 5.5 <[email protected]> * refactor: type set_mcmc_method as MCMCPosterior, reshape as in sample() `set_mcmc_method` returns the posterior itself, so its signature and docstring now say `MCMCPosterior` and type checkers follow chained calls. `NFlowsFlow.sample_and_log_prob` reshapes samples to `self.input_shape`, as `sample()` does; the shapes are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This PR implements the proposal from issue #1432 and is part of a larger goal of including tools for testing and evaluating model misspecification in
sbi. I thought it was easier to consider only density estimators coming fromzukoand have only tested what happens when they are discrete normalizing flows (e.g. MAF, NSF) for now. I'm not sure of how urgent it is to add the possibility of doing flow matching or score diffusion for unconditional pdfs.In any case, the following code tests the implementation :
The output that we get is :
Any comments, suggestions, reviews are welcome :-)