~smagoun/whoopsie/whoopsie-lp1017637

« back to all changes in this revision

Viewing changes to backend/stats/static/js/d3/examples/qq/stats.js

  • Committer: Evan Dandrea
  • Date: 2012-05-09 05:53:45 UTC
  • Revision ID: evan.dandrea@canonical.com-20120509055345-z2j41tmcbf4as5uf
The backend now lives in lp:daisy and the website (errors.ubuntu.com) now lives in lp:errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Sample from a normal distribution with mean 0, stddev 1.
2
 
function normal() {
3
 
  var x = 0, y = 0, rds, c;
4
 
  do {
5
 
    x = Math.random() * 2 - 1;
6
 
    y = Math.random() * 2 - 1;
7
 
    rds = x * x + y * y;
8
 
  } while (rds == 0 || rds > 1);
9
 
  c = Math.sqrt(-2 * Math.log(rds) / rds); // Box-Muller transform
10
 
  return x * c; // throw away extra sample y * c
11
 
}
12
 
 
13
 
// Simple 1D Gaussian (normal) distribution
14
 
function normal1(mean, deviation) {
15
 
  return function() {
16
 
    return mean + deviation * normal();
17
 
  };
18
 
}
19
 
 
20
 
// Gaussian Mixture Model (k=3) fit using E-M algorithm
21
 
function normal3(dd) {
22
 
  return function() {
23
 
    var r = Math.random(),
24
 
        i = r < dd[0][2] ? 0 : r < dd[0][2] + dd[1][2] ? 1 : 2,
25
 
        d = dd[i];
26
 
    return d[0] + Math.sqrt(d[1]) * normal();
27
 
  }
28
 
}