Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Binom {
- constructor(n, p) {
- this.n = n,
- this.p = p
- this.pmf = this.makePMF()
- this.cdf = this.makeCDF()
- }
- binomialSumArg(n, i, p) {
- return choose(n, i) * Math.pow(p, i) * Math.pow(1 - p, n - i)
- }
- makePMF() {
- const myLinSpace = linSpaceInclude(0, this.n, this.n)
- myLinSpace.forEach((val, index) => {
- myLinSpace[index] = this.binomialSumArg(this.n, index, this.p)
- })
- return myLinSpace
- }
- makeCDF() {
- var runningSum = 0;
- const newArray = [...this.pmf]
- newArray.forEach((val, index) => {
- newArray[index] = newArray[index] + runningSum
- runningSum = newArray[index]
- })
- return newArray
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement