All problems
Softmax Policy Probabilities
Problem
Convert action preferences into a probability distribution with a temperature parameter.
Return softmax(logits / temperature) computed with the max-subtraction trick so large logits do not overflow. The temperature is positive and logits is non-empty.
Hint
Subtracting the maximum leaves the ratio unchanged but keeps exp() in range.
Test cases
case 1
in: [[0,0],1]
expected: [0.5,0.5]
case 2
in: [[1,2,3],1]
expected: [0.09003057317038046,0.24472847105479764,0.6652409557748218]
case 3
in: [[1000,1000],1]
expected: [0.5,0.5]
case 4
in: [[2,1,0],0.5]
expected: [0.8668133321973349,0.11731042782619838,0.015876239976466765]
case 5
in: [[-1,-1,-1],2]
expected: [0.3333333333333333,0.3333333333333333,0.3333333333333333]
Starter codePython
import math
def softmax_probs(logits, temperature):
# Your code here
pass5 test cases · run your code against them in the editor