Tests summary
Joint distribution of tossing two coins, where head has probability
to appear:
observe that both proportional and normalized probabilities are the same because there is no observation that rules out some branches, therefore the normalization constant equals
.
(define (test/coin-model _)
(define result
(probcc-reify/exact
(let* ((p 'p) (x (probcc-coin p)) (y (probcc-coin p)))
`((x ,x) (y ,y)))))
(⊦= '(((V ((x #t) (y #f))) (Times -1 (Plus -1 p) p))
((V ((x #f) (y #t))) (Times -1 (Plus -1 p) p))
((V ((x #f) (y #f))) (Power (Plus -1 p) 2))
((V ((x #t) (y #t))) (Power p 2)))
result)
(⊦= result (probcc-normalize result)))
((eta 0.013) (memory #(6291456 1431888 1048576)) (stdout "") (stderr ""))
3. test/coin-model/observed
: pass
Slightly variation of the previous test, here it has been observed that at least one head appeared. Now the probabilities are proportional according to the following rules:
and they can be normalized,
to obtain a valid probability distribution, provided that the assumed observation occurred.
(define (test/coin-model/observed _)
(define result
(probcc-reify/exact
(let* ((p 'p) (x (probcc-coin p)) (y (probcc-coin p)))
(probcc-when (or x y) `((x ,x) (y ,y))))))
(define normalized (probcc-normalize result))
(⊦= '(((V ((x #t) (y #f))) (Times -1 (Plus -1 p) p))
((V ((x #f) (y #t))) (Times -1 (Plus -1 p) p))
((V ((x #t) (y #t))) (Power p 2)))
result))
((eta 0.015) (memory #(6291456 1390304 1048576)) (stdout "") (stderr ""))
4. test/grass-model
: pass
The conditional probability that rained given that a wet grass has been observed is
fully symbolic. On the other hand, the rules
allow us to get numerical values according to the expected results already shown.
(define (test/grass-model _)
(define result
(probcc-reify/exact
(let* ((rain (probcc-coin 'r))
(sprinkler (probcc-coin 's))
(grass-is-wet
(or (and (probcc-coin 'w) rain)
(and (probcc-coin 'v) sprinkler)
(probcc-coin 'e))))
(probcc-when grass-is-wet `(rain ,rain)))))
(define normalized (probcc-normalize result))
(define p/rain (second (first normalized)))
(define p/not-rain (second (second normalized)))
(define rules
'(List (Rule r 0.3) (Rule s 0.5) (Rule w 0.9) (Rule v 0.8) (Rule e 0.1)))
(⊦= '(((V (rain #t))
(Times r
(Plus (Times e (Plus -1 (Times s v)) (Plus -1 w))
w
(Times s (Plus v (Times -1 v w))))))
((V (rain #f))
(Times (Plus -1 r)
(Plus (Times -1 s v) (Times e (Plus -1 (Times s v)))))))
result)
(⊦= '(((V (rain #t)) 0.2838) ((V (rain #f)) 0.322))
(letmap ((p result)) `(,(car p) ,(W `(ReplaceAll ,(cadr p) ,rules))))))
((eta 0.039) (memory #(6291456 1331664 1048576)) (stdout "") (stderr ""))
5. test/grass-model/joint
: pass
If we remove the observation
(probcc-when grass-is-wet `(rain ,rain))
from the previous test, then we can show the joint distribution
where
is the non-normalized probability density function.
(define (test/grass-model/joint _)
(define result
(probcc-reify/exact
(let* ((rain (probcc-coin 'r))
(sprinkler (probcc-coin 's))
(grass-is-wet
(or (and (probcc-coin 'w) rain)
(and (probcc-coin 'v) sprinkler)
(probcc-coin 'e))))
`((rain ,rain) (sprinkler ,sprinkler) (grass-is-wet ,grass-is-wet)))))
(define normalized (probcc-normalize result))
(⊦= '(((V ((rain #t) (sprinkler #t) (grass-is-wet #t)))
(Times r
s
(Plus v (Times e (Plus -1 v) (Plus -1 w)) w (Times -1 v w))))
((V ((rain #t) (sprinkler #f) (grass-is-wet #t)))
(Times r (Plus -1 s) (Plus (Times e (Plus -1 w)) (Times -1 w))))
((V ((rain #f) (sprinkler #t) (grass-is-wet #t)))
(Times (Plus -1 r) s (Plus (Times e (Plus -1 v)) (Times -1 v))))
((V ((rain #t) (sprinkler #t) (grass-is-wet #f)))
(Times -1 (Plus -1 e) r s (Plus -1 v) (Plus -1 w)))
((V ((rain #t) (sprinkler #f) (grass-is-wet #f)))
(Times -1 (Plus -1 e) r (Plus -1 s) (Plus -1 w)))
((V ((rain #f) (sprinkler #t) (grass-is-wet #f)))
(Times -1 (Plus -1 e) (Plus -1 r) s (Plus -1 v)))
((V ((rain #f) (sprinkler #f) (grass-is-wet #f)))
(Times -1 (Plus -1 e) (Plus -1 r) (Plus -1 s)))
((V ((rain #f) (sprinkler #f) (grass-is-wet #t)))
(Times e (Plus -1 r) (Plus -1 s))))
result))
((eta 0.047) (memory #(6291456 1775888 1048576)) (stdout "") (stderr ""))
(define (test/geometric _)
(define result ((probcc-reify 5) (τ (probcc-geometric 'p 's 'f))))
(define t6 (cadr (car (sixth result))))
(define t7 (cadr (car (seventh result))))
(define t8 (cadr (car (eighth result)))))
((eta 0.019) (memory #(6291456 1550384 1048576)) (stdout "") (stderr ""))