tag:blogger.com,1999:blog-4925159124120434624.post7638784806152977803..comments2020-07-04T11:17:21.717+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.comBlogger27125tag:blogger.com,1999:blog-4925159124120434624.post-64548958957569573872020-06-21T13:51:43.527+05:302020-06-21T13:51:43.527+05:30You'll be getting this error because you are r...You'll be getting this error because you are running your program sigmoidGradient.m<br />The variable z is defined in the main ex4.m file. So run the ex4.m file after running the sigmoidGradient.m file.Anonymoushttps://www.blogger.com/profile/01784040389683709262noreply@blogger.comtag:blogger.com,1999:blog-4925159124120434624.post-16200712872325387742020-06-17T19:02:09.812+05:302020-06-17T19:02:09.812+05:30As per the theory in lectures, you don't apply...As per the theory in lectures, you don't apply regularization on theta_0, so, to exclude theta_0 from regularization we have replaced it with 0. so, regularization effected will be nullified for theta_0. (since, 0 multiplied by anything is 0). <br /><br />In other words, we have applied regularization on 2nd entry to last entry using Theta1(:,2:end) and first entry i.e. theta_0 is replaced by 0 using zeros(size(Theta1, 1), 1)) Akshay Daga (APDaga)https://www.blogger.com/profile/04899846959607912677noreply@blogger.comtag:blogger.com,1999:blog-4925159124120434624.post-62160993324935038112020-06-17T09:04:09.191+05:302020-06-17T09:04:09.191+05:30Hi Akshay,
Thanks for the guide. I had a questio...Hi Akshay, <br /><br />Thanks for the guide. I had a question regarding the following code: <br /><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 />I'm not sure why the zeros(size(Theta1, 1), 1) is combined with the Theta1. I know from the lectures the formula to calculate the reg term is just: <br /><br />lambda/m * Thetaij ^ (L). <br /><br />Can you help me get a better understanding? I wasn't able to finish this part before the due date. coderhttps://www.blogger.com/profile/04714678042055468352noreply@blogger.comtag:blogger.com,1999:blog-4925159124120434624.post-8628594249172240292020-06-08T12:01:11.086+05:302020-06-08T12:01:11.086+05:30Please read about vectorized implemention. vectori...Please read about vectorized implemention. vectorized implementation is faster than for loop because it does operations on the all elements of the matrix / array simultaneously. <br /><br />About the above code, It is "%Converting y into vector of 0's and 1's for multi-class classification"<br />1. Initialing y_Vec as Zero matrix<br />2. then as per the multiclass, it is assigning 1 for correct category.<br />NOTE: each row in y_Vec correspond to one inplut example (x)<br />each column in y_vec represent output category. (1 represent correct category, 0 means incorrect)Akshay Daga (APDaga)https://www.blogger.com/profile/04899846959607912677noreply@blogger.comtag:blogger.com,1999:blog-4925159124120434624.post-38958339675849404522020-06-06T14:47:28.488+05:302020-06-06T14:47:28.488+05:30%%%%% WORKING %%%%%
% y_Vec = zeros(m,num_labels... %%%%% WORKING %%%%%<br /> % y_Vec = zeros(m,num_labels);<br /> % for i = 1:m<br /> % y_Vec(i,y(i)) = 1;<br /> % end<br /> %%%%%%%%%%%%%%%%%%% OR<br /> <br /> y_Vec = (1:num_labels)==y; <br />----------------------------------------------------------<br />% yVector = (1:num_labels)'==y(t);<br /><br />why it is in the code, what it is doing and how to visualize this, Brother?. Thanks From Gujarat?Dhruvhttps://www.blogger.com/profile/18344176613840855462noreply@blogger.comtag:blogger.com,1999:blog-4925159124120434624.post-24891928793112571192020-06-06T14:38:01.533+05:302020-06-06T14:38:01.533+05:30yeah thats what you have also commented in the cod...yeah thats what you have also commented in the code as well, but brother will you please elaborate, why it is done and also please provide a picture if you can, i tried it but i cannot visualize itDhruvhttps://www.blogger.com/profile/18344176613840855462noreply@blogger.comtag:blogger.com,1999:blog-4925159124120434624.post-78545042840565446992020-05-21T17:40:58.303+05:302020-05-21T17:40:58.303+05:30Thank you very much for the appreciation. Thank you very much for the appreciation. Akshay Daga (APDaga)https://www.blogger.com/profile/04899846959607912677noreply@blogger.comtag:blogger.com,1999:blog-4925159124120434624.post-1404869961513033072020-05-21T09:11:23.490+05:302020-05-21T09:11:23.490+05:30Cheers from brazil,my friend.
This was of great he...Cheers from brazil,my friend.<br />This was of great help!!lhttps://www.blogger.com/profile/15981087162185869444noreply@blogger.comtag:blogger.com,1999:blog-4925159124120434624.post-12487168154047420032020-04-16T13:15:57.727+05:302020-04-16T13:15:57.727+05:30This line of code does exact same operation as bel...This line of code does exact same operation as below:<br />y_Vec = zeros(m,num_labels);<br />for i = 1:m<br /> y_Vec(i,y(i)) = 1;<br />endAkshay Daga (APDaga)https://www.blogger.com/profile/04899846959607912677noreply@blogger.comtag:blogger.com,1999:blog-4925159124120434624.post-10844114966828577042020-04-16T12:52:17.065+05:302020-04-16T12:52:17.065+05:30 y_Vec = (1:num_labels)==y; ...what is this line o... y_Vec = (1:num_labels)==y; ...what is this line of code doing ..plz help me get a clear picture. i it converting y to a vectorAnonymoushttps://www.blogger.com/profile/13816054494919761547noreply@blogger.comtag:blogger.com,1999:blog-4925159124120434624.post-132487746431001692020-04-15T18:20:20.530+05:302020-04-15T18:20:20.530+05:30Please refer theory lecture for that.Please refer theory lecture for that.Akshay Daga (APDaga)https://www.blogger.com/profile/04899846959607912677noreply@blogger.comtag:blogger.com,1999:blog-4925159124120434624.post-3770554679248047132020-04-15T00:26:21.948+05:302020-04-15T00:26:21.948+05:30Hey,
Why we are initialising epsilon as
epsilon_in...Hey,<br />Why we are initialising epsilon as<br />epsilon_init = sqrt(6)/(sqrt(L_in)+sqrt(L_out));<br />Why by 6?Anonymoushttps://www.blogger.com/profile/13168595561951167112noreply@blogger.comtag:blogger.com,1999:blog-4925159124120434624.post-58580837788493994962019-11-19T13:15:32.572+05:302019-11-19T13:15:32.572+05:30HI Akshay, thanks for your great work, could you p...HI Akshay, thanks for your great work, could you please explain the below code,<br /><br /> DELTA2 = (DELTA3 * Theta2) .* [ones(size(Z2,1),1) sigmoidGradient(Z2)]; % 5000 x 26Azizhttps://www.blogger.com/profile/14776942143350891456noreply@blogger.comtag: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 /> Anonymoushttps://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 week5Anonymoushttps://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 /> Anonymoushttps://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 10Anonymoushttps://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.com