Answers.Body: <p>In batch gradient descent computing the loss function every time serves several purposes. While the value of the loss itself may not directly affect the backpropagation process, as you said monitoring the loss over time is essential to ensure that the optimization process is converging. Also many optimization algorithms such as learning rate schedules or adaptive learning rate methods adjust the learning rate or other hyperparameters based on the behavior of the loss function during training. Therefore, computing the loss function is crucial for determining how the learning rate should be updated. Finally, monitoring the loss function can also be used for early stopping, a technique where training is halted if the loss on a validation set stops decreasing or starts increasing, which helps prevent the usual overfitting of neural networks and wasting computational resources.</p>
  <p>Updating parameters with respect to a batch means computing the gradients of the (average) loss function with respect to the parameters using all examples in the batch and then updating the parameters accordingly. This process is repeated for each batch during each epoch of training and in your case each batch could simply mean the entire training dataset.</p>
  <p>The input vector used to compute gradients for the first set of weights is a matrix whose row represents an individual example from the batch and whose columns represent the features of that example, and the number of features would typically determine the number of input nodes of your network. During training the neural network processes this entire batch at once with operations including forward and backward passes performed in a vectorized or parallelized manner for efficiency.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-05T23:48:45.667Z
Answers.Text: How can you propagate the error back when the very value of L is of no significance?
Answers.UserDisplayName: insipidintegrator
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-06T00:22:24.243Z
Answers.Text: The gradients of L w.r.t. all the weight parameters computed in the backward passes sourced from the error computed from forward passes are very significant to be back propagated to update the parameters.
Answers.UserDisplayName: cinch
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-07T16:57:25.633Z
Answers.Text: could you please explain how they are "sourced from the error computed from forward passes" ?
Answers.UserDisplayName: insipidintegrator
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-07T22:19:43.093Z
Answers.Text: based on your specific loss function (usually MSE) it's just matrix add-mult operations flow through each layer in any forward pass to get the sum of each output node's squared error, you may average too as you rightly claimed. Some lib such as pytorch only has one line code to do a forward pass which would do all these things for you, you may read its open source code to see programming detail. Ideally here only one main question for each post, if still unclear I encourage you to close this post and ask a new question.
Answers.UserDisplayName: cinch
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-05T06:49:25.543Z
Answers.LastActivityDate: 2024-02-05T06:49:25.543Z
Answers.UserDisplayName: cinch
Body: <p>My understanding is this: When doing Stochastic Gradient Descent over a neural network, in every epoch, we run <span class="math-container">$n$</span> iterations (where the dataset has <span class="math-container">$n$</span> training examples) and in every iteration, we take a random sample and update the parameters wrt the sample.</p>
  <p>However, in batch gradient descent, we take the whole dataset every epoch, and update the parameters wrt the batch. I have the following questions:</p>
  <ol>
  <li>Why do we need to compute the loss function every time, especially if the value of the loss has no importance as such in the backprop process? Is it just to ensure that the loss decreases over time? How can you propagate the error back when the value of L is of no significance?</li>
  <li>What exactly does updating wrt a &quot;batch&quot; mean? What would you take the input vector (required to compute gradients for the first set of weights) as? I assume that the loss is taken to be the average of the losses for the entire batch</li>
  </ol>
  
Tags: <backpropagation><gradient-descent>
Title: What do you mean by "updating based on a training example/batch" in Gradient Descent?
UserDisplayName: insipidintegrator
ThreadText: # What do you mean by "updating based on a training example/batch" in Gradient Descent?
  
  (Asked by: username_0 on 2024-02-05)
  
  My understanding is this: When doing Stochastic Gradient Descent over a neural network, in every epoch, we run $n$ iterations (where the dataset has $n$ training examples) and in every iteration, we take a random sample and update the parameters wrt the sample.
  
  However, in batch gradient descent, we take the whole dataset every epoch, and update the parameters wrt the batch. I have the following questions:
  
  1. Why do we need to compute the loss function every time, especially if the value of the loss has no importance as such in the backprop process? Is it just to ensure that the loss decreases over time? How can you propagate the error back when the value of L is of no significance?
  2. What exactly does updating wrt a "batch" mean? What would you take the input vector (required to compute gradients for the first set of weights) as? I assume that the loss is taken to be the average of the losses for the entire batch
  
  **Tags:** backpropagation, gradient-descent
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-02-05. Score: 3 | Accepted answer
  
  In batch gradient descent computing the loss function every time serves several purposes. While the value of the loss itself may not directly affect the backpropagation process, as you said monitoring the loss over time is essential to ensure that the optimization process is converging. Also many optimization algorithms such as learning rate schedules or adaptive learning rate methods adjust the learning rate or other hyperparameters based on the behavior of the loss function during training. Therefore, computing the loss function is crucial for determining how the learning rate should be updated. Finally, monitoring the loss function can also be used for early stopping, a technique where training is halted if the loss on a validation set stops decreasing or starts increasing, which helps prevent the usual overfitting of neural networks and wasting computational resources.
  
  Updating parameters with respect to a batch means computing the gradients of the (average) loss function with respect to the parameters using all examples in the batch and then updating the parameters accordingly. This process is repeated for each batch during each epoch of training and in your case each batch could simply mean the entire training dataset.
  
  The input vector used to compute gradients for the first set of weights is a matrix whose row represents an individual example from the batch and whose columns represent the features of that example, and the number of features would typically determine the number of input nodes of your network. During training the neural network processes this entire batch at once with operations including forward and backward passes performed in a vectorized or parallelized manner for efficiency.
  
  > **Comments:**
  > **username_0**: How can you propagate the error back when the very value of L is of no significance?  
  > **username_1**: The gradients of L w.r.t. all the weight parameters computed in the backward passes sourced from the error computed from forward passes are very significant to be back propagated to update the parameters.  
  > **username_0**: could you please explain how they are "sourced from the error computed from forward passes" ?  
  > **username_1**: based on your specific loss function (usually MSE) it's just matrix add-mult operations flow through each layer in any forward pass to get the sum of each output node's squared error, you may average too as you rightly claimed. Some lib such as pytorch only has one line code to do a forward pass which would do all these things for you, you may read its open source code to see programming detail. Ideally here only one main question for each post, if still unclear I encourage you to close this post and ask a new question.  
  
  ---
  
  