tag:blogger.com,1999:blog-4925159124120434624.post7638784806152977803..comments2019-10-16T12:11:41.055+05:30Comments on APDaga DumpBox : The Thirst for Learning...: Coursera: Machine Learning (Week 5) [Assignment Solution] - Andrew NGAkshay Daga (APDaga)http://www.blogger.com/profile/04899846959607912677noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-4925159124120434624.post-54043851073694576252019-08-09T12:15:51.936+05:302019-08-09T12:15:51.936+05:30Hi Akshay,
My approach to this problem is somewhat...Hi Akshay,<br />My approach to this problem is somewhat similar to yours (i.e going from part 1 to part 3 in exact order). However the relative difference I am getting is far to high. Don't you think we should first calculate regularised cost function before implementing backpropogation? What difference will it make? Also I have used a slightly different function to generate randomized initial weights assuming it is random anyways. Can that cause any problem?Sarthakhttps://www.blogger.com/profile/12180643090635147550noreply@blogger.comtag:blogger.com,1999:blog-4925159124120434624.post-78263569566202664092019-07-31T19:30:26.820+05:302019-07-31T19:30:26.820+05:30My first concern is "Why did you copied the c...My first concern is "Why did you copied the code as it is ?".<br />Understand the code and do it on your own. Above code is just for reference.<br /><br />I have tested all my codes multiple times and they are 100% correct.Akshay Daga (APDaga)https://www.blogger.com/profile/04899846959607912677noreply@blogger.comtag:blogger.com,1999:blog-4925159124120434624.post-14084802364871527342019-07-31T19:19:37.033+05:302019-07-31T19:19:37.033+05:30I have entered same code u mentioned for nncostfun...I have entered same code u mentioned for nncostfunction and submit it but backward propagation part has not submitted.<br /> A1 = X; % 5000 x 401<br /> <br /> Z2 = A1 * Theta1'; % m x hidden_layer_size == 5000 x 25<br /> A2 = sigmoid(Z2); % m x hidden_layer_size == 5000 x 25<br /> A2 = [ones(size(A2,1),1), A2]; % Adding 1 as first column in z = (Adding bias unit) % m x (hidden_layer_size + 1) == 5000 x 26<br /> <br /> Z3 = A2 * Theta2'; % m x num_labels == 5000 x 10<br /> A3 = sigmoid(Z3); % m x num_labels == 5000 x 10<br /> <br /> % h_x = a3; % m x num_labels == 5000 x 10<br /> <br /> y_Vec = (1:num_labels)==y; % m x num_labels == 5000 x 10<br /> <br /> DELTA3 = A3 - y_Vec; % 5000 x 10<br /> DELTA2 = (DELTA3 * Theta2) .* [ones(size(Z2,1),1) sigmoidGradient(Z2)]; % 5000 x 26<br /> DELTA2 = DELTA2(:,2:end); % 5000 x 25 %Removing delta2 for bias node<br /> <br /> Theta1_grad = (1/m) * (DELTA2' * A1); % 25 x 401<br /> Theta2_grad = (1/m) * (DELTA3' * A2); % 10 x 26<br /> <br /> %%%%%%%%%%%% WORKING: DIRECT CALCULATION OF THETA GRADIENT WITH REGULARISATION %%%%%%%%%%%<br /> % %Regularization term is later added in Part 3<br /> % Theta1_grad = (1/m) * Theta1_grad + (lambda/m) * [zeros(size(Theta1, 1), 1) Theta1(:,2:end)]; % 25 x 401<br /> % Theta2_grad = (1/m) * Theta2_grad + (lambda/m) * [zeros(size(Theta2, 1), 1) Theta2(:,2:end)]; % 10 x 26<br /> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%<br /> <br /> <br /> %%%%%%%%%%%% Part 3: Adding Regularisation term in J and Theta_grad %%%%%%%%%%%%%<br /> reg_term = (lambda/(2*m)) * (sum(sum(Theta1(:,2:end).^2)) + sum(sum(Theta2(:,2:end).^2))); %scalar<br /> <br /> %Costfunction With regularization<br /> J = J + reg_term; %scalar<br /> <br /> %Calculating gradients for the regularization<br /> Theta1_grad_reg_term = (lambda/m) * [zeros(size(Theta1, 1), 1) Theta1(:,2:end)]; % 25 x 401<br /> Theta2_grad_reg_term = (lambda/m) * [zeros(size(Theta2, 1), 1) Theta2(:,2:end)]; % 10 x 26<br /> <br /> %Adding regularization term to earlier calculated Theta_grad<br /> Theta1_grad = Theta1_grad + Theta1_grad_reg_term;<br /> Theta2_grad = Theta2_grad + Theta2_grad_reg_term;<br /> Unknownhttps://www.blogger.com/profile/09982248454065914009noreply@blogger.comtag:blogger.com,1999:blog-4925159124120434624.post-12406812917445123162019-07-28T21:50:33.210+05:302019-07-28T21:50:33.210+05:30Hi Akshay,
I have a quick Q about the delta2 calc...Hi Akshay,<br /><br />I have a quick Q about the delta2 calculation in the 'nnCostFunction.m'<br /><br />delta2 = (Theta2' * delta3) .* [1; sigmoidGradient(z2)]; % (hidden_layer_size+1) x 1 == 26 x 1<br /><br />Why do you use a '1' --> .* [1; sigmoidGradient(z2)]; and just not multiply by the --> .* sigmoidGradient(z2) ?<br /><br />thank you in advance<br />Bruno<br />Brunohttps://www.blogger.com/profile/02648875360566448601noreply@blogger.comtag:blogger.com,1999:blog-4925159124120434624.post-33629378964873242192019-07-27T17:22:44.570+05:302019-07-27T17:22:44.570+05:30In the link I have provided, Go and check the comm...In the link I have provided, Go and check the comment by "Chethan Bhandarkar" <br />She has provided the solution for the similar to your problem.Akshay Daga (APDaga)https://www.blogger.com/profile/04899846959607912677noreply@blogger.comtag:blogger.com,1999:blog-4925159124120434624.post-73626903383265263902019-07-27T14:42:59.307+05:302019-07-27T14:42:59.307+05:30Hi Akshay,the link you sent is for week2 and refer...Hi Akshay,the link you sent is for week2 and referring to week5Unknownhttps://www.blogger.com/profile/03259280905848668404noreply@blogger.comtag:blogger.com,1999:blog-4925159124120434624.post-76054509256803052042019-07-26T09:24:35.238+05:302019-07-26T09:24:35.238+05:30Hi, I am not Andrew. I am Akshay.
I think you are ...Hi, I am not Andrew. I am Akshay.<br />I think you are doing this assignment in Octave and that's why you are facing this issue.<br /><br />Chethan Bhandarkar has provided solution for it. Please check it out: https://www.apdaga.com/2018/06/coursera-machine-learning-week-2.html?showComment=1563986935868#c4682866656714070064<br /><br />ThanksAkshay Daga (APDaga)https://www.blogger.com/profile/04899846959607912677noreply@blogger.comtag:blogger.com,1999:blog-4925159124120434624.post-10471613288213547542019-07-26T09:18:48.404+05:302019-07-26T09:18:48.404+05:30Hi Andrew,when I tried to test the sigmoid gradien...Hi Andrew,when I tried to test the sigmoid gradient descent by inputing the code <br /> g = sigmoid(z).*(1-sigmoid(z));<br /><br />I got the following error:<br />undefined function or variable 'z'.<br /><br />Please why is this happening?<br /><br /><br /> Unknownhttps://www.blogger.com/profile/03259280905848668404noreply@blogger.comtag:blogger.com,1999:blog-4925159124120434624.post-50481666030265727572019-06-15T18:13:35.251+05:302019-06-15T18:13:35.251+05:30The program is giving the following error when run...The program is giving the following error when runnning the nnCostFunction.m<br /><br />Error using == <br />Matrix dimensions must agree.<br /><br />Error in nnCostFunction (line 87)<br /> y_Vec = (1:num_labels)==y; % m x num_labels == 5000 x 10Unknownhttps://www.blogger.com/profile/06213289132201619090noreply@blogger.comtag:blogger.com,1999:blog-4925159124120434624.post-88672467768416731702019-06-15T13:41:33.529+05:302019-06-15T13:41:33.529+05:30Hi Sarthak, You should also post the error you are...Hi Sarthak, You should also post the error you are getting.<br /><br />All above programs are working and tested by me multiple times.Akshay Daga (APDaga)https://www.blogger.com/profile/04899846959607912677noreply@blogger.comtag:blogger.com,1999:blog-4925159124120434624.post-23271757357094460752019-06-15T13:22:07.081+05:302019-06-15T13:22:07.081+05:30Your Program is not running.
When I try to run th...Your Program is not running. <br />When I try to run this program sigmoidGradient.m it says error in line 9. Now what is the error ?sarthakhttps://www.blogger.com/profile/02652643683378197218noreply@blogger.comtag:blogger.com,1999:blog-4925159124120434624.post-90542287772872883602019-06-02T23:31:06.562+05:302019-06-02T23:31:06.562+05:30Just to keep two implementations separate for easy...Just to keep two implementations separate for easy understanding of users.Prateek Suraksha Bhushanhttps://www.blogger.com/profile/04543194552806361156noreply@blogger.comtag:blogger.com,1999:blog-4925159124120434624.post-10542534814762804082019-05-30T19:24:25.051+05:302019-05-30T19:24:25.051+05:30please clear why you have used different variables...please clear why you have used different variables in cost fumctiof and BackpropagationUnknownhttps://www.blogger.com/profile/01127589362904930640noreply@blogger.comtag:blogger.com,1999:blog-4925159124120434624.post-85599745482638606092019-04-09T17:34:26.836+05:302019-04-09T17:34:26.836+05:30Hi,
I am clear up to how to calculate partial der...Hi,<br /><br />I am clear up to how to calculate partial derivatives. But, I am having doubt after calculating delta values. I have got delta-2 values in the dimension 10 X 25 and delta-1 with dimension 25X400. This is I have got for first row of input layer. So, for 5000 rows how these delta values will be calculated?<br /><br />Thanks.Shankarhttps://www.blogger.com/profile/07134868573317811040noreply@blogger.com