Exercises
Last updated
Last updated
For example, suppose that we are interested in diagnosing cancer in patients who visit a chest clinic.
Let A represent the event "Person has cancer".
Let B represent the event "Person is a smoker".
Suppose we know the probability of the prior event A is 0.1 on the basis of past data (10% of patients entering the clinic turn out to have cancer). Thus:
P(A)=0.1
We want to compute the probability of the posterior event P(A|B).
It is difficult to find this out directly. However, we are likely to know P(B) by considering the percentage of patients who smoke suppose P(B)=0.5. We are also likely to know P(B|A) by checking from our records the proportion of smokers among those diagnosed with cancer. Suppose P(B|A)=0.8.
Use Bayes' rule to compute P(A|B).
Doing it using Erlang:
First we represent the basic probability facts as Erlang functions: - p({patient, cancer}) -> 0.1; - p({patient, smoker}) -> 0.5.
We then represent the conditional probabilities. - cp({patient, smoker}, {patient, cancer}) -> 0.8; - cp(_, _) -> none.
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.
We now have a simple system for representing and querying knowledge expressed as probabilities.
1> bayes:getp({{patient, cancer}, {patient, smoker}});