|
| 1 | +# Using the logit transformation |
| 2 | +If you've ruled out simulator issues, you can try |
| 3 | +training your density or ratio estimator in an unbounded space |
| 4 | +using a logit transformation: |
| 5 | + |
| 6 | +- **For NPE**: The transformation maps bounded parameters θ |
| 7 | +to unbounded space before training, then applies the inverse (sigmoid) |
| 8 | +after training to ensure posterior samples stay within prior bounds. |
| 9 | + |
| 10 | +- **For NLE/NRE**: The transformation would need to map bounded |
| 11 | +data x to unbounded space, which requires estimating data bounds |
| 12 | +from simulations (more complex). |
| 13 | + |
| 14 | +To enable this for NPE: |
| 15 | + |
| 16 | +```python |
| 17 | +density_estimator_build_fun = posterior_nn( |
| 18 | + model="zuko_nsf", |
| 19 | + hidden_features=60, |
| 20 | + num_transforms=3, |
| 21 | + z_score_theta="transform_to_unconstrained" # Transforms parameters to unconstrained space |
| 22 | + x_dist=prior # For NPE, this specifies bounds for parameters (internally called 'x') |
| 23 | +) |
| 24 | +inference = NPE(prior, density_estimator=density_estimator_build_fun) |
| 25 | +``` |
| 26 | + |
| 27 | +This ensures that your density estimator operates in a |
| 28 | +transformed space where it respects prior bounds, |
| 29 | +improving the efficiency of rejection sampling. |
| 30 | + |
| 31 | +Note: The `x_dist=prior` might seem confusing - internally, |
| 32 | +sbi uses generic `x,y` notation where for NPE, `x` represents |
| 33 | +parameters (θ) and `y` represents data. |
| 34 | +This is why we pass the prior as `x_dist`. |
| 35 | + |
| 36 | +Important: |
| 37 | + |
| 38 | +- This transformation is currently only supported for zuko density estimators. |
| 39 | +- For **NLE/NRE**, setting up this transformation is more |
| 40 | +complex as it requires estimating bounds for the simulated data |
| 41 | +rather than using prior bounds. |
0 commit comments