Skip to content
DeepForgeby svx
All problems
MediumCalculusca-189

Hessian of Logistic Loss

Problem

For the logistic loss L(w) = log(1 + exp(-y * w dot x)) with y in {+1, -1}, let p = 1 / (1 + exp(y * w dot x)).

The Hessian with respect to w is p * (1 - p) * x x^T, an outer product scaled by the variance of the sigmoid. Return it as a nested list.

Hint

The Hessian of the logistic loss is always positive semidefinite.

Test cases

case 1
in: [[0,0],[1,1],1]
expected: [[0.25,0.25],[0.25,0.25]]
case 2
in: [[1,0],[2,0],1]
expected: [[0.419974341614026,0],[0,0]]
case 3
in: [[0,1],[1,-2],-1]
expected: [[0.1049935854035065,-0.209987170807013],[-0.209987170807013,0.419974341614026]]
case 4
in: [[0.5,0.5],[2,1],1]
expected: [[0.5965858082813315,0.2982929041406657],[0.2982929041406657,0.14914645207033286]]
Starter codePython
def hessian_logistic(w, x, y):
    # Your code here
    pass

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