pass@k Estimator
Problem Statement
Estimate pass@k, the probability that at least one of k sampled generations passes, given n total samples of which c passed. This is the standard unbiased HumanEval estimator.
Background
The unbiased estimator is
If n - c < k (fewer failures than k), pass@k is exactly 1.0 (every draw of k must include a pass). Compute it stably.
Your Task
def pass_at_k(n, c, k):
Return the pass@k estimate as a float rounded to 6 decimals.
Input Format
- n (int total samples), c (int correct), k (int), with 0 <= c <= n, 1 <= k <= n.
Output Format
- A float rounded to 6 decimals.
Sample
print(pass_at_k(5, 1, 1))
Output:
0.2
Example
print(pass_at_k(5, 1, 1))
0.2
- Check for guaranteed pass: Compare the number of failures () against . With and , there are failures. Since (), it is not guaranteed that a pass is included in the sample, so we proceed to the probabilistic calculation.
- Calculate the failure probability: The term represents the probability that all samples are failures. For , this simplifies to the ratio of failures to total samples: .
- Compute the pass probability: Subtract the failure probability from 1 to find the probability of at least one pass: .
- Format the result: Round the result to 6 decimal places, yielding , which is represented as
0.2. - The final output is 0.2
Constraints
- If
n - c < k, return1.0. - Otherwise
1 - C(n-c,k)/C(n,k); compute with a stable product. - Round to 6 decimals.