Header
% =================================================================
% == ==
% == An Introduction to ARTIFICIAL INTELLIGENCE ==
% == Janet Finlay and Alan Dix ==
% == UCL Press, 1996 ==
% == ==
% =================================================================
% == ==
% == chapter 2, page 36: Baysian inference ==
% == ==
% == Prolog example, Alan Dix, August 1996 ==
% == ==
% =================================================================
Code
% extra facts to use with inference rules in bayes.p
hypothesis(h3,measles).
evidence(e1,headache).
evidence(e2,spots).
evidence(e3,'fear of light').
p(measles,0.01).
p_eh(headache,measles,0.9).
p_eh(spots,cold,0.0000001). % only happens for some other reason
p_eh(spots,meningitis,0.0000001). % ditto
p_eh(spots,measles,1.0).
p_eh('fear of light',cold,0.0000001). % as for spots
p_eh('fear of light',meningitis,0.7).
p_eh('fear of light',measles,0.0000001).
% also original facts from bayes.p this may be needed on some Prologs as consulting
% a new file removes the old definitions if so uncomment the following lines.
% on others having this here may cause 2 definitions of p(cold,0.2). etc.
% comment out these lines if your prolog works like this.
% p(cold,0.2).
% p(meningitis,0.000001).
% p_eh(headache,cold,0.8).
% p_eh(headache,meningitis,0.9).
Running this Code
% RUNNING THIS CODE
%
% Try the goal:
%> p_he(cold,headache,P).
% The answer is different frpm bayes.p
% This is because we now know of another potential cause of headaches,
% measles, so are less likely to attribute a headache to a cold,
% although it is still the most likely cause.
% However, if you look at
%> p_he(meningitis,'fear of light',P).
% you will see that meningitis becomes very likely.
% In fact, the only reason for putting a non-zero value in for colds
% is that you may just happen to have someone with a cold who also
% just happens to be sensitive to light.
Examples
% EXAMPLES
%
%> p_he(cold,headache,P).
%
%> p_he(meningitis,'fear of light',P).