Skip to content

Commit

Permalink
minor indentation stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
tuananhle7 committed Aug 8, 2017
1 parent 01faa27 commit a5a7016
Showing 1 changed file with 71 additions and 73 deletions.
144 changes: 71 additions & 73 deletions src/bopp/program_transformations.clj
Expand Up @@ -70,42 +70,41 @@
(vector? expr) (mapv #(acq-prior-helper-transformation % optim-args mode :acq-f acq-f) expr)
(map? expr) (update-values expr #(acq-prior-helper-transformation % optim-args mode :acq-f acq-f))
(set? expr) (set (map #(acq-prior-helper-transformation % optim-args mode :acq-f acq-f) expr))
(seq? expr)
(let [[kwd & args] expr]
(case kwd
observe nil
let (loop [bindings (first args)
transformed-bindings []]
(if (empty? bindings)
(apply list kwd (vec transformed-bindings) (map #(acq-prior-helper-transformation % optim-args mode :acq-f acq-f) (rest args)))
(let [[name value] (take 2 bindings)]
(recur (drop 2 bindings)
(concat transformed-bindings [name (if (some #(= name %) optim-args)
`(~'let [~'value ~(acq-prior-helper-transformation value optim-args mode :acq-f acq-f)]

;; Error checking for detecting multiple instances of declaration of optim-vars during runtime.
(~'if (~'retrieve (~'symbol ~optim-args-key)
(~'symbol ~(str name)))
(~'throw-exception ~(str "BOPP ERROR: Multiple instances of declaration of optimization variable " (str name) " detected!")))

;; Store the sampled value in store-retrieve hashmap
(~'store (~'symbol ~optim-args-key)
(~'symbol ~(str name))
~'value)

(~'if (~'= (~'set (~'keys (~'retrieve (~'symbol ~optim-args-key))))
(~'set ~(mapv #(list 'symbol (str %)) optim-args)))
(~'return ~(cond (= mode "acq")
(acq-prologue-code optim-args acq-f)

(= mode "prior")
(prior-prologue-code optim-args))))

~'value)
(acq-prior-helper-transformation value optim-args mode :acq-f acq-f))])))))

;; else
(map #(acq-prior-helper-transformation % optim-args mode :acq-f acq-f) expr)))
(seq? expr) (let [[kwd & args] expr]
(case kwd
observe nil
let (loop [bindings (first args)
transformed-bindings []]
(if (empty? bindings)
(apply list kwd (vec transformed-bindings) (map #(acq-prior-helper-transformation % optim-args mode :acq-f acq-f) (rest args)))
(let [[name value] (take 2 bindings)]
(recur (drop 2 bindings)
(concat transformed-bindings [name (if (some #(= name %) optim-args)
`(~'let [~'value ~(acq-prior-helper-transformation value optim-args mode :acq-f acq-f)]

;; Error checking for detecting multiple instances of declaration of optim-vars during runtime.
(~'if (~'retrieve (~'symbol ~optim-args-key)
(~'symbol ~(str name)))
(~'throw-exception ~(str "BOPP ERROR: Multiple instances of declaration of optimization variable " (str name) " detected!")))

;; Store the sampled value in store-retrieve hashmap
(~'store (~'symbol ~optim-args-key)
(~'symbol ~(str name))
~'value)

(~'if (~'= (~'set (~'keys (~'retrieve (~'symbol ~optim-args-key))))
(~'set ~(mapv #(list 'symbol (str %)) optim-args)))
(~'return ~(cond (= mode "acq")
(acq-prologue-code optim-args acq-f)

(= mode "prior")
(prior-prologue-code optim-args))))

~'value)
(acq-prior-helper-transformation value optim-args mode :acq-f acq-f))])))))

;; else
(map #(acq-prior-helper-transformation % optim-args mode :acq-f acq-f) expr)))
:else expr))

(defn- prior-transformation
Expand Down Expand Up @@ -189,45 +188,44 @@
replaced by a deterministic assignment."
[expr optim-args mode]
(cond
(vector? expr) (mapv #(marg-transformation % optim-args mode) expr)
(map? expr) (update-values expr #(marg-transformation % optim-args mode))
(set? expr) (set (map #(marg-transformation % optim-args mode) expr))
(seq? expr)
(let [[kwd & args] expr]
(case kwd
let (loop [bindings (first args)
transformed-bindings []]
(if (empty? bindings)
(apply list kwd (vec transformed-bindings) (map #(marg-transformation % optim-args mode) (rest args)))
(let [[name value & bindings] bindings]
(recur bindings
(concat transformed-bindings
[name (if (some #(= name %) optim-args)
(if (= (first value) 'sample)
`(~'do
;; Error checking for detecting instances of declaration of optim-vars during runtime.
(~'if (~'retrieve (~'symbol ~optim-args-key)
(~'symbol ~(str name)))
(~'throw-exception ~(str "BOPP ERROR: Multiple instances of declaration of optimization variable " (str name) " detected!")))

;; Store the sampled value in store-retrieve hashmap
(~'store (~'symbol ~optim-args-key)
(~'symbol ~(str name))
~(symbol (str (str name) "-hat")))

~(cond (= mode "mmap")
`(~'observe ~(marg-transformation (second value) optim-args mode) ~(symbol (str (str name) "-hat")))

(= mode "ml2")
nil)
(vector? expr) (mapv #(marg-transformation % optim-args mode) expr)
(map? expr) (update-values expr #(marg-transformation % optim-args mode))
(set? expr) (set (map #(marg-transformation % optim-args mode) expr))
(seq? expr) (let [[kwd & args] expr]
(case kwd
let (loop [bindings (first args)
transformed-bindings []]
(if (empty? bindings)
(apply list kwd (vec transformed-bindings) (map #(marg-transformation % optim-args mode) (rest args)))
(let [[name value & bindings] bindings]
(recur bindings
(concat transformed-bindings
[name (if (some #(= name %) optim-args)
(if (= (first value) 'sample)
`(~'do
;; Error checking for detecting instances of declaration of optim-vars during runtime.
(~'if (~'retrieve (~'symbol ~optim-args-key)
(~'symbol ~(str name)))
(~'throw-exception ~(str "BOPP ERROR: Multiple instances of declaration of optimization variable " (str name) " detected!")))

;; Store the sampled value in store-retrieve hashmap
(~'store (~'symbol ~optim-args-key)
(~'symbol ~(str name))
~(symbol (str (str name) "-hat")))

~(cond (= mode "mmap")
`(~'observe ~(marg-transformation (second value) optim-args mode) ~(symbol (str (str name) "-hat")))

(= mode "ml2")
nil)

~(symbol (str (str name) "-hat")))
(throw-exception "BOPP ERROR: Prior of optimization variables must be defined directly by a sample statement."))
(marg-transformation value optim-args mode))])))))
~(symbol (str (str name) "-hat")))
(throw-exception "BOPP ERROR: Prior of optimization variables must be defined directly by a sample statement."))
(marg-transformation value optim-args mode))])))))

;; else
(map #(marg-transformation % optim-args mode) expr)))
:else expr))
;; else
(map #(marg-transformation % optim-args mode) expr)))
:else expr))

(defmacro mmap-query
"Returns CPS'd query with the MMAP transformation applied."
Expand Down

0 comments on commit a5a7016

Please sign in to comment.