probprog / bopp Goto Github PK
View Code? Open in Web Editor NEWBOPP: Bayesian Optimization for Probabilistic Programs
License: Other
BOPP: Bayesian Optimization for Probabilistic Programs
License: Other
I am trying to figure out how to correctly provide a list of initial points in BOPP. Am I overlooking something simple?
Here are the details. The doopt, the output of BOPP, and the defopt.
(def model (atom (lazy-seq (doopt :smc stochSIR [] 1
:speed-option :careful
;;
:bo-options {:verbose 2
:num-initial-points 2
:num-scaling-thetas 1000
:debug-folder true
:initial-points [{:intro_day 35, :intro_duration 1, :distancing 0.6322107370456067, :beta_b 0.05537357023136269, :beta_bS 0.19621440146596547, :beta_lice 0.16614719314835572, :beta_p 0.16744317384178953}]
}))))
And from the output I get before the thing crashes is that BOPP doesn't like the format I use for initial-points. One, it reformats the map into a collcetion of [keyword values], and two, it drops the last keyword-value pair ({:beta_p 0.16744317384178953} in this case)
:intial-points ([:intro_day 35] [:intro_duration 1] [:distancing 0.6322107370456067] [:beta_b 0.05537357023136269] [:beta_bS 0.19621440146596547] [:beta_lice 0.16614719314835572] {:intro_day 32, :intro_duration 1, :distancing 1.024606244767797, :beta_b 0.06818428961187084, :beta_bS 0.1391747830274707, :beta_lice 0.14780650814426455, :beta_p 0.27853257654947244}
If I do not specify any initial points, BOPP runs fine, and feeds the run-epidemic function with the sampled maps of priors that the run-epidemic function expects.
(anglican.emit/with-primitive-procedures
[run-epidemic]
(defopt stochSIR [] [intro_day intro_duration distancing beta_b beta_bS beta_lice beta_p]
(let [intro_day (sample (uniform-discrete 30 80))
intro_duration (sample (uniform-discrete 0 5))
distancing (sample (uniform-continuous 0.5 1.3))
beta_b (sample (uniform-continuous 0 0.1))
beta_bS (sample (uniform-continuous 0 0.3))
beta_lice (sample (uniform-continuous 0 0.3))
beta_p (sample (uniform-continuous 0 0.3))
_ (println {:intro_day intro_day :intro_duration intro_duration :distancing distancing :beta_b beta_b :beta_bS beta_bS :beta_lice beta_lice :beta_p beta_p})
epidemic-score (run-epidemic {:intro_day intro_day :intro_duration intro_duration :distancing distancing :beta_b beta_b :beta_bS beta_bS :beta_lice beta_lice :beta_p beta_p})]
;;
;; scores that are higher than (log 2) are due to the classifier neural network guessing worse than random. No need to give that bonus-points for guessing worse than random, so the peak score lies at (log 2)
(observe (normal (log 2) 0.1) (:score epidemic-score)))))
I am getting a
clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: Method code too large!, compiling:(C:\Users\Boris\Boris\home\projects\methodlarge\src\methodlarge\core.clj:13:1)
error when feeding BOPP too many priors and a primitive procedure. Here is a minimal example with BOPP 0.1.5 with java version 1.8.0_191, in which the first defopt example spits the method code too large error. The problem doesn't seem to be with anglican, but with BOPP. Is there any way around it?
(ns methodlarge.core
(:require [bopp.core :refer :all])
(:require [anglican.core :refer :all])
(:require [anglican.runtime :refer :all])
(:require [anglican.emit :refer :all]))
;;
;; With a primitive procedure, defopt seems to have a max of 10 priors.
;; Adding s11 gives a "method code too large!"
;;
(defn dummy [n] n)
(anglican.emit/with-primitive-procedures [dummy]
(defopt condenser [] [s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11]
(let [s1 (sample (uniform-continuous 0 1))
s2 (sample (uniform-continuous 0 1))
s3 (sample (uniform-continuous 0 1))
s4 (sample (uniform-continuous 0 1))
s5 (sample (uniform-continuous 0 1))
s6 (sample (uniform-continuous 0 1))
s7 (sample (uniform-continuous 0 1))
s8 (sample (uniform-continuous 0 1))
s9 (sample (uniform-continuous 0 1))
s10 (sample (uniform-continuous 0 1))
s11 (sample (uniform-continuous 0 1))
score (+ s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11)]
(observe (normal 0 0.1) score))))
;;
;; Without the primitive procedure, defopt can deal with many priors
;;
(defopt condenser [] [s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13 s14 s15 s16 s17 s18 s19 s20]
(let [s1 (sample (uniform-continuous 0 1))
s2 (sample (uniform-continuous 0 1))
s3 (sample (uniform-continuous 0 1))
s4 (sample (uniform-continuous 0 1))
s5 (sample (uniform-continuous 0 1))
s6 (sample (uniform-continuous 0 1))
s7 (sample (uniform-continuous 0 1))
s8 (sample (uniform-continuous 0 1))
s9 (sample (uniform-continuous 0 1))
s10 (sample (uniform-continuous 0 1))
s11 (sample (uniform-continuous 0 1))
s12 (sample (uniform-continuous 0 1))
s13 (sample (uniform-continuous 0 1))
s14 (sample (uniform-continuous 0 1))
s15 (sample (uniform-continuous 0 1))
s16 (sample (uniform-continuous 0 1))
s17 (sample (uniform-continuous 0 1))
s18 (sample (uniform-continuous 0 1))
s19 (sample (uniform-continuous 0 1))
s20 (sample (uniform-continuous 0 1))
score (+ s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13 s14 s15 s16 s17 s18 s19 s20)]
(observe (normal 0 0.1) score)))
;;
;; the 11 priors sampled doesn't seem to be a restriction of anglican.
;;
(anglican.emit/with-primitive-procedures [dummy]
(defquery condenser []
(let [s1 (sample (uniform-continuous 0 1))
s2 (sample (uniform-continuous 0 1))
s3 (sample (uniform-continuous 0 1))
s4 (sample (uniform-continuous 0 1))
s5 (sample (uniform-continuous 0 1))
s6 (sample (uniform-continuous 0 1))
s7 (sample (uniform-continuous 0 1))
s8 (sample (uniform-continuous 0 1))
s9 (sample (uniform-continuous 0 1))
s10 (sample (uniform-continuous 0 1))
s11 (sample (uniform-continuous 0 1))
s12 (sample (uniform-continuous 0 1))
s13 (sample (uniform-continuous 0 1))
s14 (sample (uniform-continuous 0 1))
s15 (sample (uniform-continuous 0 1))
s16 (sample (uniform-continuous 0 1))
s17 (sample (uniform-continuous 0 1))
s18 (sample (uniform-continuous 0 1))
s19 (sample (uniform-continuous 0 1))
s20 (sample (uniform-continuous 0 1))
score (+ s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13 s14 s15 s16 s17 s18 s19 s20)]
(observe (normal 0 0.1) score))))
What I can find on the internet, is that some functions in clojure can generate errors like that. See:
https://stackoverflow.com/questions/26353658/for-vs-doseq-and-method-code-too-large
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.