{"id":13689427,"url":"https://github.com/ColCarroll/minimc","last_synced_at":"2025-05-01T23:34:21.664Z","repository":{"id":45242180,"uuid":"179073521","full_name":"ColCarroll/minimc","owner":"ColCarroll","description":"Just a little MCMC","archived":false,"fork":false,"pushed_at":"2024-06-25T15:48:28.000Z","size":4788,"stargazers_count":215,"open_issues_count":1,"forks_count":28,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-10-30T06:58:11.299Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/ColCarroll.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-02T12:30:58.000Z","updated_at":"2024-10-29T11:36:35.000Z","dependencies_parsed_at":"2024-10-30T05:13:54.613Z","dependency_job_id":null,"html_url":"https://github.com/ColCarroll/minimc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ColCarroll%2Fminimc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ColCarroll%2Fminimc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ColCarroll%2Fminimc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ColCarroll%2Fminimc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ColCarroll","download_url":"https://codeload.github.com/ColCarroll/minimc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224282267,"owners_count":17285798,"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":[],"created_at":"2024-08-02T15:01:47.369Z","updated_at":"2024-11-12T13:31:41.067Z","avatar_url":"https://github.com/ColCarroll.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"minimc\n======\n\n*Just a little MCMC*\n--------------------\n[![Build Status](https://travis-ci.org/ColCarroll/minimc.svg?branch=master)](https://travis-ci.org/ColCarroll/minimc) [![Coverage Status](https://coveralls.io/repos/github/ColCarroll/minimc/badge.svg?branch=master)](https://coveralls.io/github/ColCarroll/minimc?branch=master)\n\nThis is a test library to provide reference implementations of MCMC algorithms and ideas. The basis and reference for much of this library is from Michael Betancourt's wonderful [A Conceptual Introduction to Hamiltonian Monte Carlo](https://arxiv.org/abs/1701.02434).\n\n**The highlight of the library** right now is the ~15 line [Hamiltonian Monte Carlo implementation](minimc/minimc.py) (which relies on an 8 line integrator). Both of these are commented and documented, but aim to be instructive to read.\n\nCurrently Implemented\n---------------------\n\n- Step size tuning\n- Leapfrog integrator\n- Hamiltonian Monte Carlo\n- Some log probabilities (normal, multivariate normal, mixtures, funnel)\n\nRoadmap\n-------\n\n- Divergences\n- Mass matrix adaptation\n- Diagnostics\n- [NUTS](https://arxiv.org/abs/1111.4246)\n- [Empirical HMC](https://arxiv.org/abs/1810.04449)\n- Riemannian Manifold HMC [Girolami \u0026 Calderhead](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.221.6963\u0026rep=rep1\u0026type=pdf) and [Betancourt](https://arxiv.org/abs/1212.4693)\n\nInstallation\n------------\n\nI would suggest cloning this and playing with the source code, but it can be pip installed with\n```bash\npip install git+git://github.com/colcarroll/minimc.git\n```\n\nExamples\n--------\n\nThe API of `minimc` is mimicked in `minimc.minimc_slow`, which returns trajectories instead of just samples. This makes for nicer images and experiments, but it is a bit slower.\n\n```python\nimport autograd.numpy as np\nfrom minimc import neg_log_normal, hamiltonian_monte_carlo\nfrom minimc.autograd_interface import AutogradPotential\n\nneg_log_p = AutogradPotential(neg_log_normal(0, 0.1))\nsamples = hamiltonian_monte_carlo(2_000, neg_log_p, initial_position=0.)\n\n100%|███████████████████████████████████████████| 2500/2500 [00:04\u003c00:00, 615.91it/s]\n```\n\n\u003cimg src=\"examples/plot1.png\" width=\"400\"\u003e\n\n```python\nfrom minimc.minimc_slow import hamiltonian_monte_carlo as hmc_slow\n\nsamples, positions, momentums, accepted, p_accepts = hmc_slow(50, neg_log_p,\n                                                              initial_position=0.,\n                                                              step_size=0.01)\n\n100%|███████████████████████████████████████████| 50/50 [00:00\u003c00:00, 52.72it/s]\n```\n\u003cimg src=\"examples/plot2.png\" width=\"400\"\u003e\n\n```python\nfrom minimc import neg_log_mvnormal\n\nmu = np.zeros(2)\ncov = np.array([[1.0, 0.8], [0.8, 1.0]])\nneg_log_p = AutogradPotential(neg_log_mvnormal(mu, cov))\n\nsamples = hamiltonian_monte_carlo(1000, neg_log_p, np.zeros(2))\n\n100%|███████████████████████████████████████████| 1500/1500 [00:02\u003c00:00, 623.13.92it/s]\n```\n\n\u003cimg src=\"examples/plot3.png\" width=\"400\"\u003e\n\n```python\nsamples, positions, momentums, accepted, p_accepts = hmc_slow(10, neg_log_p,\n                                                              np.zeros(2),\n                                                              path_len=4,\n                                                              step_size=0.01)\n\n100%|███████████████████████████████████████████| 10/10 [00:01\u003c00:00, 9.06it/s]\n```\n\n\u003cimg src=\"examples/plot4.png\" width=\"400\"\u003e\n\n```python\nfrom minimc import mixture\n\nneg_log_probs = [neg_log_normal(1.0, 0.5), neg_log_normal(-1.0, 0.5)]\nprobs = np.array([0.2, 0.8])\nneg_log_p = AutogradPotential(mixture(neg_log_probs, probs))\nsamples = hamiltonian_monte_carlo(2000, neg_log_p, 0.0)\n\nneg_log_probs = [\n    neg_log_normal(-1.0, 0.3),\n    neg_log_normal(0., 0.2),\n    neg_log_normal(1.0, 0.3),\n    ]\nprobs = np.array([0.1, 0.5, 0.4])\nneg_log_p = AutogradPotential(mixture(neg_log_probs, probs))\nsamples = hamiltonian_monte_carlo(2_000, neg_log_p, 0.)\n\n100%|███████████████████████████████████████████| 2000/2000 [00:09\u003c00:00, 261.17it/s]\n```\n\n\u003cimg src=\"examples/plot5.png\" width=\"400\"\u003e\n\n```python\nsamples, positions, momentums, accepted, p_accepts = hmc_slow(100, neg_log_p,\n                                                              0.0,\n                                                              step_size=0.01)\n\n100%|███████████████████████████████████████████| 100/100 [00:07\u003c00:00, 14.04it/s]\n```\n\n\u003cimg src=\"examples/plot6.png\" width=\"400\"\u003e\n\n```python\nmu1 = np.ones(2)\ncov1 = 0.5 * np.array([[1.0, 0.7],\n                       [0.7, 1.0]])\nmu2 = -np.ones(2)\ncov2 = 0.2 * np.array([[1.0, -0.6],\n                       [-0.6, 1.0]])\n\nmu3 = np.array([-1.0, 2.0])\ncov3 = 0.3 * np.eye(2)\n\nneg_log_p = AutogradPotential(mixture(\n    [\n        neg_log_mvnormal(mu1, cov1),\n        neg_log_mvnormal(mu2, cov2),\n        neg_log_mvnormal(mu3, cov3),\n    ],\n    [0.3, 0.3, 0.4],\n))\n\nsamples = hamiltonian_monte_carlo(2000, neg_log_p, np.zeros(2))\n\n100%|███████████████████████████████████████████| 2500/2500 [00:11\u003c00:00, 212.83it/s]\n```\n\n\u003cimg src=\"examples/plot7.png\" width=\"400\"\u003e\n\n```python\nsamples, positions, momentums, accepted, p_accepts = hmc_slow(20, neg_log_p,\n                                                              np.zeros(2),\n                                                              path_len=3,\n                                                              step_size=0.01)\n\n100%|███████████████████████████████████████████| 20/20 [00:08\u003c00:00, 2.31it/s]\n```\n\n\u003cimg src=\"examples/plot8.png\" width=\"400\"\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FColCarroll%2Fminimc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FColCarroll%2Fminimc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FColCarroll%2Fminimc/lists"}