TensorTonic
Problems
Binomial Probability Mass Function
Probability and Statistics
Easy

For nnn independent Bernoulli trials with success probability ppp, compute the probability of exactly kkk successes:

P(X=k)=(nk)pk(1−p)n−kP(X=k) = \binom{n}{k}p^k(1-p)^{n-k}P(X=k)=(kn​)pk(1−p)n−k

Also compute the probability of at most kkk successes:

P(X≤k)=∑i=0k(ni)pi(1−p)n−iP(X\le k) = \sum_{i=0}^{k}\binom{n}{i}p^i(1-p)^{n-i}P(X≤k)=i=0∑k​(in​)pi(1−p)n−i

Here, iii is a possible success count. Return a dictionary containing pmf and cdf as Python floats.

Loading visualization...

Examples

Input: n = 5, p = 0.5, k = 2

Output: {"pmf": 0.3125, "cdf": 0.5}

Explanation: Exactly two successes has probability 0.3125, while zero through two successes sum to 0.5.

Input: n = 10, p = 0.3, k = 0

Output: {"pmf": 0.028248, "cdf": 0.028248}

Input: n = 8, p = 0.7, k = 8

Output: {"pmf": 0.057648, "cdf": 1.0}

Hint 1

Use math.comb(n, i) for each binomial coefficient.

Hint 2

Build probabilities for i from 0 through k, then use the last value as the PMF and their sum as the CDF.

Requirements

  • Use the stated binomial PMF
  • Sum success counts from 0 through k for the CDF
  • Return exactly pmf and cdf in a dictionary of Python floats

Constraints

  • n is an integer between 1 and 100
  • k is an integer between 0 and n
  • p is between 0 and 1
  • Use the Python standard library only
Try Similar Problems
Expected Value (Discrete Distribution)EasySample Variance & Standard DeviationEasyGeometric Probability Mass Function & MeanEasyBernoulli Probability Mass Function & MomentsEasyPoisson PMF and CDF in PythonMediumPercentiles / QuantilesEasyMean, Median and Mode in PythonEasyCompute Covariance MatrixEasyCalculate P50, P95, and P99 Inference LatencyEasyMean, Median, ModeEasySoftmax (Boltzmann) ExplorationEasyConditional ProbabilityEasy

Accepts: number

Accepts: number

Accepts: number

You must run your code first.
Binomial Probability Mass Function

Binomial Probability Mass Function

Probability and Statistics
Easy

For nnn independent Bernoulli trials with success probability ppp, compute the probability of exactly kkk successes:

P(X=k)=(nk)pk(1−p)n−kP(X=k) = \binom{n}{k}p^k(1-p)^{n-k}P(X=k)=(kn​)pk(1−p)n−k

Also compute the probability of at most kkk successes:

P(X≤k)=∑i=0k(ni)pi(1−p)n−iP(X\le k) = \sum_{i=0}^{k}\binom{n}{i}p^i(1-p)^{n-i}P(X≤k)=i=0∑k​(in​)pi(1−p)n−i

Here, iii is a possible success count. Return a dictionary containing pmf and cdf as Python floats.

Loading visualization...

Examples

Input: n = 5, p = 0.5, k = 2

Output: {"pmf": 0.3125, "cdf": 0.5}

Explanation: Exactly two successes has probability 0.3125, while zero through two successes sum to 0.5.

Input: n = 10, p = 0.3, k = 0

Output: {"pmf": 0.028248, "cdf": 0.028248}

Input: n = 8, p = 0.7, k = 8

Output: {"pmf": 0.057648, "cdf": 1.0}

Hint 1

Use math.comb(n, i) for each binomial coefficient.

Hint 2

Build probabilities for i from 0 through k, then use the last value as the PMF and their sum as the CDF.

Requirements

  • Use the stated binomial PMF
  • Sum success counts from 0 through k for the CDF
  • Return exactly pmf and cdf in a dictionary of Python floats

Constraints

  • n is an integer between 1 and 100
  • k is an integer between 0 and n
  • p is between 0 and 1
  • Use the Python standard library only
Try Similar Problems
Expected Value (Discrete Distribution)EasySample Variance & Standard DeviationEasyGeometric Probability Mass Function & MeanEasyBernoulli Probability Mass Function & MomentsEasyPoisson PMF and CDF in PythonMediumPercentiles / QuantilesEasyMean, Median and Mode in PythonEasyCompute Covariance MatrixEasyCalculate P50, P95, and P99 Inference LatencyEasyMean, Median, ModeEasySoftmax (Boltzmann) ExplorationEasyConditional ProbabilityEasy

Accepts: number

Accepts: number

Accepts: number

You must run your code first.
Problems
Loading...
1 / 1