Why is this the correct way to do a cost function for a neural network?Neural Network Cost Function in MATLABUnderstanding Neural Network BackpropagationRole of Bias in Neural NetworksEpoch vs Iteration when training neural networksWhat are advantages of Artificial Neural Networks over Support Vector Machines?In Neural network prediction(not classification), What Cost function shall i use?Neural Network Cost Function in MATLABNeural Network not fitting XORNeural network backpropagation with RELUCalculation of Cost function in Neural Network Getting NaN or InfNeural Network Cost function returning Nan in Matlab

Leveraging cash for buying car

How did the European Union reach the figure of 3% as a maximum allowed deficit?

Why are almost all the people in this orchestra recording wearing headphones with one ear on and one ear off?

Why can't I craft scaffolding in Minecraft 1.14?

High-end PC graphics circa 1990?

Is there a risk to write an invitation letter for a stranger to obtain a Czech (Schengen) visa?

How to know whether to write accidentals as sharps or flats?

When is the phrase "j'ai bon" used?

How would Japanese people react to someone refusing to say “itadakimasu” for religious reasons?

1960s sci-fi anthology with a Viking fighting a U.S. army MP on the cover

How could I create a situation in which a PC has to make a saving throw or be forced to pet a dog?

Basic power tool set for Home repair and simple projects

I have found ports on my Samsung smart tv running a display service. What can I do with it?

Digital signature that is only verifiable by one specific person

What could be the physiological mechanism for a biological Geiger counter?

How does the Linux command "mount -a" work?

Co-worker is now managing my team. Does this mean that I'm being demoted?

How can the US president give an order to a civilian?

The instant an accelerating object has zero speed, is it speeding up, slowing down, or neither?

How to prevent cables getting intertwined

Cut power on a remote Raspberry Pi 3 via another raspi

Using roof rails to set up hammock

Manager wants to hire me; HR does not. How to proceed?

Like a Baby - Riddle



Why is this the correct way to do a cost function for a neural network?


Neural Network Cost Function in MATLABUnderstanding Neural Network BackpropagationRole of Bias in Neural NetworksEpoch vs Iteration when training neural networksWhat are advantages of Artificial Neural Networks over Support Vector Machines?In Neural network prediction(not classification), What Cost function shall i use?Neural Network Cost Function in MATLABNeural Network not fitting XORNeural network backpropagation with RELUCalculation of Cost function in Neural Network Getting NaN or InfNeural Network Cost function returning Nan in Matlab






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-1















So after beating my head against the wall for a few hours, I looked online for a solution to my problem, and it worked great. I just want to know what caused the issue with the way I was originally going about it.



enter image description here



enter image description here



here are some more details. The input is a 20x20px image from the MNIST datset, and there are 5000 samples, so X, or A1 is 5000x400. There are 25 nodes in the single hidden layer. The output is a one hot vector of 0-9 digits. y (not Y, which is the one hot encoding of y) is a 5000x1 vector with the value of 1-10.



enter image description here



Here was my original code for the cost function:



Y = zeros(m, num_labels);
for i = 1:m
Y(i, y(i)) = 1;
endfor
H = sigmoid(Theta2*[ones(1,m);sigmoid(Theta1*[ones(m, 1) X]'))
J = (1/m) * sum(sum((-Y*log(H]))' - (1-Y)*log(1-H]))')))


But then I found this:



A1 = [ones(m, 1) X];
Z2 = A1 * Theta1';
A2 = [ones(size(Z2, 1), 1) sigmoid(Z2)];
Z3 = A2*Theta2';
H = A3 = sigmoid(Z3);

J = (1/m)*sum(sum((-Y).*log(H) - (1-Y).*log(1-H), 2));


I see that this may be slightly cleaner, but what functionally causes my original code to get 304.88 and the other to get ~ 0.25? Is it the element wise multiplication?



FYI, this is the same problem as this question if you need the formal equation written out.



Thanks for any help I can get! I really want to understand where I'm going wrong










share|improve this question
























  • MCVE ? So that we can see the two codes actually in action?

    – tryman
    Mar 25 at 4:15












  • @tryman Do those two screen grabs help clear it up? The whole problem is just writing a cost function for a neural network in Octave

    – Carson P
    Mar 25 at 4:19











  • @tryman I added a lot more details. Hopefully that will clear everything up

    – Carson P
    Mar 25 at 4:24











  • With a quick look, in J = (1/m) * sum(sum((-Y*log(H]))' - (1-Y)*log(1-H]))'))) there is definetely something going on with the parenthesis, but probably on how you pasted it here, not with the original code as this would throw an error when you run it. If I understand correctly and Y, H are matrices, then in your 1st version Y*log(H) is matrix multiplication while in the 2nd version Y.*log(H) is an entrywise multiplication (not matrix-multiplication, just c(i,j)=a(i,j)*b(i,j) ).

    – tryman
    Mar 25 at 4:36












  • @tryman thanks! What I’m really trying to figure out is how I was supposed to know to do an element wise multiply instead of matrix wise, just from those equations and figures above. Since In that equation, y and log don’t have some kind of * does that technically mean it’s element wise? Or is there something else here I’m not getting

    – Carson P
    Mar 25 at 4:38


















