Skip to content

jiemingyou/bayesian-networks-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Python D-separation checker

A simple Python implementation of Bayesian Networks (BN). Not the most efficient implementation, but it's simple and it works.

Features

  • Add nodes
  • Add edges
  • Check colliders
  • Check unblocked paths
  • Check d-separation
  • Check conditional independence
  • Check Markov blanket
  • Check Markov equivalence

Usage

Clone the repository and navigate to the project directory.

git clone https://github.com/jiemingyou/bayesian-networks-python.git
cd bayesian-networks-python

Run the main script:

python3 src/network.py

Example

Here's an example of how to assess the conditional independence between $C \perp \!\!\! \perp E \mid B, D$ given the following Bayesian Network:

from src.network import BayesianNetwork

# Initiate the network
bn = BayesianNetwork()

# Add the nodes
bn.add_node("A")
bn.add_node("B")
bn.add_node("C")
bn.add_node("D")
bn.add_node("E")
bn.add_node("F")

# Add the directed edges
bn.add_edge("A", "C")
bn.add_edge("A", "D")
bn.add_edge("A", "F")
bn.add_edge("B", "C")
bn.add_edge("B", "E")
bn.add_edge("C", "D")
bn.add_edge("D", "E")
bn.add_edge("F", "E")

# Calculate the d-separation
bn.is_d_separated("C", "E", ["B", "D"])

# Returns: (False , {unblocked set})

About

A Simple Bayesian Network class for assessing d-separation and conditional independence.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published