Type at least 2 letters. Enter opens the first result, Esc closes.

    Quick recap

    The key takeaways of every lesson on one page. Read it in ten minutes to refresh the whole track; open a lesson when a point feels unclear.

    01 How to learn here

    • Recognition (it looks familiar) is not recall (you can produce it). Re-reading trains recognition and creates an illusion of fluency.
    • Retrieval practice (answering from memory) and spacing (study spread over days) are the two study methods with the strongest evidence (Dunlosky et al., 2013).
    • Pretesting (guess before you learn), interleaving (mix problem types) and desirable difficulties (effortful but successful recall) also improve long-term memory.
    • Simplified forgetting model: R(t)=e−(t−t0)/SR(t) = e^{-(t - t_0)/S}; a review that succeeds multiplies the stability SS by more when recall was harder; a review that fails starts over.
    • This site's scheduler (an SM-2 variant): a card rated Good every time returns after 1, 3, 8, 20, 50, 125 days; Again brings it back in 10 minutes and restarts it at 1 day with a lower ease.
    • The review deck lives only in your browser; save it to a file to move it or keep a copy.
    • An active quick look: cover the summary, recall, then compare. Daily: review first (10–15 minutes), then new material.

    02 Reading math notation

    • A set has no order and no repeats. x∈Ax \in A: element; A⊆BA \subseteq B: subset; ∪\cup (or), ∩\cap (and), ∖\setminus (without); ∣A∣\lvert A \rvert: size; {x∈R:x>0}\{x \in \mathbb{R} : x > 0\} = "all real xx such that x>0x > 0".
    • f:X→Yf: X \to Y gives each input exactly one output. The range is the set of outputs that occur. (f∘g)(x)=f(g(x))(f \circ g)(x) = f(g(x)): gg acts first. f(x;θ)f(x; \theta): input xx, parameters θ\theta.
    • X∈Rm×nX \in \mathbb{R}^{m \times n}: mm rows (samples), nn columns (features). Xij=xj(i)X_{ij} = x^{(i)}_j is Python X[i-1, j-1]. x(i)x^{(i)} is sample ii, not a power.
    • ∑i=1nai\sum_{i=1}^{n} a_i is a loop that adds the terms. Rules: ∑(c ai+bi)=c∑ai+∑bi\sum (c\,a_i + b_i) = c \sum a_i + \sum b_i; ∑i=1nc=nc\sum_{i=1}^{n} c = nc; ∑i∑jaibj=(∑iai)(∑jbj)\sum_i \sum_j a_i b_j = (\sum_i a_i)(\sum_j b_j), but ∑iaibi≠(∑ai)(∑bi)\sum_i a_i b_i \ne (\sum a_i)(\sum b_i) in general.
    • ∑i=1ni=n(n+1)/2\sum_{i=1}^{n} i = n(n+1)/2. The empty sum is 0 and the empty product is 1; log⁡∏iai=∑ilog⁡ai\log \prod_i a_i = \sum_i \log a_i for ai>0a_i > 0.
    • max⁡xf(x)\max_x f(x) is a value; arg⁡max⁡xf(x)\arg\max_x f(x) is the set of places where it is reached (it can have several elements). Training: θ⋆=arg⁡min⁡θL(θ)\theta^\star = \arg\min_\theta L(\theta).
    • Context decides the meaning of a symbol: σ\sigma (standard deviation or sigmoid), Σ\Sigma (sum or covariance matrix), λ\lambda (regularization or eigenvalue), ∣⋅∣\lvert \cdot \rvert (absolute value or set size).

    03 Python and NumPy for math

    • A NumPy array has a shape (the length of each axis), a dtype and ndim. x∈Rnx \in \R^n is shape (n,); A∈Rm×nA \in \R^{m \times n} is shape (m, n); math index xix_i is x[i-1].
    • Slices a[i:j] exclude j; negative indices count from the end. An integer index removes an axis, a slice keeps it. Slices are views that share memory; masks return copies; use .copy() to be safe.
    • A reduction with axis=k removes axis k ((m, n) → (n,) for axis=0); keepdims=True keeps it with length 1.
    • Broadcasting: align shapes on the right; sizes must be equal or one of them 1 (missing counts as 1); size-1 dimensions are stretched. (n,) with (n, 1) silently gives (n, n).
    • * is elementwise; @ is the matrix product, (m, p) @ (p, n) → (m, n); for 1-D arrays x @ y is the dot product ∑ixiyi\sum_i x_i y_i.
    • np.arange(a, b, step) excludes b; np.linspace(a, b, n) includes b and gives n points.
    • rng = np.random.default_rng(seed) makes random numbers reproducible: the same seed gives the same sequence.
    • Floats are not exact: compare with np.isclose/np.allclose; np.exp overflows to inf above about 709.78.

    04 Lines, powers, exp and log

    • The line through (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) has slope w=(y2−y1)/(x2−x1)w = (y_2 - y_1)/(x_2 - x_1) and intercept b=y1−wx1b = y_1 - w x_1; in ML, y^=wx+b\hat y = wx + b has weight ww and bias bb.
    • a f(c(x−h))+ka\,f(c(x - h)) + k moves the graph of ff right by hh and up by kk, stretches it vertically by aa and squeezes it horizontally by cc.
    • Power rules: aman=am+na^m a^n = a^{m+n}, (am)n=amn(a^m)^n = a^{mn}, a0=1a^0 = 1, a−n=1/ana^{-n} = 1/a^n; for the exponential, ea+b=eaebe^{a+b} = e^a e^b and ex>0e^x > 0 for every xx.
    • log⁡by\log_b y is the power xx with bx=yb^x = y; it is defined only for y>0y > 0. In ML, log⁡\log means the natural log (base ee).
    • Log rules: log⁡(ab)=log⁡a+log⁡b\log(ab) = \log a + \log b, log⁡(ak)=klog⁡a\log(a^k) = k\log a, log⁡by=log⁡y/log⁡b\log_b y = \log y / \log b. But log⁡(a+b)≠log⁡a+log⁡b\log(a + b) \ne \log a + \log b.
    • log⁡\log is strictly increasing, so arg⁡max⁡θlog⁡L(θ)=arg⁡max⁡θL(θ)\arg\max_\theta \log L(\theta) = \arg\max_\theta L(\theta); and log⁡∏ipi=∑ilog⁡pi\log \prod_i p_i = \sum_i \log p_i avoids underflow.
    • Exponential data are straight on a semilog plot (slope log⁡b\log b); a power law y=axky = ax^k is straight on a log-log plot with slope kk.
    • Every exponential bxb^x with b>1b > 1 eventually beats every power xkx^k; 2x2^x passes x10x^{10} only at x≈58.77x \approx 58.77.

    05 Sigmoid, softmax, log-sum-exp

    • The sigmoid σ(z)=1/(1+e−z)\sigma(z) = 1/(1 + e^{-z}) maps a real score to (0,1)(0, 1), with σ(0)=1/2\sigma(0) = 1/2 and σ(−z)=1−σ(z)\sigma(-z) = 1 - \sigma(z).
    • The inverse of the sigmoid is the logit, log⁡p1−p\log\frac{p}{1-p} (the log-odds); the slope is σ′(z)=σ(z)(1−σ(z))≤1/4\sigma'(z) = \sigma(z)(1 - \sigma(z)) \le 1/4, and it is tiny for large ∣z∣|z| (saturation).
    • softmax⁡(z)k=ezk/∑jezj\operatorname{softmax}(z)_k = e^{z_k}/\sum_j e^{z_j} gives positive entries that sum to 1 and keeps the order of the logits.
    • Softmax is shift invariant: softmax⁡(z+c1)=softmax⁡(z)\operatorname{softmax}(z + c\mathbf 1) = \operatorname{softmax}(z); with two classes, softmax⁡(z1,z2)1=σ(z1−z2)\operatorname{softmax}(z_1, z_2)_1 = \sigma(z_1 - z_2).
    • Temperature: softmax⁡(z/T)\operatorname{softmax}(z/T) tends to a one-hot vector at the argmax as T→0T \to 0 and to the uniform vector as T→∞T \to \infty.
    • LSE⁡(z)=log⁡∑jezj\operatorname{LSE}(z) = \log\sum_j e^{z_j} satisfies max⁡jzj≤LSE⁡(z)≤max⁡jzj+log⁡n\max_j z_j \le \operatorname{LSE}(z) \le \max_j z_j + \log n, and log⁡softmax⁡(z)k=zk−LSE⁡(z)\log\operatorname{softmax}(z)_k = z_k - \operatorname{LSE}(z).
    • The cross-entropy loss from logits is LSE⁡(z)−zy\operatorname{LSE}(z) - z_y.
    • Stable code subtracts m=max⁡jzjm = \max_j z_j: LSE⁡(z)=m+log⁡∑jezj−m\operatorname{LSE}(z) = m + \log\sum_j e^{z_j - m}; in float64, eze^z overflows above about 709.78 (float32: 88.72).

    06 A gentle tour of vectors

    • A vector x∈Rnx \in \R^n is a list of nn numbers. In 2-D and 3-D it is also an arrow from the origin; in higher dimensions we compute with the list.
    • Addition and scalar multiplication work entry by entry. As arrows, addition is tip to tail, and u−vu - v goes from the tip of vv to the tip of uu.
    • The norm is ∥x∥=x12+⋯+xn2\|x\| = \sqrt{x_1^2 + \dots + x_n^2} (Pythagoras). x/∥x∥x/\|x\| is the unit vector in the direction of xx, and ∥x−y∥\|x - y\| is the distance.
    • The dot product is x⊤y=∑ixiyi=∥x∥∥y∥cos⁡θx^\top y = \sum_i x_i y_i = \|x\|\|y\|\cos\theta. Its sign tells an acute (+), right (0) or obtuse (−) angle; x⊤x=∥x∥2x^\top x = \|x\|^2.
    • ∥x±y∥2=∥x∥2+∥y∥2±2x⊤y\|x \pm y\|^2 = \|x\|^2 + \|y\|^2 \pm 2x^\top y. With the law of cosines, this proves the geometric formula of the dot product.
    • Cosine similarity x⊤y/(∥x∥∥y∥)∈[−1,1]x^\top y / (\|x\|\|y\|) \in [-1, 1] compares directions and ignores length. For unit vectors, ∥x−y∥2=2−2cos⁡(x,y)\|x - y\|^2 = 2 - 2\cos(x, y), so distance and cosine give the same ranking.
    • A linear model y^=w⊤x+b\hat y = w^\top x + b is a dot product: each weight wjw_j is the change of y^\hat y per unit of feature jj.

    07 Slope, derivative, gradient

    • The average rate of change f(x+h)−f(x)h\frac{f(x+h) - f(x)}{h} is the slope of a secant line. The derivative f′(x)f'(x) is its limit as h→0h \to 0, the slope of the tangent line.
    • Local linear approximation: f(x+h)≈f(x)+f′(x)hf(x + h) \approx f(x) + f'(x)h; for smooth ff the error shrinks like h2h^2. Example: 4.1≈2.025\sqrt{4.1} \approx 2.025.
    • Rules: (xn)′=nxn−1(x^n)' = nx^{n-1}, (ex)′=ex(e^x)' = e^x, (log⁡x)′=1/x(\log x)' = 1/x, derivatives of sums and constant multiples, and the chain rule (f(g(x)))′=f′(g(x))g′(x)(f(g(x)))' = f'(g(x))g'(x), which gives σ′=σ(1−σ)\sigma' = \sigma(1 - \sigma).
    • At a smooth inner minimum or maximum, f′(x)=0f'(x) = 0; the converse is false (x3x^3 at 0).
    • The central difference f(x+h)−f(x−h)2h\frac{f(x+h) - f(x-h)}{2h} has error of order h2h^2, the forward difference of order hh; too small an hh adds round-off error, so use h≈10−5h \approx 10^{-5} (central).
    • A partial derivative ∂f/∂xj\partial f/\partial x_j changes xjx_j and holds the other inputs fixed. The gradient ∇f\nabla f collects them into a vector in the input space.
    • Duf=∇f⊤u=∥∇f∥cos⁡θD_u f = \nabla f^\top u = \|\nabla f\|\cos\theta: the gradient is the direction of steepest ascent with slope ∥∇f∥\|\nabla f\|, −∇f-\nabla f is steepest descent, and ∇f\nabla f is perpendicular to the contour lines.
    • Gradient descent x←x−η∇f(x)x \leftarrow x - \eta\nabla f(x) on x2x^2 multiplies xx by 1−2η1 - 2\eta each step: it converges for 0<η<10 < \eta < 1, zig-zags for 0.5<η<10.5 < \eta < 1, and diverges for η>1\eta > 1.

    08 Chance and data

    • Probability is long-run relative frequency. The frequency of an event in nn independent trials has typical error p(1−p)/n\sqrt{p(1-p)/n}: it shrinks like 1/n1/\sqrt n.
    • Rules: P(not A)=1−P(A)P(\text{not } A) = 1 - P(A); P(A or B)=P(A)+P(B)−P(A and B)P(A \text{ or } B) = P(A) + P(B) - P(A \text{ and } B); P(A and B)=P(A)P(B)P(A \text{ and } B) = P(A)P(B) only for independent events.
    • Mean xˉ=1n∑ixi\bar x = \frac1n\sum_i x_i (balance point); variance 1n∑i(xi−xˉ)2\frac1n\sum_i (x_i - \bar x)^2; standard deviation = its square root, in the unit of the data. The median is robust to outliers; the mean and std are not.
    • Sample variance divides by n−1n - 1 and is unbiased. NumPy uses nn (ddof=0) by default, pandas uses n−1n - 1 (ddof=1).
    • If y=ax+by = ax + b, then yˉ=axˉ+b\bar y = a\bar x + b and σy=∣a∣σx\sigma_y = |a|\sigma_x. For independent variables, variances add, so the mean of nn has std σ/n\sigma/\sqrt n.
    • A density histogram has bar areas that add up to 1. For a continuous variable, probability = area under the density; a density value can be larger than 1.
    • Normal N(μ,σ2)\mathcal N(\mu, \sigma^2): z-score z=(x−μ)/σz = (x - \mu)/\sigma; within 1,2,31, 2, 3 std: 0.6827,0.9545,0.99730.6827, 0.9545, 0.9973.
    • CLT: the mean of nn independent, identically distributed variables with finite variance is approximately N(μ,σ2/n)\mathcal N(\mu, \sigma^2/n) for large nn. It says nothing about the data being normal.

    09 Reading and writing proofs

    • A theorem says: if the assumptions hold, then the conclusion holds. A proof is a chain of steps, each justified by a definition, an assumption or an earlier result.
    • P⇒QP \Rightarrow Q is false only when PP is true and QQ is false. Its contrapositive ¬Q⇒¬P\neg Q \Rightarrow \neg P is equivalent; its converse Q⇒PQ \Rightarrow P is a different claim. "Iff" needs both directions.
    • ¬(∀x P(x))≡∃x ¬P(x)\neg(\forall x\, P(x)) \equiv \exists x\, \neg P(x) and ¬(∃x P(x))≡∀x ¬P(x)\neg(\exists x\, P(x)) \equiv \forall x\, \neg P(x). The order of ∀\forall and ∃\exists matters.
    • Direct proof: from the assumptions to the conclusion. Contrapositive: from "not QQ" to "not PP". Contradiction: assume the claim is false and derive something impossible.
    • Induction: prove the base case P(n0)P(n_0) and the step P(k)⇒P(k+1)P(k) \Rightarrow P(k+1) for every k≥n0k \ge n_0. Both are needed; the step alone proves nothing.
    • One counterexample disproves a "for all" claim. Any number of checked examples does not prove it.
    • Useful results proved here: 2\sqrt 2 is irrational; 1+⋯+n=n(n+1)/21 + \dots + n = n(n+1)/2; 2n>n22^n > n^2 for n≥5n \ge 5; the mean minimizes ∑i(xi−c)2\sum_i (x_i - c)^2; one linear threshold unit cannot compute XOR.