Skip to content
DeepForgeby svx
All problems
HardML Fundamentalsml-271

Propensity Newton Step

Problem

Perform one Newton-Raphson step for a logistic propensity model p = sigmoid(b + w*x). Compute the average gradient g = [mean(p - t), mean((p - t)*x)] and the average Hessian H = [[mean(p(1-p)), mean(p(1-p)x)], [mean(p(1-p)x), mean(p(1-p)x^2)]], then update [b, w] by H^-1 g.

Return [b_new, w_new]; if H is singular or the input is empty, return [b, w].

Hint

Newton steps use curvature, not just the gradient, so they converge in few iterations.

Test cases

case 1
in: [[1,2,3],[0,1,1],0,0]
expected: [-3.3333333333333313,1.9999999999999991]
case 2
in: [[1,2,3],[0,0,1],0,0]
expected: [-4.666666666666664,1.9999999999999991]
case 3
in: [[1,1],[1,1],0,0]
expected: [0,0]
case 4
in: [[],[],0.5,1]
expected: [0.5,1]
Starter codePython
import math
def propensity_newton(X, t, b, w):
    # Returns [b_new, w_new]
    # Your code here
    pass

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