Created
November 16, 2011 10:05
-
-
Save mrc/1369739 to your computer and use it in GitHub Desktop.
Dinky probability helpers for ai-class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun bayes-transform-form (PB!A PA PB) | |
"Return a form to compute P(A|B) | |
given P(B|A), P(A) and P(B)." | |
`(/ (* ,(or PB!A 'PB!A) ,(or PA 'PA)) | |
,(or PB 'PB))) | |
(defun total-probability-complementary (PA!B PA!notB PB) | |
"Return a form to compute the total probability of | |
complementary events P(B) = P(A|B)P(B) + P(A|!B)P(!B)." | |
`(+ (* ,(or PA!B 'PA!B) | |
,(or PB 'PB)) | |
(* ,(or PA!notB 'PA!notB) | |
(- 1,(or PB 'PB))))) | |
;; AICLASS> (bayes-transform-form | |
;; 2/5 | |
;; (total-probability-complementary 2/5 9/10 2/5) | |
;; (total-probability-complementary 3/5 1/5 1/2)) | |
;; ; (/ (* 2/5 (+ (* 3/5 1/2) (* 1/5 (- 1 1/2)))) (+ (* 2/5 2/5) (* 9/10 (- 1 2/5)))) | |
;; AICLASS> (eval *) | |
;; ; 8/35 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
same answer, another session: