Answers.Body: <p>The smaller the <code>batch_size</code> is, the larger number of batches is processed per one epoch.</p>
  <p>On one hand, since one makes more steps per epoch, one can think, that less epochs are required to achieve the same level of accuracy.</p>
  <p>On the other side, smaller <code>batch size</code> leads to more noisy and stochastic estimates of the gradient, therefore, convergence would not be as steady most likely.</p>
  <p>I think it is difficult to give a definite answer about the exact relation on the number of epochs - since say, to achieve a certain level of accuracy use of small batch may be more beneficial since it allows for more exploration and is more likely to escape from local minima and saddles, but when one reaches the approximation limit of the network and is in the vicinity of the good optimum - large batch would descend better to the extremum.</p>
  <p>Good strategy usually is to start from smaller batches to find wide and plain minima, which are better from the generalization point of view, and then increase batch size for steadier convergence.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-25T20:46:59.833Z
Answers.LastActivityDate: 2021-09-25T20:46:59.833Z
Answers.UserDisplayName: spiridon_the_sun_rotator
Answers.Body: <p>Smaller batch size means the model is updated more often. So, it takes longer to complete each epoch. Also, if the batch size is too small, each update is done without &quot;seeing&quot; all the data - the batch itself might not be a good representative of the dataset. So, there might be too much &quot;wiggling&quot;, which makes it harder to get real minimum. Larger batches will get you &quot;near&quot; minimum for quickly, as they have larger and step sizes.</p>
  <p>As you only asked the relation between batch size and epochs, above is the answer. But in practice, one hardly uses very large batches as it doesn't get very close to the minimum for the same reason they reach there faster - once you are there, you want to have smaller steps to get very close to the minimum. Smaller batches might take longer but once they are there, their wiggly nature becomes a strength, and gets them closer to the minimum.</p>
  <p>For a more in depth discussion and some references, see <a href="https://datascience.stackexchange.com/questions/64345/can-someone-explain-what-batch-size-is-doing-in-convolutional-nns/64348#64348">this post</a>.</p>
  <p>And batch sizes are usually picked to be a power of 2, so I would go for 16 instead of 17 if I were you. Check <a href="https://datascience.stackexchange.com/questions/20179/what-is-the-advantage-of-keeping-batch-size-a-power-of-2">this discussion</a> for the reason for this.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-25T14:11:24.980Z
Answers.Text: "Smaller batch size means the model is updated more often. So, it takes longer to complete each epoch", but if you use fewer examples at each update, wouldn't that make the update faster? So, wouldn't that smaller times for updating compensate the higher number of updates? I don't know exactly, but that statement/conclusion may not be correct. Note that I am not talking about convergence here, I'm just talking about time complexity.
Answers.UserDisplayName: nbro
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-25T14:31:28.573Z
Answers.Text: Well, still each time the update is made, the entire model is updated, that is the issue. Small batch or large batch, for each epoch entire dataset is used once in the calculation. Assuming total time for the calculation excluding updates is the same for both, the difference comes from the number of updates. And the number of times an update is made is higher for small batches.
Answers.UserDisplayName: serali
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-25T14:43:18.697Z
Answers.Text: @nbro Sorry, I guess I did not address your comment directly but I don't know why small samples would mean shorter update time. Even we assume the changes are small in small batches, the mathematical operation made on each cell is the same, and should take the same amount of time.
Answers.UserDisplayName: serali
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-25T11:58:57.737Z
Answers.LastActivityDate: 2021-09-25T11:58:57.737Z
Answers.UserDisplayName: serali
Body: <p>I am currently running a program with a batch size of 17 instead of batch size 32. The benchmark results are obtained at a batch size of 32 with the number of epochs 700.</p>
  <p>Now I am running with batch size 17 with unchanged number epochs. So I am interested to know whether there is any relationship between the batch size and the number of epochs in general.</p>
  <p>Do I need to increase the number of epochs? Or is it entirely dependent on the program?</p>
  
Tags: <neural-networks><deep-learning><hyper-parameters><batch-size><epochs>
Title: Is there any relationship between the batch size and the number of epochs?
UserDisplayName: hanugm
ThreadText: # Is there any relationship between the batch size and the number of epochs?
  
  (Asked by: username_0 on 2021-09-25)
  
  I am currently running a program with a batch size of 17 instead of batch size 32. The benchmark results are obtained at a batch size of 32 with the number of epochs 700.
  
  Now I am running with batch size 17 with unchanged number epochs. So I am interested to know whether there is any relationship between the batch size and the number of epochs in general.
  
  Do I need to increase the number of epochs? Or is it entirely dependent on the program?
  
  **Tags:** neural-networks, deep-learning, hyper-parameters, batch-size, epochs
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2021-09-25. Score: 2
  
  The smaller the `batch_size` is, the larger number of batches is processed per one epoch.
  
  On one hand, since one makes more steps per epoch, one can think, that less epochs are required to achieve the same level of accuracy.
  
  On the other side, smaller `batch size` leads to more noisy and stochastic estimates of the gradient, therefore, convergence would not be as steady most likely.
  
  I think it is difficult to give a definite answer about the exact relation on the number of epochs - since say, to achieve a certain level of accuracy use of small batch may be more beneficial since it allows for more exploration and is more likely to escape from local minima and saddles, but when one reaches the approximation limit of the network and is in the vicinity of the good optimum - large batch would descend better to the extremum.
  
  Good strategy usually is to start from smaller batches to find wide and plain minima, which are better from the generalization point of view, and then increase batch size for steadier convergence.
  
  
  ---
  
  ### Answer by username_2 on 2021-09-25. Score: 0
  
  Smaller batch size means the model is updated more often. So, it takes longer to complete each epoch. Also, if the batch size is too small, each update is done without "seeing" all the data - the batch itself might not be a good representative of the dataset. So, there might be too much "wiggling", which makes it harder to get real minimum. Larger batches will get you "near" minimum for quickly, as they have larger and step sizes.
  
  As you only asked the relation between batch size and epochs, above is the answer. But in practice, one hardly uses very large batches as it doesn't get very close to the minimum for the same reason they reach there faster - once you are there, you want to have smaller steps to get very close to the minimum. Smaller batches might take longer but once they are there, their wiggly nature becomes a strength, and gets them closer to the minimum.
  
  For a more in depth discussion and some references, see [this post](https://datascience.stackexchange.com/questions/64345/can-someone-explain-what-batch-size-is-doing-in-convolutional-nns/64348#64348).
  
  And batch sizes are usually picked to be a power of 2, so I would go for 16 instead of 17 if I were you. Check [this discussion](https://datascience.stackexchange.com/questions/20179/what-is-the-advantage-of-keeping-batch-size-a-power-of-2) for the reason for this.
  
  > **Comments:**
  > **username_3**: "Smaller batch size means the model is updated more often. So, it takes longer to complete each epoch", but if you use fewer examples at each update, wouldn't that make the update faster? So, wouldn't that smaller times for updating compensate the higher number of updates? I don't know exactly, but that statement/conclusion may not be correct. Note that I am not talking about convergence here, I'm just talking about time complexity.  
  > **username_2**: Well, still each time the update is made, the entire model is updated, that is the issue. Small batch or large batch, for each epoch entire dataset is used once in the calculation. Assuming total time for the calculation excluding updates is the same for both, the difference comes from the number of updates. And the number of times an update is made is higher for small batches.  
  > **username_2**: @nbro Sorry, I guess I did not address your comment directly but I don't know why small samples would mean shorter update time. Even we assume the changes are small in small batches, the mathematical operation made on each cell is the same, and should take the same amount of time.  
  
  ---
  
  