All problems
Log-Partition Convexity Check
Problem
Check numerically that the log-partition function A(eta) = ln(sum_t exp(eta * t)) is convex. Return True when the etas are equally spaced within 1e-9 and every second difference A[i+1] - 2 A[i] + A[i-1] is at least -1e-12. Otherwise return False.
Hint
Convexity of A(eta) is equivalent to the variance of the statistic being nonnegative.
Test cases
case 1
in: [[-1,0,1],[0,1]]
expected: true
case 2
in: [[0,1,2],[0]]
expected: true
case 3
in: [[0,1,2],[1]]
expected: true
case 4
in: [[0,1,3],[0,1]]
expected: false
Starter codePython
import math
def log_partition_convexity_check(etas, t_values):
# Your code here
pass4 test cases · run your code against them in the editor