#C3a.txt, Jan. 29, 2015, Bayes's rule Help:=proc(): print(` CP(A,B), CheckBayes(A,B),`): print(` Post(L,M) `): end: #CP(A,B): A and B are any sets, using the uniform #distribution, the conditional probability that #the element belogs to A if someone told that it #belongs to B, Pr(A|B)=|A interset B|/|B| CP:=proc(A,B) nops(A intersect B)/nops(B): end: #Pr(B|A)=Pr(A|B)*Pr(B)/Pr(A) CheckBayes:=proc(A,B) : evalb(CP(B,A)=CP(A,B)*nops(B)/nops(A)): end: #Post(L,M): inputs a list of prob. (that add to one) #of length m, say, describing the step-1 scenarios #(going to city i has prob. L[i]). #There are n secondary destinations #If you are already to city i your prob. if M[i][j] Post:=proc(L,M) local i,j,tot,P,P1: #Prob. of getting to j via i (starting at NB): #Prob(NB->i)*Prob(i->j) P:=[]: for j from 1 to nops(M[1]) do tot:=add(L[i]*M[i][j],i=1..nops(L)): P1:=[seq(L[i]*M[i][j]/tot,i=1..nops(L))]: P:=[op(P), P1]: od: P: end: