/* Path in Picat. From "Probabilistic Logic Programming Under the Distribution Semantics" page 11 """ An interesting application of PLP under the distribution semantics is the computation of the probability of a path between two nodes in a graph in which the presence of each edge is probabilistic: This program, coded in ProbLog, was used in (10) for computing the probability that two biological concepts are related in the BIOMINE network (26). """ Cf my Gamble model gamble_path.rkt This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import ppl_distributions, ppl_utils, ppl_common_utils. import util. % import ordset. main => go. /* var : path1 a Probabilities: c: 0.6140000000000000 b: 0.2896000000000000 -: 0.0964000000000000 mean = [] var : path1 b Probabilities: -: 0.8008000000000000 c: 0.1992000000000000 mean = [] var : path1 c Probabilities: -: 0.8981000000000000 a: 0.1019000000000000 mean = [] var : path a a Probabilities: true: 1.0000000000000000 mean = 1.0 var : path a b Probabilities: false: 0.6936000000000000 true: 0.3064000000000000 mean = 0.3064 var : path a c Probabilities: true: 0.6193000000000000 false: 0.3807000000000000 mean = 0.6193 var : path b a Probabilities: false: 0.9779000000000000 true: 0.0221000000000000 mean = 0.0221 var : path b b Probabilities: true: 1.0000000000000000 mean = 1.0 var : path b c Probabilities: false: 0.7862000000000000 true: 0.2138000000000000 mean = 0.2138 var : path c a Probabilities: false: 0.8990000000000000 true: 0.1010000000000000 mean = 0.101 var : path c b Probabilities: false: 0.9676000000000000 true: 0.0324000000000000 mean = 0.0324 var : path c c Probabilities: true: 1.0000000000000000 mean = 1.0 */ go ?=> reset_store, run_model(10_000,$model,[show_probs_trunc,mean]), nl, % show_store_lengths,nl, % fail, nl. go => true. path1(Node) = Res => if Node == a then Res = categorical([0.3,0.6,0.1],[b,c,'-']) elseif Node == b then Res = categorical([0.2,0.8],[c,'-']) elseif Node == c then Res = categorical([0.1,0.9],[a,'-']) else Res = "?" end. path2(X,Y) = Res => T = cond([ 1 : Z in [a,b,c], Z != X, Z != Y, Y == path1(Z),path2(X,Z) == true].sum > 0,true,false), if X == Y ; Y == path1(X) ; T == true then Res = true else Res = false end. model() => % Nodes = [a,b,c], add("path1 a",path1(a)), add("path1 b",path1(b)), add("path1 c",path1(c)), add("path a a",path2(a,a)), add("path a b",path2(a,b)), add("path a c",path2(a,c)), add("path b a",path2(b,a)), add("path b b",path2(b,b)), add("path b c",path2(b,c)), add("path c a",path2(c,a)), add("path c b",path2(c,b)), add("path c c",path2(c,c)).