Skip to content
DeepForgeby svx
All problems
MediumInformation Theoryinfo-255

Exponential Family Softmax

Problem

Return the exponential-family distribution over the given feature rows:

p_i proportional to exp(sum_k etas[k] * features[i][k])

Each feature row is one outcome. Normalize the weights and return them as a list.

Hint

Subtracting the maximum score before exponentiating keeps the computation stable.

Test cases

case 1
in: [[0],[[0],[1],[2]]]
expected: [0.3333333333333333,0.3333333333333333,0.3333333333333333]
case 2
in: [[1],[[0],[1],[2]]]
expected: [0.09003057317038046,0.24472847105479764,0.6652409557748218]
case 3
in: [[1,-1],[[0,0],[1,0],[0,1],[1,1]]]
expected: [0.19661193324148185,0.5344466453885229,0.07232948812851327,0.19661193324148185]
case 4
in: [[2],[[0],[1],[2]]]
expected: [0.015876239976466765,0.11731042782619838,0.8668133321973349]
Starter codePython
import math
def exp_family_softmax(etas, features):
    # Your code here
    pass

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