Skip to content

Commit

Permalink
Fix links (#1541)
Browse files Browse the repository at this point in the history
  • Loading branch information
ordabayevy committed Mar 6, 2023
1 parent ac05f92 commit 14fd004
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ NumPyro is a lightweight probabilistic programming library that provides a NumPy
NumPyro is designed to be *lightweight* and focuses on providing a flexible substrate that users can build on:

- **Pyro Primitives:** NumPyro programs can contain regular Python and NumPy code, in addition to [Pyro primitives](http://pyro.ai/examples/intro_part_i.html) like `sample` and `param`. The model code should look very similar to Pyro except for some minor differences between PyTorch and Numpy's API. See the [example](https://github.com/pyro-ppl/numpyro#a-simple-example---8-schools) below.
- **Inference algorithms:** NumPyro supports a number of inference algorithms, with a particular focus on MCMC algorithms like Hamiltonian Monte Carlo, including an implementation of the No U-Turn Sampler. Additional MCMC algorithms include [MixedHMC](http://num.pyro.ai/en/latest/mcmc.html#numpyro.infer.mixed_hmc.MixedHMC) (which can accommodate discrete latent variables) as well as [HMCECS](http://num.pyro.ai/en/latest/mcmc.html#hmcecs) (which only computes the likelihood for subsets of the data in each iteration). One of the motivations for NumPyro was to speed up Hamiltonian Monte Carlo by JIT compiling the verlet integrator that includes multiple gradient computations. With JAX, we can compose `jit` and `grad` to compile the entire integration step into an XLA optimized kernel. We also eliminate Python overhead by JIT compiling the entire tree building stage in NUTS (this is possible using [Iterative NUTS](https://github.com/pyro-ppl/numpyro/wiki/Iterative-NUTS)). There is also a basic Variational Inference implementation together with many flexible (auto)guides for Automatic Differentiation Variational Inference (ADVI). The variational inference implementation supports a number of features, including support for models with discrete latent variables (see [TraceGraph_ELBO](http://num.pyro.ai/en/latest/svi.html#tracegraph-elbo)).
- **Inference algorithms:** NumPyro supports a number of inference algorithms, with a particular focus on MCMC algorithms like Hamiltonian Monte Carlo, including an implementation of the No U-Turn Sampler. Additional MCMC algorithms include [MixedHMC](http://num.pyro.ai/en/latest/mcmc.html#numpyro.infer.mixed_hmc.MixedHMC) (which can accommodate discrete latent variables) as well as [HMCECS](https://num.pyro.ai/en/latest/mcmc.html#numpyro.infer.hmc_gibbs.HMCECS) (which only computes the likelihood for subsets of the data in each iteration). One of the motivations for NumPyro was to speed up Hamiltonian Monte Carlo by JIT compiling the verlet integrator that includes multiple gradient computations. With JAX, we can compose `jit` and `grad` to compile the entire integration step into an XLA optimized kernel. We also eliminate Python overhead by JIT compiling the entire tree building stage in NUTS (this is possible using [Iterative NUTS](https://github.com/pyro-ppl/numpyro/wiki/Iterative-NUTS)). There is also a basic Variational Inference implementation together with many flexible (auto)guides for Automatic Differentiation Variational Inference (ADVI). The variational inference implementation supports a number of features, including support for models with discrete latent variables (see [TraceGraph_ELBO](https://num.pyro.ai/en/latest/svi.html#numpyro.infer.elbo.TraceGraph_ELBO) and [TraceEnum_ELBO](https://num.pyro.ai/en/latest/svi.html#numpyro.infer.elbo.TraceEnum_ELBO)).
- **Distributions:** The [numpyro.distributions](https://numpyro.readthedocs.io/en/latest/distributions.html) module provides distribution classes, constraints and bijective transforms. The distribution classes wrap over samplers implemented to work with JAX's [functional pseudo-random number generator](https://github.com/google/jax#random-numbers-are-different). The design of the distributions module largely follows from [PyTorch](https://pytorch.org/docs/stable/distributions.html). A major subset of the API is implemented, and it contains most of the common distributions that exist in PyTorch. As a result, Pyro and PyTorch users can rely on the same API and batching semantics as in `torch.distributions`. In addition to distributions, `constraints` and `transforms` are very useful when operating on distribution classes with bounded support. Finally, distributions from TensorFlow Probability ([TFP](http://num.pyro.ai/en/latest/distributions.html?highlight=tfp#numpyro.contrib.tfp.distributions.TFPDistribution)) can directly be used in NumPyro models.
- **Effect handlers:** Like Pyro, primitives like `sample` and `param` can be provided nonstandard interpretations using effect-handlers from the [numpyro.handlers](https://numpyro.readthedocs.io/en/latest/handlers.html) module, and these can be easily extended to implement custom inference algorithms and inference utilities.

Expand Down Expand Up @@ -202,9 +202,10 @@ Like HMC/NUTS, all remaining MCMC algorithms support enumeration over discrete l

### Stochastic variational inference
- Variational objectives
- [Trace_ELBO](https://num.pyro.ai/en/latest/svi.html#trace-elbo) is our basic ELBO implementation.
- [TraceMeanField_ELBO](https://num.pyro.ai/en/latest/svi.html#tracemeanfield-elbo) is like `Trace_ELBO` but computes part of the ELBO analytically if doing so is possible.
- [TraceGraph_ELBO](http://num.pyro.ai/en/latest/svi.html#tracegraph-elbo) offers variance reduction strategies for models with discrete latent variables. Generally speaking, this ELBO should always be used for models with discrete latent variables.
- [Trace_ELBO](https://num.pyro.ai/en/latest/svi.html#numpyro.infer.elbo.Trace_ELBO) is our basic ELBO implementation.
- [TraceMeanField_ELBO](https://num.pyro.ai/en/latest/svi.html#numpyro.infer.elbo.TraceMeanField_ELBO) is like `Trace_ELBO` but computes part of the ELBO analytically if doing so is possible.
- [TraceGraph_ELBO](https://num.pyro.ai/en/latest/svi.html#numpyro.infer.elbo.TraceGraph_ELBO) offers variance reduction strategies for models with discrete latent variables. Generally speaking, this ELBO should always be used for models with discrete latent variables.
- [TraceEnum_ELBO](https://num.pyro.ai/en/latest/svi.html#numpyro.infer.elbo.TraceEnum_ELBO) offers variable enumeration strategies for models with discrete latent variables. Generally speaking, this ELBO should always be used for models with discrete latent variables when enumeration is possible.
- Automatic guides (appropriate for models with continuous latent variables)
- [AutoNormal](https://num.pyro.ai/en/latest/autoguide.html#autonormal) and [AutoDiagonalNormal](https://num.pyro.ai/en/latest/autoguide.html#autodiagonalnormal) are our basic mean-field guides. If the latent space is non-euclidean (due to e.g. a positivity constraint on one of the sample sites) an appropriate bijective transformation is automatically used under the hood to map between the unconstrained space (where the Normal variational distribution is defined) to the corresponding constrained space (note this is true for all automatic guides). These guides are a great place to start when trying to get variational inference to work on a model you are developing.
- [AutoMultivariateNormal](https://num.pyro.ai/en/latest/autoguide.html#automultivariatenormal) and [AutoLowRankMultivariateNormal](https://num.pyro.ai/en/latest/autoguide.html#autolowrankmultivariatenormal) also construct Normal variational distributions but offer more flexibility, as they can capture correlations in the posterior. Note that these guides may be difficult to fit in the high-dimensional setting.
Expand Down
10 changes: 5 additions & 5 deletions docs/source/mcmc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ Markov Chain Monte Carlo (MCMC)

We provide a high-level overview of the MCMC algorithms in NumPyro:

* `NUTS <https://num.pyro.ai/en/latest/mcmc.html#nuts>`_, which is an adaptive variant of `HMC <https://num.pyro.ai/en/latest/mcmc.html#hmc>`_, is probably the most commonly used MCMC algorithm in NumPyro. Note that NUTS and HMC are not directly applicable to models with discrete latent variables, but in cases where the discrete variables have finite support and summing them out (i.e. enumeration) is tractable, NumPyro will automatically sum out discrete latent variables and perform NUTS/HMC on the remaining continuous latent variables. As discussed above, model `reparameterization <https://num.pyro.ai/en/latest/reparam.html#module-numpyro.infer.reparam>`_ may be important in some cases to get good performance. Note that, generally speaking, we expect inference to be harder as the dimension of the latent space increases. See the `bad geometry <https://num.pyro.ai/en/latest/tutorials/bad_posterior_geometry.html>`_ tutorial for additional tips and tricks.
* `NUTS <https://num.pyro.ai/en/latest/mcmc.html#numpyro.infer.hmc.NUTS>`_, which is an adaptive variant of `HMC <https://num.pyro.ai/en/latest/mcmc.html#numpyro.infer.hmc.HMC>`_, is probably the most commonly used MCMC algorithm in NumPyro. Note that NUTS and HMC are not directly applicable to models with discrete latent variables, but in cases where the discrete variables have finite support and summing them out (i.e. enumeration) is tractable, NumPyro will automatically sum out discrete latent variables and perform NUTS/HMC on the remaining continuous latent variables. As discussed above, model `reparameterization <https://num.pyro.ai/en/latest/reparam.html#module-numpyro.infer.reparam>`_ may be important in some cases to get good performance. Note that, generally speaking, we expect inference to be harder as the dimension of the latent space increases. See the `bad geometry <https://num.pyro.ai/en/latest/tutorials/bad_posterior_geometry.html>`_ tutorial for additional tips and tricks.
* `MixedHMC <http://num.pyro.ai/en/latest/mcmc.html#numpyro.infer.mixed_hmc.MixedHMC>`_ can be an effective inference strategy for models that contain both continuous and discrete latent variables.
* `HMCECS <http://num.pyro.ai/en/latest/mcmc.html#hmcecs>`_ can be an effective inference strategy for models with a large number of data points. It is applicable to models with continuous latent variables. See `this example <https://num.pyro.ai/en/latest/examples/covtype.html>`_ for detailed usage.
* `BarkerMH <https://num.pyro.ai/en/latest/mcmc.html#barkermh>`_ is a gradient-based MCMC method that may be competitive with HMC and NUTS for some models. It is applicable to models with continuous latent variables.
* `HMCGibbs <https://num.pyro.ai/en/latest/mcmc.html#hmcgibbs>`_ combines HMC/NUTS steps with custom Gibbs updates. Gibbs updates must be specified by the user.
* `DiscreteHMCGibbs <https://num.pyro.ai/en/latest/mcmc.html#discretehmcgibbs>`_ combines HMC/NUTS steps with Gibbs updates for discrete latent variables. The corresponding Gibbs updates are computed automatically.
* `SA <https://num.pyro.ai/en/latest/mcmc.html#sa>`_ is the only MCMC method in NumPyro that does not leverage gradients. It is only applicable to models with continuous latent variables. It is expected to perform best for models whose latent dimension is low to moderate. It may be a good choice for models with non-differentiable log densities. Note that SA generally requires a *very* large number of samples, as mixing tends to be slow. On the plus side individual steps can be fast.
* `BarkerMH <https://num.pyro.ai/en/latest/mcmc.html#numpyro.infer.barker.BarkerMH>`_ is a gradient-based MCMC method that may be competitive with HMC and NUTS for some models. It is applicable to models with continuous latent variables.
* `HMCGibbs <https://num.pyro.ai/en/latest/mcmc.html#numpyro.infer.hmc_gibbs.HMCGibbs>`_ combines HMC/NUTS steps with custom Gibbs updates. Gibbs updates must be specified by the user.
* `DiscreteHMCGibbs <https://num.pyro.ai/en/latest/mcmc.html#numpyro.infer.hmc_gibbs.DiscreteHMCGibbs>`_ combines HMC/NUTS steps with Gibbs updates for discrete latent variables. The corresponding Gibbs updates are computed automatically.
* `SA <https://num.pyro.ai/en/latest/mcmc.html#numpyro.infer.sa.SA>`_ is the only MCMC method in NumPyro that does not leverage gradients. It is only applicable to models with continuous latent variables. It is expected to perform best for models whose latent dimension is low to moderate. It may be a good choice for models with non-differentiable log densities. Note that SA generally requires a *very* large number of samples, as mixing tends to be slow. On the plus side individual steps can be fast.
* `NestedSampler <https://num.pyro.ai/en/latest/contrib.html#nested-sampling>`_ offers a wrapper for `jaxns <https://github.com/Joshuaalbert/jaxns>`_. See `here <https://github.com/pyro-ppl/numpyro/blob/master/examples/gaussian_shells.py>`_ for an example.

Like HMC/NUTS, all remaining MCMC algorithms support enumeration over discrete latent variables if possible (see `restrictions <https://pyro.ai/examples/enumeration.html#Restriction-1:-conditional-independence>`_). Enumerated sites need to be marked with `infer={'enumerate': 'parallel'}` like in the `annotation example <https://num.pyro.ai/en/stable/examples/annotation.html>`_.
Expand Down
8 changes: 4 additions & 4 deletions docs/source/svi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Stochastic Variational Inference (SVI)

We offer a brief overview of the three most commonly used ELBO implementations in NumPyro:

* `Trace_ELBO <https://num.pyro.ai/en/latest/svi.html#trace-elbo>`_ is our basic ELBO implementation.
* `TraceMeanField_ELBO <https://num.pyro.ai/en/latest/svi.html#tracemeanfield-elbo>`_ is like `Trace_ELBO` but computes part of the ELBO analytically if doing so is possible.
* `TraceGraph_ELBO <http://num.pyro.ai/en/latest/svi.html#tracegraph-elbo>`_ offers variance reduction strategies for models with discrete latent variables. Generally speaking, this ELBO should always be used for models with discrete latent variables.
* `TraceEnum_ELBO <http://num.pyro.ai/en/latest/svi.html#traceenum-elbo>`_ offers variable enumeration strategies for models with discrete latent variables. Generally speaking, this ELBO should always be used for models with discrete latent variables when enumeration is possible.
* `Trace_ELBO <https://num.pyro.ai/en/latest/svi.html#numpyro.infer.elbo.Trace_ELBO>`_ is our basic ELBO implementation.
* `TraceMeanField_ELBO <https://num.pyro.ai/en/latest/svi.html#numpyro.infer.elbo.TraceMeanField_ELBO>`_ is like ``Trace_ELBO`` but computes part of the ELBO analytically if doing so is possible.
* `TraceGraph_ELBO <https://num.pyro.ai/en/latest/svi.html#numpyro.infer.elbo.TraceGraph_ELBO>`_ offers variance reduction strategies for models with discrete latent variables. Generally speaking, this ELBO should always be used for models with discrete latent variables.
* `TraceEnum_ELBO <https://num.pyro.ai/en/latest/svi.html#numpyro.infer.elbo.TraceEnum_ELBO>`_ offers variable enumeration strategies for models with discrete latent variables. Generally speaking, this ELBO should always be used for models with discrete latent variables when enumeration is possible.

.. autoclass:: numpyro.infer.svi.SVI
:members:
Expand Down

0 comments on commit 14fd004

Please sign in to comment.