    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 test-observations
-  [0 0 0 0 12 12 12 12])
+  [-4 -4 -4 -4 4 4 4 4])
+
+(def test-observations
+  [1.45 1 0.9 2.5 17.8 18.2 17.9 17.8])
 ;; @@
 ;; =>
 ;;; {"type":"html","content":"<span class='clj-var'>#&#x27;worksheets.dirichlet-process-mixture-stick-breaking/test-observations</span>","value":"#'worksheets.dirichlet-process-mixture-stick-breaking/test-observations"}

(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 10000)
(def is-states (take num-particles (infer :importance dirichlet-process-mixture-stick-breaking [test-observations])))
(plot/histogram (repeatedly 1000 #(sample* (categorical (vec (empirical-distribution (collect-results is-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":"de1b25c3-74b4-4e25-ba18-bea77bedda1a","values":[{"x":-29.080964191558536,"y":0},{"x":-28.18373997179151,"y":0.45696492690139534},{"x":-27.286515752024485,"y":0.0},{"x":-26.38929153225746,"y":0.0},{"x":-25.492067312490434,"y":0.0},{"x":-24.59484309272341,"y":0.0},{"x":-23.697618872956383,"y":0.0011145486021985251},{"x":-22.800394653189358,"y":0.0033436458065955756},{"x":-21.903170433422332,"y":0.0},{"x":-21.005946213655307,"y":0.0},{"x":-20.10872199388828,"y":0.0},{"x":-19.211497774121256,"y":0.0022290972043970503},{"x":-18.31427355435423,"y":0.0},{"x":-17.417049334587205,"y":0.0},{"x":-16.51982511482018,"y":0.0},{"x":-15.622600895053154,"y":0.0},{"x":-14.725376675286128,"y":0.0},{"x":-13.828152455519103,"y":0.0033436458065955756},{"x":-12.930928235752077,"y":0.0011145486021985251},{"x":-12.033704015985052,"y":0.0},{"x":-11.136479796218026,"y":0.0},{"x":-10.239255576451,"y":0.005572743010992626},{"x":-9.342031356683975,"y":0.0033436458065955756},{"x":-8.44480713691695,"y":0.02786371505496313},{"x":-7.547582917149925,"y":0.0011145486021985251},{"x":-6.6503586973829005,"y":0.0},{"x":-5.753134477615876,"y":0.0033436458065955756},{"x":-4.855910257848851,"y":0.020061874839573453},{"x":-3.9586860380818263,"y":0.0011145486021985251},{"x":-3.0614618183148012,"y":0.0044581944087941005},{"x":-2.164237598547776,"y":0.0033436458065955756},{"x":-1.2670133787807512,"y":0.0},{"x":-0.3697891590137262,"y":0.020061874839573453},{"x":0.5274350607532987,"y":0.022290972043970503},{"x":1.4246592805203235,"y":0.013374583226382302},{"x":2.3218835002873486,"y":0.010030937419786726},{"x":3.2191077200543736,"y":0.024520069248367554},{"x":4.116331939821398,"y":0.024520069248367554},{"x":5.013556159588423,"y":0.03343645806595576},{"x":5.910780379355447,"y":0.04346739548574248},{"x":6.808004599122472,"y":0.04235284688354396},{"x":7.705228818889497,"y":0.15715135290999205},{"x":8.602453038656522,"y":0.035665555270352804},{"x":9.499677258423548,"y":0.031207360861558706},{"x":10.396901478190573,"y":0.031207360861558706},{"x":11.294125697957599,"y":0.050154687098933635},{"x":12.191349917724624,"y":0.012260034624183777},{"x":13.08857413749165,"y":0.011145486021985252},{"x":13.985798357258675,"y":0.0022290972043970503},{"x":14.8830225770257,"y":0.0},{"x":15.780246796792726,"y":0.005572743010992626},{"x":16.67747101655975,"y":0.0},{"x":17.574695236326775,"y":0.0},{"x":18.4719194560938,"y":0.0},{"x":19.369143675860826,"y":0.0},{"x":20.26636789562785,"y":0.0011145486021985251},{"x":21.163592115394877,"y":0.0},{"x":22.060816335161903,"y":0.0},{"x":22.958040554928928,"y":0.0},{"x":23.855264774695954,"y":0.0},{"x":24.75248899446298,"y":0.0022290972043970503},{"x":25.649713214230005,"y":0.0},{"x":26.54693743399703,"y":0.0},{"x":27.444161653764056,"y":0.0},{"x":28.34138587353108,"y":0.0},{"x":29.238610093298107,"y":0.0},{"x":30.135834313065132,"y":0.0},{"x":31.033058532832158,"y":0.0},{"x":31.930282752599183,"y":0.0},{"x":32.82750697236621,"y":0.0},{"x":33.724731192133234,"y":0.0},{"x":34.62195541190026,"y":0.0},{"x":35.519179631667285,"y":0.0},{"x":36.41640385143431,"y":0.0},{"x":37.313628071201336,"y":0.0},{"x":38.21085229096836,"y":0.0},{"x":39.10807651073539,"y":0.0},{"x":40.00530073050241,"y":0.0},{"x":40.90252495026944,"y":0.0},{"x":41.79974917003646,"y":0.0},{"x":42.69697338980349,"y":0.0},{"x":43.594197609570514,"y":0.0},{"x":44.49142182933754,"y":0.0},{"x":45.388646049104565,"y":0.0},{"x":46.28587026887159,"y":0.0},{"x":47.183094488638616,"y":0.0},{"x":48.08031870840564,"y":0.0},{"x":48.97754292817267,"y":0.0},{"x":49.87476714793969,"y":0.0},{"x":50.77199136770672,"y":0.0},{"x":51.669215587473744,"y":0.0},{"x":52.56643980724077,"y":0.0},{"x":53.463664027007795,"y":0.0},{"x":54.36088824677482,"y":0.0},{"x":55.258112466541846,"y":0.0},{"x":56.15533668630887,"y":0.0},{"x":57.0525609060759,"y":0.0},{"x":57.94978512584292,"y":0.0},{"x":58.84700934560995,"y":0.0},{"x":59.74423356537697,"y":0.0},{"x":60.641457785144,"y":0.0022290972043970503},{"x":61.538682004911024,"y":0}]}],"marks":[{"type":"line","from":{"data":"de1b25c3-74b4-4e25-ba18-bea77bedda1a"},"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":"de1b25c3-74b4-4e25-ba18-bea77bedda1a","field":"data.x"}},{"name":"y","type":"linear","range":"height","nice":true,"zero":false,"domain":{"data":"de1b25c3-74b4-4e25-ba18-bea77bedda1a","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 \"de1b25c3-74b4-4e25-ba18-bea77bedda1a\", :values ({:x -29.080964191558536, :y 0} {:x -28.18373997179151, :y 0.45696492690139534} {:x -27.286515752024485, :y 0.0} {:x -26.38929153225746, :y 0.0} {:x -25.492067312490434, :y 0.0} {:x -24.59484309272341, :y 0.0} {:x -23.697618872956383, :y 0.0011145486021985251} {:x -22.800394653189358, :y 0.0033436458065955756} {:x -21.903170433422332, :y 0.0} {:x -21.005946213655307, :y 0.0} {:x -20.10872199388828, :y 0.0} {:x -19.211497774121256, :y 0.0022290972043970503} {:x -18.31427355435423, :y 0.0} {:x -17.417049334587205, :y 0.0} {:x -16.51982511482018, :y 0.0} {:x -15.622600895053154, :y 0.0} {:x -14.725376675286128, :y 0.0} {:x -13.828152455519103, :y 0.0033436458065955756} {:x -12.930928235752077, :y 0.0011145486021985251} {:x -12.033704015985052, :y 0.0} {:x -11.136479796218026, :y 0.0} {:x -10.239255576451, :y 0.005572743010992626} {:x -9.342031356683975, :y 0.0033436458065955756} {:x -8.44480713691695, :y 0.02786371505496313} {:x -7.547582917149925, :y 0.0011145486021985251} {:x -6.6503586973829005, :y 0.0} {:x -5.753134477615876, :y 0.0033436458065955756} {:x -4.855910257848851, :y 0.020061874839573453} {:x -3.9586860380818263, :y 0.0011145486021985251} {:x -3.0614618183148012, :y 0.0044581944087941005} {:x -2.164237598547776, :y 0.0033436458065955756} {:x -1.2670133787807512, :y 0.0} {:x -0.3697891590137262, :y 0.020061874839573453} {:x 0.5274350607532987, :y 0.022290972043970503} {:x 1.4246592805203235, :y 0.013374583226382302} {:x 2.3218835002873486, :y 0.010030937419786726} {:x 3.2191077200543736, :y 0.024520069248367554} {:x 4.116331939821398, :y 0.024520069248367554} {:x 5.013556159588423, :y 0.03343645806595576} {:x 5.910780379355447, :y 0.04346739548574248} {:x 6.808004599122472, :y 0.04235284688354396} {:x 7.705228818889497, :y 0.15715135290999205} {:x 8.602453038656522, :y 0.035665555270352804} {:x 9.499677258423548, :y 0.031207360861558706} {:x 10.396901478190573, :y 0.031207360861558706} {:x 11.294125697957599, :y 0.050154687098933635} {:x 12.191349917724624, :y 0.012260034624183777} {:x 13.08857413749165, :y 0.011145486021985252} {:x 13.985798357258675, :y 0.0022290972043970503} {:x 14.8830225770257, :y 0.0} {:x 15.780246796792726, :y 0.005572743010992626} {:x 16.67747101655975, :y 0.0} {:x 17.574695236326775, :y 0.0} {:x 18.4719194560938, :y 0.0} {:x 19.369143675860826, :y 0.0} {:x 20.26636789562785, :y 0.0011145486021985251} {:x 21.163592115394877, :y 0.0} {:x 22.060816335161903, :y 0.0} {:x 22.958040554928928, :y 0.0} {:x 23.855264774695954, :y 0.0} {:x 24.75248899446298, :y 0.0022290972043970503} {:x 25.649713214230005, :y 0.0} {:x 26.54693743399703, :y 0.0} {:x 27.444161653764056, :y 0.0} {:x 28.34138587353108, :y 0.0} {:x 29.238610093298107, :y 0.0} {:x 30.135834313065132, :y 0.0} {:x 31.033058532832158, :y 0.0} {:x 31.930282752599183, :y 0.0} {:x 32.82750697236621, :y 0.0} {:x 33.724731192133234, :y 0.0} {:x 34.62195541190026, :y 0.0} {:x 35.519179631667285, :y 0.0} {:x 36.41640385143431, :y 0.0} {:x 37.313628071201336, :y 0.0} {:x 38.21085229096836, :y 0.0} {:x 39.10807651073539, :y 0.0} {:x 40.00530073050241, :y 0.0} {:x 40.90252495026944, :y 0.0} {:x 41.79974917003646, :y 0.0} {:x 42.69697338980349, :y 0.0} {:x 43.594197609570514, :y 0.0} {:x 44.49142182933754, :y 0.0} {:x 45.388646049104565, :y 0.0} {:x 46.28587026887159, :y 0.0} {:x 47.183094488638616, :y 0.0} {:x 48.08031870840564, :y 0.0} {:x 48.97754292817267, :y 0.0} {:x 49.87476714793969, :y 0.0} {:x 50.77199136770672, :y 0.0} {:x 51.669215587473744, :y 0.0} {:x 52.56643980724077, :y 0.0} {:x 53.463664027007795, :y 0.0} {:x 54.36088824677482, :y 0.0} {:x 55.258112466541846, :y 0.0} {:x 56.15533668630887, :y 0.0} {:x 57.0525609060759, :y 0.0} {:x 57.94978512584292, :y 0.0} {:x 58.84700934560995, :y 0.0} {:x 59.74423356537697, :y 0.0} {:x 60.641457785144, :y 0.0022290972043970503} {:x 61.538682004911024, :y 0})}], :marks [{:type \"line\", :from {:data \"de1b25c3-74b4-4e25-ba18-bea77bedda1a\"}, :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 \"de1b25c3-74b4-4e25-ba18-bea77bedda1a\", :field \"data.x\"}} {:name \"y\", :type \"linear\", :range \"height\", :nice true, :zero false, :domain {:data \"de1b25c3-74b4-4e25-ba18-bea77bedda1a\", :field \"data.y\"}}], :axes [{:type \"x\", :scale \"x\"} {:type \"y\", :scale \"y\"}]}}"}
;; <=

;; **
