Simple regression

Simple regression

error: pathspec 'examples/src/worksheets/regression_simple.clj' did not match any file(s) known to git

--- examples/src/worksheets/regression_simple.clj
+++ examples/src/worksheets/regression_simple.clj
@@ -0,0 +1,132 @@
+;; gorilla-repl.fileformat = 1
+
+;; **
+;;; # Simple polynomial regression
+;; **
+
+;; @@
+(ns regression
+  (:require [gorilla-plot.core :as plot]
+            [anglican.stat :as s]
+            [anglican.stat :refer [empirical-distribution collect-results]]
+            anglican.infcomp.csis
+            anglican.smc
+            [anglican.infcomp.network :refer :all]
+            [anglican.infcomp.prior :refer [sample-from-prior]]
+            [anglican.inference :refer [infer]]
+            [helpers.general :refer [empirical-MAP]]
+            [anglican.stat :refer [collect-results]])
+  (:use [anglican core emit runtime])
+  (:import [javax.imageio ImageIO]
+           [java.io File]))
+;; @@
+;; =>
+;;; {"type":"html","content":"nil","value":"nil"}
+;; <=
+
+;; **
+;;; ## Generative model
+;; **
+
+;; @@
+(defn poly [w x]
+  (reduce #(-> %1 (* x) (+ %2)) (reverse w)))
+
+(with-primitive-procedures [poly]
+  (defquery regress [data-x data-y]
+  (let [w0 (sample "w0" (normal 0 2))
+        w1 (sample "w1" (normal 0 2))
+        w2 (sample "w2" (normal 0 2))]
+    (map #(observe (normal (poly [w0 w1 w2] %1) 0.01) %2) data-x data-y)
+    [w0 w1 w2])))
+;; @@
+;; =>
+;;; {"type":"html","content":"#'regression/regress","value":"#'regression/regress"}
+;; <=
+
+;; **
+;;; ## Train a compilation artifact
+;; **
+
+;; @@
+(defn combine-observes-fn [observes]
+  (vec (map :value observes)))
+;; @@
+;; =>
+;;; {"type":"html","content":"#'regression/combine-observes-fn","value":"#'regression/combine-observes-fn"}
+;; <=
+
+;; @@
+(sample-observes-from-prior regress [[1 2 3] [2 4 9]])
+;; @@
+;; =>
+;;; {"type":"list-like","open":"[","close":"]","separator":" ","items":[{"type":"list-like","open":"{","close":"}","separator":", ","items":[{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":":time-index","value":":time-index"},{"type":"html","content":"0","value":"0"}],"value":"[:time-index 0]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":":observe-address","value":":observe-address"},{"type":"html","content":"O27435","value":"O27435"}],"value":"[:observe-address O27435]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":":observe-instance","value":":observe-instance"},{"type":"html","content":"0","value":"0"}],"value":"[:observe-instance 0]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":":value","value":":value"},{"type":"html","content":"-3.1452462248223987","value":"-3.1452462248223987"}],"value":"[:value -3.1452462248223987]"}],"value":"{:time-index 0, :observe-address O27435, :observe-instance 0, :value -3.1452462248223987}"},{"type":"list-like","open":"{","close":"}","separator":", ","items":[{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":":time-index","value":":time-index"},{"type":"html","content":"1","value":"1"}],"value":"[:time-index 1]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":":observe-address","value":":observe-address"},{"type":"html","content":"O27435","value":"O27435"}],"value":"[:observe-address O27435]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":":observe-instance","value":":observe-instance"},{"type":"html","content":"1","value":"1"}],"value":"[:observe-instance 1]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":":value","value":":value"},{"type":"html","content":"-7.9209826915028385","value":"-7.9209826915028385"}],"value":"[:value -7.9209826915028385]"}],"value":"{:time-index 1, :observe-address O27435, :observe-instance 1, :value -7.9209826915028385}"},{"type":"list-like","open":"{","close":"}","separator":", ","items":[{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":":time-index","value":":time-index"},{"type":"html","content":"2","value":"2"}],"value":"[:time-index 2]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":":observe-address","value":":observe-address"},{"type":"html","content":"O27435","value":"O27435"}],"value":"[:observe-address O27435]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":":observe-instance","value":":observe-instance"},{"type":"html","content":"2","value":"2"}],"value":"[:observe-instance 2]"},{"type":"list-like","open":"","close":"","separator":" ","items":[{"type":"html","content":":value","value":":value"},{"type":"html","content":"-14.48406618161862","value":"-14.48406618161862"}],"value":"[:value -14.48406618161862]"}],"value":"{:time-index 2, :observe-address O27435, :observe-instance 2, :value -14.48406618161862}"}],"value":"[{:time-index 0, :observe-address O27435, :observe-instance 0, :value -3.1452462248223987} {:time-index 1, :observe-address O27435, :observe-instance 1, :value -7.9209826915028385} {:time-index 2, :observe-address O27435, :observe-instance 2, :value -14.48406618161862}]"}
+;; <=
+
+;; @@
+(combine-observes-fn (sample-observes-from-prior regress [[1 2 3] [2 4 9]]))
+;; @@
+;; =>
+;;; {"type":"list-like","open":"[","close":"]","separator":" ","items":[{"type":"html","content":"-2.4481525899017407","value":"-2.4481525899017407"},{"type":"html","content":"-5.190016929823806","value":"-5.190016929823806"},{"type":"html","content":"-8.19015981936462","value":"-8.19015981936462"}],"value":"[-2.4481525899017407 -5.190016929823806 -8.19015981936462]"}
+;; <=
+
+;; @@
+;; Start the Torch connection
+(def torch-connection (start-torch-connection regress [[1 2 3 4] [2 4 9 16]] combine-observes-fn))
+;; @@
+;; =>
+;;; {"type":"html","content":"#'regression/torch-connection","value":"#'regression/torch-connection"}
+;; <=
+
+;; @@
+(stop-torch-connection torch-connection)
+;; @@
+;; =>
+;;; {"type":"html","content":""Torch connection terminated."","value":"\"Torch connection terminated.\""}
+;; <=
+
+;; @@
+(def test-data [[1 2 3 4] [20 40 90 160]])
+(def num-particles 100)
+(def w-map
+  (->> (doquery :importance regress test-data :number-of-particles num-particles)
+    (take num-particles)
+    s/collect-results
+    (empirical-MAP)))
+w-map
+;; @@
+;; =>
+;;; {"type":"list-like","open":"[","close":"]","separator":" ","items":[{"type":"html","content":"2.7741314869263984","value":"2.7741314869263984"},{"type":"html","content":"-0.0350547156004849","value":"-0.0350547156004849"},{"type":"html","content":"4.948735802591503","value":"4.948735802591503"}],"value":"[2.7741314869263984 -0.0350547156004849 4.948735802591503]"}
+;; <=
+
+;; @@
+(plot/compose
+  (plot/list-plot (map #(vec [%1 %2]) (first test-data) (second test-data)))
+  (plot/plot (partial poly w-map) [(apply min (first test-data)) (apply max (first test-data))]))
+;; @@
+;; =>
+;;; {"type":"vega","content":{"width":400,"height":247.2187957763672,"padding":{"top":10,"left":55,"bottom":40,"right":10},"scales":[{"name":"x","type":"linear","range":"width","zero":false,"domain":{"data":"4e436413-20a9-44dd-a1ea-2bb7846f2f52","field":"data.x"}},{"name":"y","type":"linear","range":"height","nice":true,"zero":false,"domain":{"data":"4e436413-20a9-44dd-a1ea-2bb7846f2f52","field":"data.y"}}],"axes":[{"type":"x","scale":"x"},{"type":"y","scale":"y"}],"data":[{"name":"4e436413-20a9-44dd-a1ea-2bb7846f2f52","values":[{"x":1,"y":20},{"x":2,"y":40},{"x":3,"y":90},{"x":4,"y":160}]},{"name":"ebb6c5ea-6be2-4a3a-bae0-d98995af29ff","values":[{"x":1,"y":7.687812573917416},{"x":1.0299999993294477,"y":7.988138936014855},{"x":1.0599999986588955,"y":8.297373022158752},{"x":1.0899999979883432,"y":8.615514832349108},{"x":1.119999997317791,"y":8.942564366585922},{"x":1.1499999966472387,"y":9.278521624869196},{"x":1.1799999959766865,"y":9.623386607198926},{"x":1.2099999953061342,"y":9.977159313575115},{"x":1.239999994635582,"y":10.339839743997763},{"x":1.2699999939650297,"y":10.71142789846687},{"x":1.2999999932944775,"y":11.091923776982433},{"x":1.3299999926239252,"y":11.481327379544457},{"x":1.359999991953373,"y":11.879638706152937},{"x":1.3899999912828207,"y":12.286857756807878},{"x":1.4199999906122684,"y":12.702984531509275},{"x":1.4499999899417162,"y":13.128019030257132},{"x":1.479999989271164,"y":13.561961253051447},{"x":1.5099999886006117,"y":14.00481119989222},{"x":1.5399999879300594,"y":14.456568870779451},{"x":1.5699999872595072,"y":14.917234265713143},{"x":1.599999986588955,"y":15.38680738469329},{"x":1.6299999859184027,"y":15.865288227719898},{"x":1.6599999852478504,"y":16.352676794792963},{"x":1.6899999845772982,"y":16.848973085912487},{"x":1.719999983906746,"y":17.35417710107847},{"x":1.7499999832361937,"y":17.86828884029091},{"x":1.7799999825656414,"y":18.391308303549806},{"x":1.8099999818950891,"y":18.923235490855163},{"x":1.839999981224537,"y":19.464070402206985},{"x":1.8699999805539846,"y":20.013813037605253},{"x":1.8999999798834324,"y":20.572463397049987},{"x":1.9299999792128801,"y":21.14002148054118},{"x":1.9599999785423279,"y":21.71648728807883},{"x":1.9899999778717756,"y":22.301860819662934},{"x":2.0199999772012234,"y":22.896142075293504},{"x":2.049999976530671,"y":23.499331054970526},{"x":2.079999975860119,"y":24.111427758694013},{"x":2.1099999751895666,"y":24.732432186463946},{"x":2.1399999745190144,"y":25.36234433828035},{"x":2.169999973848462,"y":26.00116421414321},{"x":2.19999997317791,"y":26.648891814052526},{"x":2.2299999725073576,"y":27.305527138008294},{"x":2.2599999718368053,"y":27.97107018601053},{"x":2.289999971166253,"y":28.645520958059222},{"x":2.319999970495701,"y":29.328879454154375},{"x":2.3499999698251486,"y":30.02114567429598},{"x":2.3799999691545963,"y":30.72231961848405},{"x":2.409999968484044,"y":31.432401286718573},{"x":2.439999967813492,"y":32.15139067899956},{"x":2.4699999671429396,"y":32.879287795326995},{"x":2.4999999664723873,"y":33.6160926357009},{"x":2.529999965801835,"y":34.36180520012126},{"x":2.559999965131283,"y":35.11642548858808},{"x":2.5899999644607306,"y":35.879953501101355},{"x":2.6199999637901783,"y":36.65238923766108},{"x":2.649999963119626,"y":37.43373269826728},{"x":2.679999962449074,"y":38.22398388291993},{"x":2.7099999617785215,"y":39.02314279161904},{"x":2.7399999611079693,"y":39.83120942436461},{"x":2.769999960437417,"y":40.64818378115663},{"x":2.7999999597668648,"y":41.47406586199512},{"x":2.8299999590963125,"y":42.308855666880056},{"x":2.8599999584257603,"y":43.15255319581146},{"x":2.889999957755208,"y":44.005158448789324},{"x":2.9199999570846558,"y":44.86667142581364},{"x":2.9499999564141035,"y":45.73709212688441},{"x":2.9799999557435513,"y":46.61642055200165},{"x":3.009999955072999,"y":47.504656701165345},{"x":3.0399999544024467,"y":48.40180057437549},{"x":3.0699999537318945,"y":49.3078521716321},{"x":3.0999999530613422,"y":50.22281149293517},{"x":3.12999995239079,"y":51.1466785382847},{"x":3.1599999517202377,"y":52.07945330768069},{"x":3.1899999510496855,"y":53.02113580112312},{"x":3.2199999503791332,"y":53.97172601861203},{"x":3.249999949708581,"y":54.93122396014739},{"x":3.2799999490380287,"y":55.899629625729204},{"x":3.3099999483674765,"y":56.87694301535749},{"x":3.339999947696924,"y":57.86316412903222},{"x":3.369999947026372,"y":58.85829296675341},{"x":3.3999999463558197,"y":59.862329528521066},{"x":3.4299999456852674,"y":60.87527381433517},{"x":3.459999945014715,"y":61.897125824195754},{"x":3.489999944344163,"y":62.92788555810277},{"x":3.5199999436736107,"y":63.96755301605626},{"x":3.5499999430030584,"y":65.01612819805621},{"x":3.579999942332506,"y":66.0736111041026},{"x":3.609999941661954,"y":67.14000173419545},{"x":3.6399999409914017,"y":68.21530008833479},{"x":3.6699999403208494,"y":69.29950616652056},{"x":3.699999939650297,"y":70.3926199687528},{"x":3.729999938979745,"y":71.49464149503149},{"x":3.7599999383091927,"y":72.60557074535663},{"x":3.7899999376386404,"y":73.72540771972825},{"x":3.819999936968088,"y":74.85415241814633},{"x":3.849999936297536,"y":75.99180484061084},{"x":3.8799999356269836,"y":77.13836498712183},{"x":3.9099999349564314,"y":78.29383285767928},{"x":3.939999934285879,"y":79.45820845228319},{"x":3.969999933615327,"y":80.63149177093355},{"x":3.9999999329447746,"y":81.81368281363036}]}],"marks":[{"type":"symbol","from":{"data":"4e436413-20a9-44dd-a1ea-2bb7846f2f52"},"properties":{"enter":{"x":{"scale":"x","field":"data.x"},"y":{"scale":"y","field":"data.y"},"fill":{"value":"steelblue"},"fillOpacity":{"value":1}},"update":{"shape":"circle","size":{"value":70},"stroke":{"value":"transparent"}},"hover":{"size":{"value":210},"stroke":{"value":"white"}}}},{"type":"line","from":{"data":"ebb6c5ea-6be2-4a3a-bae0-d98995af29ff"},"properties":{"enter":{"x":{"scale":"x","field":"data.x"},"y":{"scale":"y","field":"data.y"},"stroke":{"value":"#FF29D2"},"strokeWidth":{"value":2},"strokeOpacity":{"value":1}}}}]},"value":"#gorilla_repl.vega.VegaView{:content {:width 400, :height 247.2188, :padding {:top 10, :left 55, :bottom 40, :right 10}, :scales [{:name \"x\", :type \"linear\", :range \"width\", :zero false, :domain {:data \"4e436413-20a9-44dd-a1ea-2bb7846f2f52\", :field \"data.x\"}} {:name \"y\", :type \"linear\", :range \"height\", :nice true, :zero false, :domain {:data \"4e436413-20a9-44dd-a1ea-2bb7846f2f52\", :field \"data.y\"}}], :axes [{:type \"x\", :scale \"x\"} {:type \"y\", :scale \"y\"}], :data ({:name \"4e436413-20a9-44dd-a1ea-2bb7846f2f52\", :values ({:x 1, :y 20} {:x 2, :y 40} {:x 3, :y 90} {:x 4, :y 160})} {:name \"ebb6c5ea-6be2-4a3a-bae0-d98995af29ff\", :values ({:x 1, :y 7.687812573917416} {:x 1.0299999993294477, :y 7.988138936014855} {:x 1.0599999986588955, :y 8.297373022158752} {:x 1.0899999979883432, :y 8.615514832349108} {:x 1.119999997317791, :y 8.942564366585922} {:x 1.1499999966472387, :y 9.278521624869196} {:x 1.1799999959766865, :y 9.623386607198926} {:x 1.2099999953061342, :y 9.977159313575115} {:x 1.239999994635582, :y 10.339839743997763} {:x 1.2699999939650297, :y 10.71142789846687} {:x 1.2999999932944775, :y 11.091923776982433} {:x 1.3299999926239252, :y 11.481327379544457} {:x 1.359999991953373, :y 11.879638706152937} {:x 1.3899999912828207, :y 12.286857756807878} {:x 1.4199999906122684, :y 12.702984531509275} {:x 1.4499999899417162, :y 13.128019030257132} {:x 1.479999989271164, :y 13.561961253051447} {:x 1.5099999886006117, :y 14.00481119989222} {:x 1.5399999879300594, :y 14.456568870779451} {:x 1.5699999872595072, :y 14.917234265713143} {:x 1.599999986588955, :y 15.38680738469329} {:x 1.6299999859184027, :y 15.865288227719898} {:x 1.6599999852478504, :y 16.352676794792963} {:x 1.6899999845772982, :y 16.848973085912487} {:x 1.719999983906746, :y 17.35417710107847} {:x 1.7499999832361937, :y 17.86828884029091} {:x 1.7799999825656414, :y 18.391308303549806} {:x 1.8099999818950891, :y 18.923235490855163} {:x 1.839999981224537, :y 19.464070402206985} {:x 1.8699999805539846, :y 20.013813037605253} {:x 1.8999999798834324, :y 20.572463397049987} {:x 1.9299999792128801, :y 21.14002148054118} {:x 1.9599999785423279, :y 21.71648728807883} {:x 1.9899999778717756, :y 22.301860819662934} {:x 2.0199999772012234, :y 22.896142075293504} {:x 2.049999976530671, :y 23.499331054970526} {:x 2.079999975860119, :y 24.111427758694013} {:x 2.1099999751895666, :y 24.732432186463946} {:x 2.1399999745190144, :y 25.36234433828035} {:x 2.169999973848462, :y 26.00116421414321} {:x 2.19999997317791, :y 26.648891814052526} {:x 2.2299999725073576, :y 27.305527138008294} {:x 2.2599999718368053, :y 27.97107018601053} {:x 2.289999971166253, :y 28.645520958059222} {:x 2.319999970495701, :y 29.328879454154375} {:x 2.3499999698251486, :y 30.02114567429598} {:x 2.3799999691545963, :y 30.72231961848405} {:x 2.409999968484044, :y 31.432401286718573} {:x 2.439999967813492, :y 32.15139067899956} {:x 2.4699999671429396, :y 32.879287795326995} {:x 2.4999999664723873, :y 33.6160926357009} {:x 2.529999965801835, :y 34.36180520012126} {:x 2.559999965131283, :y 35.11642548858808} {:x 2.5899999644607306, :y 35.879953501101355} {:x 2.6199999637901783, :y 36.65238923766108} {:x 2.649999963119626, :y 37.43373269826728} {:x 2.679999962449074, :y 38.22398388291993} {:x 2.7099999617785215, :y 39.02314279161904} {:x 2.7399999611079693, :y 39.83120942436461} {:x 2.769999960437417, :y 40.64818378115663} {:x 2.7999999597668648, :y 41.47406586199512} {:x 2.8299999590963125, :y 42.308855666880056} {:x 2.8599999584257603, :y 43.15255319581146} {:x 2.889999957755208, :y 44.005158448789324} {:x 2.9199999570846558, :y 44.86667142581364} {:x 2.9499999564141035, :y 45.73709212688441} {:x 2.9799999557435513, :y 46.61642055200165} {:x 3.009999955072999, :y 47.504656701165345} {:x 3.0399999544024467, :y 48.40180057437549} {:x 3.0699999537318945, :y 49.3078521716321} {:x 3.0999999530613422, :y 50.22281149293517} {:x 3.12999995239079, :y 51.1466785382847} {:x 3.1599999517202377, :y 52.07945330768069} {:x 3.1899999510496855, :y 53.02113580112312} {:x 3.2199999503791332, :y 53.97172601861203} {:x 3.249999949708581, :y 54.93122396014739} {:x 3.2799999490380287, :y 55.899629625729204} {:x 3.3099999483674765, :y 56.87694301535749} {:x 3.339999947696924, :y 57.86316412903222} {:x 3.369999947026372, :y 58.85829296675341} {:x 3.3999999463558197, :y 59.862329528521066} {:x 3.4299999456852674, :y 60.87527381433517} {:x 3.459999945014715, :y 61.897125824195754} {:x 3.489999944344163, :y 62.92788555810277} {:x 3.5199999436736107, :y 63.96755301605626} {:x 3.5499999430030584, :y 65.01612819805621} {:x 3.579999942332506, :y 66.0736111041026} {:x 3.609999941661954, :y 67.14000173419545} {:x 3.6399999409914017, :y 68.21530008833479} {:x 3.6699999403208494, :y 69.29950616652056} {:x 3.699999939650297, :y 70.3926199687528} {:x 3.729999938979745, :y 71.49464149503149} {:x 3.7599999383091927, :y 72.60557074535663} {:x 3.7899999376386404, :y 73.72540771972825} {:x 3.819999936968088, :y 74.85415241814633} {:x 3.849999936297536, :y 75.99180484061084} {:x 3.8799999356269836, :y 77.13836498712183} {:x 3.9099999349564314, :y 78.29383285767928} {:x 3.939999934285879, :y 79.45820845228319} {:x 3.969999933615327, :y 80.63149177093355} {:x 3.9999999329447746, :y 81.81368281363036})}), :marks ({:type \"symbol\", :from {:data \"4e436413-20a9-44dd-a1ea-2bb7846f2f52\"}, :properties {:enter {:x {:scale \"x\", :field \"data.x\"}, :y {:scale \"y\", :field \"data.y\"}, :fill {:value \"steelblue\"}, :fillOpacity {:value 1}}, :update {:shape \"circle\", :size {:value 70}, :stroke {:value \"transparent\"}}, :hover {:size {:value 210}, :stroke {:value \"white\"}}}} {:type \"line\", :from {:data \"ebb6c5ea-6be2-4a3a-bae0-d98995af29ff\"}, :properties {:enter {:x {:scale \"x\", :field \"data.x\"}, :y {:scale \"y\", :field \"data.y\"}, :stroke {:value \"#FF29D2\"}, :strokeWidth {:value 2}, :strokeOpacity {:value 1}}}})}}"}
+;; <=
+
+;; @@
+(def num-particles 1)
+(def csis-states (take num-particles (infer :csis regress test-data :observe-embedder-input (second test-data))))
+(def w-map-csis (empirical-MAP (s/collect-results csis-states)))
+w-map-csis
+;; @@
+;; =>
+;;; {"type":"list-like","open":"[","close":"]","separator":" ","items":[{"type":"html","content":"3.1621068162122796","value":"3.1621068162122796"},{"type":"html","content":"3.71794605038581","value":"3.71794605038581"},{"type":"html","content":"6.220383679082838","value":"6.220383679082838"}],"value":"[3.1621068162122796 3.71794605038581 6.220383679082838]"}
+;; <=
+
+;; @@
+(plot/compose
+  (plot/list-plot (map #(vec [%1 %2]) (first test-data) (second test-data)))
+  (plot/plot (partial poly w-map-csis) [(apply min (first test-data)) (apply max (first test-data))]))
+;; @@
+;; =>
+;;; {"type":"vega","content":{"width":400,"height":247.2187957763672,"padding":{"top":10,"left":55,"bottom":40,"right":10},"scales":[{"name":"x","type":"linear","range":"width","zero":false,"domain":{"data":"d23d11a3-0962-4f50-8429-9f464a060ee3","field":"data.x"}},{"name":"y","type":"linear","range":"height","nice":true,"zero":false,"domain":{"data":"d23d11a3-0962-4f50-8429-9f464a060ee3","field":"data.y"}}],"axes":[{"type":"x","scale":"x"},{"type":"y","scale":"y"}],"data":[{"name":"d23d11a3-0962-4f50-8429-9f464a060ee3","values":[{"x":1,"y":20},{"x":2,"y":40},{"x":3,"y":90},{"x":4,"y":160}]},{"name":"113ad830-576c-4707-8297-fcd8b272d48f","values":[{"x":1,"y":13.100436545680928},{"x":1.0299999993294477,"y":13.59079628216312},{"x":1.0599999986588955,"y":14.09235270876713},{"x":1.0899999979883432,"y":14.605105825492958},{"x":1.119999997317791,"y":15.129055632340604},{"x":1.1499999966472387,"y":15.664202129310068},{"x":1.1799999959766865,"y":16.21054531640135},{"x":1.2099999953061342,"y":16.76808519361445},{"x":1.239999994635582,"y":17.33682176094937},{"x":1.2699999939650297,"y":17.916755018406107},{"x":1.2999999932944775,"y":18.50788496598466},{"x":1.3299999926239252,"y":19.11021160368503},{"x":1.359999991953373,"y":19.723734931507224},{"x":1.3899999912828207,"y":20.34845494945123},{"x":1.4199999906122684,"y":20.98437165751706},{"x":1.4499999899417162,"y":21.6314850557047},{"x":1.479999989271164,"y":22.289795144014164},{"x":1.5099999886006117,"y":22.959301922445444},{"x":1.5399999879300594,"y":23.640005390998542},{"x":1.5699999872595072,"y":24.33190554967346},{"x":1.599999986588955,"y":25.035002398470194},{"x":1.6299999859184027,"y":25.749295937388748},{"x":1.6599999852478504,"y":26.474786166429116},{"x":1.6899999845772982,"y":27.211473085591305},{"x":1.719999983906746,"y":27.95935669487531},{"x":1.7499999832361937,"y":28.718436994281138},{"x":1.7799999825656414,"y":29.48871398380878},{"x":1.8099999818950891,"y":30.27018766345824},{"x":1.839999981224537,"y":31.06285803322952},{"x":1.8699999805539846,"y":31.866725093122618},{"x":1.8999999798834324,"y":32.68178884313753},{"x":1.9299999792128801,"y":33.50804928327426},{"x":1.9599999785423279,"y":34.34550641353282},{"x":1.9899999778717756,"y":35.19416023391319},{"x":2.0199999772012234,"y":36.05401074441537},{"x":2.049999976530671,"y":36.92505794503938},{"x":2.079999975860119,"y":37.807301835785196},{"x":2.1099999751895666,"y":38.700742416652844},{"x":2.1399999745190144,"y":39.6053796876423},{"x":2.169999973848462,"y":40.52121364875358},{"x":2.19999997317791,"y":41.44824429998667},{"x":2.2299999725073576,"y":42.386471641341586},{"x":2.2599999718368053,"y":43.33589567281832},{"x":2.289999971166253,"y":44.29651639441687},{"x":2.319999970495701,"y":45.268333806137235},{"x":2.3499999698251486,"y":46.25134790797942},{"x":2.3799999691545963,"y":47.24555869994342},{"x":2.409999968484044,"y":48.250966182029245},{"x":2.439999967813492,"y":49.26757035423688},{"x":2.4699999671429396,"y":50.295371216566345},{"x":2.4999999664723873,"y":51.334368769017615},{"x":2.529999965801835,"y":52.384563011590714},{"x":2.559999965131283,"y":53.44595394428563},{"x":2.5899999644607306,"y":54.518541567102346},{"x":2.6199999637901783,"y":55.6023258800409},{"x":2.649999963119626,"y":56.69730688310126},{"x":2.679999962449074,"y":57.80348457628345},{"x":2.7099999617785215,"y":58.92085895958745},{"x":2.7399999611079693,"y":60.04943003301327},{"x":2.769999960437417,"y":61.189197796560904},{"x":2.7999999597668648,"y":62.34016225023037},{"x":2.8299999590963125,"y":63.50232339402164},{"x":2.8599999584257603,"y":64.67568122793475},{"x":2.889999957755208,"y":65.86023575196964},{"x":2.9199999570846558,"y":67.05598696612637},{"x":2.9499999564141035,"y":68.2629348704049},{"x":2.9799999557435513,"y":69.48107946480528},{"x":3.009999955072999,"y":70.71042074932745},{"x":3.0399999544024467,"y":71.95095872397147},{"x":3.0699999537318945,"y":73.20269338873729},{"x":3.0999999530613422,"y":74.46562474362491},{"x":3.12999995239079,"y":75.73975278863438},{"x":3.1599999517202377,"y":77.02507752376565},{"x":3.1899999510496855,"y":78.32159894901875},{"x":3.2199999503791332,"y":79.62931706439366},{"x":3.249999949708581,"y":80.94823186989038},{"x":3.2799999490380287,"y":82.27834336550893},{"x":3.3099999483674765,"y":83.61965155124929},{"x":3.339999947696924,"y":84.97215642711146},{"x":3.369999947026372,"y":86.33585799309546},{"x":3.3999999463558197,"y":87.7107562492013},{"x":3.4299999456852674,"y":89.09685119542891},{"x":3.459999945014715,"y":90.49414283177836},{"x":3.489999944344163,"y":91.90263115824965},{"x":3.5199999436736107,"y":93.32231617484274},{"x":3.5499999430030584,"y":94.75319788155764},{"x":3.579999942332506,"y":96.19527627839437},{"x":3.609999941661954,"y":97.64855136535292},{"x":3.6399999409914017,"y":99.11302314243326},{"x":3.6699999403208494,"y":100.58869160963545},{"x":3.699999939650297,"y":102.07555676695944},{"x":3.729999938979745,"y":103.57361861440526},{"x":3.7599999383091927,"y":105.0828771519729},{"x":3.7899999376386404,"y":106.60333237966233},{"x":3.819999936968088,"y":108.13498429747361},{"x":3.849999936297536,"y":109.67783290540669},{"x":3.8799999356269836,"y":111.2318782034616},{"x":3.9099999349564314,"y":112.79712019163833},{"x":3.939999934285879,"y":114.37355886993686},{"x":3.969999933615327,"y":115.96119423835722},{"x":3.9999999329447746,"y":117.5600262968994}]}],"marks":[{"type":"symbol","from":{"data":"d23d11a3-0962-4f50-8429-9f464a060ee3"},"properties":{"enter":{"x":{"scale":"x","field":"data.x"},"y":{"scale":"y","field":"data.y"},"fill":{"value":"steelblue"},"fillOpacity":{"value":1}},"update":{"shape":"circle","size":{"value":70},"stroke":{"value":"transparent"}},"hover":{"size":{"value":210},"stroke":{"value":"white"}}}},{"type":"line","from":{"data":"113ad830-576c-4707-8297-fcd8b272d48f"},"properties":{"enter":{"x":{"scale":"x","field":"data.x"},"y":{"scale":"y","field":"data.y"},"stroke":{"value":"#FF29D2"},"strokeWidth":{"value":2},"strokeOpacity":{"value":1}}}}]},"value":"#gorilla_repl.vega.VegaView{:content {:width 400, :height 247.2188, :padding {:top 10, :left 55, :bottom 40, :right 10}, :scales [{:name \"x\", :type \"linear\", :range \"width\", :zero false, :domain {:data \"d23d11a3-0962-4f50-8429-9f464a060ee3\", :field \"data.x\"}} {:name \"y\", :type \"linear\", :range \"height\", :nice true, :zero false, :domain {:data \"d23d11a3-0962-4f50-8429-9f464a060ee3\", :field \"data.y\"}}], :axes [{:type \"x\", :scale \"x\"} {:type \"y\", :scale \"y\"}], :data ({:name \"d23d11a3-0962-4f50-8429-9f464a060ee3\", :values ({:x 1, :y 20} {:x 2, :y 40} {:x 3, :y 90} {:x 4, :y 160})} {:name \"113ad830-576c-4707-8297-fcd8b272d48f\", :values ({:x 1, :y 13.100436545680928} {:x 1.0299999993294477, :y 13.59079628216312} {:x 1.0599999986588955, :y 14.09235270876713} {:x 1.0899999979883432, :y 14.605105825492958} {:x 1.119999997317791, :y 15.129055632340604} {:x 1.1499999966472387, :y 15.664202129310068} {:x 1.1799999959766865, :y 16.21054531640135} {:x 1.2099999953061342, :y 16.76808519361445} {:x 1.239999994635582, :y 17.33682176094937} {:x 1.2699999939650297, :y 17.916755018406107} {:x 1.2999999932944775, :y 18.50788496598466} {:x 1.3299999926239252, :y 19.11021160368503} {:x 1.359999991953373, :y 19.723734931507224} {:x 1.3899999912828207, :y 20.34845494945123} {:x 1.4199999906122684, :y 20.98437165751706} {:x 1.4499999899417162, :y 21.6314850557047} {:x 1.479999989271164, :y 22.289795144014164} {:x 1.5099999886006117, :y 22.959301922445444} {:x 1.5399999879300594, :y 23.640005390998542} {:x 1.5699999872595072, :y 24.33190554967346} {:x 1.599999986588955, :y 25.035002398470194} {:x 1.6299999859184027, :y 25.749295937388748} {:x 1.6599999852478504, :y 26.474786166429116} {:x 1.6899999845772982, :y 27.211473085591305} {:x 1.719999983906746, :y 27.95935669487531} {:x 1.7499999832361937, :y 28.718436994281138} {:x 1.7799999825656414, :y 29.48871398380878} {:x 1.8099999818950891, :y 30.27018766345824} {:x 1.839999981224537, :y 31.06285803322952} {:x 1.8699999805539846, :y 31.866725093122618} {:x 1.8999999798834324, :y 32.68178884313753} {:x 1.9299999792128801, :y 33.50804928327426} {:x 1.9599999785423279, :y 34.34550641353282} {:x 1.9899999778717756, :y 35.19416023391319} {:x 2.0199999772012234, :y 36.05401074441537} {:x 2.049999976530671, :y 36.92505794503938} {:x 2.079999975860119, :y 37.807301835785196} {:x 2.1099999751895666, :y 38.700742416652844} {:x 2.1399999745190144, :y 39.6053796876423} {:x 2.169999973848462, :y 40.52121364875358} {:x 2.19999997317791, :y 41.44824429998667} {:x 2.2299999725073576, :y 42.386471641341586} {:x 2.2599999718368053, :y 43.33589567281832} {:x 2.289999971166253, :y 44.29651639441687} {:x 2.319999970495701, :y 45.268333806137235} {:x 2.3499999698251486, :y 46.25134790797942} {:x 2.3799999691545963, :y 47.24555869994342} {:x 2.409999968484044, :y 48.250966182029245} {:x 2.439999967813492, :y 49.26757035423688} {:x 2.4699999671429396, :y 50.295371216566345} {:x 2.4999999664723873, :y 51.334368769017615} {:x 2.529999965801835, :y 52.384563011590714} {:x 2.559999965131283, :y 53.44595394428563} {:x 2.5899999644607306, :y 54.518541567102346} {:x 2.6199999637901783, :y 55.6023258800409} {:x 2.649999963119626, :y 56.69730688310126} {:x 2.679999962449074, :y 57.80348457628345} {:x 2.7099999617785215, :y 58.92085895958745} {:x 2.7399999611079693, :y 60.04943003301327} {:x 2.769999960437417, :y 61.189197796560904} {:x 2.7999999597668648, :y 62.34016225023037} {:x 2.8299999590963125, :y 63.50232339402164} {:x 2.8599999584257603, :y 64.67568122793475} {:x 2.889999957755208, :y 65.86023575196964} {:x 2.9199999570846558, :y 67.05598696612637} {:x 2.9499999564141035, :y 68.2629348704049} {:x 2.9799999557435513, :y 69.48107946480528} {:x 3.009999955072999, :y 70.71042074932745} {:x 3.0399999544024467, :y 71.95095872397147} {:x 3.0699999537318945, :y 73.20269338873729} {:x 3.0999999530613422, :y 74.46562474362491} {:x 3.12999995239079, :y 75.73975278863438} {:x 3.1599999517202377, :y 77.02507752376565} {:x 3.1899999510496855, :y 78.32159894901875} {:x 3.2199999503791332, :y 79.62931706439366} {:x 3.249999949708581, :y 80.94823186989038} {:x 3.2799999490380287, :y 82.27834336550893} {:x 3.3099999483674765, :y 83.61965155124929} {:x 3.339999947696924, :y 84.97215642711146} {:x 3.369999947026372, :y 86.33585799309546} {:x 3.3999999463558197, :y 87.7107562492013} {:x 3.4299999456852674, :y 89.09685119542891} {:x 3.459999945014715, :y 90.49414283177836} {:x 3.489999944344163, :y 91.90263115824965} {:x 3.5199999436736107, :y 93.32231617484274} {:x 3.5499999430030584, :y 94.75319788155764} {:x 3.579999942332506, :y 96.19527627839437} {:x 3.609999941661954, :y 97.64855136535292} {:x 3.6399999409914017, :y 99.11302314243326} {:x 3.6699999403208494, :y 100.58869160963545} {:x 3.699999939650297, :y 102.07555676695944} {:x 3.729999938979745, :y 103.57361861440526} {:x 3.7599999383091927, :y 105.0828771519729} {:x 3.7899999376386404, :y 106.60333237966233} {:x 3.819999936968088, :y 108.13498429747361} {:x 3.849999936297536, :y 109.67783290540669} {:x 3.8799999356269836, :y 111.2318782034616} {:x 3.9099999349564314, :y 112.79712019163833} {:x 3.939999934285879, :y 114.37355886993686} {:x 3.969999933615327, :y 115.96119423835722} {:x 3.9999999329447746, :y 117.5600262968994})}), :marks ({:type \"symbol\", :from {:data \"d23d11a3-0962-4f50-8429-9f464a060ee3\"}, :properties {:enter {:x {:scale \"x\", :field \"data.x\"}, :y {:scale \"y\", :field \"data.y\"}, :fill {:value \"steelblue\"}, :fillOpacity {:value 1}}, :update {:shape \"circle\", :size {:value 70}, :stroke {:value \"transparent\"}}, :hover {:size {:value 210}, :stroke {:value \"white\"}}}} {:type \"line\", :from {:data \"113ad830-576c-4707-8297-fcd8b272d48f\"}, :properties {:enter {:x {:scale \"x\", :field \"data.x\"}, :y {:scale \"y\", :field \"data.y\"}, :stroke {:value \"#FF29D2\"}, :strokeWidth {:value 2}, :strokeOpacity {:value 1}}}})}}"}
+;; <=
+
+;; @@
+
+;; @@


Accept new animation targets mid-animation

When we get a new data change we have to start a new animation from the
point where we are right now in the old animation

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/dignati/om-charts.git/'


Added status and headers to eDocu respond

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/infones/http-kit.git/'


Add pass utilities

Add pass utilities

error: pathspec 'src/oxcart/passes/util.clj' did not match any file(s) known to git

--- src/oxcart/passes/util.clj
+++ src/oxcart/passes/util.clj
@@ -0,0 +1,19 @@
+;;   Copyright (c) Reid McKenzie, Rich Hickey & contributors. The use
+;;   and distribution terms for this software are covered by the
+;;   Eclipse Public License 1.0
+;;   (http://opensource.org/licenses/eclipse-1.0.php) which can be
+;;   found in the file epl-v10.html at the root of this distribution.
+;;   By using this software in any fashion, you are agreeing to be
+;;   bound by the terms of this license.  You must not remove this
+;;   notice, or any other, from this software.
+
+(ns oxcart.passes.util
+  {:doc "Packages helper utilities common to Oxcart passes."
+   :added "0.0.4"
+   :author "Reid McKenzie"})
+
+(defn whole-ast->forms
+  [{:keys [modules] :as whole-ast}]
+  (->> modules
+       (map (partial get whole-ast))
+       (mapcat :forms)))


Create mission3-answer.clj

Create mission3-answer.clj

error: pathspec 'POH4/mission3-answer.clj' did not match any file(s) known to git

--- POH4/mission3-answer.clj
+++ POH4/mission3-answer.clj
@@ -0,0 +1,19 @@
+(defn toint [n] (Integer/parseInt n))
+(let [str (re-find #"(\d+) (\d+)" (read-line))
+        t (toint (nth str 1))
+        n (toint (nth str 2))
+        maximum
+        (loop [x 0 a (int-array n (int 0)) mx 0 c 0]
+            (if (>= x n)
+                (max mx c)
+                (do
+                    (aset-int a x (toint (read-line)))
+                    (recur (inc x) a (
+                        max c mx)
+                        (- (+ c (aget a x))
+                            (if (>= x t) (aget a (- x t)) 0)
+                            )
+                        )
+                )))]
+    (println maximum)
+    )


Speculative convention to pick native or non-native dispath.

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/shaunstanislaus/cljs2go.git/'


Rough relay

Rough relay

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/terrancesnyder/engulf.git/'


Liburu titulua lortu

Liburu titulua lortu

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/lnmnd/magnet.bez.git/'


remove stray printlns

remove stray printlns

--- src/metabase/models/dashboard.clj
+++ src/metabase/models/dashboard.clj
@@ -55,7 +55,6 @@
     (doseq [dashcard-id all-dashcard-ids]
       (let [serialized-card (id->serialized-card dashcard-id)
             current-card    (id->current-card dashcard-id)]
-        (println "SERIALIZED CARD -> " serialized-card)
         (cond
           ;; If card is in current-cards but not serialized-cards then we need to delete it
           (not serialized-card) (del DashboardCard :id dashcard-id)
@@ -65,7 +64,6 @@

           ;; If card is in both we need to change :sizeX, :sizeY, :row, and :col to match serialized-card as needed
           :else (let [[_ changes] (diff current-card serialized-card)]
-                  (println "Making these changes:" changes)
                   (m/mapply upd DashboardCard dashcard-id changes))))))

   serialized-dashboard)


Fixing tests (the cutoff was lowered a bit).

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/screen6/cardinality.git/'


my-ejector should give the same "shape" as the regular comp

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/michaelsbradleyjr/transwarp.git/'


Removed util.java, reference primitive classes from Clojure

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/lprefontaine/Boing.git/'


Allow opening DataFileWriters on anything which can yield an OutputStream.

--- src/clojure/abracad/avro.clj
+++ src/clojure/abracad/avro.clj
@@ -209,11 +209,10 @@
   ([schema sink]
      (data-file-writer nil schema sink))
   ([codec schema sink]
-     (let [^DataFileWriter writer (data-file-writer)]
+     (let [^DataFileWriter writer (data-file-writer)
+           sink (coerce OutputStream io/output-stream sink)]
        (when codec (.setCodec writer (codec-for codec)))
-       (if (instance? OutputStream sink)
-         (.create writer ^Schema schema ^OutputStream sink)
-         (.create writer ^Schema schema (io/file sink)))
+       (.create writer ^Schema schema ^OutputStream sink)
        writer)))

 (defmacro ^:private encoder-factory


uniform-continuous example

uniform-continuous example

error: pathspec 'examples/src/worksheets/uniform_continuous.clj' did not match any file(s) known to git

--- examples/src/worksheets/uniform_continuous.clj
+++ examples/src/worksheets/uniform_continuous.clj
@@ -0,0 +1,110 @@
+;; gorilla-repl.fileformat = 1
+
+;; **
+;;; # Uniform Continuous
+;; **
+
+;; **
+;;; Import the minimum required libraries to run define queries, compile them, and run the inference using compiled artifacts.
+;; **
+
+;; @@
+(ns worksheets.uniform-continuous
+  (:require [anglican.runtime :refer :all]
+            [anglican.emit :refer [defquery]]
+            [anglican.stat :refer [empirical-distribution collect-predicts collect-by]]
+            anglican.infcomp.csis
+            anglican.importance
+            [anglican.infcomp.dists :refer :all]
+            [anglican.infcomp.network :refer :all]
+            [anglican.inference :refer [infer]])
+  (:use [gorilla-plot core]))
+;; @@
+
+;; **
+;;; Define a query
+;; **
+
+;; @@
+(defquery uniform-continuous-query [obs]
+  (let [uc-min (sample "uc-min" (normal 0 0.1))
+        uc-range (sample "uc-range" (normal 10 0.1))
+        uc-max (+ uc-min uc-range)
+        mean (sample "mean" (uniform-continuous uc-min uc-max))
+        std 0.01]
+    (observe (normal mean std) obs)
+    {:mean mean
+     :uc-min uc-min
+     :uc-max uc-max}))
+;; @@
+
+;; **
+;;; ## Inference Compilation
+;; **
+
+;; **
+;;; Specify a function `combine-observes-fn` that combines observes from a sample in a form suitable for Torch:
+;; **
+
+;; @@
+(defn combine-observes-fn [observes]
+  (:value (first observes)))
+;; @@
+
+;; **
+;;; In order to write this function, you'll need to look at how a typical `observes` object from your query looks like:
+;; **
+
+;; @@
+(sample-observes-from-prior uniform-continuous-query [1])
+;; @@
+
+;; **
+;;; Compile our query
+;; **
+
+;; @@
+(def torch-connection (start-torch-connection uniform-continuous-query [1] combine-observes-fn))
+;; @@
+
+;; **
+;;; Then run the following to train the neural network:
+;;;
+;;; `python -m infcomp.compile`
+;; **
+
+;; @@
+(stop-torch-connection torch-connection)
+;; @@
+
+;; **
+;;; ## Inference
+;; **
+
+;; **
+;;; First, run the inference server from torch-infcomp:
+;;;
+;;; `python -m infcomp.infer`
+;;;
+;;; Then run the query, specifying number of particles:
+;; **
+
+;; @@
+(def num-particles 100)
+(def csis-states (take num-particles (infer :csis uniform-continuous-query [5] :tcp-endpoint "tcp://pindarus:6666")))
+(list-plot (vec (empirical-distribution (collect-by (comp :mean :result) csis-states))) :y-title "mean")
+(list-plot (vec (empirical-distribution (collect-by (comp :uc-min :result) csis-states))) :y-title "uc-min")
+(list-plot (vec (empirical-distribution (collect-by (comp :uc-max :result) csis-states))) :y-title "uc-max")
+;; @@
+
+;; **
+;;; Using the same number of particles, we don't have such good results with importance sampling:
+;; **
+
+;; @@
+(def num-particles 100)
+(def is-states (take num-particles (infer :importance uniform-continuous-query [5])))
+(list-plot (vec (empirical-distribution (collect-by (comp :mean :result) is-states))) :y-title "mean")
+(list-plot (vec (empirical-distribution (collect-by (comp :uc-min :result) is-states))) :y-title "uc-min")
+(list-plot (vec (empirical-distribution (collect-by (comp :uc-max :result) is-states))) :y-title "uc-max")
+;; @@


[repl] show current instrument(s) in prompt

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/jtbeckha/alda.git/'


Added input interactivity.

Added input interactivity.

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/inchingforward/eon.git/'


Add db connection and configuration

Add db connection and configuration

error: pathspec 'src/madouc/db.clj' did not match any file(s) known to git

--- src/madouc/db.clj
+++ src/madouc/db.clj
@@ -0,0 +1,20 @@
+(ns madouc.db
+  (:require [mount.core :refer [defstate]]
+            [conman.core :as conman]
+            [madouc.config :refer [env]]))
+
+(defn- make-pool-spec
+  [host db user pass]
+  {:jdbc-url (format "jdbc:postgresql://%s/%s" host db)
+   :username user
+   :password pass})
+
+(defstate con
+  :start (conman/connect! (make-pool-spec
+                           (env :db-host)
+                           (env :db-name)
+                           (env :db-user)
+                           (env :db-password)))
+  :stop (conman/disconnect! con))
+
+


Added helpers utility file

Added helpers utility file

It contains helper function that checks if a field has the search expression.

error: pathspec 'src/hatti/utils/helpers.cljs' did not match any file(s) known to git

--- src/hatti/utils/helpers.cljs
+++ src/hatti/utils/helpers.cljs
@@ -0,0 +1,7 @@
+(ns hatti.utils.helpers)
+
+(defn uses-search-expression?
+    "Checks if the appearance-value has the search expression"
+    [appearance-value]
+    (and (string? appearance-value)
+         (re-matches #"^search\(.*\)$" appearance-value)))


add preliminary code to generate pre and post conditions to generated functions to enforce runtime typing

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/aamedina/clojure.llvm.git/'


Minor refactor to avoid round-tripping single re-parsed schemas.

--- src/clojure/abracad/avro.clj
+++ src/clojure/abracad/avro.clj
@@ -54,28 +54,13 @@
       (and (string? source)
            (.lookingAt (re-matcher #"[\[\{\"]" source)))))

-(def ^:private primitive-types
-  "Set of Avro primitive type schema strings."
-  (->> Schema$Type .getEnumConstants
-       (map #(.getName ^Schema$Type %))
-       (into #{})))
-
-(defn ^:private named-schema?
-  [^Schema schema] (-> schema .getFullName primitive-types not))
-
-(defn ^:private parse-schema*
+(defn ^:private parse-schema-raw
   [^Schema$Parser parser source]
   (if (instance? String source)
     (.parse parser ^String source)
     (.parse parser ^InputStream source)))

-(defn parse-schema
-  "Parse Avro schemas in `sources`.  Each schema source may be a JSON
-string, an input stream containing a JSON schema, a Clojure data
-structure which may be converted to a JSON schema, or an
-already-parsed Avro schema object.  The schema for each subsequent
-source may refer to the types defined in the previous schemas.  The
-parsed schema from the final source is returned."
+(defn ^:private parse-schema*
   {:tag `Schema}
   [& sources]
   (let [parser (Schema$Parser.)]
@@ -83,9 +68,19 @@
               (->> (cond (schema? source) (str source)
                          (raw-schema? source) source
                          :else (clj->json source))
-                   (parse-schema* parser)))
+                   (parse-schema-raw parser)))
             nil
             sources)))
+
+(defn parse-schema
+  "Parse Avro schemas in `source` and `sources`.  Each schema source may be a
+JSON string, an input stream containing a JSON schema, a Clojure data structure
+which may be converted to a JSON schema, or an already-parsed Avro schema
+object.  The schema for each subsequent source may refer to the types defined in
+the previous schemas.  The parsed schema from the final source is returned."
+  {:tag `Schema}
+  ([source] (if (schema? source) source (parse-schema* source)))
+  ([source & sources] (apply parse-schema* source sources)))

 (defn datum-reader
   "Return an Avro DatumReader which produces Clojure data structures."


added pearson correlation function

added pearson correlation function

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/clojure-ml/cml.git/'


correctly diffs service properties

correctly diffs service properties

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/starcity-properties/odin.git/'


placeholder: macros in Clojure

placeholder: macros in Clojure

error: pathspec 'clojure/macros.clj' did not match any file(s) known to git

--- clojure/macros.clj
+++ clojure/macros.clj
@@ -0,0 +1,15 @@
+(defmacro ignore-last-operand
+  [func-call]
+  (butlast func-call))
+
+(println (ignore-last-operand (+ 1 2 10)))
+
+(println (ignore-last-operand (+ 1 2 (println "this won't print"))))
+
+(println (macroexpand '(ignore-last-operand (+ 1 2 10))))
+
+(println (macroexpand '(ignore-last-operand (+ 1 2 (println "this won't print")))))
+
+(defmacro infix [[a b c]] (list b a c))
+
+(infix (1 + 2))


Added some documentation.

Added some documentation.

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/couragelabs/freefrog.git/'


Just cleaning up some stuff I had forgoetten in the previous commit

--- src/clj_http/conn_mgr.clj
+++ src/clj_http/conn_mgr.clj
@@ -10,7 +10,6 @@
                                         SchemeRegistry Scheme)
            (org.apache.http.impl.conn SingleClientConnManager
                                       SchemeRegistryFactory)
-           ;(org.apache.http.impl.conn.tsccm ThreadSafeClientConnManager)))
            (org.apache.http.impl.conn PoolingClientConnectionManager)
            (org.apache.http.conn.params ConnPerRouteBean)))


heheheh 7

heheheh 7

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/encho/vvento4.git/'


Start on messaging tests for eventual generative testing of messaging layer

error: pathspec 'test/onyx/messaging/messaging_gen_test.clj' did not match any file(s) known to git

--- test/onyx/messaging/messaging_gen_test.clj
+++ test/onyx/messaging/messaging_gen_test.clj
@@ -0,0 +1,123 @@
+(ns onyx.messaging.messaging-gen-test
+  (:require [onyx.messaging.netty-tcp :as netty :refer [netty-tcp-sockets]]
+            [onyx.messaging.protocol-netty :as protocol]
+            [clojure.set :refer [intersection]]
+            [clojure.test.check :as tc]
+            [clojure.test.check.generators :as gen]
+            [clojure.test.check.properties :as prop]
+            [clojure.test :refer :all]
+            [onyx.system :as system]
+            [onyx.extensions :as ext]
+            [onyx.api]
+            [onyx.types :refer [map->Leaf]]
+            [com.stuartsierra.component :as component]
+            [onyx.test-helper :refer [load-config]]
+            [com.gfredericks.test.chuck :refer [times]]
+            [com.gfredericks.test.chuck.clojure-test :refer [checking]])
+  (:import
+             [io.netty.buffer ByteBuf]
+             [io.netty.channel Channel ChannelOption ChannelFuture ChannelInitializer ChannelPipeline
+              MultithreadEventLoopGroup ChannelHandler ChannelHandlerContext ChannelInboundHandlerAdapter]
+             )
+
+  )
+
+(def id (java.util.UUID/randomUUID))
+
+(def config (load-config))
+
+(def env-config (assoc (:env-config config) :onyx/id id))
+
+(def peer-config (assoc (:peer-config config) :onyx/id id))
+
+(defn create-server-handler-mock
+  [received]
+  (fn [messenger _ _ _]
+    (fn [^ChannelHandlerContext ctx ^ByteBuf buf]
+      (try
+        (let [msg (protocol/read-buf (:decompress-f messenger) buf)]
+          (let [t ^byte (:type msg)]
+            (cond (= t protocol/messages-type-id)
+                  (doseq [message (:messages msg)]
+                    (swap! received update-in [:messages] conj message))
+
+                  (= t protocol/ack-type-id)
+                  (swap! received update-in [:acks] into (:acks msg))
+
+                  (= t protocol/completion-type-id)
+                  (swap! received update-in [:complete] conj (:id msg))
+
+                  (= t protocol/retry-type-id)
+                  (swap! received update-in [:retry] conj (:id msg))
+
+                  :else
+                  (throw (ex-info "Unexpected message received from Netty" {:message msg})))))
+        (catch Throwable e
+          (taoensso.timbre/error e)
+          (throw e))))))
+
+
+(defn test-send-commands [env peer-group commands]
+  (let [received (atom {})]
+    (with-redefs [netty/create-server-handler (create-server-handler-mock received)]
+      (let [peers (onyx.api/start-peers 2 peer-group)]
+        (try
+          (let [server-port 53001
+                _ (while (and (nil? @(:started-peer (first peers)))
+                              (nil? @(:started-peer (second peers))))
+                    (println "Waiting for full startup"))
+                recv-peer @(:started-peer (first peers))
+                send-peer @(:started-peer (second peers))
+                recv-messenger (:messenger recv-peer)]
+            (let [_ (ext/open-peer-site recv-messenger {:onyx.messaging/bind-addr "127.0.0.1"
+                                                        :netty/port server-port})
+                  send-messenger (:messenger send-peer)
+                  send-link (ext/connect-to-peer send-messenger nil {:netty/external-addr "127.0.0.1"
+                                                                     :netty/port server-port})]
+              (reduce (fn [_ command]
+                        (case (:command command)
+                          :messages (ext/send-messages send-messenger nil send-link (:payload command))
+                          :complete (ext/internal-complete-message send-messenger nil (:payload command) send-link)
+                          :retry (ext/internal-retry-message send-messenger nil (:payload command) send-link)
+                          :acks (ext/internal-ack-messages send-messenger nil send-link (:payload command))))
+                      nil commands)
+              (Thread/sleep 3000)
+              @received))
+          (finally
+            (doseq [peer peers]
+              (onyx.api/shutdown-peer peer))))))))
+
+
+(deftest start-on-messenger-test
+  (let [env (onyx.api/start-env env-config)
+        peer-group (onyx.api/start-peer-group peer-config)
+        commands [{:command :messages
+                   :payload [(map->Leaf {:id #uuid "010a1688-47ff-4055-8da5-1f02247351e1"
+                                         :acker-id #uuid "bf8fd5fc-30fd-424c-af6a-0b32568581a4"
+                                         :completion-id #uuid "7ad37c45-ce67-4fd4-8850-f3ec58ede0bf"
+                                         :message {}
+                                         :ack-val 729233382010058362})]}
+                  {:command :retry
+                   :payload #uuid "8665d0eb-7905-4a5f-8704-28f7e67d369c"}
+
+                  {:command :complete
+                   :payload #uuid "2982b77a-849e-4964-8020-a2cee50756e7"}
+
+                  {:command :acks
+                   :payload [{:id #uuid "e2ba38dd-b523-4e63-ba74-645fb91c231a"
+                             :completion-id #uuid "b57f7be1-f2f9-4d0f-aa02-939b3d48dc23"
+                             :ack-val 3323130347050513529}]}]
+        grouped-model (group-by :command commands)
+        model-results (zipmap (keys grouped-model)
+                              (map (fn [v] (sort (flatten (map :payload v))))
+                                   (vals grouped-model)))]
+    (try
+      (is
+        (= model-results
+           (into {}
+                 (map (juxt key (comp sort val))
+                      (test-send-commands env peer-group commands)))))
+      (finally (onyx.api/shutdown-peer-group peer-group)
+               (onyx.api/shutdown-env env)))))
+
+


refactor: use thread-first macro in get image function

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/rodrigo-garcia-leon/semanario-universidad-newsletter.git/'


Forward the upstream headers to the fragments

error: pathspec 'test/acceptance/step_definitions/world.clj' did not match any file(s) known to git

--- test/acceptance/step_definitions/world.clj
+++ test/acceptance/step_definitions/world.clj
@@ -0,0 +1,18 @@
+(ns world)
+
+(def ^:private the-world (atom {:result nil}))
+
+(defn value [] @the-world)
+
+(defn reset-world!
+  ([] (reset! the-world {:result nil}))
+  ([newval]
+   (reset! the-world newval)))
+
+(defn swap-world!
+  ([f x]
+   (swap! the-world f x))
+  ([f x y]
+   (swap! the-world f x y))
+  ([f x y & args]
+   (swap! the-world f x y args)))


add :call-clerk as a registration method when there is no form or online

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/democracyworks/election-authority-works.git/'


drop lein-profiles.clj

drop lein-profiles.clj

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/pervezfunctor/lean-dotfiles.git/'


update lein/profiles.clj

update lein/profiles.clj

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/jongold/dotfiles.git/'


basic skeleton for kafka-consumer component has been added

error: pathspec 'extra_components/kafka/src/clj/hellhound/components/kafka_consumer.clj' did not match any file(s) known to git

--- extra_components/kafka/src/clj/hellhound/components/kafka_consumer.clj
+++ extra_components/kafka/src/clj/hellhound/components/kafka_consumer.clj
@@ -0,0 +1,36 @@
+(ns hellhound.components.kafka-consumer
+  (:require
+   [hellhound.kafka.consumers :as consumer]
+   [hellhound.core :as hellhound]
+   [hellhound.component :as hcomp]
+   [manifold.stream :as s]
+   [manifold.deferred :as d]
+   [kafka-clj.client :as kafka]))
+
+(defn make-config
+  [config]
+  (merge (hellhound/get-config :kafka :consumers)
+         config))
+
+(defn start!
+  [config topics]
+  (fn [this context]
+    (let [[input output] (hcomp/io this)
+          c              (consumer/make-consumer config)
+          event-loop     (d/deferred)]
+      (consumer/subscribe topics)
+      (consumer/consume-each #(s/put! output %))
+      (assoc this :consumer c))))
+
+
+(defn stop!
+  [this]
+  (when (:consumer this)
+    (consumer/stop (:consumer this)))
+  (dissoc this :consumer))
+
+(defn factory
+  [config topic]
+  (hcomp/make-component ::hellhound.components/kafka-consumer
+                        (start! config topic)
+                        stop!))


use add-source-btn component

use add-source-btn component


Broadcast a message to all active users

Broadcast a message to all active users

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/couragelabs/coachbot.git/'


Added deprecated metadata to file-info middleware

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/meowcakes/ring.git/'


First ijcai experiments file

First ijcai experiments file

error: pathspec 'src/angelic/scripts/experiments_11ijcai.clj' did not match any file(s) known to git

--- src/angelic/scripts/experiments_11ijcai.clj
+++ src/angelic/scripts/experiments_11ijcai.clj
@@ -0,0 +1,60 @@
+(ns angelic.scripts.experiments-11ijcai
+ (:require [edu.berkeley.ai [util :as util]]
+	   [edu.berkeley.ai.util [charts :as charts] [datasets :as datasets] [experiments :as experiments]]
+           [angelic [env :as env] [hierarchy :as hierarchy] [sas :as sas]]
+           [angelic.domains.sas-problems :as sas-problems]
+           [angelic.domains.taxi-constrained :as taxi]
+           [angelic.search.textbook :as textbook]
+           [angelic.search.action-set.asplan :as asplan]
+           [angelic.search.action-set.stratified :as strat]
+	   [edu.berkeley.ai.util.experiments :as experiments]))
+
+(def *exp-result* ::ExpResult)
+
+(defstruct exp-result
+  :class :experiment :commit-id :timeout? :memout? :output :printed :init-ms :ms :mb
+  :next-count :add-count)
+
+(defmethod experiments/setup-experiment-result ::ExpResult [experiment]
+           (env/reset-next-counter)
+           (util/sref-set! asplan/*add-count* 0))
+
+
+(defmethod experiments/make-experiment-result ::ExpResult
+  [experiment setup-info timeout? memout? output printed init-ms ms mb]
+  (struct exp-result ::ExpResult
+          experiment (util/git-commit-id) timeout? memout? output printed init-ms ms mb
+          (util/sref-get env/*next-counter*)
+          (util/sref-get asplan/*add-count*)
+          ))
+
+
+;;;;; Taxi
+
+(def taxi-algs
+  {:strat "strat"
+   :strat+ "strat+"})
+
+(def taxi-types
+     {:independent ["independent" "individual taxis"]
+      :pairwise ["pairwise" "pairwise taxis"]
+      :single ["single" "single taxi"]})
+
+(def taxi-factories
+     {:independent taxi/make-random-independent-taxi-env
+      :pairwise taxi/make-random-pairwise-taxi-env
+      :single taxi/make-random-single-taxi-env })
+
+(defn make-taxi-exp-set []
+   (experiments/make-experiment-set
+    "ib-taxi-strat"
+    [:product
+     [:size (vec (range 1 11))]
+     [:constrain? [true]]
+     [:alg (keys taxi-algs)]
+     [:type (keys taxi-types)]]
+    (fn [m]
+      `((taxi-factories ~(:type m)) 3 3 ~(:size m) ~(:constrain? m) ~(if (= (:type m) :single) 6 1)))
+    (fn [m] `(textbook/stratified-search ~'init ~(if (= (:alg m) :strat) :simple :fluid)))
+    'angelic.scripts.experiments-11icaps 10 3600 512 false ::ExpResult))
+


zer berrezartzeko aukera

zer berrezartzeko aukera

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/lnmnd/magnet.zer.git/'


development ns has been added to system in order to provide better repl integration for systems

error: pathspec 'utils/src/clj/hellhound/system/development.clj' did not match any file(s) known to git

--- utils/src/clj/hellhound/system/development.clj
+++ utils/src/clj/hellhound/system/development.clj
@@ -0,0 +1,72 @@
+;; (ns hellhound.system.development
+;;   (:require
+;;    [hellhound.components.file-watcher :as watcher]
+;;    [hellhound.components.pretty-printer :as printer]
+;;    [hellhound.components.namespace :as nspace]
+;;    [hellhound.config :as config]
+;;    [hellhound.system.core :as syscore]
+;;    [hellhound.system :as sys]))
+
+
+;; (defn system-watcher-factory
+;;   [original-system]
+;;   (let [watcher-config (config/get-config-from-system original-system
+;;                                                       [:watcher]
+;;                                                       {})
+;;         ns-loader-config (config/get-config-from-system original-system
+;;                                                         [:ns-loader]
+;;                                                         {})]
+
+;;     {:components [(watcher/watcher-factory watcher-config)
+;;                   (nspace/loader-factory original-system ns-loader-config)]
+
+;;      :workflow [[::watcher/watcher
+;;                  ::nspace/loader]]
+
+;;      :execution {:mode :multi-thread}
+;;      :logger {:level :trace}}))
+
+;; (defn start!
+;;   [system-var]
+;;   (println "starting ...............................")
+;;   (watcher/start-watch system-var
+;;                        (nspace/refresh system-var {}))
+;;   (print "STARTED"))
+
+
+;; (defn stop!
+;;   [server]
+;;   (watcher/stop-watch server))
+
+
+(ns hellhound.system.development
+  (:require
+   [medusa.system :as system]
+   [hellhound.system :as sys]
+   [clojure.tools.namespace.repl :as repl]))
+
+
+(defn load-and-set-system!
+  [system-path]
+  (assert (symbol? system-path) "'system-path' value must be a symbol")
+  (assert (namespace system-path)
+          "'system-path' value must be a namespace-qualified symbol")
+  (let [system-fn (ns-resolve *ns* system-path)]
+    (hellhound.system.store/set-system! system-fn)))
+
+(defmacro setup-development
+  [nsname system-var]
+  `(do
+     (defn ~(symbol "start")
+       []
+       (hellhound.system.development/load-and-set-system! ~system-var)
+       (hellhound.system/start1))
+
+     (defn ~(symbol "stop")
+       []
+       (hellhound.system/stop1))
+
+     (defn ~(symbol "restart")
+       []
+       (hellhound.system/stop1)
+       (clojure.tools.namespace.repl/refresh :after  '~(symbol (str nsname "/start"))))))


First pass at clojure wrapper for URLFetch service.

error: pathspec 'src/appengine_magic/services/urlfetch.clj' did not match any file(s) known to git

--- src/appengine_magic/services/urlfetch.clj
+++ src/appengine_magic/services/urlfetch.clj
@@ -0,0 +1,43 @@
+(ns appengine-magic.services.urlfetch
+  (:import [com.google.appengine.api.urlfetch URLFetchServiceFactory]))
+
+(defonce *urlfetch-service* (atom nil))
+
+(defn- get-urlfetch-service []
+  (do (when (nil? @*urlfetch-service*)
+	(reset! *urlfetch-service* (URLFetchServiceFactory/getURLFetchService)))
+      @*urlfetch-service*))
+
+(defn- urlify [url]
+  (if (string? url) (java.net.URL. url) url))
+
+(defn fetch [url]
+  (.fetch (get-urlfetch-service) (urlify url)))
+
+(defrecord HTTPResponse [content
+			 final-url
+			 headers
+			 response-code])
+
+(defn- parse-headers [headers]
+  (zipmap (map #(keyword (.getName %)) headers)
+	  (map #(.getValue %) headers)))
+
+(defn- parse-response
+  [^com.google.appengine.api.urlfetch.HTTPResponse r]
+  (HTTPResponse. (.getContent r)
+		 (.getFinalUrl r)
+		 (parse-headers (.getHeaders r))
+		 (.getResponseCode r)))
+
+(defn fetch-async [url]
+  (let [f (.fetchAsync (urlify url))]
+    (reify
+     clojure.lang.IDeref
+      (deref [_] (parse-response (.get f)))
+     java.util.concurrent.Future
+      (get [_] (.get f))
+      (get [_ timeout unit] (.get f timeout unit))
+      (isCancelled [_] (.isCancelled f))
+      (isDone [_] (.isDone f))
+      (cancel [_ interrupt?] (.cancel f interrupt?)))))


Add a functional logging interface

Add a functional logging interface

Because I'm tired of digging through the other kind.

error: pathspec 'src/clojure/frereth_cp/shared/logging.clj' did not match any file(s) known to git

--- src/clojure/frereth_cp/shared/logging.clj
+++ src/clojure/frereth_cp/shared/logging.clj
@@ -0,0 +1,154 @@
+(ns frereth-cp.shared.logging
+  "Functional logging mechanism"
+  (:require [clojure.spec.alpha :as s])
+  (:import clojure.lang.ExceptionInfo
+           java.io.OutputStream))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;; Specs
+
+;;;; Implement this for your side-effects
+(defprotocol Logger
+  (log! [this msg])
+  (flush! [this]))
+
+(def log-levels #{::trace
+                  ::debug
+                  ::info
+                  ::warn
+                  ::error
+                  ::exception
+                  ::fatal})
+(s/def ::level log-levels)
+
+(s/def ::label keyword?)
+
+;; Go with milliseconds since epoch
+(s/def ::time nat-int?)
+
+(s/def ::message string?)
+
+(s/def ::details any?)
+
+(s/def ::entry (s/keys :req [::level
+                             ::label
+                             ::time
+                             ::message]
+                       :opt [::details]))
+
+(s/def ::entries (s/coll-of ::entry))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;; Internal
+
+(s/fdef log :args (s/cat :entries ::entries
+                         :level ::level
+                         :message ::message
+                         :details ::details))
+(defn add-log-entry
+  ([entries
+    level
+    label
+    message
+    details]
+   (conj entries {::level level
+                  ::label label
+                  ::time (System/currentTimeMillis)
+                  ::message message
+                  ::details details}))
+  ([entries
+    level
+    label
+    message]
+   (conj entries {::level level
+                  ::label label
+                  ::time (System/currentTimeMillis)
+                  ::message message})))
+
+(defmacro deflogger
+  [level]
+  ;; TODO: I'd much rather do something like this for the sake of hygiene:
+  (comment
+    `(let [lvl-holder# '~level
+           tag-holder# (keyword (str *ns*) (name lvl-holder#))]
+       (defn '~lvl-holder#
+         ([entries#
+           label#
+           message#
+           details#]
+          (add-log-entry entries# ~'~tag-holder label# message# details#))
+         ([entries#
+           label#
+           message#]
+          (add-log-entry entries# ~'~tag-holder label# message#)))))
+  (let [tag (keyword (str *ns*) (name level))]
+    ;; The auto-gensymmed parameter names are obnoxious
+    `(defn ~level
+       ([entries#
+         label#
+         message#
+         details#]
+        (add-log-entry entries# ~tag label# message# details#))
+       ([entries#
+         label#
+         message#]
+        (add-log-entry entries# ~tag label# message#)))))
+
+(defrecord StreamLogger [stream]
+  ;; I think this is mostly correct,
+  ;; but I haven't actually tried testing it
+  Logger
+  (log! [{^OutputStream stream :stream
+         :as this}
+        msg]
+    (.write stream (pr-str msg)))
+  (flush! [{^OutputStream stream :stream
+            :as this}]
+    (.flush stream)))
+
+(defrecord StdOutLogger []
+  ;; Really just a StreamLogger
+  ;; where stream is STDOUT.
+  ;; But it's simple/easy enough that it seemed
+  ;; worth writing this way instead
+  Logger
+  (log! [_ msg]
+    (println (pr-str msg)))
+  (flush! [_]
+    ;; Q: Is there any point to calling .flush
+    ;; on STDOUT?
+    ))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;; Public
+
+(deflogger trace)
+(deflogger debug)
+(deflogger info)
+(deflogger warn)
+(deflogger error)
+
+(defn exception
+  ([entries ex label message]
+   (exception entries ex label message nil))
+  ([entries ex label message original-details]
+   (let [details {::original-details original-details
+                  ::stack (.getStackTrace ex)
+                  ::exception ex}
+         details (if (instance? ExceptionInfo ex)
+                   (assoc details ::data (.getData ex))
+                   details)]
+     (add-log-entry entries ::exception label message details))))
+
+(deflogger fatal)
+
+(s/fdef flush-logs!
+        :args (s/cat :logger #(satisfies? Logger %)
+                     :logs ::entries))
+(defn flush-logs!
+  "For the side-effects to write the accumulated logs"
+  [logger
+   log-collection]
+  (doseq [message log-collection]
+    (log! logger message))
+  (flush! logger))


add helper to repo

add helper to repo

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/fhirbase/fhirplace.git/'


Check the namespace appears in the fact output.

error: pathspec 'test/implementation/firm_check_failures.clj' did not match any file(s) known to git

--- test/implementation/firm_check_failures.clj
+++ test/implementation/firm_check_failures.clj
@@ -0,0 +1,9 @@
+(ns implementation.firm-check-failures
+  (:use midje.sweet
+        midje.test-util))
+
+; The namespace of the test should appear in test failure report
+(capturing-failure-output
+  (fact (+ 1 1) => 4)
+  (fact
+    @fact-output => #"implementation.firm-check-failures"))


more Armstrong Numbers

more Armstrong Numbers

Clojure

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/nikai3d/ce-challenges.git/'


Allow Source as input/output of `NewActivity`

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/physion/ovation-webapi.git/'


Allow NewTeamRole for submitting Membership


disable pay deposit and add tooltip when no verified bank linked

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/starcity-properties/odin.git/'


simple normalization and tokenization callback

which normalizes a unicode string, removes accents,
tokenizes and assocs to a set<text> column to be used
for search

error: pathspec 'src/er_cassandra/model/callbacks/search_key_callback.clj' did not match any file(s) known to git

--- src/er_cassandra/model/callbacks/search_key_callback.clj
+++ src/er_cassandra/model/callbacks/search_key_callback.clj
@@ -0,0 +1,39 @@
+(ns er-cassandra.model.callbacks.search-key-callback
+  (:require
+   [clojure.string :as str])
+  (:import
+   [java.text Normalizer Normalizer$Form]))
+
+(defn normalize-string
+  [s]
+  (-> s
+      (Normalizer/normalize Normalizer$Form/NFD)
+      (str/replace #"\p{InCombiningDiacriticalMarks}+", "")
+      .toLowerCase))
+
+(defn ^:private prepare-string
+  [s]
+  (-> s
+      normalize-string
+      (str/split #"\s+")))
+
+(defn ^:private extract-search-keys
+  [value]
+  (cond
+    (nil? value) []
+    (string? value) (prepare-string value)
+    (sequential? value) (mapcat extract-search-keys value)
+    (set? value) (mapcat extract-search-keys value)
+    (map? value) (mapcat extract-search-keys (vals value))
+    :else (prepare-string (str value))))
+
+(defn create-search-keys-callback
+  "create a callback which splits values from source-cols
+   into words and assocs a set of those words to search-col"
+  [search-col & source-cols]
+  (fn [r]
+    (let [search-keys (->> source-cols
+                           (map #(get r %))
+                           (mapcat extract-search-keys)
+                           set)]
+      (assoc r search-col search-keys))))


Getting the base transformation stuff set up

error: pathspec 'src/main/clj/clojure_club/gurps/wmatson.clj' did not match any file(s) known to git

--- src/main/clj/clojure_club/gurps/wmatson.clj
+++ src/main/clj/clojure_club/gurps/wmatson.clj
@@ -0,0 +1,56 @@
+(ns main.clj.clojure-club.gurps.wmatson
+  (:require [clojure.data.xml :as xml]
+            [clojure.java.io :as io]))
+
+(def raw-data (->> "clojure_club/gurps/basic_set.xml" io/resource slurp xml/parse-str))
+
+(def raw-data (clojure.walk/prewalk #(if (map? %) (into {} %) %) (xml/parse file)))
+
+(def vis360 (first (:content raw-data)))
+
+(defn leaf? [node]
+  (and (:content node) (not (some :content (:content node)))))
+
+(defn numberify [s]
+  (if (and (string? s) (re-matches #"^-?\d+(\.\d+)?$" s))
+    (read-string s)
+    s))
+
+(defn single->item [s]
+  (if (and (seq s) (= 1 (count s)))
+    (numberify (first s))
+    s))
+
+(defn- collision->vec [a b]
+  (if (vector? a)
+    (conj a b)
+    (conj [] a b)))
+
+(defn safe-merge [attrs parts]
+  (if (some map? parts)
+    (apply merge-with collision->vec attrs parts)
+    parts))
+
+(defn merge-attrs [node]
+  (merge (dissoc node :attrs) (:attrs node)))
+
+(defn clean [node]
+  (let [tag (:tag node)
+        content (single->item (safe-merge (:attrs node) (:content node)))
+        rest (dissoc node :tag :content :version :attrs)]
+    (if ((complement empty?) rest)
+      {tag (assoc rest :value content)}
+      {tag content})))
+
+
+(defn remove-version [root]
+  (clojure.walk/postwalk #(if (map? %) (dissoc % :version :id) %)
+                         root))
+
+(defn walk-transform [node]
+  (if (and (leaf? node))
+    (clean node)
+    node))
+
+;; (def clean-data (map :advantage (clojure.walk/postwalk walk-transform (:content (remove-version raw-data)))))
+;; (clojure.pprint/pprint clean-data)


variable-renaming

variable-renaming

--- src/babel/generate.cljc
+++ src/babel/generate.cljc
@@ -71,15 +71,15 @@
     ;; 1) branching to a new subtree, or
     ;; 2) terminating with a lexeme (leaf node).
     (let [tree (first trees)
-          f (frontier tree)
-          depth (count f)
-          child-spec (u/get-in tree f)
+          frontier-path (frontier tree)
+          depth (count frontier-path)
+          child-spec (u/get-in tree frontier-path)
           child-lexemes #(get-lexemes child-spec)
           child-trees #(parent-with-head child-spec depth)]
       (when println? (println (str "grow at:" (morph-ps tree))))
       (log/debug (str "grow at:" (morph-ps tree)))
       (lazy-cat
-       (if (not (empty? f))
+       (if (not (empty? frontier-path))
          (grow
           (let [children
                 (cond
@@ -97,7 +97,7 @@

                   true ;; generate children that are leaves before children that are trees.
                   (lazy-cat (child-lexemes) (child-trees)))]
-            (assoc-children tree children f)))
+            (assoc-children tree children frontier-path)))
          [tree])
        (grow (rest trees))))))

@@ -178,7 +178,7 @@
    (filter #(not (= :fail %)))
    (map #(u/assoc-in! % [::done?] true))))

-;; TODO: use recur: should be more efficient(?)
+;; TODO: use reduce.
 (defn- assoc-each-default [tree children path]
   (if (not (empty? children))
     (lazy-cat
@@ -192,7 +192,7 @@
            (default-fn)))
      (assoc-each-default tree (rest children) path))))

-;; TODO: use recur: should be more efficient(?)
+;; TODO: use reduce
 (defn- assoc-children [tree children path]
   (if (not (empty? children))
     (let [child (first children)]


drop GET /ValueSet/:id route (now handled with primary fhir server)

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/fhirbase/fhirterm.git/'


pool: introduce pool which will be used for recurring snapshots.

error: pathspec 'src/io/cyanite/pool.clj' did not match any file(s) known to git

--- src/io/cyanite/pool.clj
+++ src/io/cyanite/pool.clj
@@ -0,0 +1,72 @@
+(ns io.cyanite.pool
+  (:require [com.stuartsierra.component :as component]
+            [spootnik.reporter          :as r]
+            [clojure.tools.logging      :refer [info error]])
+  (:import java.util.concurrent.ScheduledThreadPoolExecutor
+           java.util.concurrent.Executors
+           java.util.concurrent.TimeUnit))
+
+(defn set-thread-name!
+  [thread-name]
+  (.setName (Thread/currentThread) (name thread-name)))
+
+(defonce secs TimeUnit/SECONDS)
+
+(defprotocol Scheduler
+  (submit [this f])
+  (shutdown [this])
+  (shutdown-now [this])
+  (join [this])
+  (recurring [this f delay]))
+
+(defn wrapped
+  [reporter f]
+  (fn []
+    (try
+      (f)
+      (catch InterruptedException e
+        (info "caught shutdown, stopping task."))
+      (catch java.nio.channels.ClosedByInterruptException e
+        (info "caught shutdown in I/O, stopping task."))
+      (catch Exception e
+        (r/capture! reporter e)))))
+
+(defrecord Pool [pool threads reporter]
+  component/Lifecycle
+  (start [this]
+    (assoc this :pool (ScheduledThreadPoolExecutor. (or threads 10))))
+  (stop [this]
+    (let [remains (.shutdownNow pool)]
+      (info "found" (count remains) "pending tasks during shutdown."))
+    (assoc this :pool nil))
+  Scheduler
+  (submit [this f]
+    (.submit pool (wrapped reporter f)))
+  (shutdown [this]
+    (.shutdown pool))
+  (shutdown-now [this]
+    (.shutdownNow pool))
+  (join [this]
+    (while (not (.awaitTermination pool 10000 secs)) nil))
+  (recurring [this f delay]
+    (.scheduleAtFixedRate pool (wrapped reporter f) 0 delay secs)))
+
+(defn cancelled?
+  [task]
+  (.isCancelled task))
+
+(defn done?
+  [task]
+  (.isDone task))
+
+(defn stopped?
+  [task]
+  (or (cancelled? task) (done? task)))
+
+(defmacro with-pool
+  [pool & body]
+  `(submit ~pool (fn [] ~@body)))
+
+(defmacro with-schedule
+  [[pool delay] & body]
+  `(recurring ~pool (fn [] ~@body) 0 delay secs))


add query.cljs for simple ($ "#selector") functionality

error: pathspec 'src/lib/cljs/query.cljs' did not match any file(s) known to git

--- src/lib/cljs/query.cljs
+++ src/lib/cljs/query.cljs
@@ -0,0 +1,11 @@
+(ns query)
+
+(defn $
+  "A basic query selector similar to Sizzle/jQuery. Uses document.querySelectorAll(),
+  only available in modern browsers"
+  ([selector] ($ selector js/document))
+  ([selector ctx]
+     (let [result (. js/document (querySelectorAll selector ctx))]
+       (if (and result (= 1 (.-length result)))
+         (aget result 0)
+         result))))


return 404 for files starting with ^/app/ that don't exist (instead of returning index.html)

--- src/metabase/routes.clj
+++ src/metabase/routes.clj
@@ -13,8 +13,11 @@
 (let [index (serve-file "frontend_client/index.html")
       admin (serve-file "frontend_client/admin_index.html")]
   (defroutes routes
-    (GET "/" [] index)                                  ; ^/$           -> index.html
-    (context "/api" [] api/routes)                      ; ^/api/        -> API routes
-    (route/files "/app/" {:root "frontend_client/app"}) ; ^/app/        -> static files under frontend_client/app
-    (GET "/:org-slug/admin/*" [] admin)                 ; ^/org/admin/* -> admin_index.html
-    (GET "*" [] index)))                                ; Anything else (e.g. /user/edit_current) should serve up index.html; Angular app will handle the rest
+    (GET "/" [] index)                                ; ^/$           -> index.html
+    (context "/api" [] api/routes)                    ; ^/api/        -> API routes
+    (context "/app" []
+      (route/files "/" {:root "frontend_client/app"}) ; ^/app/        -> static files under frontend_client/app
+      (GET "/*" [] {:status 404                       ;                  return 404 for anything else starting with ^/app/ that doesn't exist
+                    :body "Not found."}))
+    (GET "/:org-slug/admin/*" [] admin)               ; ^/org/admin/* -> admin_index.html
+    (GET "*" [] index)))                              ; Anything else (e.g. /user/edit_current) should serve up index.html; Angular app will handle the rest


Checking in work from last night

Checking in work from last night

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/thinktopic/netlib-ccm.git/'


#59 add auth namespace for magnificent

#59 add auth namespace for magnificent

error: pathspec 'src/org/zalando/stups/friboo/auth.clj' did not match any file(s) known to git

--- src/org/zalando/stups/friboo/auth.clj
+++ src/org/zalando/stups/friboo/auth.clj
@@ -0,0 +1,39 @@
+(ns org.zalando.stups.friboo.auth
+  (:require [clj-http.client :as http]
+            [org.zalando.stups.friboo.ring :as r]
+            [org.zalando.stups.friboo.config :refer [require-config]]
+            [org.zalando.stups.friboo.log :as log]
+            [io.sarnowski.swagger1st.util.api :as api]
+            [com.netflix.hystrix.core :as hystrix :refer [defcommand]]))
+
+(defcommand fetch-auth
+  "Asks magnificent if the user for this token has access to resources of this team. Returns true or false."
+  {:hystrix/fallback-fn (constantly false)}
+  [magnificent-url policy team token]
+  (let [auth-response (http/get
+                        (r/conpath magnificent-url "/auth")
+                        {:content-type     :json
+                         :oauth-token      token
+                         :throw-exceptions false
+                         :body             {:policy  policy
+                                            :payload {:team team}}})]
+    (= 200 (:status auth-response))))
+
+(defn get-auth
+  "Convenience wrapper around fetch-auth, with logging"
+  [request & [team]]
+  (let [magnificent-url (require-config (:configuration request) :magnificent-url)
+        policy          (require-config (:configuration request) :magnificent-policy)
+        token           (get-in request [:tokeninfo "access_token"])
+        user            (get-in request [:tokeninfo "uid"] "unknown user")
+        has-access?     (fetch-auth magnificent-url policy team token)]
+    (log/info (str "Access to team" team (if has-access? "granted" "denied") "to" user))
+    has-access?))
+
+(defn require-auth
+  "Like get-auth, but throws an error if user has no access"
+  [request team]
+  (let [has-access? (get-auth request team)
+        user        (get-in request [:tokeninfo "uid"] "unknown user")]
+    (when-not has-access?
+      (api/throw-error 403 (str "Access to team" team "not granted to user" user)))))


db-ify the parsing/downloading. Might be useful for functional testing too.

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/mtravers/incidents.git/'


A stab at multi parameter lambdas with partials, doesn't work from Shen yet

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/michaelsbradleyjr/shen.clj.git/'


Grouping it with the other real primitives


Add build.boot without cloverage

Add build.boot without cloverage

error: pathspec 'build.boot' did not match any file(s) known to git

--- build.boot
+++ build.boot
@@ -0,0 +1,46 @@
+(set-env! :dependencies
+          '[[org.clojure/clojure "1.7.0"]
+            [org.clojure/core.match "0.3.0-alpha4"]
+            [prismatic/schema "1.0.5"]
+            [environ "1.0.2"]
+            [org.clojure/tools.cli "0.3.3"]
+            [clj-jgit "0.8.8"]
+            [clj-http "2.1.0"]
+            [cheshire "5.5.0"]
+            [throttler "1.0.0"]
+            [org.slf4j/slf4j-nop "1.7.18"]
+            [grimradical/clj-semver "0.3.0-20130920.191002-3" :exclusions [org.clojure/clojure]]
+            ; testing
+            [org.clojure/tools.namespace "0.2.11" :scope "test"]
+            [org.clojure/test.check "0.9.0" :scope "test"]
+            [clj-http-fake "1.0.2" :scope "test"]
+            [adzerk/boot-test "1.1.1" :scope "test"]]
+          :source-paths #{"src/"})
+
+(ns-unmap 'boot.user 'test)
+
+(require
+ '[github-changelog.core :refer [changelog]]
+ '[adzerk.boot-test :refer :all])
+
+(task-options!
+ pom {:project 'hu.ssh/github-changelog
+      :version "0.1.0-SNAPSHOT"
+      :description "GitHub changelog"
+      :url "https://github.com/raszi/github-changelog"
+      :license {:name "MIT"
+                :url  "http://choosealicense.com/licenses/mit/"}}
+ jar {:main 'github-changelog.cli}
+ aot {:all true})
+
+(deftask testing-helper []
+  "Sets up the environment for testing"
+  (merge-env! :source-paths #{"test"})
+  identity)
+
+(deftask auto-test []
+  "Test everything whenever source changes"
+  (comp
+   (testing-helper)
+   (watch)
+   (test)))


bump up timeouts

bump up timeouts

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/democracyworks/election-notification-http-api.git/'


CMR-2293 Adds unit tests for data size code.

error: pathspec 'umm-spec-lib/test/cmr/umm_spec/test/util.clj' did not match any file(s) known to git

--- umm-spec-lib/test/cmr/umm_spec/test/util.clj
+++ umm-spec-lib/test/cmr/umm_spec/test/util.clj
@@ -0,0 +1,29 @@
+(ns cmr.umm-spec.test.util
+  "Tests for cmr.umm-spec.util functions"
+  (:require [clojure.test :refer :all]
+            [cmr.umm-spec.util :as util]))
+
+(deftest test-parse-data-size
+  (are [s expected] (= expected
+                       (util/parse-data-sizes s))
+    "2 k" [{:Size 2.0 :Unit "KB"}]
+    "4,555.5mb" [{:Size 4555.5 :Unit "MB"}]
+    "9.446 Tbytes" [{:Size 9.446 :Unit "TB"}]
+    "pixel size: 1km, 500m, 250m" nil
+    "4.3 GB (total volume)" [{:Size 4.3 :Unit "GB"}]
+    "79 MB compressed; 214 MB uncompressed" [{:Size 79.0 :Unit "MB"} {:Size 214.0 :Unit "MB"}]
+    "Total Volume: 40 Mbytes for XBT data; 10 Mbytes for TSG data" [{:Size 40.0 :Unit "MB"} {:Size 10.0 :Unit "MB"}]
+    "1010 files; Total size: 2351.98 MB" [{:Size 2351.98 :Unit "MB"}]
+
+    "Single layer, raster format, 13.2 megabytes; vector format, 1.2 megabytes"
+    [{:Size 13.2 :Unit "MB"} {:Size 1.2 :Unit "MB"}]
+
+    "173.596 Gbytes" [{:Size 173.596 :Unit "GB"}]
+
+    ".5 GB" [{:Size 0.5 :Unit "GB"}]))
+
+(deftest data-size-str-test
+  (is (= (util/data-size-str [{:Size 92.4 :Unit "MB"} {:Size 0.4 :Unit "GB"}])
+         "92.4 MB, 0.4 GB"))
+  (is (= [{:Size 92.4 :Unit "MB"} {:Size 0.4 :Unit "GB"}]
+         (util/parse-data-sizes (util/data-size-str [{:Size 92.4 :Unit "MB"} {:Size 0.4 :Unit "GB"}])))))


added clojure solution

added clojure solution

error: pathspec 'solutions/day08/solution.clj' did not match any file(s) known to git

--- solutions/day08/solution.clj
+++ solutions/day08/solution.clj
@@ -0,0 +1,25 @@
+(require '[clojure.string :as str])
+
+(def input (str/split-lines (slurp "input.txt")))
+
+(defn encoding-overhead
+  [string]
+  (+ (* 3 (count (re-seq #"\\x[0-9a-f]{2}" string)))
+     (count (re-seq #"\\[\\|\"]" string))
+     2))
+
+(defn overhead-to-encode
+  [string]
+  (+ (count (re-seq #"[\"|\\]" string))
+     2))
+
+(defn part1
+  [input]
+  (reduce + (map encoding-overhead input)))
+
+(defn part2
+  [input]
+  (reduce + (map overhead-to-encode input)))
+
+(println "part 1:" (part1 input))
+(println "part 2:" (part2 input))


Added functions that enable data augmentation

error: pathspec 'src/clj/think/image/data_augmentation.clj' did not match any file(s) known to git

--- src/clj/think/image/data_augmentation.clj
+++ src/clj/think/image/data_augmentation.clj
@@ -0,0 +1,160 @@
+(ns think.image.data-augmentation
+  (:require
+    [mikera.image.core :as imagez]
+    [clojure.core.matrix.macros :refer [c-for]]
+    [think.image.pixel :as think-pixel]
+    [think.image.core :as image]
+    [think.image.image :as think-image]
+    [clojure.core.matrix :as m])
+  (:import
+    [java.awt.image BufferedImage AffineTransformOp]
+    [java.awt.geom AffineTransform]))
+
+
+(defn- generate-random-int-pixel
+  []
+  (think-pixel/pack-pixel (rand-int 255) (rand-int 255) (rand-int 255) 255))
+
+
+(defn- shift-color-component
+  [color shift]
+  (let [new-color (+ color shift)]
+    (if (> new-color 255)
+      (- new-color 256)
+      new-color)))
+
+
+(defn- shift-channels
+  [color-vec shift]
+  (let [size (+ shift (count color-vec))]
+    (subvec (vec (flatten (repeat size color-vec)))
+            shift size)))
+
+;; clips image
+(defn rotate
+  "Rotates an image (degrees) and clips parts of image that are outside the bounds"
+  [^BufferedImage img degrees random?]
+  (let [width (.getWidth img)
+        height (.getHeight img)
+        degrees (if random? (rand-int 360) degrees)
+        out-image (imagez/new-image width height)
+        tx (AffineTransform.)
+        radians (Math/toRadians degrees)
+        _ (.rotate tx radians (quot width 2) (quot height 2))
+        op (AffineTransformOp. tx AffineTransformOp/TYPE_BICUBIC)]
+    (.filter op img out-image)
+    out-image))
+
+
+(defn mirror
+  "Mirrors an image using keys :horizontal :vertical :random"
+  [^BufferedImage img & {:keys [direction]
+                         :or {direction :random}}]
+  (cond
+    (= direction :horizontal) (imagez/flip img :horizontal)
+    (= direction :vertical) (imagez/flip img :vertical)
+    (= direction :random) (imagez/flip img (first (shuffle [:horizontal :vertical])))))
+
+
+(defn normalize-image
+  "Normalizes the image (0-255 to 0-1). Returns a core.matrix vector"
+  [^BufferedImage img]
+  (let [^ints pixels (imagez/get-pixels img)
+        num-pixels (alength pixels)
+        ^doubles r-data (double-array num-pixels)
+        ^doubles g-data (double-array num-pixels)
+        ^doubles b-data (double-array num-pixels)]
+    (c-for [pixel 0 (< pixel num-pixels) (inc pixel)]
+           (think-pixel/with-unpacked-pixel (aget pixels pixel)
+             (aset r-data pixel (double r))
+             (aset g-data pixel (double g))
+             (aset b-data pixel (double b))))
+    (-> (m/array :vectorz [r-data g-data b-data])
+      (m/div! 255.0)
+      (m/sub! 0.5))))
+
+
+(defn color-shift
+  "Shifts pixel values of the image by channel. Shift amount can be different for each channel"
+  [^BufferedImage img shift-vec random?]
+  (let [^ints pixels (imagez/get-pixels img)
+        num-pixels (alength pixels)
+        [red blue green] (if random? [(rand-int 255) (rand-int 255) (rand-int 255)] shift-vec)]
+    (c-for [idx 0 (< idx num-pixels) (inc idx)]
+           (think-pixel/with-unpacked-pixel (aget pixels idx)
+             (aset pixels idx (think-pixel/pack-pixel (shift-color-component r red)
+                                                      (shift-color-component b blue)
+                                                      (shift-color-component g green) 255))))
+    (imagez/set-pixels img pixels)
+    img))
+
+
+(defn channel-shift
+  "Rearranges the channels in the image by the shift amount (RGB order)"
+  [^BufferedImage img shift]
+  (let [^ints pixels (imagez/get-pixels img)
+        num-pixels (alength pixels)]
+    (c-for [idx 0 (< idx num-pixels) (inc idx)]
+           (think-pixel/with-unpacked-pixel (aget pixels idx)
+             (aset pixels idx (think-pixel/pack-pixel
+                                (conj (shift-channels [r g b] shift) 255)))))
+    (imagez/set-pixels img pixels)
+    img))
+
+
+(defn inject-noise
+  "Injects noise (pixel-wise) based on the percentage of noise desired in the output image"
+  [^BufferedImage img noise-ratio]
+  (let [width (.getWidth img)
+        height (.getHeight img)
+        ^int pixels (imagez/get-pixels img)
+        num-pixels (alength pixels)
+        num-noisy-pixels (* noise-ratio num-pixels)
+        locations-to-edit (take num-noisy-pixels (shuffle (range num-pixels)))
+        out-image (imagez/new-image width height)]
+    (doseq [location locations-to-edit]
+      (aset pixels location (generate-random-int-pixel)))
+    (imagez/set-pixels out-image pixels)
+    out-image))
+
+(defn- rotate-img-emb-impl [img r x y]
+  (let [w (.getWidth img)
+        h (.getHeight img)
+        at (new java.awt.geom.AffineTransform)
+        _ (.translate at x y)
+        _ (.rotate at r)
+        source-corners [0 0 w 0 w h 0 h]
+        dest-corners (double-array [0.0 0.0 1.0 1.0 2.0 2.0 3.0 3.0])
+        _ (.transform at (float-array source-corners) 0 dest-corners 0 4)
+        xs (take-nth 2 dest-corners)
+        ys (take-nth 2 (rest dest-corners))
+        minp [(apply min xs) (apply min ys)]
+        maxp [(apply max xs) (apply max ys)]
+        nw (+ 1 (- (first maxp) (first minp)))
+        nh (+ 1 (- (second maxp) (second minp)))
+        at2 (new java.awt.geom.AffineTransform)
+        _ (.translate at2 x y)
+        _ (.translate at2 (- (first minp)) (- (second minp)))
+        _ (.rotate at2 r)
+        ato (new java.awt.image.AffineTransformOp at2 java.awt.image.AffineTransformOp/TYPE_BICUBIC)
+        out (imagez/new-image nw nh)
+        _ (.filter ato img out)
+        ]
+    out))
+
+;; increases size of the image
+(defn rotate-img-embiggen
+  "rotate the image by a given angle, increasing the size of the result
+  image to ensure that it is fully contained."
+  ([img r] (rotate-img-emb-impl img r (* 0.5 (.getWidth img)) (* 0.5 (.getHeight img))))
+  ([img r x y] (rotate-img-emb-impl img r x y)))
+
+(defn make-noise-image [img]
+  (let [height (.getHeight img)
+        width (.getWidth img)
+        new-img (imagez/new-image width height)
+        pxls (imagez/get-pixels img)]
+    (dotimes [i (* width height)]
+      (aset pxls i (generate-random-int-pixel)))
+    (imagez/set-pixels new-img pxls)
+    new-img))