ML-KULeuven / problog

ProbLog is a Probabilistic Logic Programming Language for logic programs with probabilities.
https://dtai.cs.kuleuven.be/problog/
297 stars 34 forks source link

save problog knowledge base as .pl file #69

Closed cse578group29 closed 2 years ago

cse578group29 commented 2 years ago

Hello, I am using Problog for a project, and save a knowledge base as file2.pl, which supports the file1.pl. However, when using the command "problog file2.pl file1.pl" the error shows that the facts saved in file2.pl can't be found by file1.pl.

Do I use it in the correct way? Does problog supports a knowledge base in the *.pl way? Thank you!

VincentDerk commented 2 years ago

Is this what you are looking for?

file2.pl

pred(1).
0.25::pred(2).
0.4::file_1_and_2 :- pred(1).

file1.pl

:- consult('file2.pl').

% tests predicate defined in file 2.
test_file_2 :- pred(1).
query(test_file_2).
query(pred(2)).

% tests probabilistic predicate defined in both files.
0.25::a.
0.5::file_1_and_2 :- a.
query(file_1_and_2). % 0.25*0.5 + (1 - 0.25*0.5)*0.4

cmd problog file1.pl

Results for file1.pl:
file_1_and_2:   0.475     
     pred(2):   0.25      
 test_file_2:   1

problog file1.pl file2.pl

Results for file1.pl:
file_1_and_2:   0.475     
     pred(2):   0.25      
 test_file_2:   1         
Results for file2.pl:
cse578group29 commented 2 years ago

Thanks! Does it have the same computation complicity compared to the database method listed on the website https://dtai.cs.kuleuven.be/problog/tutorial/advanced/02_knowledgebases.html?

VincentDerk commented 2 years ago

I'm not sure myself, but you can test it by creating some large (artificial) knowledge base and comparing both methods.

anton3s commented 2 years ago

That depends on the indexes defined in your database. Facts in ProbLog are indexed according to argument order left to right. If you need to retrieve facts based on the last argument that won't work very efficiently. However, in a database you can add an index on that argument (attribute) and it will be able to query much faster. If you database has no indexes then you won't gain that much, I imagine.

An additional benefit is that the knowledge base from a database doesn't get loaded into memory.

cse578group29 commented 2 years ago

Thanks for the details. When running problog in Ubuntu, got an error message "Killed"(only gets this error message with large size input data). What might be the possible reasons for it?

VincentDerk commented 2 years ago

Thanks for the details. When running problog in Ubuntu, got an error message "Killed"(only gets this error message with large size input data). What might be the possible reasons for it?

Your machine likely ran out of memory (see here).

If you haven't yet, you can try using the Sentential Decision Diagrams (add the -k sdd flag when running problog from CLI) for which you will need to install the pysdd package.