-1















So after beating my head against the wall for a few hours, I looked online for a solution to my problem, and it worked great. I just want to know what caused the issue with the way I was originally going about it.



enter image description here



enter image description here



here are some more details. The input is a 20x20px image from the MNIST datset, and there are 5000 samples, so X, or A1 is 5000x400. There are 25 nodes in the single hidden layer. The output is a one hot vector of 0-9 digits. y (not Y, which is the one hot encoding of y) is a 5000x1 vector with the value of 1-10.



enter image description here



Here was my original code for the cost function:



Y = zeros(m, num_labels);
for i = 1:m
Y(i, y(i)) = 1;
endfor
H = sigmoid(Theta2*[ones(1,m);sigmoid(Theta1*[ones(m, 1) X]'))
J = (1/m) * sum(sum((-Y*log(H]))' - (1-Y)*log(1-H]))')))


But then I found this:



A1 = [ones(m, 1) X];
Z2 = A1 * Theta1';
A2 = [ones(size(Z2, 1), 1) sigmoid(Z2)];
Z3 = A2*Theta2';
H = A3 = sigmoid(Z3);

J = (1/m)*sum(sum((-Y).*log(H) - (1-Y).*log(1-H), 2));


I see that this may be slightly cleaner, but what functionally causes my original code to get 304.88 and the other to get ~ 0.25? Is it the element wise multiplication?



FYI, this is the same problem as this question if you need the formal equation written out.



Thanks for any help I can get! I really want to understand where I'm going wrong










share|improve this question
























  • MCVE ? So that we can see the two codes actually in action?

    – tryman
    Mar 25 at 4:15












  • @tryman Do those two screen grabs help clear it up? The whole problem is just writing a cost function for a neural network in Octave

    – Carson P
    Mar 25 at 4:19











  • @tryman I added a lot more details. Hopefully that will clear everything up

    – Carson P
    Mar 25 at 4:24











  • With a quick look, in J = (1/m) * sum(sum((-Y*log(H]))' - (1-Y)*log(1-H]))'))) there is definetely something going on with the parenthesis, but probably on how you pasted it here, not with the original code as this would throw an error when you run it. If I understand correctly and Y, H are matrices, then in your 1st version Y*log(H) is matrix multiplication while in the 2nd version Y.*log(H) is an entrywise multiplication (not matrix-multiplication, just c(i,j)=a(i,j)*b(i,j) ).

    – tryman
    Mar 25 at 4:36












  • @tryman thanks! What I’m really trying to figure out is how I was supposed to know to do an element wise multiply instead of matrix wise, just from those equations and figures above. Since In that equation, y and log don’t have some kind of * does that technically mean it’s element wise? Or is there something else here I’m not getting

    – Carson P
    Mar 25 at 4:38














-1












-1








-1








So after beating my head against the wall for a few hours, I looked online for a solution to my problem, and it worked great. I just want to know what caused the issue with the way I was originally going about it.



enter image description here



enter image description here



