{"id":13689304,"url":"https://github.com/matt-graham/mici","last_synced_at":"2025-05-16T00:09:02.181Z","repository":{"id":41413256,"uuid":"52494384","full_name":"matt-graham/mici","owner":"matt-graham","description":"Manifold Markov chain Monte Carlo methods in Python","archived":false,"fork":false,"pushed_at":"2025-04-24T17:01:37.000Z","size":35146,"stargazers_count":230,"open_issues_count":3,"forks_count":27,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-04-24T17:32:00.018Z","etag":null,"topics":["hamiltonian-monte-carlo","hmc","hybrid-monte-carlo","inference-algorithms","markov-chain-monte-carlo","mcmc","python"],"latest_commit_sha":null,"homepage":"https://matt-graham.github.io/mici/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matt-graham.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-02-25T03:36:01.000Z","updated_at":"2025-04-24T17:00:39.000Z","dependencies_parsed_at":"2022-09-05T23:51:44.532Z","dependency_job_id":"60c86f14-e152-4c0f-92f4-16e213b21f0c","html_url":"https://github.com/matt-graham/mici","commit_stats":{"total_commits":366,"total_committers":2,"mean_commits":183.0,"dds":"0.021857923497267784","last_synced_commit":"aa209e2cf698bb9e0c7c733d7b6a5557ab5df190"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matt-graham%2Fmici","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matt-graham%2Fmici/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matt-graham%2Fmici/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matt-graham%2Fmici/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matt-graham","download_url":"https://codeload.github.com/matt-graham/mici/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254442855,"owners_count":22071878,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hamiltonian-monte-carlo","hmc","hybrid-monte-carlo","inference-algorithms","markov-chain-monte-carlo","mcmc","python"],"created_at":"2024-08-02T15:01:42.023Z","updated_at":"2025-05-16T00:08:57.136Z","avatar_url":"https://github.com/matt-graham.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"\u003cdiv style=\"text-align: center;\" align=\"center\"\u003e\n\u003cpicture\u003e\n  \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://raw.githubusercontent.com/matt-graham/mici/main/images/mici-logo-rectangular-light-text.svg\"\u003e\n  \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"https://raw.githubusercontent.com/matt-graham/mici/main/images/mici-logo-rectangular.svg\"\u003e\n  \u003cimg alt=\"Mici logo\" src=\"https://raw.githubusercontent.com/matt-graham/mici/main/images/mici-logo-rectangular.svg\" width=\"400px\"\u003e\n\u003c/picture\u003e\n\u003cdiv style=\"text-align: center;\" align=\"center\"\u003e\n\n[![PyPI version](https://badge.fury.io/py/mici.svg)](https://pypi.org/project/mici)\n[![Zenodo DOI](https://zenodo.org/badge/52494384.svg)](https://zenodo.org/badge/latestdoi/52494384)\n[![Documentation](https://img.shields.io/badge/Sphinx-documentation-blue?logo=sphinx\u0026logoColor=white)](https://matt-graham.github.io/mici/)\n[![License](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE)\n[![Test status](https://github.com/matt-graham/mici/actions/workflows/tests.yml/badge.svg)](https://github.com/matt-graham/mici/actions/workflows/tests.yml)\n[![Linting status](https://github.com/matt-graham/mici/actions/workflows/linting.yml/badge.svg)](https://github.com/matt-graham/mici/actions/workflows/linting.yml)\n[![Docs status](https://github.com/matt-graham/mici/actions/workflows/docs.yml/badge.svg)](https://github.com/matt-graham/mici/actions/workflows/docs.yml)\n[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md)\n\n\u003c/div\u003e\n\u003c/div\u003e\n\n**Mici** is a Python package providing implementations of _Markov chain Monte\nCarlo_ (MCMC) methods for approximate inference in probabilistic models, with a\nparticular focus on MCMC methods based on simulating Hamiltonian dynamics on a\nmanifold.\n\n## Features\n\nKey features include\n\n- a modular design allowing use of a wide range of inference algorithms by\n  mixing and matching different components, and making it easy to\n  extend the package,\n- a pure Python code base with minimal dependencies,\n  allowing easy integration within other code,\n- built-in support for several automatic differentiation frameworks, including\n  [JAX](https://jax.readthedocs.io/en/latest/) and\n  [Autograd](https://github.com/HIPS/autograd), or the option to supply your own\n  derivative functions,\n- implementations of MCMC methods for sampling from distributions on embedded\n  manifolds implicitly-defined by a constraint equation and distributions on\n  Riemannian manifolds with a user-specified metric,\n- computationally efficient inference via transparent caching of the results\n  of expensive operations and intermediate results calculated in derivative\n  computations allowing later reuse without recalculation,\n- memory efficient inference for large models by memory-mapping chains to\n  disk, allowing long runs on large models without hitting memory issues.\n\n## Installation\n\nTo install and use Mici the minimal requirements are a Python 3.10+ environment\nwith [NumPy](http://www.numpy.org/) and [SciPy](https://www.scipy.org)\ninstalled. The latest Mici release on PyPI (and its dependencies) can be\ninstalled in the current Python environment by running\n\n```sh\npip install mici\n```\n\nTo instead install the latest development version from the `main` branch on Github run\n\n```sh\npip install git+https://github.com/matt-graham/mici\n```\n\nIf available in the installed Python environment the following additional\npackages provide extra functionality and features\n\n- [ArviZ](https://python.arviz.org/en/latest/index.html): if ArviZ is\n  available the traces (dictionary) output of a sampling run can be directly\n  converted to an `arviz.InferenceData` container object using\n  `arviz.convert_to_inference_data` or implicitly converted by passing the\n  traces dictionary as the `data` argument\n  [to ArviZ API functions](https://python.arviz.org/en/latest/api/index.html),\n  allowing straightforward use of the ArviZ's extensive visualisation and\n  diagnostic functions.\n- [Autograd](https://github.com/HIPS/autograd): if available Autograd will\n  be used to automatically compute the required derivatives of the model\n  functions (providing they are specified using functions from the\n  `autograd.numpy` and `autograd.scipy` interfaces). To sample chains in\n  parallel using `autograd` functions you also need to install\n  [multiprocess](https://github.com/uqfoundation/multiprocess). This will\n  cause `multiprocess.Pool` to be used in preference to the in-built\n  `mutiprocessing.Pool` for parallelisation as multiprocess supports\n  serialisation (via [dill](https://github.com/uqfoundation/dill)) of a much\n  wider range of types, including of Autograd generated functions. Both\n  Autograd and multiprocess can be installed alongside Mici by running `pip\ninstall mici[autograd]`.\n- [JAX](https://jax.readthedocs.io/en/latest/): if available JAX will be used to\n  automatically compute the required derivatives of the model functions (providing\n  they are specified using functions from the [`jax`\n  interface](https://jax.readthedocs.io/en/latest/jax.html)). To sample chains\n  parallel using JAX functions you also need to install\n  [multiprocess](https://github.com/uqfoundation/multiprocess), though note due to\n  JAX's use of multithreading which [is incompatible with forking child\n  processes](https://docs.python.org/3/library/os.html#os.fork), this can result in\n  deadlock. Both JAX and multiprocess can be installed alongside Mici by running `pip\ninstall mici[jax]`.\n- [SymNum](https://github.com/matt-graham/symnum): if available SymNum will be used to\n  automatically compute the required derivatives of the model functions (providing\n  they are specified using functions from the [`symnum.numpy`\n  interface](https://matt-graham.github.io/symnum/symnum.numpy.html)). Symnum can be\n  installed alongside Mici by running `pip install mici[symnum]`.\n\n## Why Mici?\n\nMici is named for [Augusta 'Mici'\nTeller](https://en.wikipedia.org/wiki/Augusta_H._Teller), who along with\n[Arianna Rosenbluth](https://en.wikipedia.org/wiki/Arianna_W._Rosenbluth)\ndeveloped the code for the [MANIAC I](https://en.wikipedia.org/wiki/MANIAC_I)\ncomputer used in the seminal paper [_Equations of State Calculations by Fast\nComputing Machines_](https://doi.org/10.1063%2F1.1699114) which introduced the\nfirst example of a Markov chain Monte Carlo method.\n\n## Related projects\n\nOther Python packages for performing MCMC inference include\n[PyMC](https://github.com/pymc-devs/pymc),\n[PyStan](https://github.com/stan-dev/pystan) (the Python interface to\n[Stan](http://mc-stan.org/)), [Pyro](https://github.com/pyro-ppl/pyro) /\n[NumPyro](https://github.com/pyro-ppl/numpyro), [TensorFlow\nProbability](https://github.com/tensorflow/probability),\n[emcee](https://github.com/dfm/emcee),\n[Sampyl](https://github.com/mcleonard/sampyl) and\n[BlackJAX](https://github.com/blackjax-devs/blackjax).\n\nUnlike PyMC, PyStan, (Num)Pyro and TensorFlow Probability which are complete\nprobabilistic programming frameworks including functionality for defining a\nprobabilistic model / program, but like emcee, Sampyl and BlackJAX, Mici is solely\nfocused on providing implementations of inference algorithms, with the user\nexpected to be able to define at a minimum a function specifying the negative\nlog (unnormalized) density of the distribution of interest.\n\nFurther while PyStan, (Num)Pyro and TensorFlow Probability all push the\nsampling loop into external compiled non-Python code, in Mici the sampling loop\nis run directly within Python. This has the consequence that for small models\nin which the negative log density of the target distribution and other model\nfunctions are cheap to evaluate, the interpreter overhead in iterating over the\nchains in Python can dominate the computational cost, making sampling much\nslower than packages which outsource the sampling loop to a efficient compiled\nimplementation.\n\n## Overview of package\n\nAPI documentation for the package is available\n[here](https://matt-graham.github.io/mici/). The three main user-facing\nmodules within the `mici` package are the `systems`, `integrators` and\n`samplers` modules and you will generally need to create an instance of one\nclass from each module.\n\n[`mici.systems`](https://matt-graham.github.io/mici/mici.systems.html) -\nHamiltonian systems encapsulating model functions and their derivatives\n\n- `EuclideanMetricSystem` - systems with a metric on the position space with\n  a constant matrix representation,\n- `GaussianEuclideanMetricSystem` - systems in which the target distribution\n  is defined by a density with respect to the standard Gaussian measure on\n  the position space allowing analytically solving for flow corresponding to\n  the quadratic components of Hamiltonian\n  ([Shahbaba et al., 2014](#shababa2014split)),\n- `RiemannianMetricSystem` - systems with a metric on the position space\n  with a position-dependent matrix representation\n  ([Girolami and Calderhead, 2011](#girolami2011riemann)),\n- `SoftAbsRiemannianMetricSystem` - system with _SoftAbs_\n  eigenvalue-regularized Hessian of negative log target density as metric\n  matrix representation ([Betancourt, 2013](#betancourt2013general)),\n- `DenseConstrainedEuclideanMetricSystem` - Euclidean-metric system subject\n  to holonomic constraints\n  ([Hartmann and Schütte, 2005](#hartmann2005constrained);\n  [Brubaker, Salzmann and Urtasun, 2012](#brubaker2012family);\n  [Lelièvre, Rousset and Stoltz, 2019](#lelievre2019hybrid))\n  with a dense constraint function Jacobian matrix,\n\n[`mici.integrators`](https://matt-graham.github.io/mici/mici.integrators.html) -\nsymplectic integrators for Hamiltonian dynamics\n\n- `LeapfrogIntegrator` - explicit leapfrog (Störmer-Verlet) integrator for\n  separable Hamiltonian systems\n  ([Leimkulher and Reich, 2004](#leimkuhler2004simulating)),\n- `ImplicitLeapfrogIntegrator` - implicit (or generalized) leapfrog\n  integrator for Hamiltonian systems with non-separable component\n  ([Leimkulher and Reich, 2004](#leimkuhler2004simulating)),\n- `ImplicitMidpointIntegrator` - implicit midpoint\n  integrator for general Hamiltonian systems\n  ([Leimkulher and Reich, 2004](#leimkuhler2004simulating)),\n- `SymmetricCompositionIntegrator` - family of symplectic integrators for Hamiltonians\n  that can be split in to components with tractable flow maps, with specific\n  two-, three- and four-stage instantations due to [Blanes, Casas and Sanz-Serna (2014)](#blanes2014numerical),\n- `ConstrainedLeapfrogIntegrator` - constrained leapfrog integrator for\n  Hamiltonian systems subject to holonomic constraints\n  ([Andersen, 1983](#andersen1983rattle);\n  [Leimkuhler and Reich, 1994](#leimkuhler1994symplectic)).\n\n[`mici.samplers`](https://matt-graham.github.io/mici/mici.samplers.html) - MCMC\nsamplers for peforming inference\n\n- `StaticMetropolisHMC` - static integration time Hamiltonian Monte Carlo\n  with Metropolis accept step ([Duane et al., 1987](duane1987hybrid)),\n- `RandomMetropolisHMC` - random integration time Hamiltonian Monte Carlo\n  with Metropolis accept step ([Mackenzie, 1989](#mackenzie1989improved)),\n- `DynamicSliceHMC` - dynamic integration time Hamiltonian Monte Carlo\n  with slice sampling from trajectory, equivalent to the original 'NUTS' algorithm\n  ([Hoffman and Gelman, 2014](#hoffman2014nouturn)).\n- `DynamicMultinomialHMC` - dynamic integration time Hamiltonian Monte Carlo\n  with multinomial sampling from trajectory, equivalent to the current default\n  MCMC algorithm in [Stan](https://mc-stan.org/)\n  ([Hoffman and Gelman, 2014](#hoffman2014nouturn);\n  [Betancourt, 2017](#betancourt2017conceptual)).\n\n## Notebooks\n\nThe manifold MCMC methods implemented in Mici have been used in several research projects. Below links are provided to a selection of Jupyter notebooks associated with these projects as demonstrations of how to use Mici and to illustrate some of the settings in which manifold MCMC methods can be computationally advantageous.\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth colspan=\"2\"\u003e\u003ca href=\"https://github.com/thiery-lab/manifold_lifting\"\u003eManifold lifting: scaling MCMC to the vanishing noise regime\u003c/a\u003e\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eOpen non-interactive version with nbviewer\u003c/td\u003e\n    \u003ctd\u003e\n      \u003ca href=\"https://nbviewer.jupyter.org/github/thiery-lab/manifold_lifting/blob/main/notebooks/Two-dimensional_example.ipynb\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/jupyter/design/main/logos/Badges/nbviewer_badge.svg?sanitize=true\" width=\"109\" alt=\"Render with nbviewer\"  style=\"vertical-align:text-bottom\" /\u003e\n      \u003c/a\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eOpen interactive version with Binder\u003c/td\u003e\n    \u003ctd\u003e\n      \u003ca href=\"https://mybinder.org/v2/gh/thiery-lab/manifold_lifting/main?filepath=notebooks%2FTwo-dimensional_example.ipynb\"\u003e\n        \u003cimg src=\"https://mybinder.org/badge_logo.svg\" alt=\"Launch with Binder\"  style=\"vertical-align:text-bottom\"/\u003e\n      \u003c/a\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eOpen interactive version with Google Colab\u003c/td\u003e\n    \u003ctd\u003e\n      \u003ca href=\"https://colab.research.google.com/github/thiery-lab/manifold_lifting/blob/main/notebooks/Two-dimensional_example.ipynb\"\u003e\n        \u003cimg alt=\"Open in Colab\" src=\"https://colab.research.google.com/assets/colab-badge.svg\" style=\"vertical-align:text-bottom\"\u003e\n       \u003c/a\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth colspan=\"2\"\u003e\u003ca href=\"https://github.com/thiery-lab/manifold-mcmc-for-diffusions\"\u003eManifold MCMC methods for inference in diffusion models\u003c/a\u003e\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eOpen non-interactive version with nbviewer\u003c/td\u003e\n    \u003ctd\u003e\n      \u003ca href=\"https://nbviewer.jupyter.org/github/thiery-lab/manifold-mcmc-for-diffusions/blob/main/FitzHugh-Nagumo_example.ipynb\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/jupyter/design/main/logos/Badges/nbviewer_badge.svg?sanitize=true\" width=\"109\" alt=\"Render with nbviewer\"  style=\"vertical-align:text-bottom\" /\u003e\n      \u003c/a\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eOpen interactive version with Binder\u003c/td\u003e\n    \u003ctd\u003e\n      \u003ca href=\"https://mybinder.org/v2/gh/thiery-lab/manifold-mcmc-for-diffusions/main?filepath=FitzHugh-Nagumo_example.ipynb\"\u003e\n        \u003cimg src=\"https://mybinder.org/badge_logo.svg\" alt=\"Launch with Binder\"  style=\"vertical-align:text-bottom\"/\u003e\n      \u003c/a\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eOpen interactive version with Google Colab\u003c/td\u003e\n    \u003ctd\u003e\n      \u003ca href=\"https://colab.research.google.com/github/thiery-lab/manifold-mcmc-for-diffusions/blob/main/FitzHugh-Nagumo_example.ipynb\"\u003e\n        \u003cimg alt=\"Open in Colab\" src=\"https://colab.research.google.com/assets/colab-badge.svg\" style=\"vertical-align:text-bottom\"\u003e\n       \u003c/a\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n## Example: sampling on a torus\n\n\u003cimg src='https://raw.githubusercontent.com/matt-graham/mici/main/images/torus-samples.gif' width='360px'/\u003e\n\nA simple complete example of using the package to compute approximate samples from a\ndistribution on a two-dimensional torus embedded in a three-dimensional space is given\nbelow. The computed samples are visualized in the animation above. Here we use\n[SymNum](https://github.com/matt-graham/symnum) to automatically construct functions to\ncalculate the required derivatives (gradient of negative log density of target\ndistribution and Jacobian of constraint function), sample four chains in parallel using\n`multiprocessing`, use [ArviZ](https://python.arviz.org/en/stable/) to calculate\ndiagnostics and use [Matplotlib](https://matplotlib.org/) to plot the samples.\n\n```Python\nimport mici\nimport numpy as np\nimport symnum\nimport symnum.numpy as snp\nimport matplotlib.pyplot as plt\nimport matplotlib.animation as animation\nimport arviz\n\n# Define fixed model parameters\nR = 1.0  # toroidal radius ∈ (0, ∞)\nr = 0.5  # poloidal radius ∈ (0, R)\nα = 0.9  # density fluctuation amplitude ∈ [0, 1)\n\n# State dimension\ndim_q = 3\n\n\n# Define constraint function such that the set {q : constr(q) == 0} is a torus\n@symnum.numpify(dim_q)\ndef constr(q):\n    x, y, z = q\n    return snp.array([((x**2 + y**2) ** 0.5 - R) ** 2 + z**2 - r**2])\n\n\n# Define negative log density for the target distribution on torus\n# (with respect to 2D 'area' measure for torus)\n@symnum.numpify(dim_q)\ndef neg_log_dens(q):\n    x, y, z = q\n    θ = snp.arctan2(y, x)\n    ϕ = snp.arctan2(z, x / snp.cos(θ) - R)\n    return snp.log1p(r * snp.cos(ϕ) / R) - snp.log1p(snp.sin(4 * θ) * snp.cos(ϕ) * α)\n\n\n# Specify constrained Hamiltonian system with default identity metric\nsystem = mici.systems.DenseConstrainedEuclideanMetricSystem(\n    neg_log_dens,\n    constr,\n    backend=\"symnum\",\n)\n\n# System is constrained therefore use constrained leapfrog integrator\nintegrator = mici.integrators.ConstrainedLeapfrogIntegrator(system)\n\n# Seed a random number generator\nrng = np.random.default_rng(seed=1234)\n\n# Use dynamic integration-time HMC implementation as MCMC sampler\nsampler = mici.samplers.DynamicMultinomialHMC(system, integrator, rng)\n\n# Sample initial positions on torus using parameterisation (θ, ϕ) ∈ [0, 2π)²\n# x, y, z = (R + r * cos(ϕ)) * cos(θ), (R + r * cos(ϕ)) * sin(θ), r * sin(ϕ)\nn_chain = 4\nθ_init, ϕ_init = rng.uniform(0, 2 * np.pi, size=(2, n_chain))\nq_init = np.stack(\n    [\n        (R + r * np.cos(ϕ_init)) * np.cos(θ_init),\n        (R + r * np.cos(ϕ_init)) * np.sin(θ_init),\n        r * np.sin(ϕ_init),\n    ],\n    -1,\n)\n\n\n# Define function to extract variables to trace during sampling\ndef trace_func(state):\n    x, y, z = state.pos\n    return {\"x\": x, \"y\": y, \"z\": z}\n\n\n# Sample 4 chains in parallel with 500 adaptive warm up iterations in which the\n# integrator step size is tuned, followed by 2000 non-adaptive iterations\nfinal_states, traces, stats = sampler.sample_chains(\n    n_warm_up_iter=500,\n    n_main_iter=2000,\n    init_states=q_init,\n    n_process=4,\n    trace_funcs=[trace_func],\n)\n\n# Print average accept probability and number of integrator steps per chain\nfor c in range(n_chain):\n    print(f\"Chain {c}:\")\n    print(f\"  Average accept prob. = {stats['accept_stat'][c].mean():.2f}\")\n    print(f\"  Average number steps = {stats['n_step'][c].mean():.1f}\")\n\n# Print summary statistics and diagnostics computed using ArviZ\nprint(arviz.summary(traces))\n\n# Visualize concatentated chain samples as animated 3D scatter plot\nfig, ax = plt.subplots(\n    figsize=(4, 4),\n    subplot_kw={\"projection\": \"3d\", \"proj_type\": \"ortho\"},\n)\n(points_3d,) = ax.plot(*(np.concatenate(traces[k]) for k in \"xyz\"), \".\", ms=0.5)\nax.axis(\"off\")\nfor set_lim in [ax.set_xlim, ax.set_ylim, ax.set_zlim]:\n    set_lim((-1, 1))\n\n\ndef update(i):\n    angle = 45 * (np.sin(2 * np.pi * i / 60) + 1)\n    ax.view_init(elev=angle, azim=angle)\n    return (points_3d,)\n\n\nanim = animation.FuncAnimation(fig, update, frames=60, interval=100)\nplt.show()\n```\n\n## References\n\n1. \u003ca id='andersen1983rattle'\u003e\u003c/a\u003e Andersen, H.C., 1983. RATTLE: A “velocity”\n   version of the SHAKE algorithm for molecular dynamics calculations.\n   _Journal of Computational Physics_, 52(1), pp.24-34.\n   [![DOI:10.1016/0021-9991(83)90014-1](\u003chttps://zenodo.org/badge/DOI/10.1016/0021-9991(83)90014-1.svg\u003e)](\u003chttps://doi.org/10.1016/0021-9991(83)90014-1\u003e)\n2. \u003ca id='duane1987hybrid'\u003e\u003c/a\u003e Duane, S., Kennedy, A.D., Pendleton, B.J. and\n   Roweth, D., 1987. Hybrid Monte Carlo. _Physics letters B_, 195(2),\n   pp.216-222.\n   [![DOI:10.1016/0370-2693(87)91197-X](\u003chttps://zenodo.org/badge/DOI/10.1016/0370-2693(87)91197-X.svg\u003e)](\u003chttps://doi.org/10.1016/0370-2693(87)91197-X\u003e)\n3. \u003ca id='mackenzie1989improved'\u003e\u003c/a\u003e Mackenzie, P.B., 1989. An improved\n   hybrid Monte Carlo method. _Physics Letters B_, 226(3-4), pp.369-371.\n   [![DOI:10.1016/0370-2693(89)91212-4](\u003chttps://zenodo.org/badge/DOI/10.1016/0370-2693(89)91212-4.svg\u003e)](\u003chttps://doi.org/10.1016/0370-2693(89)91212-4\u003e)\n4. \u003ca id='horowitz1991generalized'\u003e\u003c/a\u003e Horowitz, A.M., 1991. A generalized\n   guided Monte Carlo algorithm. _Physics Letters B_, 268(CERN-TH-6172-91),\n   pp.247-252.\n   [![DOI:10.1016/0370-2693(91)90812-5](\u003chttps://zenodo.org/badge/DOI/10.1016/0370-2693(91)90812-5.svg\u003e)](\u003chttps://doi.org/10.1016/0370-2693(91)90812-5\u003e)\n5. \u003ca id='leimkuhler1994symplectic'\u003e\u003c/a\u003e Leimkuhler, B. and Reich, S., 1994.\n   Symplectic integration of constrained Hamiltonian systems. _Mathematics of\n   Computation_, 63(208), pp.589-605.\n   [![DOI:10.2307/2153284](https://zenodo.org/badge/DOI/10.2307/2153284.svg)](https://doi.org/10.2307/2153284)\n6. \u003ca id='leimkuhler2004simulating'\u003e\u003c/a\u003e Leimkuhler, B. and Reich, S., 2004.\n   Simulating Hamiltonian dynamics (Vol. 14). _Cambridge University Press_.\n   [![DOI:10.1017/CBO9780511614118](https://zenodo.org/badge/DOI/10.1017/CBO9780511614118.svg)](https://doi.org/10.1017/CBO9780511614118)\n7. \u003ca id='hartmann2005constrained'\u003e\u003c/a\u003e Hartmann, C. and Schütte, C., 2005. A\n   constrained hybrid Monte‐Carlo algorithm and the problem of calculating the\n   free energy in several variables. _ZAMM ‐ Journal of Applied Mathematics and\n   Mechanics_, 85(10), pp.700-710.\n   [![DOI:10.1002/zamm.200410218](https://zenodo.org/badge/DOI/10.1002/zamm.200410218.svg)](https://doi.org/10.1002/zamm.200410218)\n8. \u003ca id='girolami2011riemann'\u003e\u003c/a\u003e Girolami, M. and Calderhead, B., 2011.\n   Riemann manifold Langevin and Hamiltonian Monte Carlo methods. _Journal of\n   the Royal Statistical Society: Series B (Statistical Methodology)_, 73(2), pp.123-214.\n   [![DOI:10.1111/j.1467-9868.2010.00765.x](https://zenodo.org/badge/DOI/10.1111/j.1467-9868.2010.00765.x.svg)](https://doi.org/10.1111/j.1467-9868.2010.00765.x)\n9. \u003ca id='brubaker2012family'\u003e\u003c/a\u003e Brubaker, M., Salzmann, M. and\n   Urtasun, R., 2012. A family of MCMC methods on implicitly defined\n   manifolds. In _Artificial intelligence and statistics_ (pp. 161-172).\n   [![CiteSeerX:10.1.1.417.6111](http://img.shields.io/badge/CiteSeerX-10.1.1.417.6111-blue.svg)](https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.417.6111)\n10. \u003ca id='betancourt2013general'\u003e\u003c/a\u003e Betancourt, M., 2013. A general metric\n    for Riemannian manifold Hamiltonian Monte Carlo. In _Geometric science of\n    information_ (pp. 327-334).\n    [![DOI:10.1007/978-3-642-40020-9_35](https://zenodo.org/badge/DOI/10.1007/978-3-642-40020-9_35.svg)](https://doi.org/10.1007/978-3-642-40020-9_35)\n    [![arXiv:1212.4693](http://img.shields.io/badge/arXiv-1212.4693-B31B1B.svg)](https://arxiv.org/abs/1212.4693)\n11. \u003ca id='hoffman2014nouturn'\u003e\u003c/a\u003e Hoffman, M.D. and Gelman, A., 2014. The\n    No-U-turn sampler: adaptively setting path lengths in Hamiltonian Monte\n    Carlo. _Journal of Machine Learning Research_, 15(1), pp.1593-1623.\n    [![CiteSeerX:10.1.1.220.8395](http://img.shields.io/badge/CiteSeerX-10.1.1.220.8395-blue.svg)](https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.220.8395)\n    [![arXiv:1111.4246](http://img.shields.io/badge/arXiv-1111.4246-B31B1B.svg)](https://arxiv.org/abs/1111.4246)\n12. \u003ca id='shababa2014split'\u003e\u003c/a\u003e Shahbaba, B., Lan, S., Johnson, W.O. and\n    Neal, R.M., 2014. Split Hamiltonian Monte Carlo. _Statistics and\n    Computing_, 24(3), pp.339-349.\n    [![DOI:10.1007/s11222-012-9373-1](https://zenodo.org/badge/DOI/10.1007/s11222-012-9373-1.svg)](https://doi.org/10.1007/s11222-012-9373-1)\n    [![arXiv:1106.5941](http://img.shields.io/badge/arXiv-1106.5941-B31B1B.svg)](https://arxiv.org/abs/1106.5941)\n13. \u003ca id='blanes2014numerical'\u003e\u003c/a\u003e Blanes, S., Casas, F., \u0026 Sanz-Serna, J. M., 2014.\n    Numerical integrators for the Hybrid Monte Carlo method.\n    _SIAM Journal on Scientific Computing_, 36(4), A1556-A1580.\n    [![DOI:10.1137/130932740](https://zenodo.org/badge/DOI/10.1137/130932740.svg)](https://doi.org/10.1137/130932740)\n    [![arXiv:1405.3153](http://img.shields.io/badge/arXiv-1405.3153-B31B1B.svg)](https://arxiv.org/abs/1405.3153)\n14. \u003ca id='betancourt2017conceptual'\u003e\u003c/a\u003e Betancourt, M., 2017. A conceptual\n    introduction to Hamiltonian Monte Carlo.\n    [![arXiv:1701.02434](http://img.shields.io/badge/arXiv-1701.02434-B31B1B.svg)](https://arxiv.org/abs/1701.02434)\n15. \u003ca id='lelievre2019hybrid'\u003e\u003c/a\u003e Lelièvre, T., Rousset, M. and Stoltz, G., 2019. Hybrid Monte Carlo methods for sampling probability measures on\n    submanifolds. In _Numerische Mathematik_, 143(2), (pp.379-421).\n    [![DOI:10.1007/s00211-019-01056-4](https://zenodo.org/badge/DOI/10.1007/s00211-019-01056-4.svg)](https://doi.org/10.1007/s00211-019-01056-4)\n    [![arXiv:1807.02356](http://img.shields.io/badge/arXiv-1807.02356-B31B1B.svg)](https://arxiv.org/abs/1807.02356)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatt-graham%2Fmici","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatt-graham%2Fmici","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatt-graham%2Fmici/lists"}