<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,26 +1,3 @@
-function NormalDistribution(sigma, mu) {
-    return new Object({
-        sigma: sigma,
-        mu: mu,
-        sample: function() {
-            var res;
-            if (this.storedDeviate) {
-                res = this.storedDeviate * this.sigma + this.mu;
-                this.storedDeviate = null;
-            } else {
-                var dist = Math.sqrt(-1 * Math.log(Math.random()));
-                var angle = 2 * Math.PI * Math.random();
-                this.storedDeviate = dist*Math.cos(angle);
-                res = dist*Math.sin(angle) * this.sigma + this.mu;
-            }
-            return res;
-        },
-        sampleInt : function() {
-            return Math.round(this.sample());
-        }
-    });
-}
-
 /*
  * weight: number
  *   QQQ NOTE: what do the weights mean?
@@ -64,9 +41,17 @@ function TwoDDistribution(weight, mus, variances) {
         },
 
         sample_full: function(n) {
-            var x = this.randn(n);
-            var cho = cholesky($M(this.variances));
-            return cho;
+            var rands = randn(n);
+            var mva = $M(this.variances);
+            var mmus = $M(this.mus);
+            var l = cholesky(mva);
+            var r = l.x(rands.transpose());
+            for (i=0; i &lt; n; i++) {
+                r.elements[0][i] += mmus.elements[0][0];
+                r.elements[1][i] += mmus.elements[1][0];
+            }
+
+            return r.transpose();
         },
             
     });</diff>
      <filename>gmm/gmm.js</filename>
    </modified>
    <modified>
      <diff>@@ -3,17 +3,71 @@
 &lt;script type=&quot;text/javascript&quot; src=&quot;../linalg/cholesky.js&quot;&gt;&lt;/script&gt;
 &lt;script type=&quot;text/javascript&quot; src=&quot;../g.raphael/raphael.js&quot;&gt;&lt;/script&gt;
 &lt;script type=&quot;text/javascript&quot; src=&quot;../g.raphael/g.raphael.js&quot;&gt;&lt;/script&gt;
-&lt;script type=&quot;text/javascript&quot; src=&quot;../g.raphael/g.line.js&quot;&gt;&lt;/script&gt;
+&lt;script type=&quot;text/javascript&quot; src=&quot;../g.raphael/g.scatter.js&quot;&gt;&lt;/script&gt;
 &lt;script type=&quot;text/javascript&quot; src=&quot;gmm.js&quot;&gt;&lt;/script&gt;
 &lt;script type=&quot;text/javascript&quot; src=&quot;jquery-1.3.2.min.js&quot;&gt;&lt;/script&gt;
 &lt;script type=&quot;text/javascript&quot;&gt;
 r = &quot;&quot;;
 $(document).ready(function(){ 
+    //TODO: test with non-positive-symmetric matrices
     r = Raphael(&quot;gaussian&quot;, 500, 500);
     //normal_dist_sanity_check();
-    gaussian_dist_sanity_check(r);
+    //gaussian_dist_sanity_check(r);
+    full_gaussian_dist_sanity_check(r);
 });
 
+function full_gaussian_dist_sanity_check(canvas) {
+    var weight = eval($(&quot;#weight&quot;).val());
+    var mus = eval($(&quot;#mus&quot;).val());
+    var vars = eval($(&quot;#vars&quot;).val());
+    var t = TwoDDistribution(weight, mus, vars);
+
+    var ss = t.sample_full(1000);
+    var xs = [];
+    var ys = [];
+    for (s=0; s&lt;ss.elements.length; s++) {
+        xs.push(ss.elements[s][0]);
+        ys.push(ss.elements[s][1]);
+    }
+    //XXX TODO debugging deleteme
+    _xs = xs;
+    _ys = ys;
+
+    //TODO could do a scatter chart that accepts x,y pairs
+    r.remove();
+    r = Raphael(&quot;gaussian&quot;, 500, 500);
+    var min = Math.min(Math.min.apply(null, xs), Math.min.apply(null, ys))
+    var max = Math.max(Math.max.apply(null, xs), Math.max.apply(null, ys))
+    var shim = max-min;
+    min -= shim * .2;
+    max += shim * .2;
+    var opts = {nostroke: true, axis: &quot;0 0 1 1&quot;, symbol: &quot;o&quot;,
+            axminx:min, axmaxx: max, axminy: min, axmaxy: max};
+    r.g.scatterplot(40,0,400,400, xs, ys, opts);
+}
+
+/* TODO DELETEME DEBUGGING XXX */
+function sh(values, dim) {
+    var k = values.length / dim,
+        l = k,
+        sum = 0,
+        res = [];
+    for (j=0; j &lt; values.length; j++) {
+        console.log(&quot;k, l, sum, res, j: &quot;, k, l, sum, res, j);
+        l--;
+        if (l &lt; 0) {
+            sum += values[j] * (1 + l);
+            res.push(sum / k);
+            sum = values[j] * -l;
+            l += k;
+        } else {
+            sum += values[j];
+        }
+    }
+    return res;
+}
+/* TODO DELETEME DEBUGGING XXX */
+
 function gaussian_dist_sanity_check(canvas) {
     var weight = eval($(&quot;#weight&quot;).val());
     var mus = eval($(&quot;#mus&quot;).val());
@@ -28,12 +82,11 @@ function gaussian_dist_sanity_check(canvas) {
         ys.push(ss[s][1]);
     }
 
-    //TODO could do a scatter chart that accepts x,y pairs
     r.remove();
     r = Raphael(&quot;gaussian&quot;, 500, 500);
     opts = {nostroke: true, axis: &quot;0 0 1 1&quot;, symbol: &quot;o&quot;}
             //axminx: .8, axmaxx: 1.2, axminy: .8, axmaxy: 1.2};
-    r.g.linechart(40,0,400,400, xs, ys, opts);
+    r.g.scatterplot(40,0,400,400, xs, ys, opts);
 }
 
 //TODO: compare to numpy; does it converge on a bell curve at the same n?
@@ -96,8 +149,9 @@ function normal_dist_sanity_check() {
 &lt;div id=&quot;gaussian&quot; style=&quot;float:left&quot;&gt; &lt;/div&gt;
 weight:&lt;input type=&quot;text&quot; id=&quot;weight&quot; value=&quot;1&quot;&gt;&lt;/input&gt;&lt;br&gt;
 mus: &lt;input type=&quot;text&quot; id=&quot;mus&quot; value=&quot;[1,1]&quot;&gt;&lt;/input&gt;&lt;br&gt;
-vars: &lt;input type=&quot;text&quot; id=&quot;vars&quot; value=&quot;[1,1]&quot;&gt;&lt;/input&gt;&lt;br&gt;
-&lt;input type=&quot;submit&quot; onclick=&quot;gaussian_dist_sanity_check(r)&quot;&gt;
+vars: &lt;input type=&quot;text&quot; id=&quot;vars&quot; value=&quot;[[1,0],[0,1]]&quot;&gt;&lt;/input&gt;&lt;br&gt;
+&lt;!-- vars: &lt;input type=&quot;text&quot; id=&quot;vars&quot; value=&quot;[1,1]&quot;&gt;&lt;/input&gt;&lt;br&gt; --&gt;
+&lt;input type=&quot;submit&quot; onclick=&quot;full_gaussian_dist_sanity_check(r)&quot;&gt;
 &lt;/div&gt;
 &lt;div id=&quot;chart&quot;&gt; &lt;/div&gt;
 &lt;/body&gt;</diff>
      <filename>gmm/test.html</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>92e1fc28c09117329293c292623cd353ab447bb3</id>
    </parent>
  </parents>
  <author>
    <name>Bill Mill</name>
    <email>bill.mill@gmail.com</email>
  </author>
  <url>http://github.com/llimllib/grabcut_js/commit/13c3a41585e37348fde004b739fb20567d943cd8</url>
  <id>13c3a41585e37348fde004b739fb20567d943cd8</id>
  <committed-date>2009-11-04T05:59:36-08:00</committed-date>
  <authored-date>2009-11-04T05:59:36-08:00</authored-date>
  <message>lots of work on on the full gaussian distribution</message>
  <tree>281ea80c3ef441d2f8e6bb97f209c8549d9f5d25</tree>
  <committer>
    <name>Bill Mill</name>
    <email>bill.mill@gmail.com</email>
  </committer>
</commit>