here are some more details. The input is a 20x20px image from the MNIST datset, and there are 5000 samples, so X, or A1 is 5000x400. There are 25 nodes in the single hidden layer. The output is a one hot vector of 0-9 digits. y (not Y, which is the one hot encoding of y) is a 5000x1 vector with the value of 1-10.



enter image description here



Here was my original code for the cost function:



Y = zeros(m, num_labels);
for i = 1:m
Y(i, y(i)) = 1;
endfor
H = sigmoid(Theta2*[ones(1,m);sigmoid(Theta1*[ones(m, 1) X]'))
J = (1/m) * sum(sum((-Y*log(H]))' - (1-Y)*log(1-H]))')))


But then I found this:



A1 = [ones(m, 1) X];
Z2 = A1 * Theta1';
A2 = [ones(size(Z2, 1), 1) sigmoid(Z2)];
Z3 = A2*Theta2';
H = A3 = sigmoid(Z3);

J = (1/m)*sum(sum((-Y).*log(H) - (1-Y).*log(1-H), 2));


I see that this may be slightly cleaner, but what functionally causes my original code to get 304.88 and the other to get ~ 0.25? Is it the element wise multiplication?



FYI, this is the same problem as this question if you need the formal equation written out.



Thanks for any help I can get! I really want to understand where I'm going wrong










share|improve this question
















So after beating my head against the wall for a few hours, I looked online for a solution to my problem, and it worked great. I just want to know what caused the issue with the way I was originally going about it.



enter image description here



enter image description here



here are some more details. The input is a 20x20px image from the MNIST datset, and there are 5000 samples, so X, or A1 is 5000x400. There are 25 nodes in the single hidden layer. The output is a one hot vector of 0-9 digits. y (not Y, which is the one hot encoding of y) is a 5000x1 vector with the value of 1-10.



enter image description here



Here was my original code for the cost function:



Y = zeros(m, num_labels);
for i = 1:m
Y(i, y(i)) = 1;
endfor
H = sigmoid(Theta2*[ones(1,m);sigmoid(Theta1*[ones(m, 1) X]'))
J = (1/m) * sum(sum((-Y*log(H]))' - (1-Y)*log(1-H]))')))


But then I found this:



A1 = [ones(m, 1) X];
Z2 = A1 * Theta1';
A2 = [ones(size(Z2, 1), 1) sigmoid(Z2)];
Z3 = A2*Theta2';
H = A3 = sigmoid(Z3);

J = (1/m)*sum(sum((-Y).*log(H) - (1-Y).*log(1-H), 2));


I see that this may be slightly cleaner, but what functionally causes my original code to get 304.88 and the other to get ~ 0.25? Is it the element wise multiplication?



FYI, this is the same problem as this question if you need the formal equation written out.



Thanks for any help I can get! I really want to understand where I'm going wrong







matlab neural-network vectorization octave backpropagation






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 4:24







Carson P

















asked Mar 25 at 4:11









Carson PCarson P

836




836












  • MCVE ? So that we can see the two codes actually in action?

    – tryman
    Mar 25 at 4:15












  • @tryman Do those two screen grabs help clear it up? The whole problem is just writing a cost function for a neural network in Octave

    – Carson P
    Mar 25 at 4:19











  • @tryman I added a lot more details. Hopefully that will clear everything up

    – Carson P
    Mar 25 at 4:24











  • With a quick look, in J = (1/m) * sum(sum((-Y*log(H]))' - (1-Y)*log(1-H]))'))) there is definetely something going on with the parenthesis, but probably on how you pasted it here, not with the original code as this would throw an error when you run it. If I understand correctly and Y, H are matrices, then in your 1st version Y*log(H) is matrix multiplication while in the 2nd version Y.*log(H) is an entrywise multiplication (not matrix-multiplication, just c(i,j)=a(i,j)*b(i,j) ).

    – tryman
    Mar 25 at 4:36












  • @tryman thanks! What I’m really trying to figure out is how I was supposed to know to do an element wise multiply instead of matrix wise, just from those equations and figures above. Since In that equation, y and log don’t have some kind of * does that technically mean it’s element wise? Or is there something else here I’m not getting

    – Carson P
    Mar 25 at 4:38


















  • MCVE ? So that we can see the two codes actually in action?

    – tryman
    Mar 25 at 4:15












  • @tryman Do those two screen grabs help clear it up? The whole problem is just writing a cost function for a neural network in Octave

    – Carson P
    Mar 25 at 4:19











  • @tryman I added a lot more details. Hopefully that will clear everything up

    – Carson P
    Mar 25 at 4:24











  • With a quick look, in J = (1/m) * sum(sum((-Y*log(H]))' - (1-Y)*log(1-H]))'))) there is definetely something going on with the parenthesis, but probably on how you pasted it here, not with the original code as this would throw an error when you run it. If I understand correctly and Y, H are matrices, then in your 1st version Y*log(H) is matrix multiplication while in the 2nd version Y.*log(H) is an entrywise multiplication (not matrix-multiplication, just c(i,j)=a(i,j)*b(i,j) ).

    – tryman
    Mar 25 at 4:36












  • @tryman thanks! What I’m really trying to figure out is how I was supposed to know to do an element wise multiply instead of matrix wise, just from those equations and figures above. Since In that equation, y and log don’t have some kind of * does that technically mean it’s element wise? Or is there something else here I’m not getting

    – Carson P
    Mar 25 at 4:38

















