An example of Bayesian learning: given a prior over the weights of coins, and observed sequences of tosses for two coins, compute the posterior over those coins’ weights.
0.05::weight(C,0.1); 0.2::weight(C,0.3); 0.5::weight(C,0.5); 0.2::weight(C,0.7); 0.05::weight(C,0.9) :- coin(C).
Param::toss(_,Param,_).
heads(C,R) :- weight(C,Param),toss(C,Param,R).
tails(C,R) :- weight(C,Param),\+toss(C,Param,R).
data(C,[]).
data(C,[h|R]) :- heads(C,R), data(C,R).
data(C,[t|R]) :- tails(C,R), data(C,R).
coin(c1).
coin(c2).
param(0.1).
param(0.3).
param(0.5).
param(0.7).
param(0.9).
query(weight(C,X)) :- coin(C),param(X).
evidence(data(c1,[h,h,h,h,h,h,h,h,h,h,h,h,h]),true).
evidence(data(c2,[h,t,h,h,h,h,h,t,t,h,t,t,h]),true).