All problems
Chance-Constraint Quantile
Problem
Evaluate the empirical quantile used by a chance constraint.
Sort the sampled values and return the element at index ceil((1 - alpha) * n) - 1, clamped into range. This is the value that the constraint must not exceed with probability 1 - alpha.
Hint
The empirical (1 - alpha) quantile covers all but the worst alpha fraction.
Test cases
case 1
in: [[1,2,3,4,5],0.2]
expected: 4
case 2
in: [[1,2,3,4,5],0.5]
expected: 3
case 3
in: [[1,2,3,4,5],0]
expected: 5
case 4
in: [[1,2,3,4,5],0.9]
expected: 1
Starter codePython
def chance_constraint_quantile(values, alpha):
# Your code here
pass4 test cases · run your code against them in the editor