Commits

Simon Cross  committed 70e9e3c

Clean-up binomial and kingman's implementations a bit.

  • Participants
  • Parent commits 98d2811

Comments (0)

Files changed (1)

File lib/stats.js

             });
         },
         data: function(n, p) {
-            var data = [];
             var prob = function (i) { return distri.math.binomial(i, n, p); }
-            for (var i = 0; i <= n; i++) {
-                data[i] = {
+            return _.map(_.range(0, n, 1), function (i) {
+                return {
                     trials: i,
                     probability: prob(i),
                     cummulative: distri.math.cummulative(prob, 0, i)
-                }
-            }
-            return data;
+                };
+            });
         }
     });
 })();
 (function() {
     new distri.plots.Plot("kingmans", {
         title: "Kingman's formula",
+        footer: 'See <a href="http://en.wikipedia.org/wiki/Kingman%27s_formula">Wikipedia</a> for details.',
         setup_chart: function(chart) {
-            var x_rho = chart.addMeasureAxis("x", "rho");
+            var x_rho = chart.addCategoryAxis("x", "rho");
             x_rho.addOrderRule("rho");
             var y_wait = chart.addMeasureAxis("y", "wait");
             chart.addSeries(null, dimple.plot.line, [x_rho, y_wait]);
             });
             plot.setup_coeff({
                 name: "Ca",
-                min: 1,
+                min: 0.1,
                 max: 5,
-                step: 1,
-                initial: 1
+                step: 0.1,
+                initial: 1,
+                fixed: 2
             });
             plot.setup_coeff({
                 name: "Cs",
-                min: 1,
+                min: 0.1,
                 max: 5,
-                step: 1,
+                step: 0.1,
                 initial: 1,
+                fixed: 2
             });
         },
         data: function(tau, ca, cs) {
-            var data = [];
             var kingman = function(rho) {
                 return (rho / (1 - rho)) * ((ca*ca + cs*cs) / 2) * tau;
             };
-            var rho = 0.0, rho_step = 1.0 / 50;
-            for (var i = 0; i <= 48; i++) {
-                rho += rho_step;
-                data[i] = {
+            return _.map(_.range(0, 0.98, 0.02), function (rho) {
+                return {
                     rho: rho,
                     wait: kingman(rho)
-                }
-            }
-            return data;
+                };
+            });
         }
     });
 })();