neonwatty / machine_learning_refined

Notes, examples, and Python demos for the 2nd edition of the textbook "Machine Learning Refined" (published by Cambridge University Press).
Other
1.67k stars 603 forks source link

Error in Example 3.5 #17

Closed surtich closed 3 years ago

surtich commented 4 years ago

There is an error in the number of runs to reach the minimum using the coordinate descent algorithm for this equation:

g(w1, w2) = 2w1² + 2w² + 2w1w2

The minimum is not reached in just two iterations.

The problem is that you call the algorithm with integer values ​​for the initial estimate of the w vector.

But if you use float values instead:

w = np.array([3.0,4.0])
max_its = 5
weight_history,cost_history = coordinate_descent_for_quadratic(g,w,max_its,a,b,C)

You get the correct values:


[array([3., 4.]), array([-2.,  4.]), array([-2.,  1.]), array([-0.5,  1. ]), array([-0.5 ,  0.25]), array([-0.125,  0.25 ]), array([-0.125 ,  0.0625]), array([-0.03125,  0.0625 ]), array([-0.03125 ,  0.015625]), array([-0.0078125,  0.015625 ]), array([-0.0078125 ,  0.00390625])]```
RezaBorhani commented 3 years ago

@surtich Thanks for pointing this out! We've updated Figure 3.4 as follows

Figure_3_4