CourseraML icon indicating copy to clipboard operation
CourseraML copied to clipboard

The descendGradient function code has bug in ex1. The parameters in theta are not being updated simultaneously.

Open gautam-bmdi opened this issue 6 years ago • 0 comments

the line tmptheta = theta should be updated to tmptheta = np.copy(theta) // create a deep copy of theta instead of a new reference!

Otherwise the below statement will update theta also while the tmptheta is being updated (as both are references to same object!). theta should NOT change during an iteration of gradient descent! tmptheta[j] = theta[j] - (alpha/m)*np.sum((h(theta,X) - y)*np.array(X[:,j]).reshape(m,1))

gautam-bmdi avatar Feb 18 '19 01:02 gautam-bmdi