Skip to content
DeepForgeby svx
All problems
HardInformation Theoryinfo-180

t-Closeness Check

Problem

Return True when a group's sensitive-attribute distribution is within total variation distance t of the global distribution:

TV = 0.5 * sum(|group_i - global_i|) <= t

Use a tolerance of 1e-12 so exact boundary cases still pass.

Hint

t = 0 forces every group to match the global distribution exactly.

Test cases

case 1
in: [[0.5,0.5],[0.5,0.5],0]
expected: true
case 2
in: [[1,0],[0.5,0.5],0.5]
expected: true
case 3
in: [[1,0],[0.5,0.5],0.4]
expected: false
case 4
in: [[0.25,0.75],[0.5,0.5],0.3]
expected: true
Starter codePython
def t_closeness_holds(group_dist, global_dist, t):
    # Your code here
    pass

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