Created
November 8, 2017 21:18
-
-
Save Zhen-hao/2f5e00b8b76ae48ef9ed139b94fffb0a to your computer and use it in GitHub Desktop.
a solution to an Anglican exercise
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
;; To do this we've provided scaffolding | |
;; that can be modified to achieve | |
;; your objective: | |
(with-primitive-procedures | |
[create-world simulate-world balls-in-box] | |
(defquery arrange-bumpers [] | |
(let [;; *** TASK: REPLACE THE FOLLOWING LINE WITH | |
;; STOCHASTIC CODE TO SAMPLE POSSIBLE | |
;; BUMPER CONFIGURATIONS *** | |
n-bumpers 4 ;; (sample (poisson 4)) ;; this is to let Anglican select the number of bumpers; maybe (poisson 2) is better | |
bumper-positions (repeatedly n-bumpers #(list | |
(sample (uniform-continuous -5 16)) | |
(sample (uniform-continuous -20 8)))) | |
;; Code to simulate the world: | |
world (create-world bumper-positions) | |
end-world (simulate-world world) | |
balls (:balls end-world) | |
;; How many balls entered the box? | |
num-balls-in-box (balls-in-box end-world)] | |
;; *** ADD A LIKELIHOOD FUNCTION (observe) HERE *** | |
;;(observe (normal n-bumpers 1) 0) ;; to get as few bumpers as possible | |
(observe (normal num-balls-in-box 1) 10) | |
(predict :balls balls) | |
(predict :num-balls-in-box num-balls-in-box) | |
(predict :bumper-positions bumper-positions)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment