             [anglican.infcomp.network :refer :all]
             [anglican.infcomp.prior :refer :all]
             [anglican.inference :refer [infer]]
+            [helpers.gmm :refer [normalize move-to-unit-box gridify]]
             [gorilla-plot.core :as plot]))
 
 (anglican.infcomp.core/reset-infcomp-addressing-scheme!)

(defquery dirichlet-process-mixture-stick-breaking
  [input-data]
  (let
    [concentration 10
     base (fn []
            (let [v (/ 1.0 (sample (gamma 1 0.1)))]
              (list (sample (normal 0 (sqrt (* v 30)))) 
                    (sqrt v))))
     obs-param (DPmem concentration base)]


;; **

;; @@
(def num-particles 1000)
(def smc-states (take num-particles (infer :smc dirichlet-process-mixture-stick-breaking [test-observations] :number-of-particles 100)))
(plot/histogram (repeatedly 1000 #(sample* (categorical (vec (empirical-distribution (collect-results smc-states)))))) :normalize :probability-density :bins 100)
;; @@
;; =>
;;; {"type":"vega","content":{"width":400,"height":247.2187957763672,"padding":{"top":10,"left":55,"bottom":40,"right":10},"data":[{"name":"c46f1608-7561-48ce-beba-9467a0b6481f","values":[{"x":-74.92139415587361,"y":0},{"x":-73.74520528823822,"y":8.502035918860538E-4},{"x":-72.56901642060284,"y":0.0},{"x":-71.39282755296745,"y":0.0},{"x":-70.21663868533206,"y":0.0},{"x":-69.04044981769667,"y":0.0},{"x":-67.86426095006128,"y":0.0},{"x":-66.68807208242589,"y":0.0},{"x":-65.5118832147905,"y":0.0},{"x":-64.33569434715511,"y":0.0},{"x":-63.15950547951972,"y":0.0},{"x":-61.983316611884334,"y":0.0},{"x":-60.807127744248945,"y":0.0},{"x":-59.630938876613556,"y":0.0},{"x":-58.454750008978166,"y":0.0},{"x":-57.27856114134278,"y":0.0},{"x":-56.10237227370739,"y":0.0},{"x":-54.926183406072,"y":0.0},{"x":-53.74999453843661,"y":0.0},{"x":-52.57380567080122,"y":0.0},{"x":-51.39761680316583,"y":0.0},{"x":-50.22142793553044,"y":0.0},{"x":-49.045239067895054,"y":0.0},{"x":-47.869050200259665,"y":0.0},{"x":-46.692861332624275,"y":0.0},{"x":-45.516672464988886,"y":0.0},{"x":-44.3404835973535,"y":0.0},{"x":-43.16429472971811,"y":0.0},{"x":-41.98810586208272,"y":0.0},{"x":-40.81191699444733,"y":0.0},{"x":-39.63572812681194,"y":0.0},{"x":-38.45953925917655,"y":0.0},{"x":-37.28335039154116,"y":0.0017004071837721077},{"x":-36.10716152390577,"y":0.0},{"x":-34.930972656270384,"y":0.007651832326974485},{"x":-33.754783788634995,"y":0.0},{"x":-32.578594920999606,"y":0.0},{"x":-31.402406053364214,"y":8.502035918860538E-4},{"x":-30.22621718572882,"y":0.0},{"x":-29.05002831809343,"y":0.0},{"x":-27.873839450458036,"y":0.0},{"x":-26.697650582822643,"y":0.0},{"x":-25.52146171518725,"y":0.0},{"x":-24.345272847551858,"y":0.0017004071837721077},{"x":-23.169083979916465,"y":0.0},{"x":-21.992895112281072,"y":0.0},{"x":-20.81670624464568,"y":8.502035918860538E-4},{"x":-19.640517377010287,"y":0.0017004071837721077},{"x":-18.464328509374894,"y":0.0025506107756581614},{"x":-17.2881396417395,"y":0.0},{"x":-16.11195077410411,"y":0.0017004071837721077},{"x":-14.935761906468718,"y":0.0},{"x":-13.759573038833327,"y":8.502035918860538E-4},{"x":-12.583384171197936,"y":8.502035918860538E-4},{"x":-11.407195303562546,"y":0.004251017959430269},{"x":-10.231006435927155,"y":0.0017004071837721077},{"x":-9.054817568291764,"y":0.0034008143675442154},{"x":-7.878628700656373,"y":0.005951425143202377},{"x":-6.702439833020982,"y":0.011902850286404754},{"x":-5.526250965385591,"y":0.0017004071837721077},{"x":-4.3500620977502,"y":0.004251017959430269},{"x":-3.173873230114809,"y":0.014453461062062915},{"x":-1.9976843624794176,"y":0.016153868245835024},{"x":-0.8214954948440263,"y":0.03230773649167005},{"x":0.35469337279136504,"y":0.0552632334725935},{"x":1.5308822404267564,"y":0.07056689812654247},{"x":2.7070711080621477,"y":0.06291506579956799},{"x":3.883259975697539,"y":0.04336038318618875},{"x":5.05944884333293,"y":0.0680162873508843},{"x":6.235637710968321,"y":0.0221052933890374},{"x":7.411826578603712,"y":0.014453461062062915},{"x":8.588015446239103,"y":0.005951425143202377},{"x":9.764204313874494,"y":0.025506107756581617},{"x":10.940393181509885,"y":0.028056718532239778},{"x":12.116582049145276,"y":0.03230773649167005},{"x":13.292770916780666,"y":0.03910936522675848},{"x":14.468959784416057,"y":0.016153868245835024},{"x":15.645148652051448,"y":0.038259161634872425},{"x":16.82133751968684,"y":0.034858347267328206},{"x":17.99752638732223,"y":0.0442105867780748},{"x":19.173715254957624,"y":0.0331579400835561},{"x":20.349904122593017,"y":0.024655904164695562},{"x":21.52609299022841,"y":0.029757125716011884},{"x":22.702281857863802,"y":0.0110526466945187},{"x":23.878470725499195,"y":0.008502035918860538},{"x":25.054659593134588,"y":0.009352239510746593},{"x":26.23084846076998,"y":0.004251017959430269},{"x":27.407037328405373,"y":0.004251017959430269},{"x":28.583226196040766,"y":0.0},{"x":29.75941506367616,"y":0.0},{"x":30.93560393131155,"y":0.0034008143675442154},{"x":32.111792798946944,"y":8.502035918860538E-4},{"x":33.28798166658233,"y":8.502035918860538E-4},{"x":34.46417053421772,"y":8.502035918860538E-4},{"x":35.64035940185311,"y":0.0},{"x":36.8165482694885,"y":0.0},{"x":37.99273713712389,"y":0.0},{"x":39.16892600475928,"y":0.0},{"x":40.34511487239467,"y":0.0},{"x":41.521303740030056,"y":0.0},{"x":42.697492607665446,"y":0.0},{"x":43.873681475300835,"y":8.502035918860538E-4},{"x":45.049870342936224,"y":0}]}],"marks":[{"type":"line","from":{"data":"c46f1608-7561-48ce-beba-9467a0b6481f"},"properties":{"enter":{"x":{"scale":"x","field":"data.x"},"y":{"scale":"y","field":"data.y"},"interpolate":{"value":"step-before"},"fill":{"value":"steelblue"},"fillOpacity":{"value":0.4},"stroke":{"value":"steelblue"},"strokeWidth":{"value":2},"strokeOpacity":{"value":1}}}}],"scales":[{"name":"x","type":"linear","range":"width","zero":false,"domain":{"data":"c46f1608-7561-48ce-beba-9467a0b6481f","field":"data.x"}},{"name":"y","type":"linear","range":"height","nice":true,"zero":false,"domain":{"data":"c46f1608-7561-48ce-beba-9467a0b6481f","field":"data.y"}}],"axes":[{"type":"x","scale":"x"},{"type":"y","scale":"y"}]},"value":"#gorilla_repl.vega.VegaView{:content {:width 400, :height 247.2188, :padding {:top 10, :left 55, :bottom 40, :right 10}, :data [{:name \"c46f1608-7561-48ce-beba-9467a0b6481f\", :values ({:x -74.92139415587361, :y 0} {:x -73.74520528823822, :y 8.502035918860538E-4} {:x -72.56901642060284, :y 0.0} {:x -71.39282755296745, :y 0.0} {:x -70.21663868533206, :y 0.0} {:x -69.04044981769667, :y 0.0} {:x -67.86426095006128, :y 0.0} {:x -66.68807208242589, :y 0.0} {:x -65.5118832147905, :y 0.0} {:x -64.33569434715511, :y 0.0} {:x -63.15950547951972, :y 0.0} {:x -61.983316611884334, :y 0.0} {:x -60.807127744248945, :y 0.0} {:x -59.630938876613556, :y 0.0} {:x -58.454750008978166, :y 0.0} {:x -57.27856114134278, :y 0.0} {:x -56.10237227370739, :y 0.0} {:x -54.926183406072, :y 0.0} {:x -53.74999453843661, :y 0.0} {:x -52.57380567080122, :y 0.0} {:x -51.39761680316583, :y 0.0} {:x -50.22142793553044, :y 0.0} {:x -49.045239067895054, :y 0.0} {:x -47.869050200259665, :y 0.0} {:x -46.692861332624275, :y 0.0} {:x -45.516672464988886, :y 0.0} {:x -44.3404835973535, :y 0.0} {:x -43.16429472971811, :y 0.0} {:x -41.98810586208272, :y 0.0} {:x -40.81191699444733, :y 0.0} {:x -39.63572812681194, :y 0.0} {:x -38.45953925917655, :y 0.0} {:x -37.28335039154116, :y 0.0017004071837721077} {:x -36.10716152390577, :y 0.0} {:x -34.930972656270384, :y 0.007651832326974485} {:x -33.754783788634995, :y 0.0} {:x -32.578594920999606, :y 0.0} {:x -31.402406053364214, :y 8.502035918860538E-4} {:x -30.22621718572882, :y 0.0} {:x -29.05002831809343, :y 0.0} {:x -27.873839450458036, :y 0.0} {:x -26.697650582822643, :y 0.0} {:x -25.52146171518725, :y 0.0} {:x -24.345272847551858, :y 0.0017004071837721077} {:x -23.169083979916465, :y 0.0} {:x -21.992895112281072, :y 0.0} {:x -20.81670624464568, :y 8.502035918860538E-4} {:x -19.640517377010287, :y 0.0017004071837721077} {:x -18.464328509374894, :y 0.0025506107756581614} {:x -17.2881396417395, :y 0.0} {:x -16.11195077410411, :y 0.0017004071837721077} {:x -14.935761906468718, :y 0.0} {:x -13.759573038833327, :y 8.502035918860538E-4} {:x -12.583384171197936, :y 8.502035918860538E-4} {:x -11.407195303562546, :y 0.004251017959430269} {:x -10.231006435927155, :y 0.0017004071837721077} {:x -9.054817568291764, :y 0.0034008143675442154} {:x -7.878628700656373, :y 0.005951425143202377} {:x -6.702439833020982, :y 0.011902850286404754} {:x -5.526250965385591, :y 0.0017004071837721077} {:x -4.3500620977502, :y 0.004251017959430269} {:x -3.173873230114809, :y 0.014453461062062915} {:x -1.9976843624794176, :y 0.016153868245835024} {:x -0.8214954948440263, :y 0.03230773649167005} {:x 0.35469337279136504, :y 0.0552632334725935} {:x 1.5308822404267564, :y 0.07056689812654247} {:x 2.7070711080621477, :y 0.06291506579956799} {:x 3.883259975697539, :y 0.04336038318618875} {:x 5.05944884333293, :y 0.0680162873508843} {:x 6.235637710968321, :y 0.0221052933890374} {:x 7.411826578603712, :y 0.014453461062062915} {:x 8.588015446239103, :y 0.005951425143202377} {:x 9.764204313874494, :y 0.025506107756581617} {:x 10.940393181509885, :y 0.028056718532239778} {:x 12.116582049145276, :y 0.03230773649167005} {:x 13.292770916780666, :y 0.03910936522675848} {:x 14.468959784416057, :y 0.016153868245835024} {:x 15.645148652051448, :y 0.038259161634872425} {:x 16.82133751968684, :y 0.034858347267328206} {:x 17.99752638732223, :y 0.0442105867780748} {:x 19.173715254957624, :y 0.0331579400835561} {:x 20.349904122593017, :y 0.024655904164695562} {:x 21.52609299022841, :y 0.029757125716011884} {:x 22.702281857863802, :y 0.0110526466945187} {:x 23.878470725499195, :y 0.008502035918860538} {:x 25.054659593134588, :y 0.009352239510746593} {:x 26.23084846076998, :y 0.004251017959430269} {:x 27.407037328405373, :y 0.004251017959430269} {:x 28.583226196040766, :y 0.0} {:x 29.75941506367616, :y 0.0} {:x 30.93560393131155, :y 0.0034008143675442154} {:x 32.111792798946944, :y 8.502035918860538E-4} {:x 33.28798166658233, :y 8.502035918860538E-4} {:x 34.46417053421772, :y 8.502035918860538E-4} {:x 35.64035940185311, :y 0.0} {:x 36.8165482694885, :y 0.0} {:x 37.99273713712389, :y 0.0} {:x 39.16892600475928, :y 0.0} {:x 40.34511487239467, :y 0.0} {:x 41.521303740030056, :y 0.0} {:x 42.697492607665446, :y 0.0} {:x 43.873681475300835, :y 8.502035918860538E-4} {:x 45.049870342936224, :y 0})}], :marks [{:type \"line\", :from {:data \"c46f1608-7561-48ce-beba-9467a0b6481f\"}, :properties {:enter {:x {:scale \"x\", :field \"data.x\"}, :y {:scale \"y\", :field \"data.y\"}, :interpolate {:value \"step-before\"}, :fill {:value \"steelblue\"}, :fillOpacity {:value 0.4}, :stroke {:value \"steelblue\"}, :strokeWidth {:value 2}, :strokeOpacity {:value 1}}}}], :scales [{:name \"x\", :type \"linear\", :range \"width\", :zero false, :domain {:data \"c46f1608-7561-48ce-beba-9467a0b6481f\", :field \"data.x\"}} {:name \"y\", :type \"linear\", :range \"height\", :nice true, :zero false, :domain {:data \"c46f1608-7561-48ce-beba-9467a0b6481f\", :field \"data.y\"}}], :axes [{:type \"x\", :scale \"x\"} {:type \"y\", :scale \"y\"}]}}"}
;; <=

;; @@
(defquery dirichlet-process-mixture-stick-breaking-prior
  [input-data]
  (let
    [concentration 1.72
     base (fn []
            (let [v (/ 1.0 (sample (gamma 1 10)))]
              (list (sample (normal 0 (sqrt (* v 10)))) 
                    (sqrt v))))
     obs-param (DPmem concentration base)]

    ; observe draws from the DP mixture
    #_(map
      (fn [value]
        (observe (apply normal (obs-param)) value))
      input-data)

    ; predict a data point from the DP mixture
    (sample (apply normal (obs-param)))))

(def num-particles 1000)
(def smc-states (take num-particles (infer :smc dirichlet-process-mixture-stick-breaking-prior [test-observations] :number-of-particles 100)))
(plot/histogram (repeatedly 1000 #(sample* (categorical (vec (empirical-distribution (collect-results smc-states)))))) :normalize :probability-density :bins 100)
;; @@
;; =>
;;; {"type":"vega","content":{"width":400,"height":247.2187957763672,"padding":{"top":10,"left":55,"bottom":40,"right":10},"data":[{"name":"36f12138-60c2-4d7b-a9fe-5b039bbb1604","values":[{"x":-155.7143839474302,"y":0},{"x":-151.3724301791135,"y":9.2124426316744E-4},{"x":-147.0304764107968,"y":0.0},{"x":-142.6885226424801,"y":0.0},{"x":-138.3465688741634,"y":0.0},{"x":-134.0046151058467,"y":0.0},{"x":-129.66266133753,"y":0.0},{"x":-125.32070756921331,"y":0.0},{"x":-120.97875380089661,"y":0.0},{"x":-116.63680003257991,"y":0.0},{"x":-112.29484626426321,"y":0.0},{"x":-107.95289249594651,"y":2.3031106579186E-4},{"x":-103.61093872762982,"y":0.0},{"x":-99.26898495931312,"y":0.0},{"x":-94.92703119099642,"y":0.0},{"x":-90.58507742267972,"y":0.0},{"x":-86.24312365436302,"y":2.3031106579186E-4},{"x":-81.90116988604632,"y":2.3031106579186E-4},{"x":-77.55921611772962,"y":4.6062213158372E-4},{"x":-73.21726234941292,"y":0.0},{"x":-68.87530858109622,"y":4.6062213158372E-4},{"x":-64.53335481277952,"y":2.3031106579186E-4},{"x":-60.19140104446283,"y":2.3031106579186E-4},{"x":-55.84944727614614,"y":4.6062213158372E-4},{"x":-51.507493507829444,"y":4.6062213158372E-4},{"x":-47.16553973951275,"y":0.00161217746054302},{"x":-42.82358597119606,"y":2.3031106579186E-4},{"x":-38.48163220287937,"y":4.6062213158372E-4},{"x":-34.139678434562676,"y":0.00276373278950232},{"x":-29.797724666245983,"y":0.0025334217237104597},{"x":-25.45577089792929,"y":0.00184248852633488},{"x":-21.1138171296126,"y":0.00875182050009068},{"x":-16.771863361295907,"y":0.007600265171131379},{"x":-12.429909592979214,"y":0.01635208567122206},{"x":-8.087955824662522,"y":0.019806751658099957},{"x":-3.74600205634583,"y":0.026716083631855757},{"x":0.5959517119708622,"y":0.034776970934570856},{"x":4.937905480287554,"y":0.0299404385529418},{"x":9.279859248604247,"y":0.02164924018443484},{"x":13.621813016920939,"y":0.01888550739493252},{"x":17.96376678523763,"y":0.008060887302715099},{"x":22.305720553554323,"y":0.006679020907963939},{"x":26.647674321871015,"y":0.0025334217237104597},{"x":30.989628090187708,"y":0.0029940438552941797},{"x":35.3315818585044,"y":0.0023031106579186},{"x":39.67353562682109,"y":6.9093319737558E-4},{"x":44.015489395137784,"y":0.0025334217237104597},{"x":48.35744316345448,"y":6.9093319737558E-4},{"x":52.69939693177117,"y":4.6062213158372E-4},{"x":57.04135070008786,"y":6.9093319737558E-4},{"x":61.38330446840455,"y":4.6062213158372E-4},{"x":65.72525823672125,"y":6.9093319737558E-4},{"x":70.06721200503793,"y":0.0},{"x":74.40916577335463,"y":4.6062213158372E-4},{"x":78.75111954167133,"y":6.9093319737558E-4},{"x":83.09307330998803,"y":0.0011515553289593},{"x":87.43502707830473,"y":0.0},{"x":91.77698084662143,"y":0.0},{"x":96.11893461493813,"y":2.3031106579186E-4},{"x":100.46088838325483,"y":0.0},{"x":104.80284215157153,"y":0.0},{"x":109.14479591988822,"y":0.0},{"x":113.48674968820492,"y":0.0},{"x":117.82870345652162,"y":0.0},{"x":122.17065722483832,"y":0.0},{"x":126.51261099315502,"y":0.0},{"x":130.85456476147172,"y":9.2124426316744E-4},{"x":135.19651852978842,"y":0.0},{"x":139.53847229810512,"y":0.0},{"x":143.88042606642182,"y":0.0},{"x":148.22237983473852,"y":0.0},{"x":152.56433360305522,"y":0.0},{"x":156.90628737137192,"y":0.0},{"x":161.24824113968862,"y":0.0},{"x":165.59019490800532,"y":0.0},{"x":169.93214867632202,"y":0.0},{"x":174.27410244463871,"y":0.0},{"x":178.6160562129554,"y":0.0},{"x":182.9580099812721,"y":0.0},{"x":187.2999637495888,"y":0.0},{"x":191.6419175179055,"y":0.0},{"x":195.9838712862222,"y":0.0},{"x":200.3258250545389,"y":0.0},{"x":204.6677788228556,"y":0.0},{"x":209.0097325911723,"y":0.0},{"x":213.351686359489,"y":0.0},{"x":217.6936401278057,"y":0.0},{"x":222.0355938961224,"y":0.0},{"x":226.3775476644391,"y":0.0},{"x":230.7195014327558,"y":0.0},{"x":235.0614552010725,"y":0.0},{"x":239.4034089693892,"y":0.0},{"x":243.7453627377059,"y":0.0},{"x":248.0873165060226,"y":0.0},{"x":252.4292702743393,"y":0.0},{"x":256.771224042656,"y":0.0},{"x":261.1131778109727,"y":0.0},{"x":265.45513157928934,"y":0.0},{"x":269.797085347606,"y":0.0},{"x":274.1390391159227,"y":0.0},{"x":278.48099288423936,"y":2.3031106579186E-4},{"x":282.822946652556,"y":0}]}],"marks":[{"type":"line","from":{"data":"36f12138-60c2-4d7b-a9fe-5b039bbb1604"},"properties":{"enter":{"x":{"scale":"x","field":"data.x"},"y":{"scale":"y","field":"data.y"},"interpolate":{"value":"step-before"},"fill":{"value":"steelblue"},"fillOpacity":{"value":0.4},"stroke":{"value":"steelblue"},"strokeWidth":{"value":2},"strokeOpacity":{"value":1}}}}],"scales":[{"name":"x","type":"linear","range":"width","zero":false,"domain":{"data":"36f12138-60c2-4d7b-a9fe-5b039bbb1604","field":"data.x"}},{"name":"y","type":"linear","range":"height","nice":true,"zero":false,"domain":{"data":"36f12138-60c2-4d7b-a9fe-5b039bbb1604","field":"data.y"}}],"axes":[{"type":"x","scale":"x"},{"type":"y","scale":"y"}]},"value":"#gorilla_repl.vega.VegaView{:content {:width 400, :height 247.2188, :padding {:top 10, :left 55, :bottom 40, :right 10}, :data [{:name \"36f12138-60c2-4d7b-a9fe-5b039bbb1604\", :values ({:x -155.7143839474302, :y 0} {:x -151.3724301791135, :y 9.2124426316744E-4} {:x -147.0304764107968, :y 0.0} {:x -142.6885226424801, :y 0.0} {:x -138.3465688741634, :y 0.0} {:x -134.0046151058467, :y 0.0} {:x -129.66266133753, :y 0.0} {:x -125.32070756921331, :y 0.0} {:x -120.97875380089661, :y 0.0} {:x -116.63680003257991, :y 0.0} {:x -112.29484626426321, :y 0.0} {:x -107.95289249594651, :y 2.3031106579186E-4} {:x -103.61093872762982, :y 0.0} {:x -99.26898495931312, :y 0.0} {:x -94.92703119099642, :y 0.0} {:x -90.58507742267972, :y 0.0} {:x -86.24312365436302, :y 2.3031106579186E-4} {:x -81.90116988604632, :y 2.3031106579186E-4} {:x -77.55921611772962, :y 4.6062213158372E-4} {:x -73.21726234941292, :y 0.0} {:x -68.87530858109622, :y 4.6062213158372E-4} {:x -64.53335481277952, :y 2.3031106579186E-4} {:x -60.19140104446283, :y 2.3031106579186E-4} {:x -55.84944727614614, :y 4.6062213158372E-4} {:x -51.507493507829444, :y 4.6062213158372E-4} {:x -47.16553973951275, :y 0.00161217746054302} {:x -42.82358597119606, :y 2.3031106579186E-4} {:x -38.48163220287937, :y 4.6062213158372E-4} {:x -34.139678434562676, :y 0.00276373278950232} {:x -29.797724666245983, :y 0.0025334217237104597} {:x -25.45577089792929, :y 0.00184248852633488} {:x -21.1138171296126, :y 0.00875182050009068} {:x -16.771863361295907, :y 0.007600265171131379} {:x -12.429909592979214, :y 0.01635208567122206} {:x -8.087955824662522, :y 0.019806751658099957} {:x -3.74600205634583, :y 0.026716083631855757} {:x 0.5959517119708622, :y 0.034776970934570856} {:x 4.937905480287554, :y 0.0299404385529418} {:x 9.279859248604247, :y 0.02164924018443484} {:x 13.621813016920939, :y 0.01888550739493252} {:x 17.96376678523763, :y 0.008060887302715099} {:x 22.305720553554323, :y 0.006679020907963939} {:x 26.647674321871015, :y 0.0025334217237104597} {:x 30.989628090187708, :y 0.0029940438552941797} {:x 35.3315818585044, :y 0.0023031106579186} {:x 39.67353562682109, :y 6.9093319737558E-4} {:x 44.015489395137784, :y 0.0025334217237104597} {:x 48.35744316345448, :y 6.9093319737558E-4} {:x 52.69939693177117, :y 4.6062213158372E-4} {:x 57.04135070008786, :y 6.9093319737558E-4} {:x 61.38330446840455, :y 4.6062213158372E-4} {:x 65.72525823672125, :y 6.9093319737558E-4} {:x 70.06721200503793, :y 0.0} {:x 74.40916577335463, :y 4.6062213158372E-4} {:x 78.75111954167133, :y 6.9093319737558E-4} {:x 83.09307330998803, :y 0.0011515553289593} {:x 87.43502707830473, :y 0.0} {:x 91.77698084662143, :y 0.0} {:x 96.11893461493813, :y 2.3031106579186E-4} {:x 100.46088838325483, :y 0.0} {:x 104.80284215157153, :y 0.0} {:x 109.14479591988822, :y 0.0} {:x 113.48674968820492, :y 0.0} {:x 117.82870345652162, :y 0.0} {:x 122.17065722483832, :y 0.0} {:x 126.51261099315502, :y 0.0} {:x 130.85456476147172, :y 9.2124426316744E-4} {:x 135.19651852978842, :y 0.0} {:x 139.53847229810512, :y 0.0} {:x 143.88042606642182, :y 0.0} {:x 148.22237983473852, :y 0.0} {:x 152.56433360305522, :y 0.0} {:x 156.90628737137192, :y 0.0} {:x 161.24824113968862, :y 0.0} {:x 165.59019490800532, :y 0.0} {:x 169.93214867632202, :y 0.0} {:x 174.27410244463871, :y 0.0} {:x 178.6160562129554, :y 0.0} {:x 182.9580099812721, :y 0.0} {:x 187.2999637495888, :y 0.0} {:x 191.6419175179055, :y 0.0} {:x 195.9838712862222, :y 0.0} {:x 200.3258250545389, :y 0.0} {:x 204.6677788228556, :y 0.0} {:x 209.0097325911723, :y 0.0} {:x 213.351686359489, :y 0.0} {:x 217.6936401278057, :y 0.0} {:x 222.0355938961224, :y 0.0} {:x 226.3775476644391, :y 0.0} {:x 230.7195014327558, :y 0.0} {:x 235.0614552010725, :y 0.0} {:x 239.4034089693892, :y 0.0} {:x 243.7453627377059, :y 0.0} {:x 248.0873165060226, :y 0.0} {:x 252.4292702743393, :y 0.0} {:x 256.771224042656, :y 0.0} {:x 261.1131778109727, :y 0.0} {:x 265.45513157928934, :y 0.0} {:x 269.797085347606, :y 0.0} {:x 274.1390391159227, :y 0.0} {:x 278.48099288423936, :y 2.3031106579186E-4} {:x 282.822946652556, :y 0})}], :marks [{:type \"line\", :from {:data \"36f12138-60c2-4d7b-a9fe-5b039bbb1604\"}, :properties {:enter {:x {:scale \"x\", :field \"data.x\"}, :y {:scale \"y\", :field \"data.y\"}, :interpolate {:value \"step-before\"}, :fill {:value \"steelblue\"}, :fillOpacity {:value 0.4}, :stroke {:value \"steelblue\"}, :strokeWidth {:value 2}, :strokeOpacity {:value 1}}}}], :scales [{:name \"x\", :type \"linear\", :range \"width\", :zero false, :domain {:data \"36f12138-60c2-4d7b-a9fe-5b039bbb1604\", :field \"data.x\"}} {:name \"y\", :type \"linear\", :range \"height\", :nice true, :zero false, :domain {:data \"36f12138-60c2-4d7b-a9fe-5b039bbb1604\", :field \"data.y\"}}], :axes [{:type \"x\", :scale \"x\"} {:type \"y\", :scale \"y\"}]}}"}
;; <=

;; @@
(def input-data
  (list -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
        7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7
        3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3))

(def samples
  (take 5000
             (doquery :smc
                      dirichlet-process-mixture-stick-breaking
                      [input-data]
                      :number-of-particles 100)))

(def predictions (map :result samples))

(plot/histogram predictions :bins 100 :plot-range [[-8 15] :all])

;; @@
;; =>
;;; {"type":"vega","content":{"width":400,"height":247.2187957763672,"padding":{"top":10,"left":55,"bottom":40,"right":10},"data":[{"name":"fa231430-02c6-43fb-871b-55d1465f36bd","values":[{"x":-8.0,"y":0},{"x":-7.77,"y":0.0},{"x":-7.539999999999999,"y":0.0},{"x":-7.309999999999999,"y":2.0},{"x":-7.079999999999998,"y":3.0},{"x":-6.849999999999998,"y":1.0},{"x":-6.619999999999997,"y":1.0},{"x":-6.389999999999997,"y":3.0},{"x":-6.159999999999997,"y":1.0},{"x":-5.929999999999996,"y":3.0},{"x":-5.699999999999996,"y":3.0},{"x":-5.469999999999995,"y":4.0},{"x":-5.239999999999995,"y":4.0},{"x":-5.0099999999999945,"y":1.0},{"x":-4.779999999999994,"y":7.0},{"x":-4.549999999999994,"y":8.0},{"x":-4.319999999999993,"y":5.0},{"x":-4.089999999999993,"y":6.0},{"x":-3.8599999999999928,"y":4.0},{"x":-3.629999999999993,"y":5.0},{"x":-3.399999999999993,"y":8.0},{"x":-3.169999999999993,"y":8.0},{"x":-2.939999999999993,"y":5.0},{"x":-2.709999999999993,"y":9.0},{"x":-2.479999999999993,"y":15.0},{"x":-2.249999999999993,"y":22.0},{"x":-2.019999999999993,"y":20.0},{"x":-1.789999999999993,"y":29.0},{"x":-1.559999999999993,"y":89.0},{"x":-1.329999999999993,"y":220.0},{"x":-1.099999999999993,"y":549.0},{"x":-0.869999999999993,"y":805.0},{"x":-0.639999999999993,"y":596.0},{"x":-0.40999999999999304,"y":252.0},{"x":-0.17999999999999303,"y":130.0},{"x":0.05000000000000698,"y":60.0},{"x":0.280000000000007,"y":53.0},{"x":0.510000000000007,"y":36.0},{"x":0.740000000000007,"y":34.0},{"x":0.970000000000007,"y":41.0},{"x":1.200000000000007,"y":37.0},{"x":1.430000000000007,"y":38.0},{"x":1.660000000000007,"y":32.0},{"x":1.890000000000007,"y":35.0},{"x":2.120000000000007,"y":50.0},{"x":2.350000000000007,"y":70.0},{"x":2.580000000000007,"y":91.0},{"x":2.810000000000007,"y":115.0},{"x":3.040000000000007,"y":126.0},{"x":3.270000000000007,"y":133.0},{"x":3.500000000000007,"y":83.0},{"x":3.730000000000007,"y":59.0},{"x":3.960000000000007,"y":45.0},{"x":4.1900000000000075,"y":32.0},{"x":4.420000000000008,"y":18.0},{"x":4.650000000000008,"y":23.0},{"x":4.880000000000009,"y":24.0},{"x":5.110000000000009,"y":32.0},{"x":5.34000000000001,"y":20.0},{"x":5.57000000000001,"y":29.0},{"x":5.8000000000000105,"y":46.0},{"x":6.030000000000011,"y":45.0},{"x":6.260000000000011,"y":63.0},{"x":6.490000000000012,"y":68.0},{"x":6.720000000000012,"y":74.0},{"x":6.950000000000013,"y":103.0},{"x":7.180000000000013,"y":78.0},{"x":7.4100000000000135,"y":74.0},{"x":7.640000000000014,"y":66.0},{"x":7.870000000000014,"y":42.0},{"x":8.100000000000014,"y":37.0},{"x":8.330000000000014,"y":34.0},{"x":8.560000000000015,"y":22.0},{"x":8.790000000000015,"y":15.0},{"x":9.020000000000016,"y":15.0},{"x":9.250000000000016,"y":12.0},{"x":9.480000000000016,"y":11.0},{"x":9.710000000000017,"y":3.0},{"x":9.940000000000017,"y":6.0},{"x":10.170000000000018,"y":3.0},{"x":10.400000000000018,"y":5.0},{"x":10.630000000000019,"y":1.0},{"x":10.860000000000019,"y":2.0},{"x":11.09000000000002,"y":2.0},{"x":11.32000000000002,"y":3.0},{"x":11.55000000000002,"y":2.0},{"x":11.78000000000002,"y":0.0},{"x":12.010000000000021,"y":0.0},{"x":12.240000000000022,"y":2.0},{"x":12.470000000000022,"y":1.0},{"x":12.700000000000022,"y":1.0},{"x":12.930000000000023,"y":0.0},{"x":13.160000000000023,"y":2.0},{"x":13.390000000000024,"y":3.0},{"x":13.620000000000024,"y":1.0},{"x":13.850000000000025,"y":1.0},{"x":14.080000000000025,"y":0.0},{"x":14.310000000000025,"y":1.0},{"x":14.540000000000026,"y":0.0},{"x":14.770000000000026,"y":0.0},{"x":15.000000000000027,"y":0.0},{"x":15.230000000000027,"y":0}]}],"marks":[{"type":"line","from":{"data":"fa231430-02c6-43fb-871b-55d1465f36bd"},"properties":{"enter":{"x":{"scale":"x","field":"data.x"},"y":{"scale":"y","field":"data.y"},"interpolate":{"value":"step-before"},"fill":{"value":"steelblue"},"fillOpacity":{"value":0.4},"stroke":{"value":"steelblue"},"strokeWidth":{"value":2},"strokeOpacity":{"value":1}}}}],"scales":[{"name":"x","type":"linear","range":"width","zero":false,"domain":[-8,15]},{"name":"y","type":"linear","range":"height","nice":true,"zero":false,"domain":{"data":"fa231430-02c6-43fb-871b-55d1465f36bd","field":"data.y"}}],"axes":[{"type":"x","scale":"x"},{"type":"y","scale":"y"}]},"value":"#gorilla_repl.vega.VegaView{:content {:width 400, :height 247.2188, :padding {:top 10, :left 55, :bottom 40, :right 10}, :data [{:name \"fa231430-02c6-43fb-871b-55d1465f36bd\", :values ({:x -8.0, :y 0} {:x -7.77, :y 0.0} {:x -7.539999999999999, :y 0.0} {:x -7.309999999999999, :y 2.0} {:x -7.079999999999998, :y 3.0} {:x -6.849999999999998, :y 1.0} {:x -6.619999999999997, :y 1.0} {:x -6.389999999999997, :y 3.0} {:x -6.159999999999997, :y 1.0} {:x -5.929999999999996, :y 3.0} {:x -5.699999999999996, :y 3.0} {:x -5.469999999999995, :y 4.0} {:x -5.239999999999995, :y 4.0} {:x -5.0099999999999945, :y 1.0} {:x -4.779999999999994, :y 7.0} {:x -4.549999999999994, :y 8.0} {:x -4.319999999999993, :y 5.0} {:x -4.089999999999993, :y 6.0} {:x -3.8599999999999928, :y 4.0} {:x -3.629999999999993, :y 5.0} {:x -3.399999999999993, :y 8.0} {:x -3.169999999999993, :y 8.0} {:x -2.939999999999993, :y 5.0} {:x -2.709999999999993, :y 9.0} {:x -2.479999999999993, :y 15.0} {:x -2.249999999999993, :y 22.0} {:x -2.019999999999993, :y 20.0} {:x -1.789999999999993, :y 29.0} {:x -1.559999999999993, :y 89.0} {:x -1.329999999999993, :y 220.0} {:x -1.099999999999993, :y 549.0} {:x -0.869999999999993, :y 805.0} {:x -0.639999999999993, :y 596.0} {:x -0.40999999999999304, :y 252.0} {:x -0.17999999999999303, :y 130.0} {:x 0.05000000000000698, :y 60.0} {:x 0.280000000000007, :y 53.0} {:x 0.510000000000007, :y 36.0} {:x 0.740000000000007, :y 34.0} {:x 0.970000000000007, :y 41.0} {:x 1.200000000000007, :y 37.0} {:x 1.430000000000007, :y 38.0} {:x 1.660000000000007, :y 32.0} {:x 1.890000000000007, :y 35.0} {:x 2.120000000000007, :y 50.0} {:x 2.350000000000007, :y 70.0} {:x 2.580000000000007, :y 91.0} {:x 2.810000000000007, :y 115.0} {:x 3.040000000000007, :y 126.0} {:x 3.270000000000007, :y 133.0} {:x 3.500000000000007, :y 83.0} {:x 3.730000000000007, :y 59.0} {:x 3.960000000000007, :y 45.0} {:x 4.1900000000000075, :y 32.0} {:x 4.420000000000008, :y 18.0} {:x 4.650000000000008, :y 23.0} {:x 4.880000000000009, :y 24.0} {:x 5.110000000000009, :y 32.0} {:x 5.34000000000001, :y 20.0} {:x 5.57000000000001, :y 29.0} {:x 5.8000000000000105, :y 46.0} {:x 6.030000000000011, :y 45.0} {:x 6.260000000000011, :y 63.0} {:x 6.490000000000012, :y 68.0} {:x 6.720000000000012, :y 74.0} {:x 6.950000000000013, :y 103.0} {:x 7.180000000000013, :y 78.0} {:x 7.4100000000000135, :y 74.0} {:x 7.640000000000014, :y 66.0} {:x 7.870000000000014, :y 42.0} {:x 8.100000000000014, :y 37.0} {:x 8.330000000000014, :y 34.0} {:x 8.560000000000015, :y 22.0} {:x 8.790000000000015, :y 15.0} {:x 9.020000000000016, :y 15.0} {:x 9.250000000000016, :y 12.0} {:x 9.480000000000016, :y 11.0} {:x 9.710000000000017, :y 3.0} {:x 9.940000000000017, :y 6.0} {:x 10.170000000000018, :y 3.0} {:x 10.400000000000018, :y 5.0} {:x 10.630000000000019, :y 1.0} {:x 10.860000000000019, :y 2.0} {:x 11.09000000000002, :y 2.0} {:x 11.32000000000002, :y 3.0} {:x 11.55000000000002, :y 2.0} {:x 11.78000000000002, :y 0.0} {:x 12.010000000000021, :y 0.0} {:x 12.240000000000022, :y 2.0} {:x 12.470000000000022, :y 1.0} {:x 12.700000000000022, :y 1.0} {:x 12.930000000000023, :y 0.0} {:x 13.160000000000023, :y 2.0} {:x 13.390000000000024, :y 3.0} {:x 13.620000000000024, :y 1.0} {:x 13.850000000000025, :y 1.0} {:x 14.080000000000025, :y 0.0} {:x 14.310000000000025, :y 1.0} {:x 14.540000000000026, :y 0.0} {:x 14.770000000000026, :y 0.0} {:x 15.000000000000027, :y 0.0} {:x 15.230000000000027, :y 0})}], :marks [{:type \"line\", :from {:data \"fa231430-02c6-43fb-871b-55d1465f36bd\"}, :properties {:enter {:x {:scale \"x\", :field \"data.x\"}, :y {:scale \"y\", :field \"data.y\"}, :interpolate {:value \"step-before\"}, :fill {:value \"steelblue\"}, :fillOpacity {:value 0.4}, :stroke {:value \"steelblue\"}, :strokeWidth {:value 2}, :strokeOpacity {:value 1}}}}], :scales [{:name \"x\", :type \"linear\", :range \"width\", :zero false, :domain [-8 15]} {:name \"y\", :type \"linear\", :range \"height\", :nice true, :zero false, :domain {:data \"fa231430-02c6-43fb-871b-55d1465f36bd\", :field \"data.y\"}}], :axes [{:type \"x\", :scale \"x\"} {:type \"y\", :scale \"y\"}]}}"}
;; <=

;; @@

;; @@
