CourseraML
CourseraML copied to clipboard
The descendGradient function code has bug in ex1. The parameters in theta are not being updated simultaneously.
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))