#| Continuous weight example (Church code) in Racket Gamble. I'm not sure about the original source of this. See gamble_continuous_weight.rkt for a "pure" Gamble port of this model Coin weight, prior to observing data 0 : 1 # (0.000 / 0 ) 0.023: 216 ################################################################## (0.021 / 0.000) 0.045: 254 ############################################################################# (0.025 / 0.021) 0.068: 252 ############################################################################# (0.025 / 0.047) 0.091: 238 ######################################################################### (0.023 / 0.072) 0.114: 226 ##################################################################### (0.022 / 0.096) 0.136: 243 ########################################################################## (0.024 / 0.118) 0.159: 233 ####################################################################### (0.023 / 0.143) 0.182: 218 ################################################################### (0.021 / 0.166) 0.205: 243 ########################################################################## (0.024 / 0.188) 0.227: 222 #################################################################### (0.022 / 0.212) 0.25 : 231 ###################################################################### (0.023 / 0.234) 0.273: 219 ################################################################### (0.021 / 0.257) 0.295: 203 ############################################################## (0.020 / 0.279) 0.318: 227 ##################################################################### (0.022 / 0.299) 0.341: 225 ##################################################################### (0.022 / 0.322) 0.364: 233 ####################################################################### (0.023 / 0.345) 0.386: 214 ################################################################# (0.021 / 0.368) 0.409: 237 ######################################################################## (0.023 / 0.389) 0.432: 220 ################################################################### (0.022 / 0.413) 0.454: 204 ############################################################## (0.020 / 0.435) 0.477: 233 ####################################################################### (0.023 / 0.455) 0.5 : 230 ###################################################################### (0.023 / 0.479) 0.523: 236 ######################################################################## (0.023 / 0.502) 0.545: 218 ################################################################### (0.021 / 0.525) 0.568: 223 #################################################################### (0.022 / 0.547) 0.591: 234 ####################################################################### (0.023 / 0.569) 0.614: 230 ###################################################################### (0.023 / 0.593) 0.636: 230 ###################################################################### (0.023 / 0.616) 0.659: 226 ##################################################################### (0.022 / 0.639) 0.682: 218 ################################################################### (0.021 / 0.661) 0.704: 190 ########################################################## (0.019 / 0.683) 0.727: 220 ################################################################### (0.022 / 0.702) 0.75 : 264 ################################################################################ (0.026 / 0.724) 0.773: 234 ####################################################################### (0.023 / 0.751) 0.795: 215 ################################################################## (0.021 / 0.774) 0.818: 209 ################################################################ (0.020 / 0.796) 0.841: 213 ################################################################# (0.021 / 0.816) 0.863: 228 ###################################################################### (0.022 / 0.838) 0.886: 241 ########################################################################## (0.024 / 0.861) 0.909: 230 ###################################################################### (0.023 / 0.885) 0.932: 242 ########################################################################## (0.024 / 0.908) 0.954: 222 #################################################################### (0.022 / 0.932) 0.977: 229 ###################################################################### (0.022 / 0.954) Coin weight, conditioned on observed data 0.148: 1 # (0.000 / 0 ) 0.167: 2 # (0.000 / 0.000) 0.187: 0 (0 / 0.000) 0.206: 0 (0 / 0.000) 0.226: 0 (0 / 0.000) 0.245: 1 # (0.000 / 0.000) 0.264: 1 # (0.000 / 0.000) 0.284: 1 # (0.000 / 0.000) 0.303: 3 # (0.000 / 0.000) 0.322: 2 # (0.000 / 0.000) 0.342: 5 # (0.000 / 0.001) 0.361: 4 # (0.000 / 0.001) 0.38 : 5 # (0.000 / 0.002) 0.4 : 13 # (0.001 / 0.002) 0.419: 16 ## (0.001 / 0.003) 0.439: 21 ## (0.002 / 0.005) 0.458: 17 ## (0.001 / 0.007) 0.477: 23 ## (0.002 / 0.009) 0.497: 37 ### (0.003 / 0.011) 0.516: 44 #### (0.004 / 0.015) 0.535: 51 #### (0.005 / 0.019) 0.555: 56 ##### (0.005 / 0.024) 0.574: 78 ###### (0.007 / 0.030) 0.593: 101 ######## (0.010 / 0.038) 0.613: 105 ######## (0.010 / 0.048) 0.632: 112 ######### (0.011 / 0.058) 0.651: 128 ########## (0.012 / 0.069) 0.671: 153 ############ (0.015 / 0.082) 0.69 : 158 ############ (0.015 / 0.098) 0.71 : 169 ############# (0.016 / 0.113) 0.729: 189 ############## (0.018 / 0.130) 0.748: 266 #################### (0.026 / 0.149) 0.768: 290 ###################### (0.029 / 0.176) 0.787: 327 ######################## (0.032 / 0.205) 0.806: 384 ############################# (0.038 / 0.237) 0.826: 407 ############################## (0.040 / 0.276) 0.845: 444 ################################# (0.044 / 0.317) 0.864: 525 ####################################### (0.052 / 0.361) 0.884: 618 ############################################## (0.061 / 0.413) 0.903: 655 ################################################ (0.065 / 0.475) 0.923: 720 ##################################################### (0.072 / 0.541) 0.942: 844 ############################################################## (0.084 / 0.613) 0.961: 903 ################################################################### (0.090 / 0.697) 0.981: 1027 ############################################################################ (0.102 / 0.787) This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Racket page: http://www.hakank.org/racket/ |# #lang gamble ;;; (require gamble/viz) (require racket) (require "gamble_utils.rkt") (define observed-data '(h h h h h)) (define num-flips (length observed-data)) (define num-samples 10000) (define prior-samples (repeat (lambda () (uniform 0 1)) num-samples)) (displayln "Coin weight, prior to observing data") (show-histogram prior-samples) (define (samples) (mh-query ; num-samples 10 (define coin-weight (uniform 0 1)) (define make-coin (lambda (weight) (lambda () (if (flip weight) 'h 't)))) (define coin (make-coin coin-weight)) coin-weight #:when (equal? observed-data (repeat coin num-flips)) )) (define samples-res (repeat (lambda() (samples)) num-samples)) ; samples-res (displayln "\nCoin weight, conditioned on observed data\n") (show-histogram samples-res) ;;; (density prior-samples "Coin weight, prior to observing data" #t ) ;;; (density samples "Coin weight, conditioned on observed data" #t)