Tutorial


lpmln2asp

lpmln2asp, compiles LPMLN into the input language of clingo utilizing weak constraints. Any clingo rule R can be turned into a valid LPMLN rule by prepending that rule with a weight W.

Consider an instance where you have conflicting information from different data sources. One data source may mention that an entity jo is a resident bird however some other data source may say that jo is a migratory bird. Although we cannot say with certainty that jo is a migratory bird or a resident bird but we can say with a certain degree of confidence that jo is a Bird. Suppose we want to find out what is the probability of jo being a Bird given that one KB says it is ResidentBird and other says it is a MigratoryBird. Such a domain can be easily encoded in this language. Consider a simple clingo encoding of the above scenario,

                                    
bird(X) :- residentbird(X).
bird(X) :- migratorybird(X).
:- residentbird(X), migratorybird(X).
residentbird(jo).
migratorybird(jo).
                                    
                                

The above program is a valid clingo program. This can be turned into a valid LPMLN program by prepending the respective rule with a weight. Below is a valid LPMLN program for lpmln2asp.

                                        
% Same rules as above
bird(X) :- residentbird(X).
bird(X) :- migratorybird(X).
:- residentbird(X), migratorybird(X).

% A fact with a weight of 2. It represents our degree of confidence in this rule.
2 residentbird(jo).

% A fact with a weight of 1.
1 migratorybird(jo).
                                        
                                    
Likewise, any rule, constraint or fact can be converted to a valid LPMLN input.

To execute the above program the command line is,
lpmln2asp -i birds.lpmln

This calculates the MAP state. The intermediate file generated would be

                                
% Same rules as above
bird(X) :- residentbird(X).
bird(X) :- migratorybird(X).
:- residentbird(X) , migratorybird(X).

% A fact with a weight of 2. It represents our degree of confidence in this rule.
unsat(3,"2.000000") :-not residentbird(jo).
residentbird(jo):-not unsat(3,"2.000000").
:~ unsat(3,"2.000000"). [2000@0,3]

% A fact with a weight of 1.
unsat(4,"1.000000") :-not migratorybird(jo).
migratorybird(jo):-not unsat(4,"1.000000").
:~ unsat(4,"1.000000"). [1000@0,4]

                                
                            

Note that in the above translated code, the hard rules are not translated. This is because of the -hr option. Setting that option would have translated the first 3 rules as well.

The output is

                                
Solving...
Answer: 1
residentbird(jo) bird(jo) unsat(4,"1.000000")
Optimization: 1000
OPTIMUM FOUND

Models       : 1     
  Optimum    : yes
Optimization : 1
Calls        : 1
Time         : 0.006s (Solving: 0.00s 1st Model: 0.00s Unsat: 0.00s)
CPU Time     : 0.000s

                                
                            

The same input above can be used to calculate the marginal probability of atoms and also the probability of the Answer sets. The command line to do that is
lpmln2asp -i birds.lpmln -hr -all

Notice that using -hr option would translate the first 3 rules as well. -all option is used to invoke probability computaion module of lpmln2asp and prints all the stable models and there respective probabilities.

Probability of all stable models of the above encoding

                                
Solving...
Answer: 1
residentbird(jo) migratorybird(jo) unsat(0,"a",jo) unsat(1,"a",jo) unsat(2,"a",jo)
Optimization: 3 0
Answer: 2
unsat(3,"2.000000") migratorybird(jo) unsat(1,"a",jo)
Optimization: 1 2
Answer: 3
residentbird(jo) unsat(4,"1.000000") unsat(0,"a",jo)
Optimization: 1 1
Answer: 4
unsat(3,"2.000000") unsat(4,"1.000000")
Optimization: 0 3
Answer: 5
residentbird(jo) migratorybird(jo) bird(jo) unsat(2,"a",jo)
Optimization: 1 0
Answer: 6
unsat(3,"2.000000") migratorybird(jo) bird(jo)
Optimization: 0 2
Answer: 7
residentbird(jo) unsat(4,"1.000000") bird(jo)
Optimization: 0 1


Probability of Answer 4 :  0.0900305731703805 = 0.0900305731703805
Probability of Answer 6 :  0.244728471054798 = 0.244728471054798
Probability of Answer 7 :  0.665240955774822 = 0.665240955774822


OPTIMUM FOUND

Models       : 7     
  Optimum    : yes
Calls        : 1
Time         : 1.478s (Solving: 0.00s 1st Model: 0.00s Unsat: 0.00s)
CPU Time     : 0.360s




                                
                            

-q option is used to query for the probability of atoms. Output with query bird

lpmln2asp -i birds.lpmln -hr -all -q bird

                                
Solving...
Answer: 1
residentbird(jo) migratorybird(jo) unsat(0,"a",jo) unsat(1,"a",jo) unsat(2,"a",jo)
Optimization: 3 0
Answer: 2
unsat(3,"2.000000") migratorybird(jo) unsat(1,"a",jo)
Optimization: 1 2
Answer: 3
residentbird(jo) unsat(4,"1.000000") unsat(0,"a",jo)
Optimization: 1 1
Answer: 4
unsat(3,"2.000000") unsat(4,"1.000000")
Optimization: 0 3
Answer: 5
residentbird(jo) migratorybird(jo) bird(jo) unsat(2,"a",jo)
Optimization: 1 0
Answer: 6
unsat(3,"2.000000") migratorybird(jo) bird(jo)
Optimization: 0 2
Answer: 7
residentbird(jo) unsat(4,"1.000000") bird(jo)
Optimization: 0 1


Probability of Answer 4 : 0.0900305731703805
Probability of Answer 6 : 0.244728471054798
Probability of Answer 7 : 0.665240955774822



bird(jo) 0.909969426829620


OPTIMUM FOUND

Models       : 7     
  Optimum    : yes
Calls        : 1
Time         : 6.713s (Solving: 0.00s 1st Model: 0.00s Unsat: 0.00s)
CPU Time     : 0.370s

                                
                            

-e option is used to provide evidence file to the program. In the presence of evidence file, conditional probability of the atom is calculated. For more information use lpmln2asp -h
Note: lpmln2asp is still under active development and is a wrapper over underlying systems like lpmln2cl and clingo and as such there might be bugs in the system. Please contact the authors in this case.