Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. class Binom {
  2. constructor(n, p) {
  3. this.n = n,
  4. this.p = p
  5. this.pmf = this.makePMF()
  6. this.cdf = this.makeCDF()
  7. }
  8.  
  9. binomialSumArg(n, i, p) {
  10. return choose(n, i) * Math.pow(p, i) * Math.pow(1 - p, n - i)
  11. }
  12.  
  13. makePMF() {
  14. const myLinSpace = linSpaceInclude(0, this.n, this.n)
  15.  
  16. myLinSpace.forEach((val, index) => {
  17. myLinSpace[index] = this.binomialSumArg(this.n, index, this.p)
  18. })
  19.  
  20. return myLinSpace
  21. }
  22.  
  23. makeCDF() {
  24. var runningSum = 0;
  25. const newArray = [...this.pmf]
  26. newArray.forEach((val, index) => {
  27. newArray[index] = newArray[index] + runningSum
  28. runningSum = newArray[index]
  29. })
  30. return newArray
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement