Open chengjun opened 6 years ago
I'm not quite sure if the solution of the problem is still actual, but I hope this will help someone.
1. First of all, in the second edition of the book the stochastic gradient descent function was rewritten and the working example was added.
2. Regarding your example, the main problem is that you call the target function (sum_of_squares
) in minimize_stochastic
, giving it 3 arguments (x_i, y_i, theta
), but sum_of_squares
requires just one - the list of elements.
minimize_stochastic
:
...
value = sum( target_fn(x_i, y_i, theta) for x_i, y_i in data )
...
sum_of_squares
:
def dot(v, w):
"""v_1 * w_1 + ... + v_n * w_n"""
return sum(v_i * w_i
for v_i, w_i
in zip(v, w))
def sum_of_squares(v):
"""v_1 * v_1 + ... + v_n * v_n"""
return dot(v, v)
There is no example for Stochastic Gradient Descent in Chapter 8. I have tried to write one.
However, I would run into a problem of TypeError:
sum_of_squares() takes 1 positional argument but 3 were given