Skip to content
DeepForgeby svx
All problems
MediumOptimizationop-058

Gauss-Newton Step 1D

Problem

Take one Gauss-Newton step fitting y = a * x to data.

Return a + sum(xi * (yi - a * xi)) / sum(xi ** 2). If every xi is 0, return a unchanged. This is the exact least-squares slope update for a linear model through the origin.

Hint

The Jacobian entries are the xi values themselves.

Test cases

case 1
in: [0,[1,2,3],[2,4,6]]
expected: 2
case 2
in: [1,[1,2],[3,5]]
expected: 2.6
case 3
in: [0.5,[1,1],[1,2]]
expected: 1.5
case 4
in: [2,[],[]]
expected: 2
Starter codePython
def gauss_newton_step(a, X, y):
    # Your code here
    pass

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