#| BUGS book, 2.5.1 in Racket Gamble. "The how many trick" var : number 26181.209136598904: 0.0009999999999999994 30135.43182499509: 0.0009999999999999994 31532.69204534173: 0.0009999999999999994 36934.82740997929: 0.0009999999999999994 30731.95202277405: 0.0009999999999999994 33896.830238383765: 0.0009999999999999994 33035.38588974109: 0.0009999999999999994 27536.56772546697: 0.0009999999999999994 37809.02648610869: 0.0009999999999999994 30953.367381930126: 0.0009999999999999994 ... 30233.2389587696: 0.0009999999999999994 31814.638729164304: 0.0009999999999999994 32332.08915092479: 0.0009999999999999994 30088.729315394245: 0.0009999999999999994 40822.727961353085: 0.0009999999999999994 27721.507629055683: 0.0009999999999999994 31623.607310119995: 0.0009999999999999994 32523.24307708477: 0.0009999999999999994 39352.93917013385: 0.0009999999999999994 24754.154029673686: 0.0009999999999999994 mean: 33060.87053387217 var : ix 12: 0.2970000000000002 11: 0.2590000000000002 13: 0.16900000000000012 10: 0.1360000000000001 14: 0.07700000000000004 9: 0.028 15: 0.026 16: 0.004999999999999997 8: 0.0019999999999999987 17: 0.0009999999999999994 mean: 11.80300000000001 var : x-all (1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0): 0.21000000000000016 (1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0): 0.11500000000000007 (1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0): 0.11400000000000007 (1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0 0 0): 0.06500000000000003 (1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0 0): 0.058000000000000024 (1 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0): 0.034 (1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 0 0 0 0 0): 0.033 (1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0): 0.031000000000000003 (1 1 1 1 1 1 1 1 1 1 1 0 0 1 0 0 0 0 0 0): 0.030000000000000002 (1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 0 0 0 0): 0.028 ... (1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 1 0 0): 0.0009999999999999994 (1 1 1 1 1 1 1 1 1 0 0 0 1 0 1 0 0 0 0 0): 0.0009999999999999994 (1 1 1 1 1 1 1 1 1 1 0 1 0 0 0 1 0 0 0 0): 0.0009999999999999994 (1 1 1 1 1 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0): 0.0009999999999999994 (1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 0 0 0 0 0): 0.0009999999999999994 (1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0): 0.0009999999999999994 (1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 0 1 0 0 0): 0.0009999999999999994 (1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0): 0.0009999999999999994 (1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 0 0): 0.0009999999999999994 (1 1 1 1 1 1 1 1 0 0 1 0 0 0 1 0 0 0 0 0): 0.0009999999999999994 This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Racket page: http://www.hakank.org/racket/ |# #lang gamble (require racket) (require "gamble_utils.rkt") (define (bugs-book-2-5-1) (rejection-sampler ; importance-sampler ; mh-sampler (define n 20) (define (y i) (gamma 3.0 (/ 0.04)) ) (define (cum i) ; (displayln (list "cum " i ":" (cum i))) (if (= i 0) (+ (y 0) 1) (+ (cum (sub1 i)) (y i) i) )) (define (cum-step i) (if (> (cum i) 1000.0) (* i (cum i)) 0)) ;; A changepoint. (define (x i) (if (< (cum i) 1001.0) 1 0)) (define number (apply max (for/list ([i (range n)]) (cum-step i) ))) (define ix (apply max (for/list ([i (range n)]) (if (= (x i) 1) i 0)))) (define x-all (for/list ([i (range n)]) (x i))) (list number ix x-all ) ) ) (show-marginals (bugs-book-2-5-1) (list "number" "ix" "x-all" ) #:truncate-output 10) ; (show-model (bugs-book-2-5-1) #:no-stats? #t #:no-cred? #t)