Skip to content
DeepForgeby svx
All problems
MediumCalculusca-230

Jensen Gap Estimate

Problem

For the convex function f(x) = e^x, Jensen's inequality gives E[f(X)] >= f(E[X]), with equality for constant samples.

The gap is E[exp(X)] - exp(E[X]). Given a list of samples, return the empirical gap.

Hint

The gap grows with the variance of the samples for a strictly convex function.

Test cases

case 1
in: [[0,0]]
expected: 0
case 2
in: [[0,1]]
expected: 0.21041964352939435
case 3
in: [[1,1]]
expected: 0
case 4
in: [[0,2]]
expected: 1.4762462210062801
Starter codePython
def jensen_gap(samples):
    # Your code here
    pass

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