source: node_modules/d3-random/src/poisson.js@ e4c61dd

Last change on this file since e4c61dd was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Prototype 1.1

  • Property mode set to 100644
File size: 726 bytes
RevLine 
[e4c61dd]1import defaultSource from "./defaultSource.js";
2import binomial from "./binomial.js";
3import gamma from "./gamma.js";
4
5export default (function sourceRandomPoisson(source) {
6 var G = gamma.source(source),
7 B = binomial.source(source);
8
9 function randomPoisson(lambda) {
10 return function() {
11 var acc = 0, l = lambda;
12 while (l > 16) {
13 var n = Math.floor(0.875 * l),
14 t = G(n)();
15 if (t > l) return acc + B(n - 1, l / t)();
16 acc += n;
17 l -= t;
18 }
19 for (var s = -Math.log1p(-source()), k = 0; s <= l; ++k) s -= Math.log1p(-source());
20 return acc + k;
21 };
22 }
23
24 randomPoisson.source = sourceRandomPoisson;
25
26 return randomPoisson;
27})(defaultSource);
Note: See TracBrowser for help on using the repository browser.