# Why divide the sample size in minibatch gradient descent

Take linear regression for instance the loss is usually define as $$L = \frac{1}{2N}\sum_{i = 1}^{N}(Y_i - WX_i)^2$$. Two here, as I understand, is to make the derivative look nice. But I am not sure about the role of $$N$$ here, I suppose it is because we are trying to look at the expected loss. However, $$N$$ does not really matter because a constant factor does not affect the minima.

Actually, In this notes, the loss is defined to be $$\frac{1}{2}\sum_{i = 1}^{N}(Y_i - WX_i)^2$$, and the motivation there is coming from maximum likelihood.

Now if we look at mini-batch gradient descent, my question is whether it is necessary to divide the mini-batch size while updating the loss function. If we are taking the perspective that $$L$$ is some sort of expected loss, then certainly we need to divide the mini-batch size. However, if our original loss does not divide $$N$$ then I do not think it even makes to even use mini-batch gradient descent because I do not really think $$\sum_{i}^{M}(Y_i - WX_i)^2$$ for some $$M < N$$ is a good estimate for $$\sum_{i}^{N}(Y_i - WX_i)^2$$. When $$M$$ is very small, they can be very different from each other.