ncullen93 / pyBN

Bayesian Networks in Python
MIT License
146 stars 55 forks source link

NOTE: I wrote this code to go along with Daphne Koller's book and no longer maintain the repository, although the code should be easily adaptable.

Bayesian Networks in Python

Overview

This module provides a convenient and intuitive interface for reading, writing, plotting, performing inference, parameter learning, structure learning, and classification over Discrete Bayesian Networks - along with some other utility functions. There seems to be a lack of many high-quality options for BNs in Python, so I hope this project will be a useful addition.

I am a graduate student in the Di2Ag laboratory at Dartmouth College, and would love to collaborate on this project with anyone who has an interest in graphical models - Send me an email at ncullen.th@dartmouth.edu. If you're a researcher or student and want to use this module, I am happy to give an overview of the code/functionality or answer any questions.

For an up-to-date list of issues, go to the "issues" tab in this repository. Below is an updated list of features, along with information on usage/examples:

Current features

Marginal Inference

MAP/MPE Inference

Constraint-Based Structure Learning

Score-Based Structure Learning

Tree-Based Structure Learning

Hybrid Structure Leanring

Exact Structure Learning

Parameter Learning

Classification

Multi-Dimensional Classification

Comparing Two Bayesian Networks

Utility Functionality

I previously wrote a Python wrapper for the GOBNILP project - a state-of-the-art integer programming solver for Bayesian network structure learning that can find the EXACT Global Maximum of any score-based objective function. It also links to CPLEX for incredible speed. The wrappers can be found in the "pyGOBN" project at www.github.com/ncullen93/pyGOBN. For an overview of GOBNILP or to see its great benchmarks on even the most massive datasets, visit https://www.cs.york.ac.uk/aig/sw/gobnilp/.

Examples

This package includes a number of examples to help users get acquainted with the intuitive syntax and functionality of pyBN. For an updated list of examples, check out the collection of ipython notebooks in the "examples" folder located in the master directory.

Here is a list of current examples:

Usage

Getting up-and-running with this package is simple:

  1. Click "Download ZIP" button towards the upper right corner of the page.
  2. Unpack the ZIP file wherever you want on your local machine. You should now have a folder called "pyBN-master"
  3. In your python terminal, change directories to be IN pyBN-master. Typing "ls" should show you "data", "examples" and "pyBN" folders. Stay in the "pyBN-master" directory for now!
  4. In your python terminal, simply type "from pyBN import ". This will load all of the module's functions, classes, etc.
  5. You are now free to use the package! Perhaps you want to start by creating a BayesNet object using "bn = BayesNet()" and so on.

Unit Tests

If you want to test the functionality to make sure it all works on your local machine, navigate to the pybn-master directory and run the following command from the normal command-line (NOT ipython console):