You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gradient_norm = norm(gradient); % Break out of while loop if gradient_norm < tolerance
92
+
93
+
ifniter>=max_iter
94
+
fprintf('Gradient Descent could not converge within max_iter: %d\n\nTry to adjust the following parameters in the following order:\n1) rho\n2) max_iter\n3) tolerance ( < initial gradient_norm)\n\nTERMINATING THE PROGRAM!\n', max_iter)
95
+
break; % Break out of while loop
96
+
97
+
elseif any(isnan(w2)) % If any of the weights become 'NaN' at any iteration
98
+
fprintf('Gradient Descent could not converge due to NaN values in w2 @ niter = %d\n\nTry to adjust the following parameters in the following order:\n1) rho\n2) max_iter\n3) tolerance ( < initial gradient_norm)\n\nTERMINATING THE PROGRAM!\n',niter)
99
+
break; % Break out of while loop
100
+
end
101
+
102
+
end% End of while loop
103
+
104
+
% Printf number of iterations it took to converge (gradient descent)
105
+
ifniter<max_iter&& ~any(isnan(w2))
106
+
fprintf('Number of iterations: %d\n', niter)
107
+
end
108
+
109
+
% Convert weights obtained from gradient descent with normalized data to
110
+
% fit the un-normalized data (Not sure if necessary!)
111
+
w2 =x\(xnorm*w2);
112
+
y3 =x*w2;
113
+
114
+
% Plot Gradient Descent solution line on the scatter plot of data
0 commit comments