-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Gibbsian polar slice sampler (#4)
* add limit on maximum number of proposals * add Gibbsian polar slice sampling * fix error message * update README
- Loading branch information
1 parent
725a749
commit 0c9583c
Showing
14 changed files
with
436 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,43 @@ | ||
# Implementation of slice sampling algorithms | ||
|
||
[](https://Red-Portal.github.io/SliceSampling.jl/stable/) | ||
[](https://Red-Portal.github.io/SliceSampling.jl/dev/) | ||
[](https://github.com/Red-Portal/SliceSampling.jl/actions/workflows/CI.yml?query=branch%3Amain) | ||
[](https://codecov.io/gh/Red-Portal/SliceSampling.jl) | ||
|
||
This package implements slice sampling algorithms accessible through the the `AbstractMCMC` [interface](https://github.com/TuringLang/AbstractMCMC.jl). | ||
For general usage, please refer to [here](https://turinglang.org/SliceSampling.jl/dev/general/). | ||
|
||
## Implemented Algorithms | ||
- Univariate slice sampling algorithms with coordinate-wise Gibbs sampling by R. Neal [^N2003]. | ||
- Latent slice sampling by Li and Walker[^LW2023] | ||
- Gibbsian polar slice sampling by P. Schär, M. Habeck, and D. Rudolf[^SHR2023]. | ||
|
||
## Example with Turing Models | ||
This package supports the [Turing](https://github.com/TuringLang/Turing.jl) probabilistic programming framework: | ||
|
||
```@example turing | ||
using Distributions | ||
using Turing | ||
using SliceSampling | ||
@model function demo() | ||
s ~ InverseGamma(3, 3) | ||
m ~ Normal(0, sqrt(s)) | ||
end | ||
sampler = LatentSlice(2) | ||
n_samples = 10000 | ||
model = demo() | ||
sample(model, externalsampler(sampler), n_samples; initial_params=[1.0, 0.0]) | ||
``` | ||
|
||
[^N2003]: Neal, R. M. (2003). Slice sampling. The annals of statistics, 31(3), 705-767. | ||
[^LW2023]: Li, Y., & Walker, S. G. (2023). A latent slice sampling algorithm. Computational Statistics & Data Analysis, 179, 107652. | ||
[^SHR2023]: Schär, P., Habeck, M., & Rudolf, D. (2023, July). Gibbsian polar slice sampling. In International Conference on Machine Learning. | ||
======= | ||
[](https://TuringLang.org/SliceSampling.jl/stable/) | ||
[](https://TuringLang.org/SliceSampling.jl/dev/) | ||
[](https://github.com/Red-Portal/SliceSampling.jl/actions/workflows/CI.yml?query=branch%3Amain) | ||
[](https://codecov.io/gh/Red-Portal/SliceSampling.jl) | ||
|
||
|
||
For a working example, please see [here](https://turinglang.org/SliceSampling.jl/dev/general/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
|
||
# [Gibbsian Polar Slice Sampling](@id polar) | ||
|
||
## Introduction | ||
Gibbsian polar slice sampling (GPSS) is a recent vector-valued slice sampling algorithm proposed by P. Schär, M. Habeck, and D. Rudolf[^SHR2023]. | ||
It is an computationally efficient variant of polar slice sampler previously proposed by Roberts and Rosenthal[^RR2002]. | ||
Unlike other slice sampling algorithms, it operates a Gibbs sampler over polar coordinates, reminiscent of the elliptical slice sampler (ESS). | ||
Due to the involvement of polar coordinates, GPSS only works reliably on more than one dimension. | ||
However, unlike ESS, GPSS is applicable to any target distribution. | ||
|
||
|
||
## Description | ||
For a $$d$$-dimensional target distribution, GPSS utilizes the following augmented target distribution: | ||
```math | ||
\begin{aligned} | ||
p(x, T) &= \varrho_{\pi}^{(0)}(x) \varrho_{\pi}^{(1)}(x) \, \operatorname{Uniform}\left(T; 0, \varrho^1(x)\right) \\ | ||
\varrho_{\pi}^{(0)}(x) &= {\lVert x \rVert}^{1 - d} \\ | ||
\varrho_{\pi}^{(1)}(x) &= {\lVert x \rVert}^{d-1} \pi\left(x\right) | ||
\end{aligned} | ||
``` | ||
As described in Appendix A of the GPSS paper, sampling from $$\varrho^{(1)}(x)$$ in polar coordinates magically targets the augmented target distribution. | ||
|
||
In a high-level view, GPSS operates a Gibbs sampler in the following fashion: | ||
```math | ||
\begin{aligned} | ||
T_n &\sim \operatorname{Uniform}\left(0, \varrho^{(1)}\left(x_{n-1}\right)\right) \\ | ||
\theta_n &\sim \operatorname{Uniform}\left\{ \theta \in \mathbb{S}^{d-1} \mid \varrho^{(1)}\left(r_{n-1} \theta\right) > T_n \right\} \\ | ||
r_n &\sim \operatorname{Uniform}\left\{ r \in \mathbb{R}_{\geq 0} \mid \varrho^{(1)}\left(r \theta_n\right) > T_n \right\} \\ | ||
x &= \theta r, | ||
\end{aligned} | ||
``` | ||
where $$T_n$$ is the usual acceptance threshold auxiliary variable, while $$\theta$$ and $$r$$ are the sampler states in polar coordinates. | ||
The Gibbs steps on $$\theta$$ and $$r$$ are implemented through specialized shrinkage procedures. | ||
|
||
The only tunable parameter of the algorithm is the size of the search interval (window) of the shrinkage sampler for the radius variable $$r$$. | ||
|
||
!!! info | ||
Since the direction and radius variables are states of the Markov chain, this sampler is **not reversible** with respect to the samples of the log-target $$x$$. | ||
|
||
## Interface | ||
|
||
!!! warning | ||
By the nature of polar coordinates, GPSS only works reliably for targets with dimension at least $$d \geq 2$$. | ||
|
||
!!! warning | ||
When initializing the chain (*e.g.* the `initial_params` keyword arguments in `AbstractMCMC.sample`), it is necessary to inialize from a point $$x_0$$ that has a sensible norm $$\lVert x_0 \rVert > 0$$, otherwise, the chain will start from a pathologic point in polar coordinates. If it is smaller than `1e-5`, the current implementation automatically sets the initial radius as `1e-5`. | ||
|
||
|
||
```@docs | ||
GibbsPolarSlice | ||
``` | ||
|
||
## Demonstration | ||
As illustrated in the original paper, GPSS shows good performance on heavy-tailed targets despite being a multivariate slice sampler: | ||
```@example gpss | ||
using Distributions | ||
using Turing | ||
using SliceSampling | ||
using LinearAlgebra | ||
using Plots | ||
@model function demo() | ||
x ~ MvTDist(1, zeros(10), Matrix(I,10,10)) | ||
end | ||
model = demo() | ||
n_samples = 10000 | ||
chain = sample(model, externalsampler(GibbsPolarSlice(10)), n_samples; initial_params=ones(10)) | ||
histogram(chain[:,1,:], xlims=[-10,10]) | ||
savefig("cauchy_gpss.svg") | ||
``` | ||
 | ||
|
||
|
||
[^SHR2023]: Schär, P., Habeck, M., & Rudolf, D. (2023, July). Gibbsian polar slice sampling. In International Conference on Machine Learning. | ||
[^RR2002]: Roberts, G. O., & Rosenthal, J. S. (2002). The polar slice sampler. Stochastic Models, 18(2), 257-280. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.