Skip to content

Repository files navigation

BayesNetInfer

This project implements Bayesian Network inference using three probabilistic inference algorithms:

  1. Simple Inference (no optimizations).
  2. Variable Elimination with ABC variable ordering.
  3. 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.


Input

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.

Supported Queries

  1. Joint Probability
    Format:

    P(E1=e1, E2=e2, ..., En=en)
    

    Calculates the joint probability for fully assigned variables.

  2. 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, or 3.

If a query directly matches an existing CPT entry, it is answered immediately without computation.


Output

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, 0 is written in their place.

Algorithms Details

  • 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 separate details document.)

  • 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.


License

This project is part of an academic assignment and is intended for educational use only.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages