binomial.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. var test = require('tap').test;
  2. var distributions = require('../../distributions.js');
  3. var equals = require('../equal.js');
  4. test('testing binomial density function', function (t) {
  5. var binomial = distributions.Binomial(0.4, 100);
  6. var c = [
  7. [0, 6.533186e-23],
  8. [10 , 1.961179e-11],
  9. [30, 1.000750e-02],
  10. [40, 8.121914e-02],
  11. [50, 1.033751e-02],
  12. [60, 2.442492e-05],
  13. [70, 9.050560e-10],
  14. [100, 1.606938e-40]
  15. ];
  16. equals.absoluteEqual({
  17. test: t,
  18. map: c,
  19. fn: binomial.pdf.bind(binomial),
  20. limit: 0.0000005
  21. });
  22. t.end();
  23. });
  24. test('testing none standard binomial cumulative function', function (t) {
  25. var binomial = distributions.Binomial(0.4, 100);
  26. var c = [
  27. [0, 6.533186e-23],
  28. [10, 2.338762e-11],
  29. [30, 2.478282e-02],
  30. [40, 5.432945e-01],
  31. [50, 9.832383e-01],
  32. [60, 9.999820e-01],
  33. [70, 1.000000e+00],
  34. [100, 1.000000e+00]
  35. ];
  36. equals.absoluteEqual({
  37. test: t,
  38. map: c,
  39. fn: binomial.cdf.bind(binomial),
  40. limit: 0.0000005
  41. });
  42. t.end();
  43. });
  44. test('testing node standard binomial key values', function (t) {
  45. var binomial = distributions.Binomial(0.4, 100);
  46. t.equal(binomial.median(), 40);
  47. t.equal(binomial.mean(), 40);
  48. t.equal(binomial.variance(), 24);
  49. t.end();
  50. });