Answers.Body: <blockquote>
  <ol>
  <li>A sub-expression <span class="math-container">$\delta^l$</span>, which is the gradient of the weighted output of the current layer <span class="math-container">$l$</span>, i.e. <span class="math-container">$\nabla_{z^l}C$</span>. (there is no such symbol in the link, but I believe my usage is correct.)</li>
  </ol>
  </blockquote>
  <p>First of all, you're correct that the symbol <span class="math-container">$\delta^l$</span> represents the gradient of the cost w.r.t. the weighted output (so the activation function has not been applied) of the layer <span class="math-container">$l$</span>. This reasoning for this is simply chain-rule.</p>
  <p>But you have to be aware of that the auxiliary function <span class="math-container">$\delta^l$</span> involves the value of <span class="math-container">$(f^l)'$</span> at <span class="math-container">$z^l$</span>. This means that you will need to save <span class="math-container">$z^l$</span> for computing <span class="math-container">$\delta^l$</span>.</p>
  <blockquote>
  <p>But now I found my note saying something different: it says that to compute the gradient <span class="math-container">$\nabla_{W^l}C$</span>(or simply <span class="math-container">$g^l$</span>), it would require <span class="math-container">$W^{l+1},g^{l+1},a^l$</span>,  that is: the weight and gradient of the next layer and the output of the current layer.</p>
  </blockquote>
  <p>By <span class="math-container">$\nabla_{W^l}C=\delta^l(a^{l-1})^T$</span>, it's clear that you will need both <span class="math-container">$\delta^l$</span> and <span class="math-container">$a^{l-1}$</span> to update the weight <span class="math-container">$W^l$</span>. For <span class="math-container">$\delta^l$</span>, you will need:</p>
  <ol>
  <li>the <span class="math-container">$\nabla_{a^l}{C}=(W^{l+1})^T\delta^{l+1}$</span>, which is the gradient of the cost w.r.t. the activated weighted output of the current layer <span class="math-container">$l$</span>.</li>
  <li>the weighted output <span class="math-container">$z^l$</span> to compute <span class="math-container">$(f^l)'$</span> at <span class="math-container">$z^l$</span>, which is mentioned in my first reply.</li>
  </ol>
  <p>To compute the gradient <span class="math-container">$\nabla_{W^l}C$</span>, the value of these symbols are required:</p>
  <ol>
  <li><span class="math-container">$W^{l+1}$</span>.</li>
  <li><span class="math-container">$\nabla_{a^l}{C}$</span> instead of <span class="math-container">$g^{l+1}$</span>, which is the gradient of the <em>weight</em> as you have said.
  <ul>
  <li>this involves <span class="math-container">$z^l$</span>, as stated above.</li>
  </ul>
  </li>
  <li><span class="math-container">$a^{l-1}$</span> instead of <span class="math-container">$a^{l}$</span>, since the latter is for <span class="math-container">$\nabla_{W^{l+1}}C$</span>.</li>
  </ol>
  <p>So yes, your note is incorrect.</p>
  <hr />
  <p>reference: <a href="https://towardsdatascience.com/back-propagation-simplified-218430e21ad0" rel="nofollow noreferrer">https://towardsdatascience.com/back-propagation-simplified-218430e21ad0</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-06-11T17:08:40.980Z
Answers.LastActivityDate: 2023-06-11T17:08:40.980Z
Answers.UserDisplayName: NRain
Body: <p>I'm trying to understand a line of my note.</p>
  <p>Let's say there is a simple feedforward neural network that has <span class="math-container">$N$</span> layers, and for a given layer <span class="math-container">$l$</span>, it has weight <span class="math-container">$W^l$</span>, and <span class="math-container">$g^l$</span> is the gradient to update it. Now the problem is:</p>
  <ol>
  <li><p>From the Wiki page of <a href="https://en.wikipedia.org/wiki/Backpropagation#Matrix_multiplication" rel="nofollow noreferrer">Backpropagation</a>, to compute <span class="math-container">$\nabla_{W^l}C$</span>(or simply <span class="math-container">$g^l$</span>), i.e. the gradient of the cost function with respect to the weight of layer <span class="math-container">$l$</span>, you will need two things:</p>
  <ol>
  <li>A sub-expression <span class="math-container">$\delta^l$</span>, which is the gradient of the weighted output of the current layer <span class="math-container">$l$</span>, i.e. <span class="math-container">$\nabla_{z^l}C$</span>. (there is no such symbol in the link, but I believe my usage is correct.)</li>
  <li>The activation of the <em>previous</em> layer <span class="math-container">$l-1$</span>, i.e. <span class="math-container">$a^{l-1}$</span>.</li>
  </ol>
  </li>
  </ol>
  <p>This is why it says <span class="math-container">$\nabla_{W^l}C=\delta^l(a^{l-1})^T$</span>. My reasoning of this is that: the weighted output of layer <span class="math-container">$l$</span>, i.e. <span class="math-container">$z^l$</span>, is the result of multiplication between the output of the previous layer, i.e. <span class="math-container">$a^{l-1}$</span>, and the weight of the current layer, i.e. <span class="math-container">$W^l$</span>.</p>
  <ol start="2">
  <li>But now I found my note saying something different: it says that to compute the gradient <span class="math-container">$\nabla_{W^l}C$</span>(or simply <span class="math-container">$g^l$</span>), it would require <span class="math-container">$W^{l+1},g^{l+1},a^l$</span>,  that is: the weight and gradient of the next layer and the output of the current layer.</li>
  </ol>
  <p>Is my note wrong?</p>
  
