Optimally thinning of output from a sampling procedure, such as MCMC. Here the red samples are automatically chosen by Stein Thinning to provide a more accurate approximation to the distributional target, compared with the original MCMC output. [Read more]

View the Project on GitHub wilson-ye-chen/stein_thinning_start

Stein Thinning is a tool for post-processing the output of a sampling procedure, such as Markov chain Monte Carlo (MCMC). It aims to minimise a Stein discrepancy, selecting a subsequence of samples that best represent the distributional target.

The user provides two arrays: one containing the samples and another containing the corresponding gradients of the log-target. Stein Thinning returns a vector of indices, indicating which samples were selected.

In favourable circumstances, Stein Thinning is able to:

- automatically identify and remove the burn-in period from MCMC,
- perform bias-removal for biased sampling procedures,
- provide improved approximations of the distributional target,
- offer a compressed representation of sample-based output.

Implementations of Stein Thinning are currently available for Python and MATLAB:

- Install for Python
- Install for MATLAB
- Install for R (Coming soon!)

First, it is important to parametrise the distributional target so that it has a positive and differentiable density on .

In Python, MATLAB, or R, it takes a single function call to start Stein Thinning:

```
indices = thin(samples, gradients, m)
```

Here

`samples`

is an array with rows and columns, whose rows are the samples produced by a sampling method, such as MCMC,`gradients`

is an array with rows and columns, whose rows contain the gradients where is the corresponding row of`samples`

,`m`

is an integer, specifying the number of representative samples required,`indices`

is a vector of length , whose elements are integers in , indicating which samples were selected.

Stein Thinning can be used to post-process the output directly from the Stan family of probabilistic programming languages:

- PyStan
- MatlabStan
- RStan

Riabiz M, Chen WY, Cockayne J, Swietach P, Niederer SA, Mackey L, Oates CJ (2020) Optimal Thinning of MCMC Output. arXiv

Teymur O, Gorham J, Riabiz M, Oates CJ (2021) Optimal Quantisation of Probability Measures Using Maximum Mean Discrepancy. International Conference on Artificial Intelligence and Statistics (AISTATS 2021). Paper