Vai al contenuto

Machine Learning e Reti Neurali: formulario e flashcard

Tutte le formule di Machine Learning e Reti Neurali in una pagina, argomento per argomento, dalle lezioni del corso: stampale o ripassale con le flashcard.

Programma e lezioni Dispensa (PDF) Dispensa per appunti (PDF) Esercizi d'esame 15 formule

Regressione e discesa del gradiente

Il problema dell'apprendimento supervisionato

    \[ J(\mathbf w) = \frac{1}{n}\sum_{i=1}^n\ell\big(f_{\mathbf w}(\mathbf x_i),\ y_i\big) \]

La regressione lineare e le equazioni normali

    \[ J(\mathbf w) = \frac{1}{n}\|X\mathbf w - \mathbf y\|^2 \]

La discesa del gradiente

    \[ \mathbf w_{k+1} = \mathbf w_k - \eta\,\nabla J(\mathbf w_k) \]

Percettrone e reti a più strati

Il percettrone

    \[ \text{se } y_i(\mathbf w^T\mathbf x_i) \le 0:\quad \mathbf w \leftarrow \mathbf w + y_i\mathbf x_i \]

Le reti a più strati

    \[ \mathbf h_1 = \phi(W_1\mathbf x + \mathbf b_1),\quad \mathbf h_2 = \phi(W_2\mathbf h_1 + \mathbf b_2),\quad \dots,\quad \hat{\mathbf y} = W_L\mathbf h_{L-1} + \mathbf b_L \]

Ottimizzatori

La discesa del gradiente stocastica

    \[ \mathbf g_k = \frac{1}{|B|}\sum_{i\in B}\nabla\ell_i(\mathbf w_k),\qquad \mathbf w_{k+1} = \mathbf w_k - \eta\,\mathbf g_k \]

Il momentum

    \[ \mathbf v_{k+1} = \beta\,\mathbf v_k + \mathbf g_k,\qquad \mathbf w_{k+1} = \mathbf w_k - \eta\,\mathbf v_{k+1} \]

RMSProp e Adam: un passo per ogni parametro

    \[ \mathbf m_k = \beta_1\mathbf m_{k-1} + (1 - \beta_1)\mathbf g_k,\qquad \mathbf s_k = \beta_2\mathbf s_{k-1} + (1 - \beta_2)\mathbf g_k^2 \]

    \[ \hat{\mathbf m}_k = \frac{\mathbf m_k}{1 - \beta_1^k},\qquad \hat{\mathbf s}_k = \frac{\mathbf s_k}{1 - \beta_2^k},\qquad \mathbf w_{k+1} = \mathbf w_k - \eta\,\frac{\hat{\mathbf m}_k}{\sqrt{\hat{\mathbf s}_k} + \epsilon} \]

Reti convoluzionali

La convoluzione

    \[ (I * K)(i, j) = \sum_{m}\sum_{n}I(i + m,\ j + n)\,K(m, n) \]

Le dimensioni

    \[ n_{out} = \Big\lfloor\frac{n + 2p - k}{s}\Big\rfloor + 1 \]

Reti ricorrenti e transformer

Le reti ricorrenti

    \[ \mathbf h_t = \tanh(W\mathbf h_{t-1} + U\mathbf x_t + \mathbf b) \]

La LSTM

    \[ \mathbf f_t,\ \mathbf i_t,\ \mathbf o_t = \sigma(\dots),\qquad \mathbf c_t = \mathbf f_t\odot\mathbf c_{t-1} + \mathbf i_t\odot\tanh(\dots),\qquad \mathbf h_t = \mathbf o_t\odot\tanh(\mathbf c_t) \]

L'attenzione

    \[ \text{Attention}(Q, K, V) = \text{softmax}\Big(\frac{QK^T}{\sqrt{d_k}}\Big)V \]

Addestramento in pratica

Le metriche

    \[ \text{precisione} = \frac{VP}{VP + FP},\qquad \text{richiamo} = \frac{VP}{VP + FN},\qquad F_1 = \frac{2\cdot\text{precisione}\cdot\text{richiamo}}{\text{precisione} + \text{richiamo}} \]