All Categories

Machine Learning & AI

Core algorithms behind machine learning and AI — models, activation functions, loss functions, optimizers, deep learning and reinforcement learning.

Linear Regression Model

Basic
y^=wx+b\hat{y} = \mathbf{w}^\top \mathbf{x} + b

Predicts a continuous value as a weighted sum of input features plus a bias.

View details

Gradient Descent Update

Basic
θ:=θαθJ(θ)\theta := \theta - \alpha\,\nabla_\theta J(\theta)

Iteratively moves parameters in the direction that most reduces the loss.

View details

ReLU Activation

Basic
f(x)=max(0,x)f(x) = \max(0, x)

Rectified Linear Unit: outputs the input if positive, else zero.

View details

Leaky ReLU

Basic
f(x)=max(αx,x)f(x) = \max(\alpha x, x)

A ReLU variant that lets a small gradient flow for negative inputs.

View details

Tanh Activation

Basic
tanh(x)=exexex+ex\tanh(x) = \dfrac{e^{x}-e^{-x}}{e^{x}+e^{-x}}

Squashes input to the range (-1, 1); zero-centred activation.

View details

Softmax

Basic
σ(z)i=ezijezj\sigma(z)_i = \dfrac{e^{z_i}}{\sum_{j} e^{z_j}}

Turns a vector of scores into a probability distribution that sums to 1.

View details

Binary Cross-Entropy

Basic
L=[ylogy^+(1y)log(1y^)]L = -\big[y\log\hat{y} + (1-y)\log(1-\hat{y})\big]

Loss for binary classification comparing predicted probability to the true label.

View details

Categorical Cross-Entropy

Basic
L=iyilogy^iL = -\sum_{i} y_i \log \hat{y}_i

Multi-class loss summing the log-probability of the correct class.

View details

Logistic Regression

Basic
y^=11+e(wx+b)\hat{y} = \dfrac{1}{1+e^{-(\mathbf{w}^\top \mathbf{x}+b)}}

Applies the sigmoid to a linear model to output a class probability.

View details

Euclidean Distance (KNN)

Basic
d(p,q)=i(piqi)2d(\mathbf{p},\mathbf{q}) = \sqrt{\sum_i (p_i-q_i)^2}

Straight-line distance between two points; the default metric for k-nearest neighbours.

View details

Cosine Similarity

Basic
cosθ=abab\cos\theta = \dfrac{\mathbf{a}\cdot\mathbf{b}}{\lVert\mathbf{a}\rVert\,\lVert\mathbf{b}\rVert}

Measures the angle between two vectors; 1 means identical direction.

View details

Entropy (Information)

Intermediate
H(S)=ipilog2piH(S) = -\sum_i p_i \log_2 p_i

Measures impurity/uncertainty of a set; used to split decision trees.

View details

Gini Impurity

Intermediate
G=1ipi2G = 1 - \sum_i p_i^2

Probability of misclassifying a random sample; the default split metric in CART trees.

View details

Information Gain

Intermediate
IG=H(S)kSkSH(Sk)IG = H(S) - \sum_k \dfrac{|S_k|}{|S|}H(S_k)

Reduction in entropy achieved by splitting a node on a feature.

View details

Naive Bayes Posterior

Intermediate
P(yx)P(y)iP(xiy)P(y\mid \mathbf{x}) \propto P(y)\prod_i P(x_i\mid y)

Classifies by assuming features are conditionally independent given the class.

View details

L2 Regularization (Ridge)

Intermediate
J=MSE+λjwj2J = \text{MSE} + \lambda\sum_j w_j^2

Adds a penalty on squared weights to reduce overfitting.

View details

L1 Regularization (Lasso)

Intermediate
J=MSE+λjwjJ = \text{MSE} + \lambda\sum_j |w_j|

Penalizes absolute weights, driving many to exactly zero for feature selection.

View details

Hinge Loss (SVM)

Intermediate
L=max(0,1yy^)L = \max(0,\,1 - y\,\hat{y})

Loss for support vector machines; zero once a point is correctly classified with margin.

View details

SVM Margin

Intermediate
M=2wM = \dfrac{2}{\lVert \mathbf{w}\rVert}

Width of the separating margin an SVM maximizes between classes.

View details

Perceptron Update

Intermediate
w:=w+η(yy^)x\mathbf{w} := \mathbf{w} + \eta\,(y-\hat{y})\,\mathbf{x}

