Linear Gaussian Networks - Inference, Parameter Learning and Representation
Project description
LGNpy
Representation, Learning and Inference for Linear Gaussian Bayesian Networks
LGNs are Bayesian Networks where all the nodes have continuous data. Gaussians are surprisingly good approximation for many real world continuous distributions. This package helps in modelling the network, learning parameters through data and running inference with evidence(s)
Installation
$ pip install lgnpy
or clone the repository.
$ pip install https://github.com/ostwalprasad/lgnpy
Getting Started
1. Create Network
import pandas as pd
imoprt numpy as np
from lgnpy import LinearGaussian
lg = LinearGaussian()
lg.set_edges_from([('A', 'D'), ('B', 'D'), ('D', 'E'), ('C', 'E')])
2 Create Data and assign to it to network.
​ Create synthetic data for network using pandas and bind network with the data. There's no need to separately calculate means and covariance matrix.
np.random.seed(42)
n=100
data = pd.DataFrame(columns=['A','B','C','D','E'])
data['A'] = np.random.normal(5,2,n)
data['B'] = np.random.normal(10,2,n)
data['D'] = 2*data['A'] + 3*data['B'] + np.random.normal(0,2,n)
data['C'] = np.random.normal(-5,2,n)
data['E'] = 3*data['C'] + 3*data['D'] + np.rando m.normal(0,2,n)
lg.set_data(data)
3. Set Evidence(s)
Evidence are optional and can be set before running inference.
lg.set_evidences({'A':5,'B':10})
4. Run Inference
For each node, CPT (Conditional Probability Distribution) is defined as::
where, it's parameters are calculated using conditional distribution of parent(s) and nodes:
run_inference()
returns inferred means and variances of each nodes.
lg.run_inference(debug=False)
Additional Functions:
lg.plot_distributions(save=False)
lg.network_summary()
lg.draw_network(filename='sample_network',open=True)
References:
Probabilistic Graphical Models - Principles and Techniques , Daphne Koller, Chapter 7.2
Gaussian Bayesian Networks, Sargur Srihari
License
MIT License Copyright (c) 2020, Prasad Ostwal
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file LGNpy-0.0.5.tar.gz
.
File metadata
- Download URL: LGNpy-0.0.5.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 615fc9ae14c5f8057ef74fcf6b429f97a4d00674a93b53dfe8a5175038ded4d1 |
|
MD5 | 41cf6b218fdd2b1a94df4d74d6079a49 |
|
BLAKE2b-256 | a49a0e8ada30b07a9d856219ca55dc2eec62086e9fa1864175cf12facb862a15 |
File details
Details for the file LGNpy-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: LGNpy-0.0.5-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bbb4f9110bd3b17f6114f8398090bcb1cdc171a844cc3b226bdc4369386ea9b |
|
MD5 | 4589c214e02f715a4bb1e7a7f287d0be |
|
BLAKE2b-256 | 2927982a45a704c4358d2ad5a374f57f83bd3a3abffddcd327af0482efcde5bf |