MCVE ? So that we can see the two codes actually in action?

– tryman
Mar 25 at 4:15






MCVE ? So that we can see the two codes actually in action?

– tryman
Mar 25 at 4:15














@tryman Do those two screen grabs help clear it up? The whole problem is just writing a cost function for a neural network in Octave

– Carson P
Mar 25 at 4:19





@tryman Do those two screen grabs help clear it up? The whole problem is just writing a cost function for a neural network in Octave

– Carson P
Mar 25 at 4:19













@tryman I added a lot more details. Hopefully that will clear everything up

– Carson P
Mar 25 at 4:24





@tryman I added a lot more details. Hopefully that will clear everything up

– Carson P
Mar 25 at 4:24













With a quick look, in J = (1/m) * sum(sum((-Y*log(H]))' - (1-Y)*log(1-H]))'))) there is definetely something going on with the parenthesis, but probably on how you pasted it here, not with the original code as this would throw an error when you run it. If I understand correctly and Y, H are matrices, then in your 1st version Y*log(H) is matrix multiplication while in the 2nd version Y.*log(H) is an entrywise multiplication (not matrix-multiplication, just c(i,j)=a(i,j)*b(i,j) ).

– tryman
Mar 25 at 4:36






With a quick look, in J = (1/m) * sum(sum((-Y*log(H]))' - (1-Y)*log(1-H]))'))) there is definetely something going on with the parenthesis, but probably on how you pasted it here, not with the original code as this would throw an error when you run it. If I understand correctly and Y, H are matrices, then in your 1st version Y*log(H) is matrix multiplication while in the 2nd version Y.*log(H) is an entrywise multiplication (not matrix-multiplication, just c(i,j)=a(i,j)*b(i,j) ).

– tryman
Mar 25 at 4:36














@tryman thanks! What I’m really trying to figure out is how I was supposed to know to do an element wise multiply instead of matrix wise, just from those equations and figures above. Since In that equation, y and log don’t have some kind of * does that technically mean it’s element wise? Or is there something else here I’m not getting

– Carson P
Mar 25 at 4:38






@tryman thanks! What I’m really trying to figure out is how I was supposed to know to do an element wise multiply instead of matrix wise, just from those equations and figures above. Since In that equation, y and log don’t have some kind of * does that technically mean it’s element wise? Or is there something else here I’m not getting

– Carson P
Mar 25 at 4:38













1 Answer
1






active

oldest

votes


















1














Transfer from the comments:

With a quick look, in J = (1/m) * sum(sum((-Y*log(H]))' - (1-Y)*log(1-H]))'))) there is definetely something going on with the parenthesis, but probably on how you pasted it here, not with the original code as this would throw an error when you run it. If I understand correctly and Y, H are matrices, then in your 1st version Y*log(H) is matrix multiplication while in the 2nd version Y.*log(H) is an entrywise multiplication (not matrix-multiplication, just c(i,j)=a(i,j)*b(i,j) ).



