All problems
Jensen Gap for the Square
Problem
For the convex function f(x) = x^2, Jensen's inequality gives E[f(X)] >= f(E[X]), and the gap equals the population variance.
Given a list of samples, return mean(x^2) - mean(x)^2.
Hint
The Jensen gap for the square is the variance of the samples.
Test cases
case 1
in: [[0,0]]
expected: 0
case 2
in: [[0,2]]
expected: 1
case 3
in: [[1,3]]
expected: 1
case 4
in: [[-1,1]]
expected: 1
case 5
in: [[2,2,2]]
expected: 0
Starter codePython
def jensen_gap_square(samples):
# Your code here
pass5 test cases · run your code against them in the editor