{"id":19984513,"url":"https://github.com/intellabs/approximate-bayesian-inference","last_synced_at":"2025-07-19T03:03:45.500Z","repository":{"id":218214653,"uuid":"713550146","full_name":"IntelLabs/approximate-bayesian-inference","owner":"IntelLabs","description":null,"archived":false,"fork":false,"pushed_at":"2024-10-25T17:16:06.000Z","size":101833,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-29T17:48:16.910Z","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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IntelLabs.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,"zenodo":null}},"created_at":"2023-11-02T18:44:36.000Z","updated_at":"2024-10-25T17:16:03.000Z","dependencies_parsed_at":"2024-10-26T04:09:49.989Z","dependency_job_id":null,"html_url":"https://github.com/IntelLabs/approximate-bayesian-inference","commit_stats":null,"previous_names":["intellabs/approximate-bayesian-inference"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/IntelLabs/approximate-bayesian-inference","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IntelLabs%2Fapproximate-bayesian-inference","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IntelLabs%2Fapproximate-bayesian-inference/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IntelLabs%2Fapproximate-bayesian-inference/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IntelLabs%2Fapproximate-bayesian-inference/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IntelLabs","download_url":"https://codeload.github.com/IntelLabs/approximate-bayesian-inference/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IntelLabs%2Fapproximate-bayesian-inference/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265878922,"owners_count":23843037,"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-11-13T04:19:21.976Z","updated_at":"2025-07-19T03:03:45.470Z","avatar_url":"https://github.com/IntelLabs.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Approximate Bayesian Inference Framework\n========================================\n\nThe aim of this repository is to help developers to use analysis-by-synthesis for their specific use cases. The \nrequired tasks are to implement the required interfaces for custom generative models, likelihood functions and \ndefine the different spaces (state, latent, analysis, observation) that are used in the application. \n\nAdditionally, the framework provides the ability to create neural emulators for the generative models that in some\ncases can be used to speed-up the sampling process. As an option, probabilistic neural emulators (based on Bayesian \nNeural Networks) can be used to approximate the generative models. \n\nThis framework also provides a connection to our sampling algorithms library. Which contains reference \nimplementations of well-known sampling algorithms that can be selected as the sampling strategy for the problem \nat hand.\n\n\nInstallation\n============\nClone the repo, install dependencies and add the repo root to the pythonpath\n```shell\ngit clone https://github.com/intel-sandbox/personal.javierfe.approximate-bayesian-inference approximate-bayesian-inference\ncd approximate-bayesian-inference\npip install -r requirements.txt\nexport PYTHONPATH=$PYTHONPATH:`pwd`\n```\n\nTest that it is running with the data-generation process of the provided\nreaching intent prediction example. This process might take about 5 minutes depending\non your hardware. It will generate 1K example reaching trajectories used to train \nthe neural emulator.\n```shell\ncd reaching_intent\npython3 main_datageneration.py ./datasets/dataset1K_2D_ur5_96p.dat 1000 100\npython3 main_training.py\n```\n\nFor the inference example to run you need to install the sampling algorithms library\n```shell\ngit clone https://github.com/IntelLabs/ais-benchmarks\ncd ais-benchmarks\npip install cython scikit-build\npip install -r requirements.txt\nexport PYTHONPATH=$PYTHONPATH:`pwd`\n```\n\nNow you're ready to run the intent prediction example\n```shell\npython3 main_inference.py\n```\n\n#### Dependency details\n- General\n    - numpy\n    - scipy\n    - sampling-algorithms\n\n- Neural emulators\n    - torch\n\n- Plot results\n    - matplotlib\n\n- Reaching intent prediction application\n  - pybullet\n\n\n\nABC Notation\n============\n- x      : state space\n\n- o      : observation space.\n\n- z      : latent space. Usually model the quantities that are the target for inference.\n\n- n      : nuisance sub-space. Used to model variables that are required by the generative model but \n           are not relevant for the inference process. Such that the inference will marginalize them out.\n           \n- ε      : slack term. Used to model the gap from the generative model to the observations.\n\n- g(z,n) : Generative model that maps the latent space to either the state space or the observation space. This \n           can be a deterministic o = g(z,n) or stochastic o ~ p(o|z,n) generative model.\n           \n- L(x,x',ε): Surrogate likelihood (ABC). Provides a likelihood value using two observations or states. Usually an \n             observation from the observation model is compared with a generated observation: L(o,g(z,n),ε)\n \n- Estimations are denoted by '. For example the estimated state space is denoted as x' and an estimated latent value z'.\n- The tilde \"~\" can be read as \"distributed as\". For example, the fact that a sample x is sampled from a prior \ndistribution p(x) can be written as: x ~ p(x).\n\n\nArchitecture\n============\n- Space. Represents a multidimensional space. Has a sampler attached that allows generating valid sample from the space.\n\n- Sampler. Provides a sample from a space. Used to abstract the implementation of sampling from distributions on spaces.\n Examples are: prior distributions p(x), proposal distributions p(x_t|x_{t-1}), conditional distributions p(x|y). This \n can also be used to implement deterministic mappings x' = f(x).\n\n- Observation model (stochastic or deterministic mapping from state space \"x\" to observation space \"o\")\n    - o ~ p(o|x). If the state space is fully observed, the observation model is the identity operation: x = o\n    \n- Generative model\n    - maps latent space and nuisance space to observation space\n    \n- Surrogate likelihood function. Used to perform inference\n    - computes the likelihood of a generated observation given an observation and the slack term: L = p(g(z,n)|o,ε)\n    \n- Inference algorithm: Samples the PDF of the latent parameters z given the observations.\n    - Has access to generative model and likelihood function\n    - Provides the posterior PDF \"p(z|o)\", as a set of importance weighted samples.\n\n\nImplementing a new inference algorithm\n======================================\n- Implement a class derived from common.CBaseInferenceAlgorithm. \n- See working examples in inference.CInferenceGrid and inference.CInferenceMetropolisHastings\n- The inference algorithm can be tested by adding it to the example reaching intent application in \nreaching_intent.main_inference.py and comparing the results with some of the algorithms already there.\n\n\nImplementing a new application with neural emulators\n====================================================\n1- Define/identify/map the variables defined in the Notation section to the specific problem (See an example in reaching_intent/README.md)\n    \n2- Implement the CGenerativeModel interface (See reaching_intent.generative_models.CGenerativeModelSimulator)\n\n3- Implement the CGenerativeModelNN interface (See reaching_intent.generative_models.CReachingNeuralEmulatorNN)\n\n4- Implement the dataset_load(filename, k) and dataset_save(dataset, filename): custom functions (See reaching_intent.generative_models.dataset_load, dataset_save )\n\n5- Implement the CObservationModel interface (See reaching_intent.observation_models.CObservationModel)\n\n6- Optional: Implement your custom likelihood_function or use provided (See neural_emulators.loss_functions)\n\n7- Implement the different main scripts, copy and make changes where required:\n    - Dataset generation (e.g. reaching_intent.main_datageneration.py )\n    - Neural emulation training (e.g. reaching_intent.main_training.py)\n    - Inference (e.g. reaching_intent.main_inference.py)\n\n\nAuthors\n=======\n- Javier Felip Leon (javier.felip.leon@intel.com)\n\n\nContributors\n============\n \n\nReferences\n==========\n- Felip, J., Ahuja, N., Gómez-Gutiérrez, D., Tickoo, O., \u0026 Mansinghka, V. (2019). Real-time Approximate Bayesian \nComputation for Scene Understanding. arXiv preprint arXiv:1905.13307.\n\nLast updated: Oct 2023","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintellabs%2Fapproximate-bayesian-inference","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fintellabs%2Fapproximate-bayesian-inference","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintellabs%2Fapproximate-bayesian-inference/lists"}