Giter Site home page Giter Site logo

bayes-net's Introduction

bayes-net

A python implemention for checking D-separation and I-equivalence in Bayesian Networks (BN).

D-separation

Given a Bayesian Network, and several queries in the form of X Y | Z where X, Y are two query nodes and Z is a set of observed nodes, src/dsep.py checks whether X and Y are d-separated given Z and prints True or False.

This mainly follows the "Reachable" procedure in

Koller and Friedman (2009), "Probabilistic Graphical Models: Principles and Techniques" (page 75)

To run the code, try

cd src
python dsep.py < ../tests/dsep/test1.in

Input and Output

dsep.py takes input from stdin as follows:

  1. First line:

N M Q ``` where N and `M` are the number of nodes and edges in the BN, respectively, `Q` is the number of D-separation queries that will follow.

  1. Next M lines:
A B

Each line denotes a directed edge A -> B in the BN graph.

  1. Next Q lines:
A B | C D E ...

Each line denotes a query: whether A and B are d-separated given nodes C D E ...

The output to stdout has Q lines, one line per query, which is True if the two nodes are d-separated or False otherwise.

Example

Run

python dsep.py 

and provides input from stdin as follows:

3 2 2
A B
B C
A C | B
C A |

This constructs a BN with 3 nodes and 2 edges:

A -> B -> C

and asks 2 queries:

(1) Are A and C d-separated given B? (True)

(2) Are C and A d-separated? (False)

So the algorithm will print to stdout as

True
False

I-equivalence

Given two Bayesian Networks (BNs), src/iequiv.py tests whether they are I-equivalent. Following Koller and Friedman (2009), two BNs are I-equivalent if and only if they have the same skeletons and immoralities.

To run the code, try

cd src
python iequv.py < ../tests/iequiv/test1.in

Input and Output

iequiv.py takes input from stdin as follows:

  1. First line:
N1 M1

where N1 and M1 are the number of nodes and edges, respectively, in the first Bayesian network.

  1. Next M1 lines:
A B

Each line denotes a directed edge A -> B in the BN graph.

  1. Next line:
N2 M2

where N2 and M2 are the number of nodes and edges, respectively, in the second Bayesian network.

  1. Next M2 lines:
A B

Each line denotes a directed edge A -> B in the BN graph.

The output is printed to stdout: True if two graphs are I-equivalent or False otherwise.

Example

Run

python iequiv.py 

and provides input from stdin as follows:

3 2
A B
B C
3 2
C B
A B

This constructs and compares two BNs:

A -> B -> C
A -> B <- C

and the algorithm prints False to stdout since they are not I-equivalent.

Tests

Several simple test cases are provided in tests/dsep and tests/iequiv. Special thanks to the TAs in CMU 10-708 for the test cases. To run the tests:

cd src
python dsep.py < ../tests/dsep/test1.in
python iequv.py < ../tests/iequiv/test1.in

bayes-net's People

Contributors

lingxuez avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.