Update 1:

In regards to your question in the comment.
From the first screenshot, you represent each value yk(i) in the entry Y(i,k) of the Y matrix and each value h(x^(i))k as H(i,k). So basically, for each i,k you want to compute Y(i,k) log(H(i,k)) + (1-Y(i,k)) log(1-H(i,k)). You can do it for all the values together and store the result in matrix C. Then C = Y.*log(H) + (1-Y).*log(1-H) and each C(i,k) has the above mentioned value. This is an operation .* because you want to do the operation for each element (i,k) of each matrix (in contrast to multiplying the matrices which is totally different). Afterwards, to get the sum of all the values inside the 2D dimensional matrix C, you use the octave function sum twice: sum(sum(C)) to sum both columnwise and row-wise (or as @ Irreducible suggested, just sum(C(:))).



Note there may be other errors as well.






share|improve this answer

























  • To sum over all entries of a matrix C just write: sum(C(:))

    – Irreducible
    Mar 25 at 12:29












  • @Irreducible That too! Incorporated your suggestion.

    – tryman
    Apr 4 at 10:32











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55331170%2fwhy-is-this-the-correct-way-to-do-a-cost-function-for-a-neural-network%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Transfer from the comments:

With a quick look, in J = (1/m) * sum(sum((-Y*log(H]))' - (1-Y)*log(1-H]))'))) there is definetely something going on with the parenthesis, but probably on how you pasted it here, not with the original code as this would throw an error when you run it. If I understand correctly and Y, H are matrices, then in your 1st version Y*log(H) is matrix multiplication while in the 2nd version Y.*log(H) is an entrywise multiplication (not matrix-multiplication, just c(i,j)=a(i,j)*b(i,j) ).



Update 1:

In regards to your question in the comment.
From the first screenshot, you represent each value yk(i) in the entry Y(i,k) of the Y matrix and each value h(x^(i))k as H(i,k). So basically, for each i,k you want to compute Y(i,k) log(H(i,k)) + (1-Y(i,k)) log(1-H(i,k)). You can do it for all the values together and store the result in matrix C. Then C = Y.*log(H) + (1-Y).*log(1-H) and each C(i,k) has the above mentioned value. This is an operation .* because you want to do the operation for each element (i,k) of each matrix (in contrast to multiplying the matrices which is totally different). Afterwards, to get the sum of all the values inside the 2D dimensional matrix C, you use the octave function sum twice: sum(sum(C)) to sum both columnwise and row-wise (or as @ Irreducible suggested, just sum(C(:))).



Note there may be other errors as well.






share|improve this answer

























  • To sum over all entries of a matrix C just write: sum(C(:))

    – Irreducible
    Mar 25 at 12:29












  • @Irreducible That too! Incorporated your suggestion.

    – tryman
    Apr 4 at 10:32















1














Transfer from the comments:

With a quick look, in J = (1/m) * sum(sum((-Y*log(H]))' - (1-Y)*log(1-H]))'))) there is definetely something going on with the parenthesis, but probably on how you pasted it here, not with the original code as this would throw an error when you run it. If I understand correctly and Y, H are matrices, then in your 1st version Y*log(H) is matrix multiplication while in the 2nd version Y.*log(H) is an entrywise multiplication (not matrix-multiplication, just c(i,j)=a(i,j)*b(i,j) ).



Update 1:

In regards to your question in the comment.
From the first screenshot, you represent each value yk(i) in the entry Y(i,k) of the Y matrix and each value h(x^(i))k as H(i,k). So basically, for each i,k you want to compute Y(i,k) log(H(i,k)) + (1-Y(i,k)) log(1-H(i,k)). You can do it for all the values together and store the result in matrix C. Then C = Y.*log(H) + (1-Y).*log(1-H) and each C(i,k) has the above mentioned value. This is an operation .* because you want to do the operation for each element (i,k) of each matrix (in contrast to multiplying the matrices which is totally different). Afterwards, to get the sum of all the values inside the 2D dimensional matrix C, you use the octave function sum twice: sum(sum(C)) to sum both columnwise and row-wise (or as @ Irreducible suggested, just sum(C(:))).



