More examples
These examples are from the slides of various tutorials on ProbLog, e.g., at IJCAI 2015
This example uses evidence to express constraints:
weight(skis,6).
weight(boots,4).
weight(helmet,3).
weight(gloves,2).
P::pack(Item) :- weight(Item,Weight), P is 1.0/Weight.
excess(Limit) :- excess([skis,boots,helmet,gloves],Limit).
excess([],Limit) :- Limit<0.
excess([I|R],Limit) :- pack(I), weight(I,W), L is Limit-W, excess(R,L).
excess([I|R],Limit) :- \+pack(I), excess(R,Limit).
constraint :- pack(helmet).
constraint :- pack(boots).
evidence(constraint).
evidence(excess(10),false).
query(pack(_)).
An example of a tuple-independent probabilistic database in ProbLog; adapted from Dan Suciu et al. Probabilistic Databases. Morgan & Claypool. 2011.
0.96::producesProduct(sony,walkman).
0.96::producesProduct(microsoft,mac_os_x).
0.96::producesProduct(ibm,personal_computer).
0.9::producesProduct(microsoft,mac_os).
0.9::producesProduct(adobe,adobe_indesign).
0.87::producesProduct(adobe,adobe_dreamweaver).
1.0::headquarteredIn(microsoft,redmond).
0.99::headquarteredIn(ibm,san_jose).
0.93::headquarteredIn(emirates_airlines,dubai).
0.93::headquarteredIn(honda,torrance).
0.93::headquarteredIn(horizon,seattle).
0.93::headquarteredIn(egyptair,cairo).
0.93::headquarteredIn(adobe,san_jose).
result(Product,Company) :-
producesProduct(Company,Product),
headquarteredIn(Company,san_jose).
query(result(_,_)).
A simple weather model:
0.5::weather(sun,0) ; 0.5::weather(rain,0).
0.6::weather(sun,T) ; 0.4::weather(rain,T) :- T>0, Tprev is T-1, weather(sun,Tprev).
0.2::weather(sun,T) ; 0.8::weather(rain,T) :- T>0, Tprev is T-1, weather(rain,Tprev).
query(weather(_,10)).
An example of friends and smokers with cycles:
person(1).
person(2).
person(3).
person(4).
friend(1,2).
friend(2,1).
friend(2,4).
friend(3,4).
friend(4,2).
0.3::stress(X):- person(X).
0.2::influences(X,Y):-person(X), person(Y).
smokes(X) :- stress(X).
smokes(X) :- friend(X,Y), influences(Y,X), smokes(Y).
0.4::asthma(X) :- smokes(X).
query(asthma(_)).
query(smokes(_)).
query(stress(_)).
query(influences(_,_)).