All Projects → ostwalprasad → LGNpy

ostwalprasad / LGNpy

Licence: MIT License
Linear Gaussian Bayesian Networks - Inference, Parameter Learning and Representation. 🖧

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to LGNpy

Belief-Propagation
Overview and implementation of Belief Propagation and Loopy Belief Propagation algorithms: sum-product, max-product, max-sum
Stars: ✭ 85 (+240%)
Mutual labels:  graphical-models, message-passing, belief-propagation
fglib
factor graph library
Stars: ✭ 53 (+112%)
Mutual labels:  message-passing, belief-propagation
FactorGraph.jl
The FactorGraph package provides the set of different functions to perform inference over the factor graph with continuous or discrete random variables using the belief propagation algorithm.
Stars: ✭ 17 (-32%)
Mutual labels:  message-passing, belief-propagation
Mitosis.jl
Automatic probabilistic programming for scientific machine learning and dynamical models
Stars: ✭ 33 (+32%)
Mutual labels:  graphical-models
graphchem
Graph-based machine learning for chemical property prediction
Stars: ✭ 21 (-16%)
Mutual labels:  message-passing
ECGClassifier
CNN, RNN, and Bayesian NN classification for ECG time-series (using TensorFlow in Swift and Python)
Stars: ✭ 53 (+112%)
Mutual labels:  bayesian-network
pcalg-py
Implement PC algorithm in Python | PC 算法的 Python 实现
Stars: ✭ 52 (+108%)
Mutual labels:  bayesian-network
aether
Distributed system emulation in Common Lisp
Stars: ✭ 19 (-24%)
Mutual labels:  message-passing
genstar
Generation of Synthetic Populations Library
Stars: ✭ 17 (-32%)
Mutual labels:  bayesian-network
godsend
A simple and eloquent workflow for streaming messages to micro-services.
Stars: ✭ 15 (-40%)
Mutual labels:  message-passing
Vaquero
A scripting language for cowboy coders
Stars: ✭ 18 (-28%)
Mutual labels:  message-passing
PDN
The official PyTorch implementation of "Pathfinder Discovery Networks for Neural Message Passing" (WebConf '21)
Stars: ✭ 44 (+76%)
Mutual labels:  message-passing
ReactiveMP.jl
Julia package for automatic Bayesian inference on a factor graph with reactive message passing
Stars: ✭ 58 (+132%)
Mutual labels:  message-passing
pathpy
pathpy is an OpenSource python package for the modeling and analysis of pathways and temporal networks using higher-order and multi-order graphical models
Stars: ✭ 124 (+396%)
Mutual labels:  graphical-models
tutorial-UGM-hyperspectral
A Tutorial on Modeling and Inference in Undirected Graphical Models for Hyperspectral Image Analysis
Stars: ✭ 21 (-16%)
Mutual labels:  graphical-models
star
An experimental programming language that's made to be powerful, productive, and predictable
Stars: ✭ 88 (+252%)
Mutual labels:  message-passing
glsp-server
Java-based server framework of the graphical language server platform
Stars: ✭ 25 (+0%)
Mutual labels:  graphical-models
findr
Fast Inference of Networks from Directed Regulations
Stars: ✭ 19 (-24%)
Mutual labels:  bayesian-network
StatNLP-Framework
C++ based implementation of StatNLP framework
Stars: ✭ 17 (-32%)
Mutual labels:  graphical-models
Comparison-of-Disparity-Estimation-Algorithms
Implementation of simple block matching, block matching with dynamic programming and Stereo Matching using Belief Propagation algorithm for stereo disparity estimation
Stars: ✭ 46 (+84%)
Mutual labels:  belief-propagation

Linear Gaussian Bayesian Networks -Representation, Learning and Inference

Build Status PyPI - License PyPI - Python Version Documentation Status codecov Downloads DOI

A 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.

This package helps in modelling the network, learning parameters through data and running inference with evidence(s). Two types of Gaussian BNs are implemented:

  1. Linear Gaussian Network: A directed BN where CPDs are linear gaussian.

  2. 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.

Installation

$ pip install lgnpy

or clone the repository.

$ git clone https://github.com/ostwalprasad/lgnpy

Getting Started

Here are steps for Linear Gaussian Network. Gaussian Belief Propagation Model is also similar.

1. Create Network

import pandas as pd
import 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.random.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, its 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)



Examples

Notebook: Linear Gaussian Networks

Known Issues

GaussianBP algorithm does not converge for some specific precision matrices (inverse covariances). Solution is to use Graphcial Lasso or similar estimator methods to find precision matrix. Pull requests are welcome.

References:

Linear Gaussian Networks
  1. Probabilistic Graphical Models - Principles and Techniques , Daphne Koller, Chapter 7.2

  2. Gaussian Bayesian Networks, Sargur Srihari

Gaussian Belief Propagation
  1. Probabilistic Graphical Models - Principles and Techniques , Daphne Koller, Chapter 14.2.3
  2. Gaussian Belief Propagation: Theory and Aplication, Danny Bickson

Citation

If you use lgnpy or reference our blog post in a presentation or publication, we would appreciate citations of our package.

P. Ostwal, “ostwalprasad/LGNpy: v1.0.0.” Zenodo, 20-Jun-2020, doi: 10.5281/ZENODO.3902122.

Here is the corresponding BibText entry

@misc{https://doi.org/10.5281/zenodo.3902122,
  doi = {10.5281/ZENODO.3902122},
  url = {https://zenodo.org/record/3902122},
  author = {Ostwal,  Prasad},
  title = {ostwalprasad/LGNpy: v1.0.0},
  publisher = {Zenodo},
  year = {2020}
}

License

MIT License Copyright (c) 2020, Prasad Ostwal

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].