Bayesian Erlang: Help with translation from Prolog
Joel Reymont
joelr1@REDACTED
Wed Jan 11 23:52:07 CET 2006
Folks,
I'm looking at http://www.ainewsletter.com/newsletters/
aix_0304.htm#code_corner and trying to translate the following from
Prolog. Would someone kindly lend me a hand?
Thanks, Joel
P.S.
First we represent the basic probability facts as Prolog facts:
p(patient(cancer), 0.1).
p(patient(smoker), 0.5).
We then represent the conditional probabilities, using a ^ operator:
cp(patient(smoker) ^ patient(cancer), 0.8).
Next we write query rules that can be used to find various
probabilities. There are three rules, covering the case where the
probability is known, the conditional probability is known, or we can
compute the conditional probability using Bayes theorem. Words
beginning with upper case letters are variables in Prolog. Note that
the third rule recursively calls itself to get the individual
probabilities.
getp(A,P) :-
p(A,P), !.
getp(A^B, P) :-
cp(A^B, P), !.
getp(A^B, P) :-
cp(B^A, Pba),
getp(A, Pa),
getp(B, Pb),
P is Pba * Pa / Pb.
We now have a simple system for representing and querying knowledge
expressed as probabilities. We can consult these facts and rules into
a Prolog listener and try it:
?- getp(patient(cancer), P).
P = 0.1
?- getp(patient(smoker)^patient(cancer), P).
P = 0.8
?- getp(patient(cancer)^patient(smoker), P).
P = 0.16
--
http://wagerlabs.com/
More information about the erlang-questions
mailing list