All problems
Jensen Gap for Sigmoid Samples
Problem
The Jensen gap is E[f(X)] - f(E[X]). For the sigmoid f and a list of equally weighted samples, compute both the average of the sigmoid values and the sigmoid of the average, then return the gap.
Given the sample list, return E[sigmoid(X)] - sigmoid(E[X]).
Hint
Average the transformed values, then subtract the transform of the average.
Test cases
case 1
in: [[0,2]]
expected: -0.040660039641063794
case 2
in: [[-1,1]]
expected: 0
case 3
in: [[1,1,1]]
expected: 0
Starter codePython
def jensen_gap_sigmoid_samples(samples):
# Your code here
pass3 test cases · run your code against them in the editor