Tags: <backpropagation>
Title: About the requirement to compute the gradient at layer $l$
UserDisplayName: NRain
ThreadText: # About the requirement to compute the gradient at layer $l$
  
  (Asked by: username_0 on 2023-06-06)
  
  I'm trying to understand a line of my note.
  
  Let's say there is a simple feedforward neural network that has $N$ layers, and for a given layer $l$, it has weight $W^l$, and $g^l$ is the gradient to update it. Now the problem is:
  
  1. From the Wiki page of [Backpropagation](https://en.wikipedia.org/wiki/Backpropagation#Matrix_multiplication), to compute $\nabla\_{W^l}C$(or simply $g^l$), i.e. the gradient of the cost function with respect to the weight of layer $l$, you will need two things:
  
     1. A sub-expression $\delta^l$, which is the gradient of the weighted output of the current layer $l$, i.e. $\nabla\_{z^l}C$. (there is no such symbol in the link, but I believe my usage is correct.)
     2. The activation of the *previous* layer $l-1$, i.e. $a^{l-1}$.
  
  This is why it says $\nabla\_{W^l}C=\delta^l(a^{l-1})^T$. My reasoning of this is that: the weighted output of layer $l$, i.e. $z^l$, is the result of multiplication between the output of the previous layer, i.e. $a^{l-1}$, and the weight of the current layer, i.e. $W^l$.
  
  2. But now I found my note saying something different: it says that to compute the gradient $\nabla\_{W^l}C$(or simply $g^l$), it would require $W^{l+1},g^{l+1},a^l$, that is: the weight and gradient of the next layer and the output of the current layer.
  
  Is my note wrong?
  
  **Tags:** backpropagation
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2023-06-11. Score: 1
  
  > 1. A sub-expression $\delta^l$, which is the gradient of the weighted output of the current layer $l$, i.e. $\nabla\_{z^l}C$. (there is no such symbol in the link, but I believe my usage is correct.)
  
  First of all, you're correct that the symbol $\delta^l$ represents the gradient of the cost w.r.t. the weighted output (so the activation function has not been applied) of the layer $l$. This reasoning for this is simply chain-rule.
  
  But you have to be aware of that the auxiliary function $\delta^l$ involves the value of $(f^l)'$ at $z^l$. This means that you will need to save $z^l$ for computing $\delta^l$.
  
  > But now I found my note saying something different: it says that to compute the gradient $\nabla\_{W^l}C$(or simply $g^l$), it would require $W^{l+1},g^{l+1},a^l$, that is: the weight and gradient of the next layer and the output of the current layer.
  
  By $\nabla\_{W^l}C=\delta^l(a^{l-1})^T$, it's clear that you will need both $\delta^l$ and $a^{l-1}$ to update the weight $W^l$. For $\delta^l$, you will need:
  
  1. the $\nabla\_{a^l}{C}=(W^{l+1})^T\delta^{l+1}$, which is the gradient of the cost w.r.t. the activated weighted output of the current layer $l$.
  2. the weighted output $z^l$ to compute $(f^l)'$ at $z^l$, which is mentioned in my first reply.
  
  To compute the gradient $\nabla\_{W^l}C$, the value of these symbols are required:
  
  1. $W^{l+1}$.
  2. $\nabla\_{a^l}{C}$ instead of $g^{l+1}$, which is the gradient of the *weight* as you have said.
     * this involves $z^l$, as stated above.
  3. $a^{l-1}$ instead of $a^{l}$, since the latter is for $\nabla\_{W^{l+1}}C$.
  
  So yes, your note is incorrect.
  
  ---
  
  reference: <https://towardsdatascience.com/back-propagation-simplified-218430e21ad0>
  
  
  ---
  
  