This project implements Bayesian Network inference using three probabilistic inference algorithms:
- Simple Inference (no optimizations).
- Variable Elimination with ABC variable ordering.
- Variable Elimination with heuristic-based variable ordering.
The project was developed as part of an academic assignment focusing on performance comparison between different inference methods.
Implemented in Java 1.8.
The program receives two types of input files located in the same directory:
-
input.txt:- First line: the name of the XML file that describes the Bayesian Network structure.
- Following lines: queries to be evaluated.
-
XML File (Network Description):
A Bayesian network structured using XML format, including:- Variables (
<VARIABLE>tags with<NAME>and<OUTCOME>). - CPTs (Conditional Probability Tables) inside
<DEFINITION>tags.
- Variables (
-
Joint Probability
Format:P(E1=e1, E2=e2, ..., En=en)Calculates the joint probability for fully assigned variables.
-
Conditional Probability
Format:P(Q=q|E1=e1, E2=e2, ..., Ek=ek), <algorithm_number>Q: query variable.E1..Ek: evidence variables.<algorithm_number>indicates which algorithm to use:1,2, or3.
If a query directly matches an existing CPT entry, it is answered immediately without computation.
The program outputs the results to a file named output.txt, created in the same directory.
Each line corresponds to a query result in the following format:
<result_probability>,<number_of_additions>,<number_of_multiplications>
- Probability values are written with five decimal digits precision.
- In normalization steps, addition operations are counted but division operations are not counted as multiplications.
- If no addition/multiplication was needed,
0is written in their place.
-
Simple Inference (Algorithm 1):
Direct calculation of probabilities without optimization. -
Variable Elimination with ABC Ordering (Algorithm 2):
Variables eliminated based on a fixed alphabetical order (A → B → C...). -
Variable Elimination with Heuristic Ordering (Algorithm 3):
Variables eliminated based on a custom heuristic to optimize efficiency.
(Heuristic explanation must be provided in a separatedetailsdocument.) -
Factor Multiplication Order:
- Factors are multiplied in ascending order of size.
- If sizes are equal, factors are ordered by the sum of ASCII values of their variables' names (smallest first).
Note: No Bayes-Ball or conditional independence checks are required.
This project is part of an academic assignment and is intended for educational use only.