Skip to main content

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

Project description

PyPI Python 3.9+ License

GeoSSS: Geodesic Slice Sampling on the Sphere

This python package implements the novel and efficient tuning-free MCMC based inference methods to sample distributions defined on the sphere as published in JMLR. This includes the two variants GeoSSS (reject) and GeoSSS (shrink), where the latter is much faster and therefore recommended for practical utility.

In addition, the package also provides the implementation of the spherical variants of random-walk Metropolis-Hastings (Lie et al., 2023) and Hamiltonian Monte Carlo (Lan et al., 2014). As demonstrated in our paper, the proposed samplers outperform RWMH and HMC for several 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.

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 distributions on $\mathbb{S}^2$ with concentration parameter $\kappa=$ 80. By using 1000 samples, our samplers geoSSS (reject) and geoSSS (shrink) explore all modes, whereas RWMH and HMC get stuck in a single mode.

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.

Development and Reproducibility

To reproduce results from the numerical illustrations section of the paper, check the scripts directory. Precomputed results can also be downloaded from the Science Data Bank and used with these scripts.

However, first installing the package and it's locked dependencies is necessary and can be done as follows:

  1. Clone the repository and navigate to the root of the folder,
git clone https://github.com/microscopic-image-analysis/geosss.git
cd geosss
  1. 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
  1. The dependencies can now be installed in this environment as,
pip install -r requirements.txt
pip install -e . --no-deps

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.3.5.tar.gz (25.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

geosss-0.3.5-py3-none-any.whl (28.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: geosss-0.3.5.tar.gz
  • Upload date:
  • Size: 25.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.5 Darwin/25.0.0

File hashes

Hashes for geosss-0.3.5.tar.gz
Algorithm Hash digest
SHA256 2a310150525ec9d3a2cd06feca5d294cd2d88c0b3a67fae62f5ca484b412bb58
MD5 927cb9eb3b181eda39bf4f3d8ec24a9d
BLAKE2b-256 9381641eb6adc187d84a493aac43f1444dc5f757ec499bf1c351a717b4154305

See more details on using hashes here.

File details

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

File metadata

  • Download URL: geosss-0.3.5-py3-none-any.whl
  • Upload date:
  • Size: 28.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.5 Darwin/25.0.0

File hashes

Hashes for geosss-0.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 94ee053c4de2100e9e8bb20344e7f0302e3aef20471031f37142499d86d1597d
MD5 80759f3ef1c37d6bdfb51929f919d11c
BLAKE2b-256 e9e3c163264bbf3b31422544b8cc04faf7041f94fdb6ee0790cb3ce5b2dd38d5

See more details on using hashes here.

Supported by

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