This python package implements two novel tuning-free MCMC algorithms to sample distributions defined on the sphere embedded in ℝd, by leveraging its underlying manifold geometry. The two samplers namely ideal geodesic slice sampler based on accept/reject strategy and a shrinkage-based geodesic slice sampler are implemented. The latter is a much faster, but slightly less accurate variant and therefore recommended for practical use due to its efficiency.
In addition, the package also provides the implementation of the spherical variants of random-walk Metropolis-Hastings (RWMH) and Hamiltonian Monte Carlo (HMC). As demonstrated in our paper, the proposed samplers outperform RWMH and HMC for challenging target distributions.
To reproduce the results in the paper, see this section. However, to get started quickly, install the package and follow along with the demo provided below.
GeoSSS is available for installation from PyPI. Therefore, simply type:
pip install geosss
We consider a target that is a mixture of von Mises-Fisher distributions on
This demo can be created with the below script.
import geosss as gs
import numpy as np
# Create mixture of von Mises-Fisher distributions
mus = np.array([[0.87, -0.37, 0.33],
[-0.20, -0.89, -0.40],
[0.19, 0.22, -0.96]])
vmfs = [gs.VonMisesFisher(80.0 * mu) for mu in mus]
pdf = gs.MixtureModel(vmfs)
# Sampling parameters
n_samples, burnin = 1000, 100
init_state = np.array([-0.86, 0.19, -0.47])
seed = 3521
# Sample with different methods
samplers = {
'sss-reject': gs.RejectionSphericalSliceSampler, # very accurate, but slow
'sss-shrink': gs.ShrinkageSphericalSliceSampler, # reasonably accurate, but fast
'rwmh': gs.MetropolisHastings, # automatically tuned during burnin
'hmc': gs.SphericalHMC, # automatically tuned during burnin
}
samples = {name: cls(pdf, init_state, seed).sample(n_samples, burnin)
for name, cls in samplers.items()}
See the notebook demo.ipynb
for visualization of the samples.
To reproduce results from the numerical illustrations section of the paper, check the scripts directory. Precomputed results can also be downloaded from Zenodo and plotted with these scripts.
However, first installing the package and it's locked dependencies is necessary and can be done as follows:
- Clone the repository and navigate to the root of the folder,
git clone https://github.com/microscopic-image-analysis/geosss.git
cd geosss
- You can now create a virtual environment (with
conda
for example),
conda create --name geosss-venv python=3.12 # or python >= 3.10, < 3.13
conda activate geosss-venv
- The dependencies can be installed in this environment as,
pip install -r requirements.txt
pip install -e . --no-deps
Optionally, this can also be done with the python package manager Poetry as
poetry sync --all-extras
If you use this package or ideas from the paper, please consider citing us.
@misc{habeck2023,
title={Geodesic slice sampling on the sphere},
author={Michael Habeck and Mareike Hasenpflug and Shantanu Kodgirwar and Daniel Rudolf},
year={2023},
eprint={2301.08056},
archivePrefix={arXiv},
primaryClass={stat.ME}
}