Chapter 9 — Quick Reference Notes

📑 Key Formulas

Perceptron Update

y = sign(w · x + b)
w ← w + η(ytrue − ypred)x

MLP Forward Pass

z[l] = W[l] a[l−1] + b[l]
a[l] = f(z[l])

Backpropagation (Output Layer)

δ[L] = ∇aJ ⊙ f'(z[L])
∂J/∂W[l] = δ[l] (a[l−1])T
δ[l−1] = (W[l])T δ[l] ⊙ f'(z[l−1])

CNN Output Size

O = ⌊(W − F + 2P) / S⌋ + 1

Attention

Attention(Q,K,V) = softmax(QKT / √dk) V

Adam Update

mt = β1 mt−1 + (1−β1) gt
vt = β2 vt−1 + (1−β2) gt²
θ ← θ − η m̂t / (√v̂t + ε)

🔢 Parameter Counting Cheat Sheet

Layer TypeFormulaExample (d=100, n=256)
FC (Dense)nout × (nin + 1)256 × 101 = 25,856
Conv2DK × (Cin × F² + 1)16 × (3×3×3+1) = 448
Vanilla RNNn(d+n+1) + m(n+1)varies
LSTM4n(n + d + 1)4×256×357 = 365,568
GRU3n(n + d + 1)3×256×357 = 274,176
Batch Norm2 × C2×256 = 512
Pooling00

⚡ Activation Functions

FunctionFormulaRangeDerivativeUse In
Sigmoidσ(x) = 1/(1+e−x)(0,1)σ(1−σ)Binary output, gates
tanh(ex−e−x)/(ex+e−x)(−1,1)1−tanh²RNN hidden states
ReLUmax(0, x)[0, ∞)0 or 1Default for hidden layers
Leaky ReLUmax(αx, x)(−∞, ∞)α or 1When dying ReLU is an issue
GELUx · Φ(x)≈(−0.17, ∞)complexTransformers (BERT, GPT)
Softmaxezi/∑ezj(0,1), sums to 1—Multi-class output
Quick Rule: Use ReLU for hidden layers, sigmoid for binary output, softmax for multi-class output.

🚀 Optimizer Quick Reference

OptimizerAdaptive?Momentum?Defaults
SGDNoNoη = 0.01
SGD + MomentumNoYesβ = 0.9
AdaGradYesNoη = 0.01
RMSPropYesNoγ = 0.9, η = 0.001
AdamYesYesβ1=0.9, β2=0.999, η=0.001
Mnemonic for Adam defaults: “9-triple9-thousandth” → β1=0.9, β2=0.999, η=0.001.

🏗 Architecture Quick Comparison

ArchitectureBest ForKey FeatureSequential?
MLPTabular dataFully connectedNo
CNNImages, spatial dataWeight sharing, local connectivityNo
RNNSequencesHidden state recurrenceYes
LSTMLong sequencesCell state + 3 gatesYes
GRULong sequences (faster)2 gates, no cell stateYes
TransformerEverything (NLP, CV, …)Self-attention, parallelisableNo

⚠ Common GATE Mistakes

  • Forgetting the +1 (bias) in parameter counting.
  • Confusing floor vs ceiling in CNN output formula — always use floor.
  • Thinking pooling has learnable parameters — it has zero.
  • Applying dropout at test time — only used during training.
  • Mixing up LSTM gates: forget gate erases; input gate writes.
  • Forgetting bias correction in Adam (÷ by 1−βt).
  • Ignoring the scaling factor √dk in attention.