Python package implementing an ideal and shrinkage-based geodesic slice sampling on the sphere.
Project description
GeoSSS: Geodesic Slice Sampling on the Sphere
This python package implements two novel tuning-free MCMC algorithms, an ideal geodesic slice sampler based on accept/reject strategy and a shrinkage-based geodesic slice sampler to sample from spherical distributions on arbitrary dimensions. The package also includes the implementation of random-walk Metropolis-Hastings (RWMH) and Hamiltonian Monte Carlo (HMC) whose step-size parameter is automatically tuned. As shown in our paper, our algorithms have outperformed RWMH and HMC for spherical distributions.
This demo quickly illustrates that. We consider a target that is a mixture of von Mises-Fisher distribution on a 2-sphere with concentration parameter $\kappa=80$. By using $10^3$ samples, our samplers geoSSS (reject) and geoSSS (shrink) (top row) explore all modes, whereas RWMH and HMC (bottom row) get stuck in a single mode.
Installation
GeoSSS is available for installation from PyPI. Therefore, simply type:
pip install geosss
To install dependencies required to run scripts under scripts/,
pip install geosss[extras]
If you want to install with the latest changes including all the dependencies,
pip install geosss[extras]@git+https://github.com/microscopic-image-analysis/geosss.git@main
Getting Started
A minimal example to get started as well as reproduce the above demo:
import geosss as gs
import numpy as np
# parameters for mixture of von Mises-Fisher (vMF)
# distributions
d = 3 # required dimension
K = 3 # number of mixture components
kappa = 80.0 # concentration parameter
# mus (mean directions) of the vMF mixture components
mus = np.array([[0.86981638, -0.37077248, 0.32549536],
[-0.19772391, -0.89279985, -0.40473902],
[0.19047726, 0.22240888, -0.95616562]])
# target pdf
vmfs = [gs.VonMisesFisher(kappa*mu) for mu in mus]
pdf = gs.MixtureModel(vmfs)
# sampler parameters
n_samples = int(1e3) # no. of samples
burnin = int(0.1 * n_samples) # burnin samples
seed = 3521 # sampler seed
# initial state of the samplers
init_state = np.array([-0.86333052, 0.18685286, -0.46877117])
# sampling with the four samplers
samples = {}
# geoSSS (reject): ideal geodesic slice sampler
rsss = gs.RejectionSphericalSliceSampler(pdf, init_state, seed)
samples['sss-reject'] = rsss.sample(n_samples, burnin)
# geoSSS (shrink): shrinkage-based geodesic slice sampler
ssss = gs.ShrinkageSphericalSliceSampler(pdf, init_state, seed)
samples['sss-shrink'] = ssss.sample(n_samples, burnin)
# RWMH: random-walk Metropolis Hastings
rwmh = gs.MetropolisHastings(pdf, init_state, seed)
samples['rwmh'] = rwmh.sample(n_samples, burnin)
# HMC: Hamiltonian Monte Carlo
hmc = gs.SphericalHMC(pdf, init_state, seed)
samples['hmc'] = hmc.sample(n_samples, burnin)
# visualize samples in 3d
gs.compare_samplers_3d(pdf, samples)
The plots in the paper under numerical illustrations section were generated using bingham.py, mixture_vMF.py, ess_vMF.py and curve.py.
Development
To install this package and its development dependencies in editable mode, please do the following
git clone https://github.com/microscopic-image-analysis/geosss.git
cd geosss
pip install -e .[dev]
Citation
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}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file geosss-0.1.9.tar.gz.
File metadata
- Download URL: geosss-0.1.9.tar.gz
- Upload date:
- Size: 18.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.5 Linux/6.5.0-26-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d89811366b8af89887c6fdb61a9f5a498b21fd0dc97ace4e0b4c32bc582802c6
|
|
| MD5 |
db1d31ea0bd8cad69206df4e8b72f6ea
|
|
| BLAKE2b-256 |
6ce077d0362f979624cc2eeeae46330f7a42dd88cbe2db25117b5375622ef1eb
|
File details
Details for the file geosss-0.1.9-py3-none-any.whl.
File metadata
- Download URL: geosss-0.1.9-py3-none-any.whl
- Upload date:
- Size: 20.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.5 Linux/6.5.0-26-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5da4925c343be4af9cda32852884318a0b1cc08c072f5e97c36c439d2c5bfab
|
|
| MD5 |
c9b03366e9ca83bfc9eec2d6e5a9c3d3
|
|
| BLAKE2b-256 |
f7bcac8f01b03906ba56900b578c15152773af553527bfb21d98b4fa0d5b4d8c
|