Note there may be other errors as well.






share|improve this answer

























  • To sum over all entries of a matrix C just write: sum(C(:))

    – Irreducible
    Mar 25 at 12:29












  • @Irreducible That too! Incorporated your suggestion.

    – tryman
    Apr 4 at 10:32













1












1








1







Transfer from the comments:

With a quick look, in J = (1/m) * sum(sum((-Y*log(H]))' - (1-Y)*log(1-H]))'))) there is definetely something going on with the parenthesis, but probably on how you pasted it here, not with the original code as this would throw an error when you run it. If I understand correctly and Y, H are matrices, then in your 1st version Y*log(H) is matrix multiplication while in the 2nd version Y.*log(H) is an entrywise multiplication (not matrix-multiplication, just c(i,j)=a(i,j)*b(i,j) ).



Update 1:

In regards to your question in the comment.
From the first screenshot, you represent each value yk(i) in the entry Y(i,k) of the Y matrix and each value h(x^(i))k as H(i,k). So basically, for each i,k you want to compute Y(i,k) log(H(i,k)) + (1-Y(i,k)) log(1-H(i,k)). You can do it for all the values together and store the result in matrix C. Then C = Y.*log(H) + (1-Y).*log(1-H) and each C(i,k) has the above mentioned value. This is an operation .* because you want to do the operation for each element (i,k) of each matrix (in contrast to multiplying the matrices which is totally different). Afterwards, to get the sum of all the values inside the 2D dimensional matrix C, you use the octave function sum twice: sum(sum(C)) to sum both columnwise and row-wise (or as @ Irreducible suggested, just sum(C(:))).



Note there may be other errors as well.






share|improve this answer















Transfer from the comments:

With a quick look, in J = (1/m) * sum(sum((-Y*log(H]))' - (1-Y)*log(1-H]))'))) there is definetely something going on with the parenthesis, but probably on how you pasted it here, not with the original code as this would throw an error when you run it. If I understand correctly and Y, H are matrices, then in your 1st version Y*log(H) is matrix multiplication while in the 2nd version Y.*log(H) is an entrywise multiplication (not matrix-multiplication, just c(i,j)=a(i,j)*b(i,j) ).



Update 1:

In regards to your question in the comment.
From the first screenshot, you represent each value yk(i) in the entry Y(i,k) of the Y matrix and each value h(x^(i))k as H(i,k). So basically, for each i,k you want to compute Y(i,k) log(H(i,k)) + (1-Y(i,k)) log(1-H(i,k)). You can do it for all the values together and store the result in matrix C. Then C = Y.*log(H) + (1-Y).*log(1-H) and each C(i,k) has the above mentioned value. This is an operation .* because you want to do the operation for each element (i,k) of each matrix (in contrast to multiplying the matrices which is totally different). Afterwards, to get the sum of all the values inside the 2D dimensional matrix C, you use the octave function sum twice: sum(sum(C)) to sum both columnwise and row-wise (or as @ Irreducible suggested, just sum(C(:))).



Note there may be other errors as well.







share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 4 at 10:32

























answered Mar 25 at 5:00









trymantryman

1,120617




1,120617












  • To sum over all entries of a matrix C just write: sum(C(:))

    – Irreducible
    Mar 25 at 12:29












  • @Irreducible That too! Incorporated your suggestion.

    – tryman
    Apr 4 at 10:32

















  • To sum over all entries of a matrix C just write: sum(C(:))

    – Irreducible
    Mar 25 at 12:29












  • @Irreducible That too! Incorporated your suggestion.

    – tryman
    Apr 4 at 10:32
















To sum over all entries of a matrix C just write: sum(C(:))

– Irreducible
Mar 25 at 12:29






To sum over all entries of a matrix C just write: sum(C(:))

– Irreducible
Mar 25 at 12:29














@Irreducible That too! Incorporated your suggestion.

– tryman
Apr 4 at 10:32





@Irreducible That too! Incorporated your suggestion.

– tryman
Apr 4 at 10:32

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55331170%2fwhy-is-this-the-correct-way-to-do-a-cost-function-for-a-neural-network%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현