Binomial Probability Mass Function
Binomial Probability Mass Function
Implement the Binomial distribution Probability Mass Function (PMF) and Cumulative Distribution Function (CDF). The Binomial distribution counts the number of successes in n independent Bernoulli trials with probability p.
Binomial Distribution:
Probability Mass Function:
P(X=k)=(kn)pk(1−p)n−kCumulative Distribution Function:
P(X≤k)=i=0∑k(in)pi(1−p)n−iFunction Arguments
n: int- Number of trialsp: float- Success probability (0 ≤ p ≤ 1)k: int- Number of successes (0 ≤ k ≤ n)
Examples
Input: n=5, p=0.5, k=2
Output: pmf=0.3125, cdf=0.5
Input: n=10, p=0.3, k=0
Output: pmf=0.0282, cdf=0.0282
Input: n=8, p=0.7, k=8
Output: pmf=0.0576, cdf=1.0
Hint 1
Use scipy.special.comb() for stable binomial coefficients instead of factorial.
Hint 2
For CDF, sum PMF values from i=0 to k using a loop.
Hint 3
Convert results to float: float(pmf), float(cdf).
Requirements
- Return tuple: (pmf, cdf)
- Both pmf and cdf: scalar floats
- Use stable computation (no factorial loops)
- Handle edge cases: k=0, k=n, p=0, p=1
Constraints
- 0 ≤ k ≤ n ≤ 100
- 0 ≤ p ≤ 1
- NumPy + SciPy allowed; time limit: 300ms
Log in to take notes on this problem
Accepts: number
Accepts: number
Accepts: number
Binomial Probability Mass Function
Binomial Probability Mass Function
Implement the Binomial distribution Probability Mass Function (PMF) and Cumulative Distribution Function (CDF). The Binomial distribution counts the number of successes in n independent Bernoulli trials with probability p.
Binomial Distribution:
Probability Mass Function:
P(X=k)=(kn)pk(1−p)n−kCumulative Distribution Function:
P(X≤k)=i=0∑k(in)pi(1−p)n−iFunction Arguments
n: int- Number of trialsp: float- Success probability (0 ≤ p ≤ 1)k: int- Number of successes (0 ≤ k ≤ n)
Examples
Input: n=5, p=0.5, k=2
Output: pmf=0.3125, cdf=0.5
Input: n=10, p=0.3, k=0
Output: pmf=0.0282, cdf=0.0282
Input: n=8, p=0.7, k=8
Output: pmf=0.0576, cdf=1.0
Hint 1
Use scipy.special.comb() for stable binomial coefficients instead of factorial.
Hint 2
For CDF, sum PMF values from i=0 to k using a loop.
Hint 3
Convert results to float: float(pmf), float(cdf).
Requirements
- Return tuple: (pmf, cdf)
- Both pmf and cdf: scalar floats
- Use stable computation (no factorial loops)
- Handle edge cases: k=0, k=n, p=0, p=1
Constraints
- 0 ≤ k ≤ n ≤ 100
- 0 ≤ p ≤ 1
- NumPy + SciPy allowed; time limit: 300ms
Log in to take notes on this problem
Accepts: number
Accepts: number
Accepts: number