• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

blmoistawinde/ml_equations_latex: Classical ML equations in Latex, helps paper a ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

blmoistawinde/ml_equations_latex

开源软件地址(OpenSource Url):

https://github.com/blmoistawinde/ml_equations_latex

开源编程语言(OpenSource Language):

HTML 99.9%

开源软件介绍(OpenSource Introduction):

Classical ML Equations in LaTeX

A collection of classical ML equations in Latex . Some of them are provided with simple notes and paper link. Hopes to help writings such as papers and blogs.

Better viewed at https://blmoistawinde.github.io/ml_equations_latex/

Model

RNNs(LSTM, GRU)

encoder hidden state math at time step math , with input token embedding math

math

decoder hidden state math at time step math , with input token embedding math

math

h_t = RNN_{enc}(x_t, h_{t-1})
s_t = RNN_{dec}(y_t, s_{t-1})

The math , math are usually either

Attentional Seq2seq

The attention weight math , the math th decoder step over the math th encoder step, resulting in context vector math

math

math

math

c_i = \sum_{j=1}^{T_x} \alpha_{ij}h_j

\alpha_{ij} = \frac{\exp(e_{ij})}{\sum_{k=1}^{T_x} \exp(e_{ik})}

e_{ij} = a(s_{i-1}, h_j)

math is an specific attention function, which can be

Bahdanau Attention

Paper: Neural Machine Translation by Jointly Learning to Align and Translate

math

e_{ij} = v^T tanh(W[s_{i-1}; h_j])

Luong(Dot-Product) Attention

Paper: Effective Approaches to Attention-based Neural Machine Translation

If math and math has same number of dimension.

math

otherwise

math

e_{ij} = s_{i-1}^T h_j

e_{ij} = s_{i-1}^T W h_j

Finally, the output math is produced by:

math

math

s_t = tanh(W[s_{t-1};y_t;c_t])
o_t = softmax(Vs_t)

Transformer

Paper: Attention Is All You Need

Scaled Dot-Product attention

math

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

where math is the dimension of the key vector math and query vector math .

Multi-head attention

math

where

math

MultiHead(Q, K, V) = Concat(head_1, ..., head_h)W^O

head_i = Attention(Q W^Q_i, K W^K_i, V W^V_i)

Generative Adversarial Networks(GAN)

Paper: Generative Adversarial Networks

Minmax game objective

math

\min_{G}\max_{D}\mathbb{E}_{x\sim p_{\text{data}}(x)}[\log{D(x)}] +  \mathbb{E}_{z\sim p_{\text{z}}(z)}[1 - \log{D(G(z))}]

Variational Auto-Encoder(VAE)

Paper: Auto-Encoding Variational Bayes

Reparameterization trick

To produce a latent variable z such that math , we sample math , than z is produced by

math

z \sim q_{\mu, \sigma}(z) = \mathcal{N}(\mu, \sigma^2)
\epsilon \sim \mathcal{N}(0,1)
z = \mu + \epsilon \cdot \sigma

Above is for 1-D case. For a multi-dimensional (vector) case we use:

math

math

\epsilon \sim \mathcal{N}(0, \textbf{I})
\vec{z} \sim \mathcal{N}(\vec{\mu}, \sigma^2 \textbf{I})

Activations

Sigmoid

Related to Logistic Regression. For single-label/multi-label binary classification.

math

\sigma(z) = \frac{1} {1 + e^{-z}}

Tanh

math

tanh(x) = \frac{e^x - e^{-x}}{e^x + e^{-x}} = \frac{1 - e^{-2x}}{1 + e^{-2x}}

Softmax

For multi-class single label classification.

math

\sigma(z_i) = \frac{e^{z_{i}}}{\sum_{j=1}^K e^{z_{j}}} \ \ \ for\ i=1,2,\dots,K

Relu

math

Relu(z) = max(0, z)

Gelu

math

where math is the cumulative distribution function of Gaussian distribution.

Gelu(x) = x\Phi(x)

Loss

Regression

Below math and math are math dimensional vectors, and math denotes the value on the math th dimension of math .

Mean Absolute Error(MAE)

math

\sum_{i=1}^{D}|x_i-y_i|

Mean Squared Error(MSE)

math

\sum_{i=1}^{D}(x_i-y_i)^2

Huber loss

It’s less sensitive to outliers than the MSE as it treats error as square only inside an interval.

math

L_{\delta}=
    \left\{\begin{matrix}
        \frac{1}{2}(y - \hat{y})^{2} & if \left | (y - \hat{y})  \right | < \delta\\
        \delta ((y - \hat{y}) - \frac1 2 \delta) & otherwise
    \end{matrix}\right.

Classification

Cross Entropy

  • In binary classification, where the number of classes math equals 2, Binary Cross-Entropy(BCE) can be calculated as:

math

  • If math (i.e. multiclass classification), we calculate a separate loss for each class label per observation and sum the result.

math

-{(y\log(p) + (1 - y)\log(1 - p))}

-\sum_{c=1}^My_{o,c}\log(p_{o,c})

M - number of classes

log - the natural log

y - binary indicator (0 or 1) if class label c is the correct classification for observation o

p - predicted probability observation o is of class c

Negative Loglikelihood

math

Minimizing negative loglikelihood

math

is equivalent to Maximum Likelihood Estimation(MLE).

math

Here math is a scaler instead of vector. It is the value of the single dimension where the ground truth math lies. It is thus equivalent to cross entropy (See wiki).\

NLL(y) = -{\log(p(y))}

\min_{\theta} \sum_y {-\log(p(y;\theta))}

\max_{\theta} \prod_y p(y;\theta)

Hinge loss

Used in Support Vector Machine(SVM).

math

max(0, 1 - y \cdot \hat{y})

KL/JS divergence

math

math

KL(\hat{y} || y) = \sum_{c=1}^{M}\hat{y}_c \log{\frac{\hat{y}_c}{y_c}}

JS(\hat{y} || y) = \frac{1}{2}(KL(y||\frac{y+\hat{y}}{2}) + KL(\hat{y}||\frac{y+\hat{y}}{2}))

Regularization

The math below can be any of the above loss.

L1 regularization

A regression model that uses L1 regularization technique is called Lasso Regression.

math

Loss = Error(Y - \widehat{Y}) + \lambda \sum_1^n |w_i|

L2 regularization

A regression model that uses L1 regularization technique is called Ridge Regression.

math

Loss = Error(Y - \widehat{Y}) +  \lambda \sum_1^n w_i^{2}

Metrics

Some of them overlaps with loss, like MAE, KL-divergence.

Classification

Accuracy, Precision, Recall, F1

math

math

math

math

Accuracy = \frac{TP+TN}{TP+TN+FP+FN}
Precision = \frac{TP}{TP+FP}
Recall = \frac{TP}{TP+FN}
F1 = \frac{2*Precision*Recall}{Precision+Recall} = \frac{2*TP}{2*TP+FP+FN}

Sensitivity, Specificity and AUC

math

math

Sensitivity = Recall = \frac{TP}{TP+FN}
Specificity = \frac{TN}{FP+TN}

AUC is calculated as the Area Under the math (TPR)- math (FPR) Curve.

Regression

MAE, MSE, equation above.


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap