{"id":37071464,"url":"https://github.com/ostwalprasad/lgnpy","last_synced_at":"2026-01-14T08:23:06.607Z","repository":{"id":42180751,"uuid":"261100544","full_name":"ostwalprasad/LGNpy","owner":"ostwalprasad","description":"Linear Gaussian Bayesian Networks - Inference, Parameter Learning and Representation. 🖧","archived":false,"fork":false,"pushed_at":"2022-08-21T10:32:44.000Z","size":719,"stargazers_count":36,"open_issues_count":3,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-02T05:23:11.258Z","etag":null,"topics":["bayesian-network","belief-propagation","gabp","gaussian-bayesian-networks","gaussian-belief-propagation","gaussian-graphical-models","graphical-models","linear-gaussian-networks","message-passing"],"latest_commit_sha":null,"homepage":"","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/ostwalprasad.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}},"created_at":"2020-05-04T06:49:27.000Z","updated_at":"2024-11-10T11:18:59.000Z","dependencies_parsed_at":"2022-07-29T00:08:45.943Z","dependency_job_id":null,"html_url":"https://github.com/ostwalprasad/LGNpy","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ostwalprasad/LGNpy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ostwalprasad%2FLGNpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ostwalprasad%2FLGNpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ostwalprasad%2FLGNpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ostwalprasad%2FLGNpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ostwalprasad","download_url":"https://codeload.github.com/ostwalprasad/LGNpy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ostwalprasad%2FLGNpy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28413833,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T08:16:59.381Z","status":"ssl_error","status_checked_at":"2026-01-14T08:13:45.490Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["bayesian-network","belief-propagation","gabp","gaussian-bayesian-networks","gaussian-belief-propagation","gaussian-graphical-models","graphical-models","linear-gaussian-networks","message-passing"],"created_at":"2026-01-14T08:23:06.056Z","updated_at":"2026-01-14T08:23:06.596Z","avatar_url":"https://github.com/ostwalprasad.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"https://github.com/ostwalprasad/LGNpy/raw/master/docs/images/logo.png\" width=\"250\" \u003e \n\n## Linear Gaussian Bayesian Networks -Representation, Learning and Inference\n\n[![Build Status](https://travis-ci.org/ostwalprasad/LGNpy.svg?branch=master)](https://travis-ci.org/ostwalprasad/LGNpy)\n![PyPI - License](https://img.shields.io/pypi/l/lgnpy)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/lgnpy)\n[![Documentation Status](https://readthedocs.org/projects/lgnpy/badge/?version=latest)](https://lgnpy.readthedocs.io/en/latest/?badge=latest) \n[![codecov](https://codecov.io/gh/ostwalprasad/LGNpy/branch/master/graph/badge.svg)](https://codecov.io/gh/ostwalprasad/LGNpy) \n[![Downloads](https://pepy.tech/badge/lgnpy)](https://pepy.tech/project/lgnpy)\n[![DOI](https://zenodo.org/badge/261100544.svg)](https://zenodo.org/badge/latestdoi/261100544)\n\nA Bayesian Network (BN) is a probabilistic graphical model that represents a set of variables and their conditional dependencies via graph. Gaussian BN is a special case where set of continuous variables are represented by Gaussian Distributions. Gaussians are surprisingly good approximation for many real world continuous distributions. \n\nThis package helps in modelling the network, learning parameters through data and running inference with evidence(s). Two types of Gaussian BNs are implemented:\n\n1) **Linear Gaussian Network:** A directed BN where CPDs are linear gaussian.\n\n2) **Gaussian Belief Propagation:** An undirected BN where it runs *message passing algorithm* to iteratively solve precision matrix and find out marginals of variables with or without conditionals.\n\n## Installation\n```bash\n$ pip install lgnpy\n```\n\nor clone the repository.\n\n```bash\n$ git clone https://github.com/ostwalprasad/lgnpy\n```\n\n\n\n## Getting Started\n\nHere are steps for Linear Gaussian Network. Gaussian Belief Propagation Model is also similar. \n\n#### \t1. Create Network\n\n\u003cimg src=\"https://raw.githubusercontent.com/ostwalprasad/LGNpy/master/docs/images/network.png\" width=\"200\" \u003e\n    \n```python\nimport pandas as pd\nimport numpy as np\nfrom lgnpy import LinearGaussian\n\nlg = LinearGaussian()\nlg.set_edges_from([('A', 'D'), ('B', 'D'), ('D', 'E'), ('C', 'E')])\n```\n\n####\t2 Create Data and assign to it to network.\n\n​\tCreate synthetic data for network using pandas and bind network with the data. There's no need to separately calculate means and covariance matrix.\n\n```python\nnp.random.seed(42)\nn=100\ndata = pd.DataFrame(columns=['A','B','C','D','E'])\ndata['A'] = np.random.normal(5,2,n)\ndata['B'] = np.random.normal(10,2,n)\ndata['D'] = 2*data['A'] + 3*data['B'] + np.random.normal(0,2,n)\ndata['C'] = np.random.normal(-5,2,n)\ndata['E'] = 3*data['C'] + 3*data['D'] + np.random.normal(0,2,n)\n\nlg.set_data(data)\n```\n\n####\t3. Set Evidence(s)\n\n Evidence are optional and can be set before running inference.\n\n```python\n lg.set_evidences({'A':5,'B':10})\n```\n\n####\t4. Run Inference \n\nFor each node, CPT (Conditional Probability Distribution) is defined as::\u003cbr/\u003e\n\n\u003cimg src=\"https://raw.githubusercontent.com/ostwalprasad/LGNpy/master/docs/images/cpd.png\" width=\"210\" \u003e\u003cbr/\u003e\n\nwhere, its parameters  are calculated using conditional distribution of parent(s) and nodes: \u003cbr/\u003e\n\n\u003cimg src=\"https://raw.githubusercontent.com/ostwalprasad/LGNpy/master/docs/images/betas.png\"  width=\"180\" \u003e \u003cbr/\u003e\n\n`run_inference()` returns inferred means and variances of each nodes.\n\n   ```python\nlg.run_inference(debug=False)\n   ```\n\n   \u003cimg src=\"https://github.com/ostwalprasad/LGNpy/raw/master/docs/images/inference.png\" width=\"500\" \u003e\n\n## Additional Functions:\n\n```python\nlg.plot_distributions(save=False)\n```\n\u003cimg src=\"https://github.com/ostwalprasad/LGNpy/raw/master/docs/images/distributions.png\" width=\"800\" \u003e \u003cbr/\u003e\n\n```python\nlg.network_summary()\n```\n\u003cimg src=\"https://raw.githubusercontent.com/ostwalprasad/LGNpy/master/docs/images/summary.png\"  width=\"300\" \u003e \u003cbr/\u003e\n\n```python\nlg.draw_network(filename='sample_network',open=True)\n```\n\u003cbr/\u003e\u003cimg src=\"https://raw.githubusercontent.com/ostwalprasad/LGNpy/master/docs/images/drawn_network.png\"  width=\"200\"\u003e \u003cbr/\u003e\n\n## Examples\n\nNotebook: [Linear Gaussian Networks](https://github.com/ostwalprasad/LGNpy/blob/master/examples/lgnpy_examples.ipynb)\n\n## Known Issues\n\nGaussianBP algorithm does not converge for some specific precision matrices (inverse covariances). Solution is to use [Graphcial Lasso](https://scikit-learn.org/stable/modules/generated/sklearn.covariance.GraphicalLasso.html) or similar estimator methods to find precision matrix. Pull requests are welcome.\n\n## References:\n\n##### Linear Gaussian Networks\n\n1. [Probabilistic Graphical Models - Principles and Techniques ](https://mitpress.mit.edu/books/probabilistic-graphical-models), Daphne Koller, Chapter 7.2\n\n2. [Gaussian Bayesian Networks](https://cedar.buffalo.edu/~srihari/CSE674/Chap7/7.2-GaussBNs.pdf), Sargur Srihari\n\n#####  Gaussian Belief Propagation \n\n1. [Probabilistic Graphical Models - Principles and Techniques ](https://mitpress.mit.edu/books/probabilistic-graphical-models), Daphne Koller, Chapter 14.2.3\n2. [Gaussian Belief Propagation: Theory and Aplication](https://arxiv.org/abs/0811.2518), Danny Bickson\n\n## Citation\n\nIf you use lgnpy or reference our blog post in a presentation or publication, we would appreciate citations of our package.\n\n\u003e P. Ostwal, “ostwalprasad/LGNpy: v1.0.0.” Zenodo, 20-Jun-2020, doi: 10.5281/ZENODO.3902122.\n\nHere is the corresponding BibText entry\n\n```\n@misc{https://doi.org/10.5281/zenodo.3902122,\n  doi = {10.5281/ZENODO.3902122},\n  url = {https://zenodo.org/record/3902122},\n  author = {Ostwal,  Prasad},\n  title = {ostwalprasad/LGNpy: v1.0.0},\n  publisher = {Zenodo},\n  year = {2020}\n}\n```\n\n## License\n\nMIT License Copyright (c) 2020, Prasad Ostwal\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fostwalprasad%2Flgnpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fostwalprasad%2Flgnpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fostwalprasad%2Flgnpy/lists"}