{"id":13688869,"url":"https://github.com/aesara-devs/aemcmc","last_synced_at":"2025-04-29T01:30:37.201Z","repository":{"id":36988786,"uuid":"438370314","full_name":"aesara-devs/aemcmc","owner":"aesara-devs","description":"AeMCMC is a Python library that automates the construction of samplers for Aesara graphs representing statistical models.","archived":false,"fork":false,"pushed_at":"2023-10-23T07:31:24.000Z","size":392,"stargazers_count":39,"open_issues_count":33,"forks_count":11,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-19T08:53:42.245Z","etag":null,"topics":["gibbs-sampling","hmc","mcmc","ppl","samplers","symbolic-computation","term-rewriting"],"latest_commit_sha":null,"homepage":"https://aemcmc.readthedocs.io/en/latest/","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/aesara-devs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null},"funding":{"github":null}},"created_at":"2021-12-14T19:09:26.000Z","updated_at":"2024-11-24T19:57:24.000Z","dependencies_parsed_at":"2023-12-09T20:48:22.933Z","dependency_job_id":null,"html_url":"https://github.com/aesara-devs/aemcmc","commit_stats":{"total_commits":107,"total_committers":11,"mean_commits":9.727272727272727,"dds":0.4953271028037384,"last_synced_commit":"549406fa090d3e5613e6ed615c7f3902fd444e4e"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":"aesara-devs/aesara-repo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aesara-devs%2Faemcmc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aesara-devs%2Faemcmc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aesara-devs%2Faemcmc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aesara-devs%2Faemcmc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aesara-devs","download_url":"https://codeload.github.com/aesara-devs/aemcmc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251415573,"owners_count":21585854,"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":["gibbs-sampling","hmc","mcmc","ppl","samplers","symbolic-computation","term-rewriting"],"created_at":"2024-08-02T15:01:25.623Z","updated_at":"2025-04-29T01:30:36.839Z","avatar_url":"https://github.com/aesara-devs.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n\n\u003cimg src=\"./docs/source/_static/aemcmc_logo.png#gh-light-mode-only\" alt=\"AeMCMC Logo Dark\" width=400\u003e\u003c/img\u003e\n\u003cimg src=\"./docs/source/_static/aemcmc_logo_dark.png#gh-dark-mode-only\" alt=\"AeMCMC Logo Dark\" width=400\u003e\u003c/img\u003e\n\n# AeMCMC\n\n[![Pypi][pypi-badge]][pypi]\n[![Gitter][gitter-badge]][gitter]\n[![Discord][discord-badge]][discord]\n[![Twitter][twitter-badge]][twitter]\n\nAeMCMC automatically constructs samplers for probabilistic models written in [Aesara](https://github.com/aesara-devs/aesara).\n\n*A compiler for Bayesian inference.*\n\n[Features](#features) •\n[Get started](#get-started) •\n[Install](#install) •\n[Get help](#get-help) •\n[Contribute](#contribute)\n\n\u003c/div\u003e\n\n## Features\n\nThis project is currently in an alpha state, but the core objectives are as follows:\n\n- Provide utilities that simplify the process of constructing Aesara graphs/functions for posterior and posterior predictive sampling\n- Host a wide array of \"exact\" posterior sampling steps (e.g. Gibbs steps, scale-mixture/decomposition-based conditional samplers, etc.)\n- Build a framework for identifying and composing said sampler steps and enumerating the possible samplers for an arbitrary model\n\nOverall, we would like this project to serve as a hub for community-sourced specialized samplers and facilitate their general use.\n\n## Get started\n\nUsing AeMCMC, one can construct sampling steps from a graph containing Aesara\n`RandomVariable`s. AeMCMC analyzes the model graph and possibly rewrites it\nto find the most suitable sampler.\n\nAeMCMC can recognize closed-form posteriors; for instance the following\nBeta-Binomial model amounts to sampling from a Beta distribution:\n\n``` python\nimport aesara\nimport aemcmc\nimport aesara.tensor as at\n\nsrng = at.random.RandomStream(0)\n\np_rv = srng.beta(1., 1., name=\"p\")\nY_rv = srng.binomial(10, p_rv, name=\"Y\")\n\ny_vv = Y_rv.clone()\ny_vv.name = \"y\"\n\nsampler, initial_values = aemcmc.construct_sampler({Y_rv: y_vv}, srng)\n\np_posterior_step = sampler.sample_steps[p_rv]\naesara.dprint(p_posterior_step)\n# beta_rv{0, (0, 0), floatX, False}.1 [id A]\n#  |RandomGeneratorSharedVariable(\u003cGenerator(PCG64) at 0x7F77B2831200\u003e) [id B]\n#  |TensorConstant{[]} [id C]\n#  |TensorConstant{11} [id D]\n#  |Elemwise{add,no_inplace} [id E]\n#  | |TensorConstant{1.0} [id F]\n#  | |y [id G]\n#  |Elemwise{sub,no_inplace} [id H]\n#    |Elemwise{add,no_inplace} [id I]\n#    | |TensorConstant{1.0} [id F]\n#    | |TensorConstant{10} [id J]\n#    |y [id G]\n\nsample_fn = aesara.function([y_vv], p_posterior_step)\n```\n\n\nAeMCMC also contains a database of Gibbs samplers that can be used to sample\nsome models more efficiently than a general-purpose sampler like NUTS\nwould:\n\n``` python\nimport aemcmc\nimport aesara\nimport aesara.tensor as at\n\nsrng = at.random.RandomStream(0)\n\nX = at.matrix(\"X\")\n\n# Horseshoe prior for `beta_rv`\ntau_rv = srng.halfcauchy(0, 1, name=\"tau\")\nlmbda_rv = srng.halfcauchy(0, 1, size=X.shape[1], name=\"lambda\")\nbeta_rv = srng.normal(0, lmbda_rv * tau_rv, size=X.shape[1], name=\"beta\")\n\na = at.scalar(\"a\")\nb = at.scalar(\"b\")\nh_rv = srng.gamma(a, b, name=\"h\")\n\n# Negative-binomial regression\neta = X @ beta_rv\np = at.sigmoid(-eta)\nY_rv = srng.nbinom(h_rv, p, name=\"Y\")\n\ny_vv = Y_rv.clone()\ny_vv.name = \"y\"\n\nsampler, initial_values = aemcmc.construct_sampler({Y_rv: y_vv}, srng)\n\n# `sampler.sample_steps` contains the sample step for each random variable\nprint(sampler.sample_steps[h_rv])\n# h_posterior\n\n# `sampler.stages` contains the sampling kernels sorted by scan order\nprint(sampler.stages)\n# {HorseshoeGibbsKernel: [tau, lambda], NBRegressionGibbsKernel: [beta], DispersionGibbsKernel: [h]}\n\n# Build a function that returns new samples\nto_sample_rvs = [tau_rv, lmbda_rv, beta_rv, h_rv]\ninputs = [a, b, X, y_vv] + [initial_values[rv] for rv in to_sample_rvs]\noutputs = [sampler.sample_steps[rv] for rv in to_sample_rvs]\nsample_fn = aesara.function(inputs, outputs, updates=sampler.updates)\n```\n\nIn case no specialized sampler is found, AeMCMC assigns the NUTS sampler to the\nremaining variables. AeMCMC reparametrizes the model automatically to improve\nsampling if needed:\n\n``` python\nimport aemcmc\nimport aesara\nimport aesara.tensor as at\n\nsrng = at.random.RandomStream(0)\nmu_rv = srng.normal(0, 1, name=\"mu\")\nsigma_rv = srng.halfnormal(0.0, 1.0, name=\"sigma\")\nY_rv = srng.normal(mu_rv, sigma_rv, name=\"Y\")\n\ny_vv = Y_rv.clone()\n\nsampler, initial_values = aemcmc.construct_sampler({Y_rv: y_vv}, srng)\n\nprint(sampler.sample_steps.keys())\n# dict_keys([sigma, mu])\nprint(sampler.stages)\n# {NUTSKernel: [sigma, mu]}\nprint(sampler.parameters)\n# {NUTSKernel: (step_size, inverse_mass_matrix)}\n\n# Build a function that returns new samples\nstep_size, inverse_mass_matrix = list(sampler.parameters.values())[0]\ninputs = [\n    initial_values[mu_rv],\n    initial_values[sigma_rv],\n    y_vv,\n    step_size,\n    inverse_mass_matrix\n]\noutputs = [sampler.sample_steps[mu_rv], sampler.sample_steps[sigma_rv]]\nsample_fn = aesara.function(inputs, outputs, updates=sampler.updates)\n```\n\n\n\n## Install\n\nThe latest release of AeMCMC can be installed from PyPI using `pip`:\n\n``` bash\npip install aemcmc\n```\n\nOr via conda-forge:\n\n``` bash\nconda install -c conda-forge aemcmc\n```\n\nThe nightly (bleeding edge) version of `aemcmc` can be installed using `pip`:\n\n``` bash\npip install aemcmc-nightly\n```\n\n## Get help\n\nReport bugs by opening an [issue][issues]. If you have a question regarding the usage of AeMCMC, start a [discussion][discussions]. For real-time feedback or more general chat about AeMCMC use our [Discord server][discord] or [Gitter room][gitter].\n\n## Contribute\n\nAeMCMC welcomes contributions. A good place to start contributing is by looking at the [issues][issues].\n\nIf you want to implement a new feature, open a [discussion][discussions] or come chat with us on [Discord][discord] or [Gitter][gitter].\n\n\n[contributors]: https://github.com/aesara-devs/aemcmc/graphs/contributors\n[contributors-badge]: https://img.shields.io/github/contributors/aesara-devs/aemcmc?style=flat-square\u0026logo=github\u0026logoColor=white\u0026color=ECEFF4\n[discussions]: https://github.com/aesara-devs/aemcmc/discussions\n[documentation-examples]: https://aemcmc.readthedocs.io/en/latest/examples.html\n[downloads-badge]: https://img.shields.io/pypi/dm/aemcmc?style=flat-square\u0026logo=pypi\u0026logoColor=white\u0026color=8FBCBB\n[discord]: https://discord.gg/h3sjmPYuGJ\n[discord-badge]: https://img.shields.io/discord/1072170173785723041?color=81A1C1\u0026logo=discord\u0026logoColor=white\u0026style=flat-square\n[gitter]: https://gitter.im/aesara-devs/aemcmc\n[gitter-badge]: https://img.shields.io/gitter/room/aesara-devs/aemcmc?color=81A1C1\u0026logo=matrix\u0026logoColor=white\u0026style=flat-square\n[issues]: https://github.com/aesara-devs/aemcmc/issues\n[releases]: https://github.com/aesara-devs/aemcmc/releases\n[twitter]: https://twitter.com/AesaraDevs\n[twitter-badge]: https://img.shields.io/twitter/follow/AesaraDevs?style=social\n[pypi]: https://pypi.org/project/aemcmc/\n[pypi-badge]: https://img.shields.io/pypi/v/aemcmc?color=ECEFF4\u0026logo=python\u0026logoColor=white\u0026style=flat-square\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faesara-devs%2Faemcmc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faesara-devs%2Faemcmc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faesara-devs%2Faemcmc/lists"}