Every equation in the certificate, with a plain-English translation
One page per topic area. Each formula has a plain-English translation, because knowing what it means is what the quizzes test.
| Name | Formula | Says | ||
|---|---|---|---|---|
| MSE | (1/m)·Σ(y−ŷ)² | average squared miss; big errors hurt disproportionately | ||
| MAE | `(1/m)·Σ | y−ŷ | ` | average miss; robust to outliers |
| RMSE | √MSE | MSE back in the original units | ||
| Binary cross-entropy | −(1/m)·Σ[y·log ŷ + (1−y)·log(1−ŷ)] | pay −log(probability you assigned to the truth) | ||
| Categorical cross-entropy | −Σ y_i·log(ŷ_i) | same, over K classes; only the true class contributes | ||
| KL divergence | Σ P(x)·log(P(x)/Q(x)) | how much distribution Q differs from P |
The one insight: cross-entropy = negative log-likelihood. Minimising it is maximum likelihood estimation.
| Name | Formula | Range | Derivative |
|---|---|---|---|
| Sigmoid | σ(z) = 1/(1+e⁻ᶻ) | (0,1) | σ(z)(1−σ(z)), max 0.25 |
| Tanh | (eᶻ−e⁻ᶻ)/(eᶻ+e⁻ᶻ) | (−1,1) | 1−tanh²(z), max 1.0 |
| ReLU | max(0,z) | [0,∞) | 0 or 1 |
| Leaky ReLU | max(0.01z, z) | (−∞,∞) | 0.01 or 1 |
| Softmax | e^(z_i)/Σe^(z_j) | (0,1), sums to 1 | — |
The 0.25 is why sigmoid causes vanishing gradients: 0.25¹⁰ ≈ 10⁻⁶.
Gradient descent w := w − α·∂J/∂w
Momentum v := ρv + ∂J/∂w ; w := w − αv
L2 / Ridge J + α·Σθ² shrinks toward 0
L1 / Lasso J + α·Σ|θ| drives to exactly 0 (feature selection)
Weight decay same as L2, set on the optimiser in PyTorch
C = 1/α in sklearn's LogisticRegression and SVC. Small C = strong regularisation.
Predicted
Neg Pos
Actual Neg | TN | FP |
Pos | FN | TP |
Accuracy = (TP+TN)/total
Precision = TP/(TP+FP) when I say yes, how often right
Recall/TPR = TP/(TP+FN) of real yeses, how many caught
Specificity = TN/(TN+FP)
FPR = FP/(FP+TN)
F1 = 2PR/(P+R) harmonic mean
ROC = TPR vs FPR across thresholds. AUC: 1.0 perfect, 0.5 random. R² = 1 − SS_res/SS_tot. Silhouette = (b−a)/max(a,b).
Gini 1 − Σp²
Entropy −Σ p·log₂p
Information gain entropy(parent) − weighted-avg entropy(children)
Both are 0 at purity, maximal at an even mix.
Output size out = floor((in − k + 2p)/s) + 1
Transpose conv out = (in − 1)·s − 2p + k
Conv params k·k·C_in·C_out + C_out
Dense params in·out + out
Worked: input 28, k=5, p=2, s=1 → (28−5+4)/1+1 = 28 (same padding). Conv2d(3,16,5) → 5·5·3·16 + 16 = 1,216.
x̂ = (x − μ_B)/√(σ²_B + ε)
y = γ·x̂ + β γ, β learned
Train uses batch statistics; eval uses running averages. That's what model.eval() switches.
Xavier/Glorot Var(W) = 2/(n_in + n_out) with tanh, sigmoid
He/Kaiming Var(W) = 2/n_in with ReLU
He uses twice the variance because ReLU zeroes half the activations.
Attention(Q,K,V) = softmax(Q·Kᵀ/√d_k)·V
head_i = Attention(QW_i^Q, KW_i^K, VW_i^V)
MultiHead = Concat(head_1…head_h)·W^O
√d_k prevents softmax saturation. Cost is O(n²·d) in sequence length.
Positional encoding:
PE(pos,2i) = sin(pos/10000^(2i/d))
PE(pos,2i+1) = cos(pos/10000^(2i/d))
Causal mask: set the upper triangle to −inf before softmax.
Perplexity = exp(cross-entropy loss) lower is better
N-gram P(wₙ|wₙ₋₂,wₙ₋₁) = count(w₋₂,w₋₁,wₙ)/count(w₋₂,w₋₁)
Cosine sim = (a·b)/(‖a‖·‖b‖)
Perplexity ≈ the effective number of choices the model is deciding between per token.
W' = W₀ + (α/r)·B·A
W₀ : d×k frozen
A : r×k trainable, random init
B : d×r trainable, ZERO init ← so BA=0 at step 0
Parameters: r·(d+k) instead of d·k. d=k=4096, r=8 → 65k vs 16.7M.
Return G_t = R_{t+1} + γR_{t+2} + γ²R_{t+3} + …
Bellman/Q Q(s,a) ← Q(s,a) + α[r + γ·max_a' Q(s',a') − Q(s,a)]
The bracket is the temporal-difference error.
Bradley-Terry P(y_c ≻ y_r) = σ(r(x,y_c) − r(x,y_r))
Reward loss −log σ(r(x,y_c) − r(x,y_r))
RLHF objective max E[r(x,y)] − β·KL(π ‖ π_ref)
PPO clipped L = min(ratio·Â, clip(ratio, 1−ε, 1+ε)·Â)
ratio = π_new(a|s)/π_old(a|s), ε ≈ 0.2
Optimal policy π*(y|x) = (1/Z(x))·π_ref(y|x)·exp(r(x,y)/β)
DPO loss −log σ( β·log[πθ(y_c|x)/π_ref(y_c|x)]
− β·log[πθ(y_r|x)/π_ref(y_r|x)] )
Log-derivative ∇θ E[f(x)] = E[f(x)·∇θ log πθ(x)]
The DPO trick: invert the optimal-policy equation to express reward in terms of the policy, substitute into Bradley-Terry, and β·log Z(x) cancels because it's identical for both responses to the same prompt. No reward model, no RL.
| Sigmoid derivative max | 0.25 |
| Tanh derivative max | 1.0 |
| Typical fine-tuning LR | 2e-5 – 5e-5 |
| Typical from-scratch LR | 1e-3 |
| DPO LR | 5e-7 – 1e-6 |
| PPO clip ε | 0.2 |
| DPO/RLHF β | ~0.1 |
| BERT masking | 15%, split 80/10/10 |
| LoRA r to start | 8, α = 16 |
| Dropout p | 0.2 – 0.5 |
| Momentum ρ | 0.9 |
| RAG chunk / overlap | 1000 / 200 chars |
| RAG top-k | 3 – 5 |
| BERT max sequence | 512 tokens |
| Transformer FFN expansion | 4× |
| Tokens per English word | ~1.3 |