The original learning rule that nudges weights when a prediction is wrong.

View details

SGD with Momentum

Intermediate
v:=βv+(1β)J;    θ:=θαvv := \beta v + (1-\beta)\nabla J;\;\; \theta := \theta - \alpha v

Accelerates gradient descent by accumulating a velocity of past gradients.

View details

Adam Optimizer

Intermediate
θ:=θαm^tv^t+ϵ\theta := \theta - \alpha\,\dfrac{\hat{m}_t}{\sqrt{\hat{v}_t}+\epsilon}

Adaptive optimizer combining momentum and per-parameter learning rates.

View details

RMSProp

Intermediate
E[g2]t=γE[g2]t1+(1γ)gt2E[g^2]_t = \gamma E[g^2]_{t-1} + (1-\gamma)g_t^2

Scales the learning rate by a running average of recent squared gradients.

View details

Exponential LR Decay

Intermediate
αt=α0ekt\alpha_t = \alpha_0\, e^{-k t}

Gradually lowers the learning rate as training progresses.

View details

K-Means Objective (WCSS)

Intermediate
J=k=1KxCkxμk2J = \sum_{k=1}^{K}\sum_{\mathbf{x}\in C_k}\lVert \mathbf{x}-\mu_k\rVert^2

Clustering minimizes the total squared distance of points to their cluster centre.

View details

Batch Normalization

Advanced
x^=xμBσB2+ϵ\hat{x} = \dfrac{x-\mu_B}{\sqrt{\sigma_B^2+\epsilon}}

Normalizes layer inputs across a mini-batch to speed and stabilize training.

View details

Dropout (Inverted)

Advanced
x~=xm1p\tilde{x} = \dfrac{x\odot m}{1-p}

Randomly zeroes activations during training to prevent co-adaptation.

View details

TF-IDF

Advanced
tfidf=tflogNdf\text{tfidf} = tf \cdot \log\dfrac{N}{df}

Weights a word by its frequency in a document against its rarity across the corpus.

View details

PCA (Covariance)

Advanced
C=1nXX,    Cv=λv\mathbf{C} = \tfrac{1}{n}\mathbf{X}^\top\mathbf{X},\;\; \mathbf{C}\mathbf{v}=\lambda\mathbf{v}

Finds directions of maximum variance via eigenvectors of the covariance matrix.

View details

Scaled Dot-Product Attention

Advanced
Attn(Q,K,V)=softmax ⁣(QKdk)V\text{Attn}(Q,K,V)=\text{softmax}\!\left(\dfrac{QK^\top}{\sqrt{d_k}}\right)V

Lets each token weigh and aggregate information from all others — the heart of Transformers.

View details

Positional Encoding

Advanced
PE(pos,2i)=sin ⁣(pos100002i/d)PE_{(pos,2i)}=\sin\!\left(\dfrac{pos}{10000^{2i/d}}\right)

Injects word-order information into a Transformer that otherwise ignores position.

View details

Layer Normalization

Advanced
x^=xμσ2+ϵγ+β\hat{x}=\dfrac{x-\mu}{\sqrt{\sigma^2+\epsilon}}\,\gamma+\beta

Normalizes across features within a single sample; standard in Transformers.

View details

KL Divergence

Advanced
DKL(PQ)=iP(i)logP(i)Q(i)D_{KL}(P\Vert Q)=\sum_i P(i)\log\dfrac{P(i)}{Q(i)}

Measures how one probability distribution differs from a reference distribution.

View details

Bellman Equation

Advanced
V(s)=maxa[R(s,a)+γsP(ss,a)V(s)]V(s)=\max_a\Big[R(s,a)+\gamma\sum_{s^{\prime}}P(s^{\prime}\mid s,a)V(s^{\prime})\Big]

Expresses the value of a state as the best immediate reward plus discounted future value.

View details

Q-Learning Update

Advanced
Q(s,a):=Q(s,a)+α[r+γmaxaQ(s,a)Q(s,a)]Q(s,a):=Q(s,a)+\alpha\big[r+\gamma\max_{a^{\prime}}Q(s^{\prime},a^{\prime})-Q(s,a)\big]

Model-free reinforcement learning rule that learns action values from experience.

View details

Discrete Convolution

Advanced
(fg)(t)=τf(τ)g(tτ)(f*g)(t)=\sum_{\tau} f(\tau)\,g(t-\tau)

Slides a filter over an input to detect local patterns; the core of CNNs.

View details