Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add details about zuko density estimators #1387

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions tutorials/03_density_estimators.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,31 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"`sbi` allows to specify a custom density estimator for each of the implemented methods. For all options, check the API reference [here](https://sbi-dev.github.io/sbi/reference/models/).\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Changing the type of density estimator\n"
"`sbi` allows to specify a specific density estimator for each of the implemented methods.\n",
"We support a variety of density estimators, e.g., mixtures of Gaussians, normalizing\n",
"flows, and diffusion models. Some of the density estimators are implemented as part of\n",
"`sbi`, for others we rely on other packages like\n",
"[`nflows`](https://github.com/bayesiains/nflows/) (via `pyknos`) or [`zuko`](https://github.com/probabilists/zuko). \n",
"\n",
"For all options, check the API reference\n",
"[here](https://sbi-dev.github.io/sbi/reference/models/).\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"One option is using one of the preconfigured density estimators by passing a string in the `density_estimator` keyword argument to the inference object (`NPE` or `NLE`), e.g., \"maf\" for a Masked Autoregressive Flow, of \"nsf\" for a Neural Spline Flow with default hyperparameters.\n"
"## Changing the type of density estimator\n",
"\n",
"One option is using one of the preconfigured density estimators by passing a string in\n",
"the `density_estimator` keyword argument to the inference object (`NPE` or `NLE`), e.g.,\n",
"\"maf\" for a Masked Autoregressive Flow, of \"nsf\" for a Neural Spline Flow with default\n",
"hyperparameters.\n",
"\n",
"**New with sbi 0.23:** Note that `\"maf\"` or `\"nsf\"` correspond to `nflows` density\n",
"estimators. Those have proven to work well, but the `nflows` package is not maintained\n",
"anymore. To use more recent and actively maintained density estimators, we tentatively\n",
"recommend using `zuko`, e.g., by passing `zuko_maf` or `zuko_nsf`. \n"
]
},
{
Expand All @@ -47,7 +57,7 @@
"outputs": [],
"source": [
"prior = BoxUniform(torch.zeros(2), torch.ones(2))\n",
"inference = NPE(prior=prior, density_estimator=\"maf\")"
"inference = NPE(prior=prior, density_estimator=\"zuko_maf\")"
]
},
{
Expand Down Expand Up @@ -92,7 +102,7 @@
"from sbi.neural_nets import posterior_nn\n",
"\n",
"density_estimator_build_fun = posterior_nn(\n",
" model=\"nsf\", hidden_features=60, num_transforms=3\n",
" model=\"zuko_nsf\", hidden_features=60, num_transforms=3\n",
")\n",
"inference = NPE(prior=prior, density_estimator=density_estimator_build_fun)"
]
Expand Down
Loading