All problems
Smooth Approximation of Max
Problem
The log-sum-exp function smooths the maximum:
max_i x_i <= (1/tau) * log(sum exp(tau * x_i)) <= max_i x_i + log(n)/tau
Given values and the temperature parameter tau > 0, return the smooth maximum. Subtract the max before exponentiating for stability.
Hint
As tau grows the approximation approaches the exact maximum.
Test cases
case 1
in: [[0,0],1]
expected: 0.6931471805599453
case 2
in: [[1,2],1]
expected: 2.313261687518223
case 3
in: [[0],5]
expected: 0
case 4
in: [[0,0],0.5]
expected: 1.3862943611198906
Starter codePython
def smooth_max(values, tau):
# Your code here
pass4 test cases · run your code against them in the editor