logo

Online Learning vs. Batch Learning in Machine Learning 📂Machine Learning

Online Learning vs. Batch Learning in Machine Learning

Overview

This document explains online learning, batch learning, and mini-batch learning. It emphasizes that the names and differences among them are not actually crucial, but rather inconsequential. In fact, it can be assumed that only mini-batch learning is used in recent deep learning.

Definition

Let’s suppose we have a true value $\mathbf{y} = \left\{ y_{i} \right\}_{i=1}^{N}$ and an estimated value $\hat{\mathbf{y}} = \left\{ \hat{y}_{i} \right\}_{i=1}^{N}$. Assuming the loss function for parameter $\theta$ is $L(y, \hat{y}) = L(y, \hat{y} ;\theta)$, and the method for optimizing the parameter is $f(L, \theta)$, then the approach of updating the parameter all at once for every $i$ is called batch learning.

$$ \theta \leftarrow f(L(\mathbf{y}, \hat{\mathbf{y}}), \theta) $$

The method of updating the parameter individually for each $i$ is called online learning.

$$ \begin{align*} &\text{For $i=1$ to $N$} \\ &\qquad \theta \leftarrow f(L(y_{i}, \hat{y}_{i}), \theta) \end{align*} $$

설명

경사하강법으로 예를 들면, 모든 데이터에 대해서 한 번에 그래디언트를 구해서 그걸로 업데이트하면 배치러닝이다.

$$ \text{Batch learning: } \theta \leftarrow \theta - \alpha \nabla_{\theta}L(\mathbf{y}, \hat{\mathbf{y}}) $$

각각의 데이터에 대해서 그래디언트를 구해서 파라매터를 업데이트하는 것을 반복하면 온라인러닝이다.

$$ \text{Online learning: } \text{For $i=1$ to $N$,}\quad \theta \leftarrow \theta - \alpha \nabla_{\theta}L(y_{i}, \hat{y}_{i}) $$

딥러닝의 우수한 퍼포먼스를 가능하게 한 이유중 하나가 거대한 데이터 셋인데, 이에 대해서 배치러닝을 적용하는 것은 하드웨어 적으로 사실한 불가능하다. 또한 온라인러닝을 적용하기엔 시간이 오래걸린다는 단점이 있다. 따라서 딥러닝에서 사실상 배치러닝, 온라인러닝은 사용하지 않으며 데이터 셋의 부분집합을 단위로 학습하는 미니배치 러닝만이 사용된다. 그렇다보니 미니배치러닝이라는 말도 실질적으로 쓰이지는 않는다. 그냥 학습이라고 하면 당연히 미니배치 러닝을 말한다고 생각하면 되고, 배치 러닝이라는 말도 (미니)배치 러닝을 의미한다고 봐도 된다.

미니배치 러닝

미니배치 러닝이란, 데이터 셋의 크기가 $N = n \times m$일 때, 데이터를 $m$개씩 묶어 $n$개의 부분집합을 만들어 이를 하나의 학습의 단위로 두는 것을 말한다. $\mathbf{y} = \mathbf{b}_{1} \cup \cdots \mathbf{b}_{n}$ $(\left| \mathbf{b}_{i} \right| = m)$이라 하면,

$$ \text{Minibatch learning: } \text{For $i=1$ to $n$,}\quad \theta \leftarrow \theta - \alpha \nabla_{\theta}L(\mathbf{b}_{i}, \hat{\mathbf{b}}_{i}) $$

이때 $m$을 배치 사이즈라고 부르며, $16, 32, 64$ 등 $2$ is typically set as a square number of 2, but it is not strictly necessary.

Specifically, applying gradient descent in mini-batches is called Stochastic Gradient Descent.