Skip to main content

Python package implementing an ideal and shrinkage-based geodesic slice sampling on the sphere.

Project description

PyPI Python 3.9+ arXiv License

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. To reproduce the results in the paper, see this section. However, to get started, please install the package and follow along with the demo to illustrate the use of the algorithm as given below.

Installation

GeoSSS is available for installation from PyPI. Therefore, simply type:

pip install geosss

Minimal Example

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.

This demo can be created with the below script.

Open In Colab

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)

Development and Reproducibility

It is preferable to install the package in the development mode for modifications. Additionally, this will also ensure reproducibility of the results from the numerical illustrations section of the paper.

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.11 # or python >= 3.10, < 3.13
conda activate geosss-venv

The dependencies can be installed in this environment with pip as,

pip install -r requirements.txt

Alternatively, because the pyproject.toml file is based on the python package manager Poetry, it is possible to install with poetry in the activated conda environment.

poetry install --all-extras --sync

For reproducing the results in the paper, please check the scripts directory. Precomputed results can also be downloaded from Zenodo and plotted with these scripts.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

geosss-0.2.1.tar.gz (22.9 kB view details)

Uploaded Source

Built Distribution

geosss-0.2.1-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file geosss-0.2.1.tar.gz.

File metadata

  • Download URL: geosss-0.2.1.tar.gz
  • Upload date:
  • Size: 22.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Darwin/24.0.0

File hashes

Hashes for geosss-0.2.1.tar.gz
Algorithm Hash digest
SHA256 bc890e06e1d4e2ed43e4afea16e6cd3ee24bf26f241b50c78b4453da3092782b
MD5 a5a2a4347b9cdd314ee0f5a22fd038c0
BLAKE2b-256 e401621c2ef1402107130d4dd9ae6ba638e982777f2a414cb55be55e10d16688

See more details on using hashes here.

File details

Details for the file geosss-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: geosss-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Darwin/24.0.0

File hashes

Hashes for geosss-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 59bb4d1d7fa0b9c2b2a00828057622e7ee8bed3a326607b8c4b1387445b58803
MD5 8e28389c8cc9b28ce923303394b3cb82
BLAKE2b-256 1b5e14d3c94a9c4cda9f1995691d2fcd87da571f247102f7bfcdd49aa59357eb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page