 ;; **
 
 ;; @@
-(defquery polynomial-regression [inputs outputs]
-  (let [[w0 w1 w2] (doall (map (fn [std] (sample "w" (normal 0 std))) [10 1 0.1]))]
-    (doall (map (fn [input output]
-                  (observe (normal (+ w0 (* w1 input) (* w2 input input)) 3) output))
-                inputs
-                outputs))
-    [w0 w1 w2]))
+(defn poly [w x]
+  (reduce #(-> %1 (* x) (+ %2)) (reverse w)))
+
+(with-primitive-procedures [poly]
+  (defquery polynomial-regression [inputs outputs]
+    (let [w0 (sample "w0" (laplace 0 3))
+          w1 (sample "w1" (laplace 0 3))
+          w2 (sample "w2" (laplace 0 3))]
+      (map #(observe (student-t 4 (poly [w0 w1 w2] %1) 1) %2) inputs outputs)
+      [w0 w1 w2])))
 ;; @@
 ;; =>
 ;;; {"type":"html","content":"<span class='clj-var'>#&#x27;worksheets.polynomial-regression/polynomial-regression</span>","value":"#'worksheets.polynomial-regression/polynomial-regression"}
 ;; <=
 
-;; **
-;;; Define fixed inputs
-;; **
-
 ;; @@
 (def fixed-inputs (range -9 10 2))
+fixed-inputs
 ;; @@
 ;; =>
-;;; {"type":"html","content":"<span class='clj-var'>#&#x27;worksheets.polynomial-regression/fixed-inputs</span>","value":"#'worksheets.polynomial-regression/fixed-inputs"}
+;;; {"type":"html","content":"<span class='clj-unkown'>(-9 -7 -5 -3 -1 1 3 5 7 9)</span>","value":"(-9 -7 -5 -3 -1 1 3 5 7 9)"}
 ;; <=
 
 ;; **

(sample-observes-from-prior polynomial-regression [fixed-inputs (repeat 10 0)])
;; @@
;; =>
;;; {"type":"list-like","open":"<span class='clj-vector'>[</span>","close":"<span class='clj-vector'>]</span>","separator":" ","items":[{"type":"list-like","open":"<span class='clj-map'>{</span>","close":"<span class='clj-map'>}</span>","separator":", ","items":[{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:time-index</span>","value":":time-index"},{"type":"html","content":"<span class='clj-unkown'>0</span>","value":"0"}],"value":"[:time-index 0]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:observe-address</span>","value":":observe-address"},{"type":"html","content":"<span class='clj-symbol'>O27817</span>","value":"O27817"}],"value":"[:observe-address O27817]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:observe-instance</span>","value":":observe-instance"},{"type":"html","content":"<span class='clj-unkown'>0</span>","value":"0"}],"value":"[:observe-instance 0]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:value</span>","value":":value"},{"type":"html","content":"<span class='clj-double'>-20.31947962963023</span>","value":"-20.31947962963023"}],"value":"[:value -20.31947962963023]"}],"value":"{:time-index 0, :observe-address O27817, :observe-instance 0, :value -20.31947962963023}"},{"type":"list-like","open":"<span class='clj-map'>{</span>","close":"<span class='clj-map'>}</span>","separator":", ","items":[{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:time-index</span>","value":":time-index"},{"type":"html","content":"<span class='clj-unkown'>1</span>","value":"1"}],"value":"[:time-index 1]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:observe-address</span>","value":":observe-address"},{"type":"html","content":"<span class='clj-symbol'>O27817</span>","value":"O27817"}],"value":"[:observe-address O27817]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:observe-instance</span>","value":":observe-instance"},{"type":"html","content":"<span class='clj-unkown'>1</span>","value":"1"}],"value":"[:observe-instance 1]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:value</span>","value":":value"},{"type":"html","content":"<span class='clj-double'>-14.684162804356596</span>","value":"-14.684162804356596"}],"value":"[:value -14.684162804356596]"}],"value":"{:time-index 1, :observe-address O27817, :observe-instance 1, :value -14.684162804356596}"},{"type":"list-like","open":"<span class='clj-map'>{</span>","close":"<span class='clj-map'>}</span>","separator":", ","items":[{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:time-index</span>","value":":time-index"},{"type":"html","content":"<span class='clj-unkown'>2</span>","value":"2"}],"value":"[:time-index 2]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:observe-address</span>","value":":observe-address"},{"type":"html","content":"<span class='clj-symbol'>O27817</span>","value":"O27817"}],"value":"[:observe-address O27817]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:observe-instance</span>","value":":observe-instance"},{"type":"html","content":"<span class='clj-unkown'>2</span>","value":"2"}],"value":"[:observe-instance 2]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:value</span>","value":":value"},{"type":"html","content":"<span class='clj-double'>-16.333617361017446</span>","value":"-16.333617361017446"}],"value":"[:value -16.333617361017446]"}],"value":"{:time-index 2, :observe-address O27817, :observe-instance 2, :value -16.333617361017446}"},{"type":"list-like","open":"<span class='clj-map'>{</span>","close":"<span class='clj-map'>}</span>","separator":", ","items":[{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:time-index</span>","value":":time-index"},{"type":"html","content":"<span class='clj-unkown'>3</span>","value":"3"}],"value":"[:time-index 3]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:observe-address</span>","value":":observe-address"},{"type":"html","content":"<span class='clj-symbol'>O27817</span>","value":"O27817"}],"value":"[:observe-address O27817]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:observe-instance</span>","value":":observe-instance"},{"type":"html","content":"<span class='clj-unkown'>3</span>","value":"3"}],"value":"[:observe-instance 3]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:value</span>","value":":value"},{"type":"html","content":"<span class='clj-double'>-16.43220136479934</span>","value":"-16.43220136479934"}],"value":"[:value -16.43220136479934]"}],"value":"{:time-index 3, :observe-address O27817, :observe-instance 3, :value -16.43220136479934}"},{"type":"list-like","open":"<span class='clj-map'>{</span>","close":"<span class='clj-map'>}</span>","separator":", ","items":[{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:time-index</span>","value":":time-index"},{"type":"html","content":"<span class='clj-unkown'>4</span>","value":"4"}],"value":"[:time-index 4]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:observe-address</span>","value":":observe-address"},{"type":"html","content":"<span class='clj-symbol'>O27817</span>","value":"O27817"}],"value":"[:observe-address O27817]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:observe-instance</span>","value":":observe-instance"},{"type":"html","content":"<span class='clj-unkown'>4</span>","value":"4"}],"value":"[:observe-instance 4]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:value</span>","value":":value"},{"type":"html","content":"<span class='clj-double'>-15.694179741642296</span>","value":"-15.694179741642296"}],"value":"[:value -15.694179741642296]"}],"value":"{:time-index 4, :observe-address O27817, :observe-instance 4, :value -15.694179741642296}"},{"type":"list-like","open":"<span class='clj-map'>{</span>","close":"<span class='clj-map'>}</span>","separator":", ","items":[{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:time-index</span>","value":":time-index"},{"type":"html","content":"<span class='clj-unkown'>5</span>","value":"5"}],"value":"[:time-index 5]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:observe-address</span>","value":":observe-address"},{"type":"html","content":"<span class='clj-symbol'>O27817</span>","value":"O27817"}],"value":"[:observe-address O27817]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:observe-instance</span>","value":":observe-instance"},{"type":"html","content":"<span class='clj-unkown'>5</span>","value":"5"}],"value":"[:observe-instance 5]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:value</span>","value":":value"},{"type":"html","content":"<span class='clj-double'>-18.26116649207199</span>","value":"-18.26116649207199"}],"value":"[:value -18.26116649207199]"}],"value":"{:time-index 5, :observe-address O27817, :observe-instance 5, :value -18.26116649207199}"},{"type":"list-like","open":"<span class='clj-map'>{</span>","close":"<span class='clj-map'>}</span>","separator":", ","items":[{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:time-index</span>","value":":time-index"},{"type":"html","content":"<span class='clj-unkown'>6</span>","value":"6"}],"value":"[:time-index 6]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:observe-address</span>","value":":observe-address"},{"type":"html","content":"<span class='clj-symbol'>O27817</span>","value":"O27817"}],"value":"[:observe-address O27817]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:observe-instance</span>","value":":observe-instance"},{"type":"html","content":"<span class='clj-unkown'>6</span>","value":"6"}],"value":"[:observe-instance 6]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:value</span>","value":":value"},{"type":"html","content":"<span class='clj-double'>-14.974984361925312</span>","value":"-14.974984361925312"}],"value":"[:value -14.974984361925312]"}],"value":"{:time-index 6, :observe-address O27817, :observe-instance 6, :value -14.974984361925312}"},{"type":"list-like","open":"<span class='clj-map'>{</span>","close":"<span class='clj-map'>}</span>","separator":", ","items":[{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:time-index</span>","value":":time-index"},{"type":"html","content":"<span class='clj-unkown'>7</span>","value":"7"}],"value":"[:time-index 7]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:observe-address</span>","value":":observe-address"},{"type":"html","content":"<span class='clj-symbol'>O27817</span>","value":"O27817"}],"value":"[:observe-address O27817]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:observe-instance</span>","value":":observe-instance"},{"type":"html","content":"<span class='clj-unkown'>7</span>","value":"7"}],"value":"[:observe-instance 7]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:value</span>","value":":value"},{"type":"html","content":"<span class='clj-double'>-17.54782569797817</span>","value":"-17.54782569797817"}],"value":"[:value -17.54782569797817]"}],"value":"{:time-index 7, :observe-address O27817, :observe-instance 7, :value -17.54782569797817}"},{"type":"list-like","open":"<span class='clj-map'>{</span>","close":"<span class='clj-map'>}</span>","separator":", ","items":[{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:time-index</span>","value":":time-index"},{"type":"html","content":"<span class='clj-unkown'>8</span>","value":"8"}],"value":"[:time-index 8]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:observe-address</span>","value":":observe-address"},{"type":"html","content":"<span class='clj-symbol'>O27817</span>","value":"O27817"}],"value":"[:observe-address O27817]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:observe-instance</span>","value":":observe-instance"},{"type":"html","content":"<span class='clj-unkown'>8</span>","value":"8"}],"value":"[:observe-instance 8]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:value</span>","value":":value"},{"type":"html","content":"<span class='clj-double'>-24.401886271860867</span>","value":"-24.401886271860867"}],"value":"[:value -24.401886271860867]"}],"value":"{:time-index 8, :observe-address O27817, :observe-instance 8, :value -24.401886271860867}"},{"type":"list-like","open":"<span class='clj-map'>{</span>","close":"<span class='clj-map'>}</span>","separator":", ","items":[{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:time-index</span>","value":":time-index"},{"type":"html","content":"<span class='clj-unkown'>9</span>","value":"9"}],"value":"[:time-index 9]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:observe-address</span>","value":":observe-address"},{"type":"html","content":"<span class='clj-symbol'>O27817</span>","value":"O27817"}],"value":"[:observe-address O27817]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:observe-instance</span>","value":":observe-instance"},{"type":"html","content":"<span class='clj-unkown'>9</span>","value":"9"}],"value":"[:observe-instance 9]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":"<span class='clj-keyword'>:value</span>","value":":value"},{"type":"html","content":"<span class='clj-double'>-24.413211722081016</span>","value":"-24.413211722081016"}],"value":"[:value -24.413211722081016]"}],"value":"{:time-index 9, :observe-address O27817, :observe-instance 9, :value -24.413211722081016}"}],"value":"[{:time-index 0, :observe-address O27817, :observe-instance 0, :value -20.31947962963023} {:time-index 1, :observe-address O27817, :observe-instance 1, :value -14.684162804356596} {:time-index 2, :observe-address O27817, :observe-instance 2, :value -16.333617361017446} {:time-index 3, :observe-address O27817, :observe-instance 3, :value -16.43220136479934} {:time-index 4, :observe-address O27817, :observe-instance 4, :value -15.694179741642296} {:time-index 5, :observe-address O27817, :observe-instance 5, :value -18.26116649207199} {:time-index 6, :observe-address O27817, :observe-instance 6, :value -14.974984361925312} {:time-index 7, :observe-address O27817, :observe-instance 7, :value -17.54782569797817} {:time-index 8, :observe-address O27817, :observe-instance 8, :value -24.401886271860867} {:time-index 9, :observe-address O27817, :observe-instance 9, :value -24.413211722081016}]"}
;; <=

;; **

;; **

;; @@
(def w0 1)
(def w1 1)
(def w2 1)
(def test-outputs (mapv #(sample* (laplace (+ w0 (* w1 %) (* w2 % %)) 1)) fixed-inputs))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-var'>#&#x27;worksheets.polynomial-regression/test-outputs</span>","value":"#'worksheets.polynomial-regression/test-outputs"}
