This project follows this paper to implement a structure learning algorithm known as K2. Tests on it are done using Insurance network from the bnlearn package.
srccontains the Python codeassetsfolder used for input and output files of Python scriptsstructure_learningmain Python module for structure learningnetworkssub-module for Bayesian networksbayesian.pyBayesian network classes (Node and Network)cpt_bayesian.pySame classes as inbayesian.pybut with conditional probability tables for savings bnlearn's networksnet_reader.pyFunctions to read networks from.netfiles
heuristics.pyHeuristics classes for K2 algorithm (Factorial Heuristic and Logarithmic Heuristic)k2.pyK2 algorithm implementationsamples.pyClass for creating and managing samples from a Bayesian network with CPTs
main_comparison.pyScript to compare K2 algorithm with different parameters and sample sizesmin_diff.pyScript that tries to find the minimum colliders difference between a K2's generated network and the original network from bnlearn
docscontains LaTeX source files for documentation
You might need to install Python 3.8, pip, graphviz and gzip for decompressing the bnlearn network. Then, run the following commands:
cd src
wget -O - https://www.bnlearn.com/bnrepository/insurance/insurance.net.gz | gzip -d > assets/insurance.net
pip install -r requirements.txt
python main_comparison.py
python min_diff.py