Skip to content
DeepForgeby svx
All problems
HardTime Seriests-222

PIT Histogram Uniformity

Problem

Check the uniformity of probability integral transform values with a chi-square-style statistic: divide [0, 1) into equal bins, count values per bin, and return sum((count - expected)^2 / expected) with expected = n / bins.

Return 0.0 for empty input or bins <= 0. Values exactly 1.0 fall into the last bin.

Hint

Perfectly calibrated forecasts produce a flat PIT histogram.

Test cases

case 1
in: [[0.1,0.2,0.3,0.4],4]
expected: 4
case 2
in: [[0.1,0.1,0.1,0.1],4]
expected: 12
case 3
in: [[0.5],2]
expected: 1
case 4
in: [[],4]
expected: 0
Starter codePython
def pit_histogram_uniformity(pit_values, bins):
    # Your code here
    pass

4 test cases · run your code against them in the editor