Skip to content

arminnh/ma2-csai-probabilistic-programming

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Inference for Statistical Relational Learning

The goal of the Probabilistic Programming assignment is to build your own state-of-the-art inference and learning engine for probabilistic graphical models such as Bayesian networks and statistical relational models.

Usage

The program can evaluate ProbLog programs and Bayesian networks.

Problog programs

To evaluate ProbLog programs:

python3 scripts/inference.py --problog files/problog/ball_colors_and_types.pl

The underlying model counter that is used for evaluation can be set with the --model_counter parameter. It can be minic2d or sdd.

The program will print the following steps of the inference pipeline:

  • The ground version of the input program
  • The ground program converted to a First Order Logic theory
  • The ground program in a CNF encoding
  • The CNF encoding in dimacs format
  • The results using our pipeline
  • The results using the problog library

Bayesian networks

For Bayesian networks, the process is a bit different. The following command will convert the Bayesian network to a ground ProbLog program and run the pipeline on it.

python3 scripts/inference.py -bn files/networks/earthquake.net

The output will contain the same elements mentioned above. However, as there are no queries in the ground ProbLog program, there will be nothing to evaluate. In order to add queries, simply copy the ground ProbLog output of the program to a new file and add the queries you want. Then run the command for evaluating a ProbLog file.

Bayesian networks in the following file formats are supported: uai, net, xdsl, xml. The networks are converted to ProbLog code using conversion scripts taken (and slightly adapted) from the ProbLog repository.

Parameter learning

There is support for parameter learning. To do this, the program expects a file containing tunable probabilities and another file containing values for all probabilities (the ground truth). The ground truth is necessary for generation of interpretations (training evidence). The amount of interpretations to be generated can be set as well.

python3 scripts/inference.py --problog_learn file --problog_learn_truth file_ground_truth --learning_interpretations 100

The interpretations that were generated for the execution will be written to src/files/interpretations.txt.

Note

The file with tunable probabilities needs to be in ground ProbLog form and cannot contain any comments. This is because we uses the problog library to ground files, and the library cannot ground files with tunable probabilities.

Also, in order to generate interpretations, the file with the ground truth must have query(...). statements for all predicates for which evidence should be generated.

Tests

Tests have been created to make sure our pipeline delivers the same results as the problog library. They can be ran as follows:

python3 tests/pipeline.py

The ProbLog code used for testing is mainly taken from the online ProbLog tutorial.

Dependencies

  • Python >= 3.6
  • graphviz

MiniC2D

The program relies on the MiniC2D package in model_counters/ to be installed. To install it, simply unpack them and run make. MiniC2D might return compilation errors with g++ versions greater than 4.8. To fix this issue, install an older compiler and explicitly add your version in MiniC2D's makefile.

The code of the MiniC2D package in model_counters/ has been edited to make it return results with higher precision.

Python dependencies

To install most of the Python dependencies.

pip3 install --upgrade setuptools
pip3 install -r requirements.txt

The program relies on PySDD for model counting using SDDs. To install PySDD, see the compilation instructions.

Papers