The goal of this guide is to connect the equations used in Quiz 1 to the calculations you actually perform. It brings together the supplied Machine Learning Foundations and Machine Learning Techniques material, including calculus, linear algebra, projections, regression, PCA, kernels, clustering, maximum likelihood, and EM.

The notebook contains two question sets: ML Techniques Mock Quiz 1 (21 questions) and ML Foundations Mock Quiz 1 (25 questions). They are included with their answers and explanations, but are mock-quiz questions, not independently verified past-year exam questions. The separate practice prompts and recall cards from the original site are omitted, as requested.

1. Machine learning basics

Tasks, data, models, loss functions, and dataset splits.

1.1 ML definition and applications

What machine learning does

Machine learning fits a mathematical model using examples. After training, the model is used on new inputs. For example, a house-price model learns from houses whose prices are known, then estimates the price of another house.

  • Data: the examples available for learning.
  • Model: a rule that converts an input into a prediction or a probability score.
  • Learning algorithm: the procedure that chooses the model’s adjustable values using the data.
  • Generalization: how well the fitted model works on unseen examples. Memorizing the training examples is insufficient.

When ML is useful

Use ML when useful example data exist but the input-output rule is difficult to program explicitly. Face detection, spam filtering, and rainfall prediction are examples. Password verification already has an exact rule, so ordinary programming is sufficient.

Two kinds of model

A predictive model estimates a target, such as house price. A probabilistic model describes how likely different observations are, such as the distribution of heights. Linear algebra represents relationships in data; probability describes uncertainty; optimization chooses the fitted parameters.

Source IDs: S08, S09, S10, S11, S12, S13, S36.

1.2 Data and notation

1. Start with a data table

A sample is one observed example: one house, person, image, or coin toss. A feature is one measured property used to describe that example. For house-price prediction, rooms, area, and distance to the metro are three input features. Price is the target: the value to predict.

The housing table in the slides contains six houses. Its metadata specifies units: area in hundreds of square feet, distance in kilometres, and price in units of ten lakh rupees. Thus an area entry of 9 means 900 square feet.

Dataset notation explorer · Interactive demonstration

2. What x, i, j, n, and d mean

We use the letter x for the input measurements. A subscript i identifies which sample we mean. It is a counting label, not multiplication. The letter n is the total number of samples; d is the number of input features in each sample.

i=1,…,n,j=1,…,d,xi=[xi1xi2⋮xid]∈Rd.i=1,\ldots,n,\qquad j=1,\ldots,d,\qquad x_i=\begin{bmatrix}x_{i1}\\x_{i2}\\\vdots\\x_{id}\end{bmatrix}\in\mathbb R^d.
(1)

The expression “xi∈Rdx_i\in\mathbb R^d” says that sample i is represented by d real numbers. Here we treat xix_i as a column vector: d rows and one column. A scalar is a single number; a vector is an ordered list of numbers; a matrix is a rectangular arrangement of numbers.

Read house 2

n=6,d=3,x2=[272.1],y2=3.2.n=6,\quad d=3,\quad x_2=\begin{bmatrix}2\\7\\2.1\end{bmatrix},\quad y_2=3.2.
(2)

The three entries of x2x_2 mean 2 rooms, 700 square feet, and 2.1 km from the metro. The separate scalar y2y_2 is its known price. The notation x23=2.1x_{23}=2.1 means feature 3 of sample 2; it does not mean sample 23.

Slide notation: some slides write the i-th sample as xix^i, and its j-th feature as xjix_j^i. These correspond to xix_i and xijx_{ij} here. In that slide convention, the superscript i is a sample label, not an exponent. A genuine square is written (xj)2(x_j)^2.

3. Row vectors, transpose, and the full dataset

The superscript T means transpose: exchange rows and columns. Thus x2T=[2  7  2.1]x_2^T=[2\;7\;2.1] is a 1×3 row vector. The table displays a sample across a row, even though we define its individual vector as a column. There is no contradiction: the row is the transpose of that column vector.

A=[x1Tx2T⋮xnT]∈Rn×d,y=[y1⋮yn]∈Rn×1.A=\begin{bmatrix}x_1^T\\x_2^T\\\vdots\\x_n^T\end{bmatrix}\in\mathbb R^{n\times d},\qquad y=\begin{bmatrix}y_1\\\vdots\\y_n\end{bmatrix}\in\mathbb R^{n\times1}.
(3)

This is the regression design matrix: one row per sample and one column per feature. For this dataset A is 6×3. In PCA, the source uses a different arrangement: centered sample vectors are stacked as columns in a d×n matrix X. Read the stated convention before multiplying matrices.

4. Features versus parameters

Features are the observed inputs. Parameters are the model’s adjustable values, chosen during training. In a linear prediction, w is a d×1 column vector of weights, one per input feature, and b is a scalar intercept:

f(x)=wTx+b=∑j=1dwjxj+b.f(x)=w^Tx+b=\sum_{j=1}^{d}w_jx_j+b.
(4)

The sum symbol ∑\sum means add the indicated terms as j runs from 1 to d. The product wTxw^Tx is a dot product: multiply corresponding entries and add. Its shape is (1×d)(d×1), so its result is one number.

Example of a prediction, using illustrative weights

w=[10.5−1],x2=[272.1],b=0,f(x2)=1(2)+0.5(7)−1(2.1)=3.4.w=\begin{bmatrix}1\\0.5\\-1\end{bmatrix},\quad x_2=\begin{bmatrix}2\\7\\2.1\end{bmatrix},\quad b=0,\qquad f(x_2)=1(2)+0.5(7)-1(2.1)=3.4.
(5)

The prediction 3.4 differs from the observed target 3.2. Training adjusts the parameters to reduce such errors. These weights illustrate the arithmetic; they are not claimed to be the fitted model.

5. Other notation used in the notes

Notation Meaning and example
∣v∣2=vTv|v|_2=\sqrt{v^Tv} Euclidean length of vector v. For v=(3,4)ᵀ, length = √(9+16)=5.
1[B]\mathbf1[B] Indicator of statement B: 1 if true, 0 if false. For example, 1[2 is even]=1.
min⁡θL(θ)\min_\theta L(\theta) The smallest loss value.
arg⁡min⁡θL(θ)\arg\min_\theta L(\theta) The parameter value giving the smallest loss. If L(θ)=(θ−2)², its minimum value is 0 and its argmin is θ=2.

6. Matrix operations used later

To multiply a matrix by a column vector, take the dot product of each matrix row with that column. The inner dimensions must match:

[1234][56]=[1(5)+2(6)3(5)+4(6)]=[1739].\begin{bmatrix}1&2\\3&4\end{bmatrix}\begin{bmatrix}5\\6\end{bmatrix}=\begin{bmatrix}1(5)+2(6)\\3(5)+4(6)\end{bmatrix}=\begin{bmatrix}17\\39\end{bmatrix}.
(6)

A 2×2 matrix times a 2×1 column gives a 2×1 column. Matrix order matters: AB and BA need not have the same values, and one may be undefined. The identity matrix I has ones on the diagonal and zeros elsewhere; Iv=v. The inverse A⁻¹, when it exists for a square A, reverses A’s transformation: A⁻¹A=AA⁻¹=I. A matrix without an inverse is called singular.

Source IDs: S08, S09, S10, S11, S12, S13, S36.

1.3 ML tasks and loss functions

Supervised versus unsupervised learning

In supervised learning, each sample has both inputs xix_i and a known target yiy_i. The model learns a mapping from inputs to targets. In unsupervised learning, only the input samples are supplied; the aim is to describe, compress, or group them.

Task What is learned Example
Regression A numerical target Predict house price
Classification A category or class label Predict spam/non-spam
Dimensionality reduction A smaller representation of each sample Represent many gene measurements with fewer coordinates
Clustering Groups of similar samples Group photographs without supplied labels
Density estimation A probability model for observations Describe likely observations from a random source

Loss measures how wrong a model is

A loss is a number used to score errors. In the following expressions n is the sample count, i selects one sample, f is the model, and f(xᵢ) is its output. Averaging means adding the errors across samples and dividing by n.

Regression: yᵢ is a real-valued target. Squared loss penalizes large prediction errors more strongly:

L(f)=1n∑i=1n(f(xi)−yi)2.L(f)=\frac1n\sum_{i=1}^{n}(f(x_i)-y_i)^2.
(7)

Example: squared loss

True values (2,5), predictions (3,3): errors are 1 and −2; squared errors are 1 and 4. Average loss = (1+4)/2 = 2.5.

Binary classification: encode the two classes as −1 and +1. The indicator counts incorrect labels:

L(f)=1n∑i=1n1[f(xi)≠yi].L(f)=\frac1n\sum_{i=1}^{n}\mathbf1[f(x_i)\ne y_i].
(8)

Two wrong predictions among ten give loss 0.2 (20% error). A linear classifier uses f(x)=sign⁡(wTx+b)f(x)=\operatorname{sign}(w^Tx+b): a positive score gives +1, and a negative score gives −1. Its decision boundary is wTx+b=0w^Tx+b=0. Define a tie rule at zero.

Dimensionality reduction: an encoder f converts a d-feature vector into k coordinates, where k is smaller than d. A decoder g maps those coordinates back to d dimensions. The reconstruction g(f(xᵢ)) should be close to xᵢ:

f:Rd→Rk,g:Rk→Rd,L=1n∑i∥g(f(xi))−xi∥22.f:\mathbb R^d\to\mathbb R^k,\quad g:\mathbb R^k\to\mathbb R^d,\qquad L=\frac1n\sum_i\|g(f(x_i))-x_i\|_2^2.
(9)

The arrow describes input and output dimensions. The norm measures the length of the reconstruction-error vector. Clustering minimizes distances to group representatives; density estimation minimizes negative log-likelihood. Their objectives are derived in later chapters.

Other tasks named in the introduction

Multiclass classification chooses among more than two classes. Ordinal classification uses ordered categories, such as ratings. Ranking orders items. Link prediction predicts connections, such as friend suggestions. Online learning updates as data arrive; bandits and reinforcement learning concern sequential decisions. The introduction names these tasks; their detailed algorithms are outside the supplied portions.

Source IDs: S08, S09, S10, S11, S12, S13, S36.

1.4 Dataset splits and probability models

Training, validation, and test sets

Split the available labeled samples according to their role:

  1. Training set: used to fit the model parameters, such as w and b.
  2. Validation set: used to choose settings such as polynomial degree or regularization strength. Compare candidate models here.
  3. Test set: used to evaluate the selected model on unseen data. Do not use it to make model-selection decisions.

A low training loss can come from memorization. A separate test set measures whether the learned relationship generalizes. For example, fit degree-1 and degree-5 polynomials on the training data, choose their degree using validation errors, then report the chosen model’s test error.

Probability versus density

For a discrete random variable, p(x) is the probability of outcome x. Its probabilities add to one. For a continuous random variable, p(x) is a density; probabilities correspond to areas under the density curve:

∑xp(x)=1(discrete),∫−∞∞p(x) dx=1(continuous).\sum_x p(x)=1\quad\text{(discrete)},\qquad\int_{-\infty}^{\infty}p(x)\,dx=1\quad\text{(continuous)}.
(10)

The symbol ∫ denotes integration, which adds the area over a continuous range. For continuous X, the probability of one exact value is zero; the density there can still be positive. A density value is not itself a probability.

Uniform-density example

A uniform model on [0,2] has constant density 1/2 inside that interval and zero outside. Probability of the interval [0,1] = width 1 × density 1/2 = 1/2. An observation outside [0,2] has zero density under this model.

Density-estimation objective

We want a normalized model that assigns high probability or density to observed data. A larger p(xᵢ) gives a smaller negative log term:

L=−1n∑i=1nlog⁡p(xi).L=-\frac1n\sum_{i=1}^n\log p(x_i).
(11)

The logarithm is increasing, so minimizing this loss is equivalent to maximizing log-likelihood. If an observation has zero model probability/density, its log term is −∞ and the negative log-loss is +∞.

Source IDs: S08, S09, S10, S11, S12, S13, S36.

2. Calculus

Continuity, derivatives, Taylor approximation, gradients, and Hessians.

2.1 Sets, logic, and functions

Sets, statements, and functions

A set is a collection of objects. The notation x∈Ax\in A says that x is an element of set A; A⊆BA\subseteq B says every element of A is also in B. The union A∪BA\cup B contains elements in either set, the intersection A∩BA\cap B contains elements in both, and the complement AcA^c contains elements in the stated universe that are not in A.

In logic, ∀\forall means “for every” and ∃\exists means “there is at least one.” The implication P⇒QP\Rightarrow Q says that whenever P is true, Q is true. The equivalence P⇔QP\Leftrightarrow Q means each statement implies the other. Complements reverse union and intersection (De Morgan’s laws):

(A∪B)c=Ac∩Bc,(A∩B)c=Ac∪Bc.(A\cup B)^c=A^c\cap B^c,\qquad (A\cap B)^c=A^c\cup B^c.
(12)

Example: apply a complement rule.

Suppose the universe is {1,2,3,4,5}\{1,2,3,4,5\}, A={1,2,3}A=\{1,2,3\}, and B={3,4}B=\{3,4\}. Then A∪B={1,2,3,4}A\cup B=\{1,2,3,4\}, so (A∪B)c={5}(A\cup B)^c=\{5\}. Also Ac={4,5}A^c=\{4,5\}, Bc={1,2,5}B^c=\{1,2,5\}, and their intersection is {5}\{5\}, as the identity predicts.

Number spaces, distance, and functions

Z\mathbb Z denotes the integers, R\mathbb R the real numbers, and Rd\mathbb R^d the set of real vectors with d coordinates. A point x∈Rdx\in\mathbb R^d has Euclidean length ∥x∥2=x12+⋯+xd2\|x\|_2=\sqrt{x_1^2+\cdots+x_d^2}; the distance between x and y is D(x,y)=∥x−y∥2D(x,y)=\|x-y\|_2. An epsilon-ball around a is the set of points whose distance from a is less than ϵ\epsilon, where ϵ>0\epsilon>0 is a chosen radius. A vector subspace must contain zero and remain closed under addition and scalar multiplication.

A function f:A→Bf:A\to B assigns each input in domain A exactly one output in codomain B. Its graph is {(x,f(x)):x∈A}\{(x,f(x)):x\in A\}. For a scalar function of two variables, a contour connects inputs with the same output value; a heat map uses color to show those values.

Example: subspace or shifted plane?

The plane x+y+z=0x+y+z=0 contains (0,0,0)(0,0,0) and is a subspace: sums and scalar multiples of vectors satisfying the equation still satisfy it. The plane x+y+z=1x+y+z=1 does not contain zero, so it is an affine hyperplane, not a vector subspace.

Source IDs: S14, S15, S16, S17, S18, S19, S20.

2.2 Sequences, continuity, and differentiability

What convergence says

A sequence (xn)(x_n) is a list of values indexed by positive integers n. It converges to a if its terms eventually get as close to a as any positive tolerance allows. Here ϵ>0\epsilon>0 is an arbitrary distance tolerance, N is an index that may depend on that tolerance, and “for all n≥Nn\ge N” means every later term stays within the tolerance.

∀ϵ>0  ∃N  ∀n≥N: ∥xn−a∥<ϵ.\forall\epsilon>0\;\exists N\;\forall n\ge N:\ \|x_n-a\|<\epsilon.
(13)

This order of quantifiers matters: choose the tolerance first, then find a cutoff N that works for every later term. For example, xn=1/nx_n=1/n converges to 0: given any ϵ>0\epsilon>0, choose an integer N>1/ϵN>1/\epsilon; then n≥Nn\ge N gives ∣xn−0∣=1/n<ϵ|x_n-0|=1/n<\epsilon.

Continuity and derivatives

A function is continuous at a when inputs near a have outputs near f(a)f(a). In one variable this is equivalent to lim⁡x→af(x)=f(a)\lim_{x\to a}f(x)=f(a), and also to preserving limits of every sequence approaching a. At a piece boundary, check the left-hand limit, right-hand limit, and the actual value separately.

The derivative measures the limiting slope of secant lines. In the definition, h is a nonzero input change that tends to zero.

f′(a)=lim⁡h→0f(a+h)−f(a)h.f'(a)=\lim_{h\to0}\frac{f(a+h)-f(a)}{h}.
(14)

Differentiability at a implies continuity there, but continuity need not imply differentiability. For f(x)=∣x∣f(x)=|x|, the left slope at zero is −1 and the right slope is +1, so the function is continuous but has no derivative at zero. A jump discontinuity is not continuous.

Example: check a piecewise join.

Let f(x)=x+1f(x)=x+1 for x≤0x\le0, and f(x)=1+2xf(x)=1+2x for x>0x>0. At the join, both one-sided limits and the value equal 1, so f is continuous. The left derivative is 1 and the right derivative is 2, so f is not differentiable there.

Procedure at a piecewise boundary

  1. Compute the left-hand limit and right-hand limit.
  2. Compare both limits with the defined value f(a)f(a); all three must agree for continuity.
  3. For differentiability, compute the left and right difference-quotient limits; both must exist and agree.

Source IDs: S14, S15, S16, S17, S18, S19, S20.

2.3 Linear and Taylor approximations

Replace a curved function locally by a line

Choose a base input a and let h be a small change from a. The tangent-line approximation uses the function value and slope at a:

f(a+h)≈f(a)+f′(a)h.f(a+h)\approx f(a)+f'(a)h.
(15)

It is useful when h is small and the function is differentiable near a. The symbol ≈\approx means an estimate, not an identity; accuracy usually worsens as the input moves farther from a.

Add curvature with Taylor terms

If f has enough derivatives near a, include curvature and higher-order shape. The k-th derivative is denoted f(k)f^{(k)}, and k!k! is the factorial (for example, 3!=63!=6). The cubic Taylor polynomial is

f(a+h)≈f(a)+f′(a)h+f′′(a)2!h2+f′′′(a)3!h3.f(a+h)\approx f(a)+f'(a)h+\frac{f''(a)}{2!}h^2+\frac{f^{\prime\prime\prime}(a)}{3!}h^3.
(16)

Each added term records another local feature: value, slope, curvature, then change in curvature. Common expansions about zero are sin⁡h≈h\sin h\approx h, eh≈1+h+h2/2e^h\approx1+h+h^2/2, log⁡(1+h)≈h−h2/2\log(1+h)\approx h-h^2/2, and (1+h)−1≈1−h+h2(1+h)^{-1}\approx1-h+h^2. For the logarithm and reciprocal, require ∣h∣<1|h|<1; all are local approximations near zero.

Worked example: estimate 50\sqrt{50}.

  1. Set f(x)=xf(x)=\sqrt{x}, base point a=49a=49, and change h=50−49=1h=50-49=1.
  2. Compute f(49)=7f(49)=7 and f′(x)=1/(2x)f'(x)=1/(2\sqrt{x}), hence f′(49)=1/14f'(49)=1/14.
  3. Use the tangent estimate: 50≈7+(1/14)(1)=7.07143\sqrt{50}\approx 7+(1/14)(1)=7.07143.

The exact value is about 7.07107; the small difference is the approximation error.

First-order Taylor approximation · Interactive demonstration

Source IDs: S14, S15, S16, S17, S18, S19, S20.

2.4 Derivative rules and stationary points

Rules for combining derivatives

For differentiable functions g and h of the same real input x, the product rule accounts for each factor changing, while the chain rule differentiates an outer function after an inner one:

(gh)′=g′h+gh′,(g∘h)′(x)=g′(h(x))h′(x).(gh)'=g'h+gh',\qquad (g\circ h)'(x)=g'(h(x))h'(x).
(17)

Here g′g' and h′h' mean derivatives with respect to their input, and g∘hg\circ h means g(h(x))g(h(x)). In the chain rule, evaluate the outer derivative at the inner output, then multiply by the inner derivative.

Worked example: chain rule.

For f(x)=ex2f(x)=e^{x^2}, the outer function is g(u)=eug(u)=e^u, the inner function is u=x2u=x^2. Since g′(u)=eug'(u)=e^u and du/dx=2xdu/dx=2x, f′(x)=2xex2f'(x)=2xe^{x^2}. At x=1x=1, the slope is 2e2e.

Find and classify candidates

An interior local maximum or minimum of a differentiable function must have zero first derivative. Such a point is called stationary. Zero derivative only identifies a candidate: x3x^3 has derivative zero at zero but keeps increasing through zero, so it has no extremum there.

At a stationary point a Conclusion
f′′(a)>0f''(a)>0 Strict local minimum (curve bends upward)
f′′(a)<0f''(a)<0 Strict local maximum (curve bends downward)
f′′(a)=0f''(a)=0 Inconclusive; inspect higher derivatives or nearby function values

To find a global optimum on a closed interval, also check the endpoints. If a function is not differentiable at a point, that point can still be an extremum and must be checked separately.

Worked example: minimum of a quadratic.

For f(x)=x2−4x+5f(x)=x^2-4x+5, f′(x)=2x−4f'(x)=2x-4; setting it to zero gives x=2x=2. Since f′′(x)=2>0f''(x)=2>0, this is a strict local minimum, with value f(2)=1f(2)=1. On any interval containing 2, compare this value with any endpoint values to decide a global minimum.

Source IDs: S14, S15, S16, S17, S18, S19, S20.

2.5 Hyperplanes, partial derivatives, and gradients

Lines, planes, and hyperplanes

In Rd\mathbb R^d, a line through point aa in direction vector uu is x=a+tux=a+tu, where t is any real number. To write the line through distinct points a and b, take u=b−au=b-a. A hyperplane is the set of points satisfying wTx=bw^Tx=b, where we0w e0 is a normal vector perpendicular to the plane, b is a scalar offset, and x∈Rdx\in\mathbb R^d. It has dimension d−1d-1. The transpose symbol T turns a column vector into a row, so wTxw^Tx is the dot product.

Example: interpret a plane equation.

In R3\mathbb R^3, 2x1−x2+x3=42x_1-x_2+x_3=4 has normal w=(2,−1,1)Tw=(2,-1,1)^T. It is a two-dimensional plane, and the right side 4 shifts it away from the origin; since it does not contain zero, it is not a vector subspace.

Partial derivatives and gradient

Let f:Rd→Rf:\mathbb R^d\to\mathbb R be a scalar-valued function and let a be an input vector. The vector eje_j has a 1 in coordinate j and zeros elsewhere. A partial derivative changes coordinate j while holding every other coordinate fixed. Here h is a small scalar change:

∂f∂xj(a)=lim⁡h→0f(a+hej)−f(a)h,∇f(a)=[∂f/∂x1⋮∂f/∂xd].\frac{\partial f}{\partial x_j}(a)=\lim_{h\to0}\frac{f(a+he_j)-f(a)}h,\qquad \nabla f(a)=\begin{bmatrix}\partial f/\partial x_1\\\vdots\\\partial f/\partial x_d\end{bmatrix}.
(18)

The gradient is a column vector of all first partial derivatives. If f is differentiable, its local linear approximation is

f(a+h)≈f(a)+∇f(a)Th,f(a+h)\approx f(a)+\nabla f(a)^Th,
(19)

where h is now a d-dimensional displacement vector (not the scalar from the limit above), and the transpose makes the dot product a scalar.

Worked example: tangent plane estimate.

For f(x,y)=xexyf(x,y)=xe^{xy}, f(1,0)=1f(1,0)=1. The partial derivatives are fx=exy(1+xy)f_x=e^{xy}(1+xy) and fy=x2exyf_y=x^2e^{xy}, so ∇f(1,0)=(1,1)T\nabla f(1,0)=(1,1)^T. For displacement h=(0.1,−0.1)Th=(0.1,-0.1)^T, the linear estimate is 1+(1,1)h=11+(1,1)h=1; thus f(1.1,−0.1)≈1f(1.1,-0.1)\approx1 (the actual value is about 0.98542).

Condition: the displayed gradient approximation follows from differentiability. Having all partial derivatives at a point alone does not guarantee a valid linear approximation.

Source IDs: S14, S15, S16, S17, S18, S19, S20.

2.6 Directional derivatives and Hessian

Directional rate of change

For a differentiable scalar function f:Rd→Rf:\mathbb R^d\to\mathbb R, input point a, and unit direction vector u (so ∥u∥2=1\|u\|_2=1), the directional derivative is the rate of change per unit distance:

Duf(a)=∇f(a)Tu.D_uf(a)=\nabla f(a)^Tu.
(20)

The dot product selects the component of the gradient along the direction. The Cauchy-Schwarz inequality ∣vTu∣≤∥v∥∥u∥|v^Tu|\le\|v\|\|u\| says this component cannot exceed the gradient length when u is a unit vector. Therefore, when ∇f(a)e0\nabla f(a) e0, steepest ascent is along ∇f/∥∇f∥\nabla f/\|\nabla f\|, at rate ∥∇f∥\|\nabla f\|; steepest descent is the opposite direction. Any unit u with ∇f(a)Tu<0\nabla f(a)^Tu<0 decreases f locally. The gradient is perpendicular to a smooth level contour through a, because movement along that contour has zero first-order change.

Worked example: compute a directional rate.

  1. Let f(x,y)=x2−xyf(x,y)=x^2-xy and a=(2,−3)a=(2,-3). Its gradient is (2x−y,−x)T(2x-y,-x)^T, so ∇f(a)=(7,−2)T\nabla f(a)=(7,-2)^T.
  2. The direction u=(0.6,0.8)Tu=(0.6,0.8)^T is unit length, because 0.62+0.82=10.6^2+0.8^2=1.
  3. Thus Duf(a)=7(0.6)−2(0.8)=2.6D_uf(a)=7(0.6)-2(0.8)=2.6: f increases at rate 2.6 per unit distance in that direction.
  4. If the requested direction is v=(2,1)Tv=(2,1)^T, first normalize it to u=v/∥v∥=(2,1)T/5u=v/\|v\|=(2,1)^T/\sqrt5; its rate is then (14−2)/5=12/5(14-2)/\sqrt5=12/\sqrt5.
Gradient descent on a quadratic · Interactive demonstration

Hessian and local shape

The Hessian H(a)H(a) is the d-by-d matrix of second partial derivatives; its entry in row i, column j is Hij=∂2f/(∂xi∂xj)H_{ij}=\partial^2 f/(\partial x_i\partial x_j) at a. For a small displacement h, the second-order approximation adds curvature:

f(a+h)≈f(a)+∇f(a)Th+12hTH(a)h.f(a+h)\approx f(a)+\nabla f(a)^Th+\tfrac12h^TH(a)h.
(21)

At a stationary point the gradient term vanishes. Positive definite H (positive quadratic curvature in every nonzero direction) gives a strict local minimum; negative definite gives a strict local maximum; indefinite curvature gives a saddle. A semidefinite Hessian may be inconclusive. For two variables, define D=fxxfyy−fxy2D=f_{xx}f_{yy}-f_{xy}^2, using second partials at the candidate: if D>0D>0 and fxx>0f_{xx}>0, it is a minimum; if D>0D>0 and fxx<0f_{xx}<0, a maximum; if D<0D<0, a saddle. If D=0 this test gives no conclusion.

Worked example: classify a stationary point.

For f(x,y)=x2+3y2f(x,y)=x^2+3y^2, the gradient (2x,6y)T(2x,6y)^T vanishes at (0,0)(0,0). The Hessian is [2006]\begin{bmatrix}2&0\\0&6\end{bmatrix}, which is positive definite; hence the origin is a strict local minimum (indeed, the global minimum).

Source IDs: S14, S15, S16, S17, S18, S19, S20.

3. Four fundamental subspaces

Column, row, null, and left null spaces; rank; linear systems.

3.1 Subspaces and dimensions

Span, independence, basis, and dimension

A linear combination of vectors means multiplying them by scalar weights and adding: c₁v₁+c₂v₂. Their span is the set of all combinations obtainable by varying the weights. Vectors are linearly independent if the only weights producing the zero vector are all zero; otherwise one vector adds no new independent direction. A basis is an independent list spanning a space. The dimension is its number of basis vectors. For example, (1,0)ᵀ and (0,1)ᵀ form a basis of ℝ²: a(1,0)ᵀ+b(0,1)ᵀ=(a,b)ᵀ.

The four spaces associated with a matrix

Let AA be an mm-row, n-column real matrix, written A∈Rm×nA\in\mathbb R^{m\times n}; let r be its rank, the number of pivot columns after row reduction. Each space collects vectors related to multiplication by A:

Space What it contains Ambient space Dimension
Column space C(A)C(A) All linear combinations of A’s columns, equivalently all outputs AxAx Rm\mathbb R^m r
Row space C(AT)C(A^T) All linear combinations of A’s rows Rn\mathbb R^n r
Null space N(A)N(A) Inputs x satisfying Ax=0Ax=0 Rn\mathbb R^n n−r
Left null space N(AT)N(A^T) Vectors y satisfying ATy=0A^Ty=0 Rm\mathbb R^m m−r

For a subspace U, U⊥U^\perp means all vectors perpendicular to every vector in U. The fundamental orthogonality relationships and rank-nullity theorem are

rank⁡(A)+nullity⁡(A)=n,C(AT)=N(A)⊥,C(A)=N(AT)⊥.\operatorname{rank}(A)+\operatorname{nullity}(A)=n,\qquad C(A^T)=N(A)^\perp,\qquad C(A)=N(A^T)^\perp.
(22)

The null space is a subspace because if Au=Av=0, then for any scalars α,β\alpha,\beta, A(αu+βv)=αAu+βAv=0A(\alpha u+\beta v)=\alpha Au+\beta Av=0. Also every row of A has zero dot product with any x in N(A), which explains why the row space is perpendicular to the null space.

Worked dimension example.

If A has 5 rows, 8 columns, and rank 3, then its column and row spaces each have dimension 3. There are 8−3=58-3=5 free dimensions in the null space and 5−3=25-3=2 in the left null space. Check the pairs add to their ambient dimensions: 3+5=83+5=8 and 3+2=53+2=5.

Source IDs: S21, S22, S26, S27.

3.2 Bases using row reduction

Allowed row operations

Row reduction uses three operations that preserve solutions of a system: swap two rows; multiply a row by a nonzero scalar; add a multiple of another row. For example, subtracting twice row 1 from row 2 changes (1,2) and (2,5) into (1,2) and (0,1). Continue eliminating entries to expose independent equations. In echelon form, each successive pivot lies farther right; RREF additionally makes each pivot 1 and the only nonzero entry in its column. A variable in a nonpivot column is free.

Use row reduction to find bases

A basis is a linearly independent list that spans the whole space. Row operations simplify equations, but which basis can be read from the reduced matrix depends on the space being found.

  1. Reduce A to echelon form or reduced row echelon form (RREF). Each leading entry is a pivot; the number of pivots is the rank r.
  2. Column space: identify pivot-column indices in the reduced matrix, then take those columns from the original A. Row operations can change the column vectors and the column space itself.
  3. Row space: the nonzero rows of an echelon form are a basis. Row operations preserve the row space.
  4. Null space: solve the reduced homogeneous system. Express pivot variables in terms of free variables, then set each free variable to 1 in turn and the others to 0 to get basis vectors.
  5. Left null space: solve ATy=0A^Ty=0, where y has one coordinate per row of A.

Worked example: null-space basis (S21, pp. 5-8).

For the 3-by-4 matrix below, the displayed U is obtained by row operations. The pivot columns are 1 and 3; the free variables are x2,x4x_2,x_4.

A=[1222246836810],U=[122200240000].A=\begin{bmatrix}1&2&2&2\\2&4&6&8\\3&6&8&10\end{bmatrix},\qquad U=\begin{bmatrix}1&2&2&2\\0&0&2&4\\0&0&0&0\end{bmatrix}.
(23)

To solve Ax=0Ax=0, solve the equivalent equations Ux=0Ux=0: 2x3+4x4=02x_3+4x_4=0, so x3=−2x4x_3=-2x_4; and x1+2x2+2x3+2x4=0x_1+2x_2+2x_3+2x_4=0, so x1=−2x2+2x4x_1=-2x_2+2x_4. Therefore

x=x2[−2100]+x4[20−21],N(A)=span⁡{[−2100],[20−21]}.x=x_2\begin{bmatrix}-2\\1\\0\\0\end{bmatrix}+x_4\begin{bmatrix}2\\0\\-2\\1\end{bmatrix},\quad N(A)=\operatorname{span}\left\{\begin{bmatrix}-2\\1\\0\\0\end{bmatrix},\begin{bmatrix}2\\0\\-2\\1\end{bmatrix}\right\}.
(24)

There are two independent basis vectors, matching nullity 4−2=24-2=2. The left null space is span⁡{(1,1,−1)T}\operatorname{span}\{(1,1,-1)^T\}, since the third row of A is the sum of its first two rows.

Common mistake: do not report pivot columns of U as a column-space basis for A. Use those column indices to select the original columns.

Source IDs: S21, S22, S26, S27.

3.3 Existence and uniqueness of solutions

When does Ax=bAx=b have a solution?

Let A be an m×nm\times n matrix, x an unknown vector in Rn\mathbb R^n, and b a target vector in Rm\mathbb R^m. Multiplication AxAx forms a linear combination of A’s columns, with the entries of x as its coefficients. Thus a solution exists exactly when b lies in the column space C(A)C(A), equivalently when adding b as a column does not increase rank:

b∈C(A)⟺rank⁡(A)=rank⁡([A∣b]).b\in C(A)\quad\Longleftrightarrow\quad \operatorname{rank}(A)=\operatorname{rank}([A\mid b]).
(25)

In row reduction of the augmented matrix [A∣b][A\mid b], a row of the form [0  ⋯  0∣c][0\;\cdots\;0\mid c] with ce0c e0 means the impossible equation 0=c0=c, so the system is inconsistent.

How many solutions?

If xpx_p is one particular solution, every solution is obtained by adding a null-space vector:

x=xp+xn,Axp=b,xn∈N(A).x=x_p+x_n,\qquad Ax_p=b,\quad x_n\in N(A).
(26)

This works because A(xp+xn)=b+0=bA(x_p+x_n)=b+0=b. Therefore a consistent system has a unique solution precisely when N(A)={0}N(A)=\{0\}, equivalently A has full column rank n. If the null space contains a nonzero vector, adding any scalar multiple of it gives another solution, so there are infinitely many. A square invertible A has full column rank and the unique solution x=A−1bx=A^{-1}b. For a rectangular matrix, “not invertible” alone does not determine whether its null space is nonzero.

Worked example: a consistent system with infinitely many solutions.

Take A=[1236]A=\begin{bmatrix}1&2\\3&6\end{bmatrix} and b=(5,15)Tb=(5,15)^T. The second equation is three times the first, so there is one independent equation x1+2x2=5x_1+2x_2=5. Let the free variable x2=tx_2=t. Then x1=5−2tx_1=5-2t, giving x=(5,0)T+t(−2,1)Tx=(5,0)^T+t(-2,1)^T. The vector (−2,1)T(-2,1)^T spans N(A), and the infinitely many solutions are one particular solution plus that null-space direction.

Shape check: full column rank means rank(A)=n and guarantees uniqueness when the system is consistent; for a tall matrix it may not cover every b. Full row rank means rank(A)=m and guarantees a solution for every b; if n>m, free variables can still make the solution non-unique.

Conditions and a contrast

Full column rank guarantees uniqueness if a solution exists, but does not guarantee a solution for every b when the matrix is tall. Full row rank guarantees a solution for every b; if there are extra columns, those solutions may not be unique. For the example above, solvability requires b to lie on the line spanned by (1,3)T(1,3)^T, because the column space has dimension 1.

Source IDs: S21, S22, S26, S27.

4. Projection and least squares

Orthogonality, projections, normal equations, and line fitting.

4.1 Orthogonality and line projection

Vectors and perpendicularity. A vector is a list of coordinates; we write it as a column. For example, a=(2,1)Ta=(2,1)^T has two entries and is a 2×12\times1 vector. The superscript TT means transpose: it turns a column into a row. The dot product uTvu^Tv multiplies matching entries and adds them; it is zero exactly when the vectors are perpendicular (orthogonal). A vector has length ∥u∥=uTu\|u\|=\sqrt{u^Tu}. Orthogonal vectors of length one are orthonormal. Nonzero mutually orthogonal vectors are linearly independent. Two subspaces are orthogonal if every vector in one is perpendicular to every vector in the other.

Projecting onto a line. Let a≠0a\ne0 be a direction vector and let bb be the vector we want to approximate. The line consists of all multiples of aa. Its closest point to bb has form p=c^ap=\hat c a, where the scalar c^\hat c is chosen so the error e=b−pe=b-p is perpendicular to the line direction. Thus aT(b−c^a)=0a^T(b-\hat c a)=0, giving:

aTb−c^(aTa)=0⇒c^=aTbaTa,p=aaTaTab.a^Tb-\hat c(a^Ta)=0\quad\Rightarrow\quad\hat c=\frac{a^Tb}{a^Ta},\qquad p=\frac{aa^T}{a^Ta}b.
(27)

Here a,b,p,ea,b,p,e each have shape n×1n\times1 for some dimension nn; aTba^Tb and aTaa^Ta are scalars. Scaling aa by any nonzero number changes its length but not the line or its projection. Since p⊥ep\perp e, Pythagoras gives ∥b∥2=∥p∥2+∥e∥2\|b\|^2=\|p\|^2+\|e\|^2: the projection is the closest point on the line.

Orthogonal vector projection · Interactive demonstration

Tutorial 3.3 · projection in four dimensions

For a=(2,−1,2,3)Ta=(2,-1,2,3)^T, b=(1,3,−2,5)Tb=(1,3,-2,5)^T, both are 4×14\times1. Compute aTa=22+(−1)2+22+32=18a^Ta=2^2+(-1)^2+2^2+3^2=18 and aTb=2(1)+(−1)(3)+2(−2)+3(5)=10a^Tb=2(1)+(-1)(3)+2(-2)+3(5)=10. Thus c^=10/18=5/9\hat c=10/18=5/9, and multiplying every coordinate gives p=(5/9)a=(10/9,−5/9,10/9,5/3)Tp=(5/9)a=(10/9,-5/9,10/9,5/3)^T. Subtraction gives residual e=b−p=(−1/9,32/9,−28/9,30/9)Te=b-p=(-1/9,32/9,-28/9,30/9)^T; check aTe=0a^Te=0.

Source IDs: S22, S23, S24, S25, S28.

4.2 Least squares and normal equations

What least squares solves. Suppose AA is an m×nm\times n matrix (m rows, n columns), xx is an unknown coefficient column of shape n×1n\times1, and bb is an observed column of shape m×1m\times1. Then AxAx is an m×1m\times1 prediction. Often no choice of xx makes Ax=bAx=b exactly, so choose x^\hat x to minimize the squared length of the residual e=b−Axe=b-Ax:

min⁡x∥Ax−b∥2.\min_x\|Ax-b\|^2.
(28)

The fitted vector p=Ax^p=A\hat x lies in the column space C(A)C(A), the set of all linear combinations of A’s columns. At the closest point, the residual is perpendicular to every column of A and hence to every vector in C(A)C(A). This is e∈N(AT)e\in N(A^T), or ATe=0A^Te=0. Substituting e=b−Ax^e=b-A\hat x yields the normal equations:

AT(b−Ax^)=0⟺ATAx^=ATb.A^T(b-A\hat x)=0\quad\Longleftrightarrow\quad A^TA\hat x=A^Tb.
(29)

Dimensions help check the equation: ATA^T is n×mn\times m, so both sides are n×1n\times1. Equivalently minimize f(x)=12∥Ax−b∥2f(x)=\tfrac12\|Ax-b\|^2. Differentiating gives ∇xf=AT(Ax−b)\nabla_x f=A^T(Ax-b), and setting this gradient to zero gives the same equations. The factor 1/21/2 cancels the 2 from differentiating a square.

x^=(ATA)−1ATbif A has full column rank (its n columns are independent).\hat x=(A^TA)^{-1}A^Tb\quad\text{if A has full column rank (its n columns are independent).}
(30)

The normal equations always have at least one solution, even when A’s columns are dependent. If rank deficient, several coefficient columns can describe the same best fit, but the fitted vector p and residual e are still unique. Full column rank makes ATAA^TA invertible: for any nonzero zz, zTATAz=∥Az∥2>0z^TA^TAz=\|Az\|^2>0, because independent columns ensure Az≠0Az\ne0.

Source IDs: S22, S23, S24, S25, S28.

4.3 Projection matrices and line-fitting example

Projection matrix. When AA is m×nm\times n with independent columns, it has a unique least-squares coefficient vector for each observation b∈Rmb\in\mathbb R^m. Applying the formula for x^\hat x to get the fitted vector p=Ax^p=A\hat x gives:

P=A(ATA)−1AT,p=Pb.P=A(A^TA)^{-1}A^T,\qquad p=Pb.
(31)

Here PP is an m×mm\times m matrix acting on an m×1m\times1 observation. It satisfies PT=PP^T=P (symmetric) and P2=PP^2=P (projecting twice changes nothing). For an orthonormal column basis Q, QTQ=IQ^TQ=I, so the formula simplifies to P=QQTP=QQ^T. The identity matrix I has ones on its diagonal and zeros elsewhere; multiplying by I leaves a vector unchanged. A symmetric, idempotent matrix is an orthogonal projection. P fixes vectors in C(A)C(A), sends vectors in N(AT)N(A^T) to zero, and I−PI-P projects onto the perpendicular complement.

Example · S25

Fit a line y=mx+cy=mx+c to points (−1,1),(1,1),(2,3)(-1,1),(1,1),(2,3). We seek slope m and intercept c. Let xdatax_{data} denote each input coordinate (to distinguish it from the coefficient vector). For a line, each predicted value is mxdata+cm x_{data}+c. Stacking the three equations makes AA a 3×23\times2 matrix (one row per point and one column per coefficient), θ=(m,c)T\theta=(m,c)^T a 2×12\times1 coefficient vector, and b the 3×13\times1 observed outputs:

A=[−111121],θ=[mc],b=[113].A=\begin{bmatrix}-1&1\\1&1\\2&1\end{bmatrix},\quad \theta=\begin{bmatrix}m\\c\end{bmatrix},\quad b=\begin{bmatrix}1\\1\\3\end{bmatrix}.
(32)

Multiply row by column to build the normal equations: ATA=[(−1)2+12+22−1+1+2−1+1+21+1+1]=[6223]A^TA=\begin{bmatrix}(-1)^2+1^2+2^2&-1+1+2\\-1+1+2&1+1+1\end{bmatrix}=\begin{bmatrix}6&2\\2&3\end{bmatrix}, and ATb=[(−1)(1)+(1)(1)+(2)(3)1+1+3]=[65]A^Tb=\begin{bmatrix}(-1)(1)+(1)(1)+(2)(3)\\1+1+3\end{bmatrix}=\begin{bmatrix}6\\5\end{bmatrix}. Solve [6223]θ^=[65]\begin{bmatrix}6&2\\2&3\end{bmatrix}\hat\theta=\begin{bmatrix}6\\5\end{bmatrix} to get θ^=(4/7,9/7)T\hat\theta=(4/7,9/7)^T. So the fitted line is y=(4/7)x+9/7y=(4/7)x+9/7.

p=Aθ^=17[51317],e=b−p=17[2−64].p=A\hat\theta=\tfrac17\begin{bmatrix}5\\13\\17\end{bmatrix},\qquad e=b-p=\tfrac17\begin{bmatrix}2\\-6\\4\end{bmatrix}.
(33)

Check the perpendicularity: ATe=17[−2−6+82−6+4]=0A^Te=\tfrac17\begin{bmatrix}-2-6+8\\2-6+4\end{bmatrix}=0. The minimum squared vertical error is ∥e∥2=(4+36+16)/49=8/7\|e\|^2=(4+36+16)/49=8/7. This fit minimizes vertical prediction errors (differences in y), not perpendicular distances in the original x-y plot.

Source IDs: S22, S23, S24, S25, S28.

5. Linear, polynomial, and ridge regression

Design matrices, Gaussian noise, polynomial features, and regularization.

5.1 Linear regression

Inputs, features, and coefficients. A training set has n observations. Observation i has feature column xi∈Rdx_i\in\mathbb R^d (d measured inputs) and scalar target yiy_i. The index i labels which observation is meant; it runs from 1 to n. A coefficient column θ∈Rd\theta\in\mathbb R^d assigns a weight to each feature. The dot product xiTθx_i^T\theta is a weighted sum and predicts observation i: y^i=xiTθ\hat y_i=x_i^T\theta. To include an intercept, append a constant 1 to every feature vector and give it its own coefficient.

Put each feature row xiTx_i^T into a design matrix A. Then A has shape n×dn\times d (or n×(d+1)n\times(d+1) when an intercept column is included); the coefficient vector has the matching number of entries, and the target column y=(y1,…,yn)Ty=(y_1,\ldots,y_n)^T has shape n×1n\times1. Thus AθA\theta is the column of all predictions. The residual Aθ−yA\theta-y stores prediction minus observation for each row.

L(θ)=12∑i=1n(xiTθ−yi)2=12∥Aθ−y∥2.L(\theta)=\tfrac12\sum_{i=1}^n(x_i^T\theta-y_i)^2=\tfrac12\|A\theta-y\|^2.
(34)

This is linear regression because predictions are linear in the unknown coefficients, even if we later transform the inputs. The gradient points in the direction of increasing loss; at a least-squares minimum it is zero:

∇θL=AT(Aθ−y),H=ATA,ATAθ^=ATy.\nabla_\theta L=A^T(A\theta-y),\qquad H=A^TA,\qquad A^TA\hat\theta=A^Ty.
(35)

Here H is the Hessian (matrix of second derivatives), of size d-by-d, or the number-of-coefficients squared. It is positive semidefinite, so the loss is a convex bowl; if columns of A are independent it has a unique minimum. Multiplying the unregularized loss by a positive constant changes its scale, not its minimizer.

Why Gaussian noise gives squared error. Suppose each observed target is a prediction plus random noise: yi=xiTθ+ϵiy_i=x_i^T\theta+\epsilon_i, where the errors are independent normal random variables with mean zero and variance σ2\sigma^2. Their joint likelihood, written p(y|A,θ), is a product of Gaussian densities. It is distinct from the squared-error loss L(θ). Taking its logarithm turns that product into a sum; terms depending on θ\theta are minus the sum of squared residuals divided by 2σ22\sigma^2. Therefore maximizing likelihood over θ\theta gives exactly the least-squares solution:

log⁡p(y∣A,θ)=−n2log⁡(2πσ2)−12σ2∑i(yi−xiTθ)2.\log p(y\mid A,\theta)=-\tfrac n2\log(2\pi\sigma^2)-\frac1{2\sigma^2}\sum_i(y_i-x_i^T\theta)^2.
(36)

Source IDs: S10, S25, S29, S34.

5.2 Polynomial regression

Polynomial features. A single scalar input x can be turned into several features: for degree q, use ϕ(x)=(1,x,x2,…,xq)T\phi(x)=(1,x,x^2,\ldots,x^q)^T, a (q+1)×1(q+1)\times1 feature column. Its entries are the constant, input, input squared, and so on. A matching coefficient column is θ=(θ0,…,θq)T\theta=(\theta_0,\ldots,\theta_q)^T; the prediction is the dot product y^(x)=θTϕ(x)=θ0+θ1x+⋯+θqxq\hat y(x)=\theta^T\phi(x)=\theta_0+\theta_1x+\cdots+\theta_qx^q. Though the curve can bend as x changes, the formula is still linear in the unknown coefficients.

For n observations, put ϕ(xi)T\phi(x_i)^T in row i of A and put observed values in y. Then A is n×(q+1)n\times(q+1), θ\theta is (q+1)×1(q+1)\times1, and y is n×1n\times1; solve the same least-squares normal equations. For inputs −1, 0, 2 and degree 2, each row lists (1,x,x2)(1,x,x^2):

A=[1−11100124].A=\begin{bmatrix}1&-1&1\\1&0&0\\1&2&4\end{bmatrix}.
(37)

There are q+1 coefficients including the intercept. Raising q adds flexibility but can make the fitted curve chase noise; choose degree using data held out for validation.

Exact quadratic fit · S34

For observations (1,3), (2,1.5), (3,2.5), seek three coefficients for a degree 2 polynomial. Each row is (1,xi,xi2)(1,x_i,x_i^2), so the design system is:

[111124139][θ0θ1θ2]=[31.52.5].\begin{bmatrix}1&1&1\\1&2&4\\1&3&9\end{bmatrix}\begin{bmatrix}\theta_0\\\theta_1\\\theta_2\end{bmatrix}=\begin{bmatrix}3\\1.5\\2.5\end{bmatrix}.
(38)

Solving gives (θ0,θ1,θ2)=(7,−5.25,1.25)(\theta_0,\theta_1,\theta_2)=(7,-5.25,1.25), hence y=7−5.25x+1.25x2y=7-5.25x+1.25x^2. Substitute x=1, 2, and 3 to check predictions 3, 1.5, and 2.5, respectively.

Source IDs: S10, S25, S29, S34.

5.3 Ridge regression

Ridge regression shrinks coefficients. When features overlap strongly or there are more coefficients than independent observations, least squares can be unstable or non-unique. Ridge adds a penalty for large coefficients. Let A be the n×dn\times d design matrix, θ\theta the d×1d\times1 coefficient column and y the n×1n\times1 observations. The identity matrix I is d×dd\times d; λ>0\lambda>0 controls penalty strength:

J(θ)=12∥Aθ−y∥2+λ2∥θ∥2,(ATA+λI)θ^=ATy.J(\theta)=\tfrac12\|A\theta-y\|^2+\tfrac\lambda2\|\theta\|^2,\qquad(A^TA+\lambda I)\hat\theta=A^Ty.
(39)

Differentiate both terms: the loss contributes AT(Aθ−y)A^T(A\theta-y), while the penalty contributes λθ\lambda\theta. Setting their sum to zero gives the displayed equation. The added diagonal term penalizes coefficients and stabilizes the solve. For any nonzero coefficient vector v, vT(ATA+λI)v=∥Av∥2+λ∥v∥2>0v^T(A^TA+\lambda I)v=\|Av\|^2+\lambda\|v\|^2>0, so the matrix is positive definite and the solution unique, even if A’s columns are dependent. Small λ gives weak shrinkage and greater overfitting risk; large λ gives stronger shrinkage and greater underfitting risk.

Conditions

Factor clarification · S29, p. 7. If the penalty is written as λ∥θ∥2\lambda\|\theta\|^2 without a factor of 1/2, its derivative is 2λθ2\lambda\theta, so the normal equations contain ATA+2λIA^TA+2\lambda I. The objective here uses λ/2\lambda/2. It penalizes every coefficient, including an included intercept.

Source IDs: S10, S25, S29, S34.

6. Eigenvalues and diagonalization

Eigenvectors, diagonalization, matrix powers, and Fibonacci recurrence.

6.1 Eigenvalues and eigenvectors

Determinant used in the eigenvalue calculation

For a 2×2 matrix, the determinant is the product of the main diagonal entries minus the product of the other diagonal:

det⁡[abcd]=ad−bc.\det\begin{bmatrix}a&b\\c&d\end{bmatrix}=ad-bc.
(40)

A square matrix is singular exactly when its determinant is zero. The characteristic equation below applies this test to A−λI, so a nonzero eigenvector can solve (A−λI)v=0.

Meaning. A square n×nn\times n matrix A transforms n-dimensional columns into n-dimensional columns. Most vectors change direction when transformed. An eigenvector is a nonzero column v whose direction is preserved (or reversed) by A; its eigenvalue λ tells the scale:

Av=λv,v≠0.Av=\lambda v,\qquad v\ne0.
(41)

Here v is n×1n\times1, λ is a scalar, and both sides are n×1n\times1. If λ is positive the direction stays oriented; if negative it reverses; if zero the vector is sent to zero. The zero vector is excluded because every matrix sends it to zero, which would make the definition meaningless.

Rearrange to (A−λI)v=0(A-\lambda I)v=0, where I is the n×nn\times n identity. For this system to have a nonzero solution, A−λIA-\lambda I must be singular, so its determinant is zero. This gives a practical procedure:

  1. Find roots λ of the characteristic equation det⁡(A−λI)=0\det(A-\lambda I)=0.
  2. For each root, solve (A−λI)v=0(A-\lambda I)v=0; any nonzero solution is an eigenvector.
  3. Check by multiplying A v and checking it equals λv. As quick checks including repeated roots, eigenvalues sum to trace (diagonal sum) and multiply to determinant.

Example · multiply to check

A=[3113],det⁡(A−λI)=(3−λ)2−1=λ2−6λ+8.A=\begin{bmatrix}3&1\\1&3\end{bmatrix},\qquad\det(A-\lambda I)=(3-\lambda)^2-1=\lambda^2-6\lambda+8.
(42)

The roots are 4 and 2. For λ=4, choose v=(1,1)Tv=(1,1)^T: Av=(3+1,1+3)T=(4,4)T=4vAv=(3+1,1+3)^T=(4,4)^T=4v. For λ=2, v=(1,−1)Tv=(1,-1)^T: Av=(3−1,1−3)T=(2,−2)T=2vAv=(3-1,1-3)^T=(2,-2)^T=2v. Adding cI keeps eigenvectors and adds c to each eigenvalue. General real matrices can have complex eigenvalues; for example, a 90° rotation has eigenvalues ±i. Eigenvalues of A+B generally cannot be found by simply adding those of A and B.

Source IDs: S30, S31, S32, S33, S35.

6.2 Diagonalization and matrix powers

Diagonalization changes to an eigenvector coordinate system. An n×nn\times n matrix A is diagonalizable (over the chosen number system) if it has n independent eigenvectors. Make S the n×nn\times n matrix whose columns are those eigenvectors, and make Λ the diagonal matrix of matching eigenvalues in the same column order. The relation is:

AS=SΛ,S−1AS=Λ,A=SΛS−1.AS=S\Lambda,\qquad S^{-1}AS=\Lambda,\qquad A=S\Lambda S^{-1}.
(43)

S is invertible because its columns are independent. In coordinates along eigenvectors, applying A only scales each coordinate by its eigenvalue; Λ expresses this simple scaling. Consequently powers are easy:

Ak=SΛkS−1,k a nonnegative integer.A^k=S\Lambda^kS^{-1},\qquad k\text{ a nonnegative integer}.
(44)

To compute Aku0A^k u_0, first change the starting vector u0u_0 into eigenvector coordinates with S−1S^{-1}, raise each diagonal entry of Λ to kth power, then change back with S. Distinct eigenvalues have independent eigenvectors, so n distinct eigenvalues guarantee diagonalizability. A repeated eigenvalue may or may not provide enough independent eigenvectors. S is not unique: eigenvectors can be rescaled, or columns reordered if matching entries of Λ are reordered too.

Why distinct eigenvalues give independent eigenvectors

For two vectors with distinct eigenvalues, suppose c1v1+c2v2=0c_1v_1+c_2v_2=0. Apply A and subtract λ2\lambda_2 times the original relation: c1(λ1−λ2)v1=0c_1(\lambda_1-\lambda_2)v_1=0. Since the eigenvalues differ and v1≠0v_1\ne0, c1=0c_1=0, then c2=0c_2=0. The same argument extends to any finite set of distinct eigenvalues.

Example · S31

A=[1423],S=[1−211],Λ=[500−1].A=\begin{bmatrix}1&4\\2&3\end{bmatrix},\quad S=\begin{bmatrix}1&-2\\1&1\end{bmatrix},\quad\Lambda=\begin{bmatrix}5&0\\0&-1\end{bmatrix}.
(45)

The first column checks as A(1,1)T=(5,5)T=5(1,1)TA(1,1)^T=(5,5)^T=5(1,1)^T; the second as A(−2,1)T=(2,−1)T=−1(−2,1)TA(-2,1)^T=(2,-1)^T=-1(-2,1)^T. Thus AS=SΛAS=S\Lambda, with matching eigenvectors and eigenvalues. By contrast, [3103]\begin{bmatrix}3&1\\0&3\end{bmatrix} has only one independent eigenvector, so a 2-by-2 S cannot be formed and it is not diagonalizable.

Source IDs: S30, S31, S32, S33, S35.

6.3 Symmetric matrices and orthogonal diagonalization

Symmetric matrices have an orthonormal eigenbasis. If a real matrix A equals its transpose (AT=AA^T=A), the spectral theorem says all eigenvalues are real and we can choose mutually perpendicular eigenvectors of length one. Put them in the columns of Q and their eigenvalues in diagonal Λ:

A=QΛQT,QTQ=I,Q−1=QT.A=Q\Lambda Q^T,\qquad Q^TQ=I,\qquad Q^{-1}=Q^T.
(46)

Because the columns of Q are orthonormal, transforming coordinates back uses transpose instead of a general inverse. Eigenvectors with distinct eigenvalues are perpendicular; for a repeated eigenvalue, choose an orthonormal basis within its eigenspace. A real matrix is orthogonally diagonalizable exactly when it is symmetric.

A symmetric matrix is positive semidefinite (PSD) if vTAv≥0v^TAv\ge0 for every vector v. For a symmetric matrix this is equivalent to all eigenvalues being nonnegative. Covariance matrices and valid kernel Gram matrices are PSD.

Conditions

Orthogonality clarification · S33, p. 1. For symmetric A, eigenvectors associated with distinct eigenvalues are orthogonal.

Source IDs: S30, S31, S32, S33, S35.

6.4 Differential systems and Fibonacci recurrence

Continuous system. In the differential equation u′(t)=Au(t)u'(t)=Au(t), u(t) is an n-entry state column that changes over time and A is an n×nn\times n matrix. If Av=λvAv=\lambda v, then u(t)=eλtvu(t)=e^{\lambda t}v is a solution: differentiating multiplies v by λ, and applying A does the same. When A is diagonalizable, combine these eigenvector solutions to match the initial state. A real mode decays for λ<0, stays constant for λ=0 and grows for λ>0.

Discrete recurrence and Fibonacci. For repeated updates uk+1=Auku_{k+1}=Au_k, the index k counts steps and the starting column is u0u_0. Repeated multiplication gives uk=Aku0u_k=A^ku_0. Fibonacci numbers start F0=0,F1=1F_0=0,F_1=1 and satisfy Fk+2=Fk+1+FkF_{k+2}=F_{k+1}+F_k. Package two consecutive values in a column so one matrix update performs the recurrence:

[Fk+2Fk+1]=[1110]⏟A[Fk+1Fk].\begin{bmatrix}F_{k+2}\\F_{k+1}\end{bmatrix}=\underbrace{\begin{bmatrix}1&1\\1&0\end{bmatrix}}_{A}\begin{bmatrix}F_{k+1}\\F_k\end{bmatrix}.
(47)

The matrix A has eigenvalues λ±=(1±5)/2\lambda_\pm=(1\pm\sqrt5)/2 and corresponding eigenvectors v±=(λ±,1)Tv_\pm=(\lambda_\pm,1)^T. The initial state (F1,F0)T=(1,0)T(F_1,F_0)^T=(1,0)^T equals (v+−v−)/5(v_+-v_-)/\sqrt5. Applying A k times scales these two eigenvectors by λ+k\lambda_+^k and λ−k\lambda_-^k, so the second component is:

Fk=λ+k−λ−k5.F_k=\frac{\lambda_+^k-\lambda_-^k}{\sqrt5}.
(48)

Since ∣λ−∣<1|\lambda_-|\lt1, its powers shrink to zero. For large k, Fk≈λ+k/5F_k\approx\lambda_+^k/\sqrt5. The same diagonalization shortcut applies to any recurrence representable as a fixed matrix update.

Source IDs: S30, S31, S32, S33, S35.

7. Principal component analysis (PCA)

Centering, reconstruction error, explained variance, and dual PCA.

7.1 Centering, encoding, and reconstruction

Center the samples

PCA represents each sample using fewer coordinates while keeping reconstruction error small. Let n be the sample count and d the number of features. Each original sample xᵢ is a d×1 column vector. The mean vector μ contains the average of each feature. Subtract it from every sample:

μ=1n∑i=1nxi,x~i=xi−μ,X=[x~1  ⋯  x~n]∈Rd×n.\mu=\frac1n\sum_{i=1}^n x_i,\qquad\tilde x_i=x_i-\mu,\qquad X=[\tilde x_1\;\cdots\;\tilde x_n]\in\mathbb R^{d\times n}.
(49)

The tilde marks a centered sample. In this PCA matrix X, samples are columns and features are rows. Centering moves the mean to the origin; it does not change the relative positions of samples.

Covariance records variation

A feature’s variance is its average squared deviation from its mean. A covariance is the average product of deviations of two features: positive means they tend to move together, negative means they tend to move oppositely. Put these values in a d×d covariance matrix C:

C=1nXXT=1n∑i=1nx~ix~iT,Cab=1n∑i(x~i)a(x~i)b.C=\frac1nXX^T=\frac1n\sum_{i=1}^n\tilde x_i\tilde x_i^T,\qquad C_{ab}=\frac1n\sum_i(\tilde x_i)_a(\tilde x_i)_b.
(50)

Here a and b index features; i indexes samples; (x̃ᵢ)ₐ is coordinate a of sample i. Diagonal entries are variances. The source uses 1/n throughout; some statistics texts use 1/(n−1).

Encode and reconstruct along one direction

Choose a d×1 unit vector w. The dot product gives the signed coordinate zᵢ along that direction. The reconstructed sample x̂ᵢ is the mean plus that coordinate times the direction:

zi=wTx~i∈R,x^i=μ+ziw∈Rd.z_i=w^T\tilde x_i\in\mathbb R,\qquad\hat x_i=\mu+z_iw\in\mathbb R^d.
(51)

This stores one number per sample instead of d. A hat marks a reconstruction here, and the residual xᵢ−x̂ᵢ is the lost information. PCA chooses the direction that makes these residuals small.

Use k directions

Put k orthonormal direction vectors into the columns of a d×k matrix W. “Orthonormal” means mutually perpendicular, each of length one; consequently WᵀW=Iₖ. The code zᵢ now has k entries:

zi=WTx~i∈Rk,x^i=μ+Wzi∈Rd.z_i=W^T\tilde x_i\in\mathbb R^k,\qquad\hat x_i=\mu+Wz_i\in\mathbb R^d.
(52)

Shape check: (k×d)(d×1) gives a k×1 code; (d×k)(k×1) gives a d×1 reconstruction. Storage is nk values for codes, dk for W, and d for μ, compared with nd original values. Keeping a complete basis reconstructs exactly but does not compress.

Example: follow a sample through PCA

For x₁=(1,2)ᵀ and x₂=(3,4)ᵀ, the mean is μ=(2,3)ᵀ. The centered columns are (−1,−1)ᵀ and (1,1)ᵀ. Both features have variance 1 and their covariance is 1, so C has all four entries equal to 1.

Choose w=(1,1)ᵀ/√2. Sample 2’s code is z₂=wᵀ(1,1)ᵀ=√2. Reconstruction gives μ+z₂w=(2,3)ᵀ+(1,1)ᵀ=(3,4)ᵀ. One coordinate suffices here because both samples lie on the same line through their mean.

Source IDs: S01, S02, S12.

7.2 PCA objective and derivation

PCA chooses a kk-dimensional linear subspace that makes the average squared reconstruction residual small. First consider one unit vector ww. The projection is (wTx~i)w(w^T\tilde x_i)w. The Pythagorean theorem splits the centered point into its projection and an orthogonal residual:

∥x~i∥2=∥x~i−(wTx~i)w∥2+(wTx~i)2.\|\tilde x_i\|^2=\|\tilde x_i-(w^T\tilde x_i)w\|^2+(w^T\tilde x_i)^2.
(53)

The left side does not depend on ww. Therefore, minimizing the sum of squared residual lengths is equivalent to maximizing the average squared projection coordinate. Because the centered coordinates have mean zero, this average squared coordinate is their variance.

min⁡∥w∥=11n∑i∥x~i−(wTx~i)w∥2⟺max⁡∥w∥=11n∑i(wTx~i)2=max⁡∥w∥=1wTCw.\min_{\|w\|=1}\frac1n\sum_i\|\tilde x_i-(w^T\tilde x_i)w\|^2\quad\Longleftrightarrow\quad\max_{\|w\|=1}\frac1n\sum_i(w^T\tilde x_i)^2=\max_{\|w\|=1}w^TCw.
(54)

The equality follows by expanding the scalar: (wTx~i)2=wTx~ix~iTw(w^T\tilde x_i)^2=w^T\tilde x_i\tilde x_i^Tw, and summing gives wTCww^TCw. The Rayleigh quotient theorem says the maximum over unit ww is the largest eigenvalue λ1\lambda_1 of CC; a maximizing ww is its eigenvector. For component 22, maximize wTCww^TCw while requiring wTw1=0w^Tw_1=0; then repeat with orthogonality to every earlier component. Since CC is symmetric positive semidefinite, its eigenvectors can be chosen orthonormal and eigenvalues are nonnegative.

Projected coordinates along different PCA directions have zero covariance (they are uncorrelated). This does not generally mean they are statistically independent; independence requires stronger distributional assumptions.

Principal component direction · Interactive demonstration

Why the largest eigenvalue? Express a unit direction w as a combination of C’s orthonormal eigenvectors vⱼ: w=∑jajvjw=\sum_j a_jv_j, where ∑jaj2=1\sum_j a_j^2=1. Then wTCw=∑jλjaj2w^TCw=\sum_j\lambda_j a_j^2, a weighted average of eigenvalues with nonnegative weights summing to 1. It cannot exceed the largest eigenvalue; choosing its eigenvector attains that maximum.

Source IDs: S01, S02, S12.

7.3 PCA algorithm and component selection

Procedure. For observations xi∈Rdx_i\in\mathbb R^d, compute μ\mu and centered columns x~i\tilde x_i, form C=XXT/nC=XX^T/n, and find its orthonormal eigenvectors w1,…,wdw_1,\ldots,w_d ordered by eigenvalues λ1≥⋯≥λd≥0\lambda_1\ge\cdots\ge\lambda_d\ge0. Put the first kk eigenvectors in WW. Encode each sample with zi=WT(xi−μ)z_i=W^T(x_i-\mu), then decode with x^i=μ+Wzi\hat x_i=\mu+Wz_i. These formulas also specify precisely where centering and adding the mean back occur.

The average squared reconstruction error per observation is the sum of omitted eigenvalues. The fraction of total variance retained is the cumulative eigenvalue sum divided by the full sum:

MSErecon=∑j=k+1dλj,rk=∑j=1kλj∑j=1dλj.\mathrm{MSE}_{\rm recon}=\sum_{j=k+1}^d\lambda_j,\qquad r_k=\frac{\sum_{j=1}^k\lambda_j}{\sum_{j=1}^d\lambda_j}.
(55)

Choose kk to meet a target such as 95% retained variance, or select a value that balances storage and reconstruction quality. If all eigenvalues are zero, every centered observation is zero; the ratio is undefined, but the mean reconstructs every sample exactly. If an eigenvalue is repeated, its individual eigenvectors are not unique: any orthonormal basis for that eigenspace is valid.

Numerical eigenvalue example.

Suppose λ=(9,3,1)\lambda=(9,3,1), so total variance is 1313. One component retains 9/13≈69.2%9/13\approx69.2\%; two retain 12/13≈92.3%12/13\approx92.3\%; all three retain 100%100\%. A 95%95\% threshold therefore requires k=3k=3. With k=2k=2, the omitted eigenvalue is 11, so average squared reconstruction error is 11 under the C=XXT/nC=XX^T/n convention.

An equivalent way to understand the sequence is deflation: subtract each selected projection from every sample residual. After removing the first direction, residuals are orthogonal to it; subsequent PCA directions explain the largest remaining variance. After a complete basis, no residual remains. Each selected eigenvalue is the variance captured in its direction and the decrease in average squared error when that component is added.

Source IDs: S01, S02, S12.

7.4 Dual PCA

Use a smaller eigenproblem when d is large

X is the d×n centered-data matrix. Computing all eigenvectors of the d×d covariance C can cost roughly O(d³). When d is much larger than n, instead form the Gram matrix K=XᵀX, which is n×n. Its entry Kᵢⱼ is the dot product of centered samples i and j.

Let βⱼ be a unit eigenvector of K with positive eigenvalue ρⱼ (rho). βⱼ has n entries, one coefficient for each sample; it is not yet a direction in the d-feature space:

Kβj=ρjβj,∥βj∥=1,ρj>0.K\beta_j=\rho_j\beta_j,\qquad\|\beta_j\|=1,\quad\rho_j>0.
(56)

Multiply by X to turn those n sample coefficients into a d-dimensional feature vector, then normalize its length:

wj=Xβjρj,Cwj=λjwj,λj=ρjn.w_j=\frac{X\beta_j}{\sqrt{\rho_j}},\qquad Cw_j=\lambda_jw_j,\qquad\lambda_j=\frac{\rho_j}{n}.
(57)

The normalization works because ∥Xβj∥2=βjTXTXβj=ρj\|X\beta_j\|^2=\beta_j^TX^TX\beta_j=\rho_j. The source also writes αj=βj/nλj\alpha_j=\beta_j/\sqrt{n\lambda_j}, giving wj=Xαjw_j=X\alpha_j. The nonzero eigenvalues of XXᵀ and XᵀX agree; the division by n enters only when converting to C=XXᵀ/n.

  1. Center data, then form K=XᵀX.
  2. Find the leading positive eigenpairs (ρⱼ,βⱼ) of K, with unit βⱼ.
  3. Compute wⱼ=Xβⱼ/√ρⱼ.
  4. Use these feature directions to encode and reconstruct as in ordinary PCA.

Do not divide by a zero eigenvalue: it carries no variance. Centered X has rank at most min(d,n−1), so there are at most n−1 nonzero components. The eigenproblem costs roughly O(n³); forming K costs roughly O(dn²), with additional cost to map directions.

Example: check the normalization

X=[−11−11],K=[2−2−22].X=\begin{bmatrix}-1&1\\-1&1\end{bmatrix},\qquad K=\begin{bmatrix}2&-2\\-2&2\end{bmatrix}.
(58)

The unit vector β=(−1,1)ᵀ/√2 has eigenvalue ρ=4. Then Xβ=(√2,√2)ᵀ, so w=Xβ/2=(1,1)ᵀ/√2. Its covariance eigenvalue is ρ/n=2. This small example checks the algebra; the computational benefit matters when d≫n.

Source IDs: S01, S02, S12.

8. Kernel PCA

Feature maps, valid kernels, Gram centering, and component coordinates.

8.1 Feature maps and kernels

Why map features? Ordinary PCA finds linear directions in the input coordinates. If the pattern is curved, a linear subspace can miss it. A feature map ϕ\phi sends input x∈Rdx\in\mathbb R^d to a vector ϕ(x)\phi(x) in a possibly much larger space RD\mathbb R^D. A nonlinear pattern in the original coordinates may become linear in the mapped coordinates. For example, the circle (x1−a)2+(x2−b)2=r2(x_1-a)^2+(x_2-b)^2=r^2 becomes a linear equation in features 1,x1,x2,x12,x221,x_1,x_2,x_1^2,x_2^2.

A kernel evaluates the feature-space dot product directly:

k(x,z)=ϕ(x)Tϕ(z).k(x,z)=\phi(x)^T\phi(z).
(59)

It lets us compute similarities without writing down every coordinate of ϕ\phi. This matters because DD may be large or even infinite. Kernel PCA uses these pairwise dot products in place of ordinary dot products.

Polynomial example. For x,z∈R2x,z\in\mathbb R^2, k(x,z)=(1+xTz)2k(x,z)=(1+x^Tz)^2 expands to 1+2x1z1+2x2z2+x12z12+2x1x2z1z2+x22z221+2x_1z_1+2x_2z_2+x_1^2z_1^2+2x_1x_2z_1z_2+x_2^2z_2^2. Thus one valid map is:

ϕ(x)=[12x12x2x122x1x2x22].\phi(x)=\begin{bmatrix}1\\\sqrt2x_1\\\sqrt2x_2\\x_1^2\\\sqrt2x_1x_2\\x_2^2\end{bmatrix}.
(60)

Taking its dot product with ϕ(z)\phi(z) reproduces the expansion. The 2\sqrt2 coefficients are needed to match the cross terms.

Common examples are the degree-pp polynomial kernel k(x,z)=(1+xTz)pk(x,z)=(1+x^Tz)^p for positive integer pp, and the Gaussian or RBF kernel k(x,z)=exp⁡(−∥x−z∥2/(2σ2))k(x,z)=\exp(-\|x-z\|^2/(2\sigma^2)) with σ>0\sigma>0. The RBF corresponds to an infinite-dimensional feature space. The kernel trick avoids explicit ϕ\phi, but it does not make all computations free: the n×nn\times n Gram matrix still stores pairwise training similarities.

Source IDs: S02, S03.

8.2 Kernel validity and centering

For a chosen kernel and observations x1,…,xnx_1,\ldots,x_n, define the Gram matrix K∈Rn×nK\in\mathbb R^{n\times n} by Kij=k(xi,xj)K_{ij}=k(x_i,x_j). A valid real kernel is symmetric and produces a positive semidefinite Gram matrix for every finite dataset:

K=KT,aTKa≥0for every a∈Rn.K=K^T,\qquad a^TKa\ge0\quad\text{for every }a\in\mathbb R^n.
(61)

Positive semidefinite means all eigenvalues are nonnegative. If one dataset gives a negative eigenvalue (beyond numerical rounding), that disproves validity. A successful check on just one dataset does not prove validity universally. An explicit feature map proves validity because a Gram matrix of dot products has aTKa=∥∑iaiϕ(xi)∥2≥0a^TKa=\|\sum_i a_i\phi(x_i)\|^2\ge0.

PCA requires centered features, so kernel PCA must center the mapped observations, even if raw input coordinates already have mean zero. Let 1\mathbf1 be the all-ones vector and define:

H=I−1n11T,Kc=HKH.H=I-\frac1n\mathbf1\mathbf1^T,\qquad K_c=HKH.
(62)

The centered Gram matrix represents centered feature vectors. In entry form, centering subtracts each row and column mean and adds back the grand mean:

(Kc)ij=Kij−1n∑ℓKiℓ−1n∑ℓKℓj+1n2∑ℓ,mKℓm.(K_c)_{ij}=K_{ij}-\frac1n\sum_\ell K_{i\ell}-\frac1n\sum_\ell K_{\ell j}+\frac1{n^2}\sum_{\ell,m}K_{\ell m}.
(63)

KcK_c has zero row and column means. In general, centering the original xx values does not center ϕ(x)\phi(x), because nonlinear transformations change feature means.

Example: center a 2×2 Gram matrix

If K is the 2×2 identity, each row and column mean is 1/2 and the grand mean is 1/2. Thus diagonal entries become 1−1/2−1/2+1/2=1/2, and off-diagonal entries become 0−1/2−1/2+1/2=−1/2:

Kc=[1/2−1/2−1/21/2].K_c=\begin{bmatrix}1/2&-1/2\\-1/2&1/2\end{bmatrix}.
(64)

Each centered row now sums to zero.

Source IDs: S02, S03.

8.3 Kernel PCA algorithm

Training coordinates. Build Kij=k(xi,xj)K_{ij}=k(x_i,x_j), center it to Kc=HKHK_c=HKH, and eigendecompose Kcβj=ρjβjK_c\beta_j=\rho_j\beta_j with unit βj\beta_j. Keep only positive eigenvalues. Feature covariance eigenvalues are ρj/n\rho_j/n. The corresponding unit principal direction in feature space is wj=∑iαijϕ~(xi)w_j=\sum_i\alpha_{ij}\tilde\phi(x_i), where αj=βj/ρj\alpha_j=\beta_j/\sqrt{\rho_j} and ϕ~(xi)\tilde\phi(x_i) is the centered mapped observation. Usually this direction is only conceptual; the algorithm need not form it.

zij=∑ℓ=1n(Kc)iℓαℓj=ρj βij,λj=ρjn.z_{ij}=\sum_{\ell=1}^n(K_c)_{i\ell}\alpha_{\ell j}=\sqrt{\rho_j}\,\beta_{ij},\qquad \lambda_j=\frac{\rho_j}{n}.
(65)

For training observation ii, its coordinate along component jj is the inner product ϕ~(xi)Twj\tilde\phi(x_i)^Tw_j. Replacing the inner products by entries of KcK_c gives zij=∑ℓ(Kc)iℓαℓj=ρjβijz_{ij}=\sum_\ell(K_c)_{i\ell}\alpha_{\ell j}=\sqrt{\rho_j}\beta_{ij}. Thus normalization by ρj\sqrt{\rho_j} gives unit directions, while the coordinate has scale ρj\sqrt{\rho_j}. Zero eigenvalues must be discarded because normalization is undefined and those directions contain no variance.

  1. Evaluate the chosen kernel for every training pair to form KK.
  2. Center the Gram matrix using training row means and its grand mean to obtain KcK_c.
  3. Find positive eigenpairs (ρj,βj)(\rho_j,\beta_j) of KcK_c and normalize βj\beta_j to length one.
  4. Set αj=βj/ρj\alpha_j=\beta_j/\sqrt{\rho_j} and calculate coordinates from KcαjK_c\alpha_j.
  5. Keep the leading components according to retained variance or another dimension choice.

Kernel PCA produces coordinates in feature space. It does not automatically produce a reconstruction in the original input coordinates; that inverse mapping is a separate problem.

Project a new point using the training centering

For a new xx, first compute ki(x)=k(xi,x)k_i(x)=k(x_i,x) for each training point. Center this vector with the training feature mean, using training Gram sums:

kc,i(x)=k(xi,x)−1n∑ℓKiℓ−1n∑ℓk(xℓ,x)+1n2∑ℓ,mKℓm.k_{c,i}(x)=k(x_i,x)-\frac1n\sum_\ell K_{i\ell}-\frac1n\sum_\ell k(x_\ell,x)+\frac1{n^2}\sum_{\ell,m}K_{\ell m}.
(66)

Then its coordinate is zj(x)=αjTkc(x)z_j(x)=\alpha_j^Tk_c(x). Reusing training means is important: the new point must be expressed relative to the same centered feature coordinates used to fit PCA.

Source IDs: S02, S03.

9. K-means clustering

Lloyd’s algorithm, convergence, Voronoi regions, initialization, and k selection.

9.1 K-means objective and Lloyd’s algorithm

Setup and symbols. The input is nn points xi∈Rdx_i\in\mathbb R^d and a chosen number kk of clusters. Each label zi∈{1,…,k}z_i\in\{1,\ldots,k\} says which cluster contains point ii. Each centroid μj∈Rd\mu_j\in\mathbb R^d represents cluster jj. The within-cluster sum of squared Euclidean distances is

J(z,μ)=∑i=1n∥xi−μzi∥2.J(z,\mu)=\sum_{i=1}^n\|x_i-\mu_{z_i}\|^2.
(67)

For fixed centroids, the best label for each point is its nearest centroid: zi←arg⁡min⁡j∥xi−μj∥2z_i\leftarrow\arg\min_j\|x_i-\mu_j\|^2. For fixed labels, the best centroid is the mean of points carrying that label. With indicator 1[zi=j]\mathbf1[z_i=j] equal to one when point ii belongs to cluster jj and zero otherwise, the update is

μj←∑i1[zi=j]xi∑i1[zi=j].\mu_j\leftarrow\frac{\sum_i\mathbf1[z_i=j]x_i}{\sum_i\mathbf1[z_i=j]}.
(68)

The mean minimizes squared distance because differentiating ∑i:zi=j∥xi−μ∥2\sum_{i:z_i=j}\|x_i-\mu\|^2 with respect to μ\mu and setting the gradient to zero gives μ\mu equal to the sample average. If a cluster has no points, its denominator is zero; implementations reseed that centroid, drop the empty cluster, or use another explicit rule.

  1. Choose kk initial centroids (often from observations).
  2. Assign every point to a nearest centroid.
  3. Replace each centroid by the mean of its assigned points.
  4. Repeat assignment and update until labels stop changing or the objective decrease is negligible.

One assignment and update by hand.

Take one-dimensional points 0,2,8,100,2,8,10 and two starting centroids μ1=0,μ2=8\mu_1=0,\mu_2=8. Squared distances assign 0 and 2 to cluster 1, and 8 and 10 to cluster 2 (ties absent). Before updating, the objective is 0+4+0+4=80+4+0+4=8. Their means become μ1=(0+2)/2=1\mu_1=(0+2)/2=1 and μ2=(8+10)/2=9\mu_2=(8+10)/2=9. After updating, the objective is 1+1+1+1=41+1+1+1=4. In this case another iteration leaves labels and centroids unchanged. Other initial centers can produce different intermediate assignments and local solutions.

K-means: one assignment and update step · Interactive demonstration

Source IDs: S04, S05.

9.2 Convergence and Voronoi regions

Lloyd’s algorithm alternates two exact minimization steps. With centroids fixed, nearest-centroid assignment cannot increase JJ. With labels fixed, replacing each centroid by its cluster mean cannot increase JJ. Therefore each full iteration is nonincreasing in objective:

J(zt+1,μt)≤J(zt,μt),J(zt+1,μt+1)≤J(zt+1,μt).J(z^{t+1},\mu^t)\le J(z^t,\mu^t),\qquad J(z^{t+1},\mu^{t+1})\le J(z^{t+1},\mu^t).
(69)

There are only knk^n possible label assignments. With a deterministic tie rule, a consistent empty-cluster rule, and updates that reduce the objective whenever labels change, the algorithm reaches a stable assignment in finitely many steps. The objective can stay equal in a degenerate tie. This argument establishes convergence to a fixed solution, not a global optimum; initialization can lead to different results.

The assignment boundary between centroids μa\mu_a and μb\mu_b is where squared distances are equal. A point xx assigned to aa rather than bb satisfies:

∥x−μa∥2≤∥x−μb∥2⟺2xT(μb−μa)≤∥μb∥2−∥μa∥2.\|x-\mu_a\|^2\le\|x-\mu_b\|^2\quad\Longleftrightarrow\quad 2x^T(\mu_b-\mu_a)\le\|\mu_b\|^2-\|\mu_a\|^2.
(70)

Expanding both squares cancels xTxx^Tx, leaving a linear inequality. So each pairwise boundary is a hyperplane, and the region for one centroid is the intersection of its half-spaces against all others: a convex Voronoi cell. This geometry suits compact, roughly spherical clusters; curved or nonconvex groups may be split awkwardly. Kernel k-means and spectral clustering are alternatives when such structure matters.

Source IDs: S04, S05.

9.3 K-means++ and selection of k

Random starting centroids can land close together and miss a group. Running the algorithm from several initializations and keeping the lowest objective is a practical safeguard. K-means++ spreads the initial centers: choose the first observation uniformly; for each next center, select observation xix_i with probability proportional to its squared distance D(xi)2D(x_i)^2 from the nearest center already selected.

D(xi)2=min⁡j selected∥xi−μj∥2,P(xi next)=D(xi)2∑ℓD(xℓ)2.D(x_i)^2=\min_{j\,\mathrm{selected}}\|x_i-\mu_j\|^2,\qquad P(x_i\text{ next})=\frac{D(x_i)^2}{\sum_\ell D(x_\ell)^2}.
(71)

Points far from existing centers are more likely to seed a new cluster. If every remaining distance is zero, the data already lie at selected centers, so no positive-distance choice remains. The standard k-means++ guarantee is an expected O(log⁡k)O(\log k) approximation factor for the distortion relative to optimal k-means, over its random initialization.

Choosing kk is a separate modeling decision. The distortion JJ generally decreases as kk increases and becomes zero at k=nk=n if every observation receives its own centroid. Common practical tools include using a likelihood model with a complexity penalty. For a specified likelihood model:

AIC=2p−2log⁡L(θ^),BIC=plog⁡n−2log⁡L(θ^).\mathrm{AIC}=2p-2\log L(\hat\theta),\qquad \mathrm{BIC}=p\log n-2\log L(\hat\theta).
(72)

Here pp is the number of fitted free parameters, nn is the sample count, and L(θ^)L(\hat\theta) is the maximized likelihood. Lower values are preferred within the same candidate-model comparison. These criteria are not direct universal penalties for raw k-means distortion: a probability model and its parameter count must be specified.

Source IDs: S04, S05.

10. MLE and Bayesian estimation

Likelihood, Bernoulli and Gaussian MLE, Beta posterior, and MAP.

10.1 Likelihood and i.i.d. observations

What is being estimated?

Suppose a coin has an unknown head probability. The outcomes are observed data; the probability is an unknown parameter. Estimation chooses parameter values that explain the observations under an assumed probabilistic model.

Write D for the dataset, n for its size, xᵢ for observation i, and θ (theta) for the unknown parameter or collection of parameters. Unlike earlier vector-valued house inputs, a coin observation xᵢ is a scalar: 1 for heads or 0 for tails. A symbol’s shape depends on the stated model.

The i.i.d. assumption

  • Independent: knowing other outcomes does not change an outcome’s probability. This lets us multiply probabilities.
  • Identically distributed: all observations use the same distribution and parameter. Every toss uses the same head probability.
L(θ;D)=∏i=1np(xi∣θ).L(\theta;D)=\prod_{i=1}^{n}p(x_i\mid\theta).
(73)

L is the likelihood. The product symbol ∏ means multiply the n terms. The vertical bar in p(xᵢ|θ) means “given parameter θ.” To evaluate likelihood, keep the observations fixed and try different θ values. It is not a probability distribution over θ and need not sum or integrate to one over θ.

Three fixed coin outcomes: heads, heads, tails

For head probability p, likelihood = p×p×(1−p). At p=0.5 it is 0.125; at p=0.8 it is 0.128. Maximum likelihood searches the allowed parameter values for the largest likelihood.

Why take logarithms?

ℓ(θ)=log⁡L(θ)=∑i=1nlog⁡p(xi∣θ),θ^ML=arg⁡max⁡θℓ(θ).\ell(\theta)=\log L(\theta)=\sum_{i=1}^n\log p(x_i\mid\theta),\qquad\hat\theta_{ML}=\arg\max_\theta\ell(\theta).
(74)

Log turns products into sums and is strictly increasing, so the maximizing parameter stays the same. A hat on θ means an estimate; ML means maximum likelihood. “argmax” returns the parameter giving the largest value, rather than the largest value itself. With continuous observations, use densities in these likelihood formulas.

Source IDs: S07, S13.

10.2 Bernoulli and Gaussian MLE

Bernoulli model: estimate a coin bias

A Bernoulli random variable has two possible outcomes: x=1 with probability p and x=0 with probability 1−p. Here p is a scalar between 0 and 1. For n observations, let h be the number of heads and t=n−h the number of tails.

p(xi∣p)=pxi(1−p)1−xi,L(p)=ph(1−p)t,ℓ(p)=hlog⁡p+tlog⁡(1−p).p(x_i\mid p)=p^{x_i}(1-p)^{1-x_i},\quad L(p)=p^h(1-p)^t,\quad\ell(p)=h\log p+t\log(1-p).
(75)

If xᵢ=1, the first expression becomes p; if xᵢ=0 it becomes 1−p. Each head therefore contributes one factor p and each tail one factor 1−p.

  1. For both h>0 and t>0, differentiate the log-likelihood.
  2. Set the derivative equal to zero and solve.
  3. Check boundaries when all outcomes are the same.
ℓ′(p)=hp−t1−p=0⇒h(1−p)=tp⇒p^ML=hn.\ell'(p)=\frac hp-\frac t{1-p}=0\Rightarrow h(1-p)=tp\Rightarrow\hat p_{ML}=\frac hn.
(76)

The second derivative is negative for an interior solution, confirming a maximum. If h=0, the maximum is p=0; if t=0, it is p=1.

Example

Nine heads and three tails give n=12 and p^=9/12=0.75\hat p=9/12=0.75. This estimates the head probability; it does not claim that exactly 75% of every future set of tosses must be heads.

Gaussian model: estimate the mean

A Gaussian (normal) model describes a bell-shaped distribution. The scalar μ (mu) is its center, σ (sigma) is its positive standard deviation, and σ² is its variance, measuring squared spread.

p(x∣μ,σ2)=12πσexp⁡(−(x−μ)22σ2).p(x\mid\mu,\sigma^2)=\frac1{\sqrt{2\pi}\sigma}\exp\left(-\frac{(x-\mu)^2}{2\sigma^2}\right).
(77)

Here exp(a) means eᵃ; π in this density is the mathematical constant. For known positive variance, terms independent of μ can be grouped into a constant:

ℓ(μ)=constant−12σ2∑i(xi−μ)2.\ell(\mu)=\text{constant}-\frac1{2\sigma^2}\sum_i(x_i-\mu)^2.
(78)

Maximizing this expression means minimizing squared deviations. Differentiating gives ∑i(xi−μ)=0\sum_i(x_i-\mu)=0, hence:

μ^ML=xˉ=1n∑ixi.\hat\mu_{ML}=\bar x=\frac1n\sum_i x_i.
(79)

Example

For observations 2, 4, 6, the estimated mean is (2+4+6)/3=4. If the variance is also fitted, its MLE is the average squared deviation:

σ^ML2=1n∑i(xi−xˉ)2=4+0+43=83.\hat\sigma^2_{ML}=\frac1n\sum_i(x_i-\bar x)^2=\frac{4+0+4}{3}=\frac83.
(80)

The MLE denominator is n. The n−1 denominator belongs to the unbiased sample-variance estimator, a different objective.

Source IDs: S07, S13.

10.3 Beta-Bernoulli posterior and MAP

Prior and posterior

MLE fits parameters using likelihood alone. Bayesian estimation also represents uncertainty about the parameter before seeing the current data. A prior is that initial distribution; the posterior is the distribution after updating with data.

Let θ be the parameter and D the observed dataset. Bayes’ rule combines the likelihood and prior:

p(θ∣D)=p(D∣θ)p(θ)p(D),p(D)=∫p(D∣θ)p(θ) dθ.p(\theta\mid D)=\frac{p(D\mid\theta)p(\theta)}{p(D)},\qquad p(D)=\int p(D\mid\theta)p(\theta)\,d\theta.
(81)
  • p(θ): prior density over parameter values.
  • p(D|θ): likelihood of the observed data at a candidate parameter.
  • p(θ|D): posterior density over the parameter after observing D.
  • p(D): evidence, a normalizing constant that does not vary with θ.

The shorthand p(θ∣D)∝p(D∣θ)p(θ)p(\theta\mid D)\propto p(D\mid\theta)p(\theta) means “proportional to”: the two sides differ by a constant independent of θ.

Beta prior for a Bernoulli probability

A coin probability p lies between 0 and 1. A Beta distribution is a family of possible prior shapes on that interval. Its positive shape parameters α (alpha) and β (beta) describe the prior; they are distinct from p itself.

p∼Beta⁡(α,β),p(p)=1B(α,β)pα−1(1−p)β−1.p\sim\operatorname{Beta}(\alpha,\beta),\qquad p(p)=\frac1{B(\alpha,\beta)}p^{\alpha-1}(1-p)^{\beta-1}.
(82)

The symbol ∼ means “is distributed as.” B(α,β) is the constant making the density integrate to one. Beta(1,1) is uniform; increasing both shapes makes the distribution more concentrated. Prior mean is α/(α+β).

Update after h heads and t tails

Multiply the Bernoulli likelihood by the Beta prior, then combine exponents:

p(p∣D)∝ph(1−p)t pα−1(1−p)β−1=pα+h−1(1−p)β+t−1.p(p\mid D)\propto p^h(1-p)^t\,p^{\alpha-1}(1-p)^{\beta-1}=p^{\alpha+h-1}(1-p)^{\beta+t-1}.
(83)

This is another Beta density:

p∣D∼Beta⁡(α+h,β+t).p\mid D\sim\operatorname{Beta}(\alpha+h,\beta+t).
(84)

A prior is conjugate when this update keeps the same distribution family. Here heads increase the first shape and tails increase the second.

Turn the posterior into a point estimate

E[p∣D]=α+hα+β+n,p^MAP=α+h−1α+β+n−2.E[p\mid D]=\frac{\alpha+h}{\alpha+\beta+n},\qquad\hat p_{MAP}=\frac{\alpha+h-1}{\alpha+\beta+n-2}.
(85)

E denotes an expected value, or probability-weighted average. MAP means maximum a posteriori: the mode (peak) of the posterior, not its mean. The displayed interior MAP formula requires α+h>1 and β+t>1; otherwise check boundary modes or a nonunique mode.

Example

Prior Beta(2,2), then 3 heads and 1 tail: posterior Beta(5,3). Posterior mean = 5/8 = 0.625; MAP = 4/6 ≈ 0.667; MLE = 3/4 = 0.75. They differ because they summarize the information differently.

Beta-Binomial posterior · Interactive demonstration

Source IDs: S07, S13.

10.4 MLE, MAP, and posterior mean

Method What it uses Result
MLE Likelihood only Parameter maximizing observed-data likelihood
MAP Likelihood × prior Mode of posterior
Posterior mean Whole posterior Average parameter under posterior
Bayesian posterior Likelihood, prior, normalization Distribution describing remaining uncertainty

MAP maximizes log⁡p(D∣θ)+log⁡p(θ)\log p(D\mid\theta)+\log p(\theta). A uniform prior makes MAP maximizers agree with likelihood maximizers where the prior is constant and nonzero. A fixed Beta prior has less relative influence as n increases.

For the coin, the posterior mean is a weighted average of the prior mean and observed head fraction:

α+βα+β+nαα+β+nα+β+nhn.\frac{\alpha+\beta}{\alpha+\beta+n}\frac\alpha{\alpha+\beta}+\frac n{\alpha+\beta+n}\frac hn.
(86)

How much does the prior contribute?

In the weighted-mean formula above, α+β is the prior strength and n is the observation count. The two weights sum to 1. With α=β=2 and h=3 out of n=4, prior mean is 0.5 and observed head fraction is 0.75. Their weights are 4/8 each, giving 0.5(0.5)+0.5(0.75)=0.625. For fixed α and β, more data give the observations a larger weight.

What to report: MLE and MAP each return a parameter value. A Bayesian posterior is a whole distribution; it retains uncertainty. A posterior mean is one numerical summary of that distribution.

Source IDs: S07, S13.

11. Gaussian mixture models and EM

Mixture likelihood, Jensen’s inequality, responsibilities, and parameter updates.

11.1 Gaussian mixture model

Why use a mixture?

A single Gaussian has one center and one spread. Data with several separated groups may require several Gaussian components. A mixture adds their densities with nonnegative weights.

The source develops a univariate model: each observation xᵢ is one real number. n is the number of observations; k is the number of Gaussian components; i indexes observations and j indexes components. Each component j has a mean μⱼ, positive variance σⱼ², and weight πⱼ.

Symbol Meaning
zi∈{1,…,k}z_i\in\{1,\ldots,k\} Hidden component that generated observation i
πj\pi_j Probability of choosing component j, before seeing an observation
μj,σj2\mu_j,\sigma_j^2 Center and squared spread of Gaussian component j
θ\theta All fitted mixture weights, means, and variances together

Generative process

  1. Choose zᵢ=j with probability πⱼ. The weights satisfy πj≥0\pi_j\ge0 and ∑jπj=1\sum_j\pi_j=1.
  2. Given that component, draw xi∼N(μj,σj2)x_i\sim\mathcal N(\mu_j,\sigma_j^2).

We observe xᵢ but not zᵢ. This makes z a latent variable. To get the density for x, add the weighted contributions of all possible hidden components:

p(x∣θ)=∑j=1kπjN(x∣μj,σj2),N(x∣μ,σ2)=e−(x−μ)2/(2σ2)2πσ.p(x\mid\theta)=\sum_{j=1}^{k}\pi_j\mathcal N(x\mid\mu_j,\sigma_j^2),\quad\mathcal N(x\mid\mu,\sigma^2)=\frac{e^{-(x-\mu)^2/(2\sigma^2)}}{\sqrt{2\pi}\sigma}.
(87)

In πⱼ, π denotes a learned mixture weight; in √(2π), π is the mathematical constant. Subscripts distinguish the two uses.

Example of the mixture sum

At some x, suppose the two component densities are 0.1 and 0.4, with weights 0.25 and 0.75. The total density is 0.25(0.1)+0.75(0.4)=0.325. It is a density value, not a component assignment.

Likelihood and parameter count

L(θ)=∏i[∑jπjN(xi∣μj,σj2)],ℓ(θ)=∑ilog⁡[∑jπjN(xi∣μj,σj2)].L(\theta)=\prod_i\left[\sum_j\pi_j\mathcal N(x_i\mid\mu_j,\sigma_j^2)\right],\quad\ell(\theta)=\sum_i\log\left[\sum_j\pi_j\mathcal N(x_i\mid\mu_j,\sigma_j^2)\right].
(88)

The log of the component sum prevents the simple closed-form fit used for a single Gaussian. EM handles this by alternating between estimates of the hidden assignments and parameter updates.

There are k means, k variances, and k−1 independent weights because the weights sum to 1: 3k−1 free parameters.

Source IDs: S06, S07, S05.

11.2 Jensen’s inequality and EM lower bound

Convexity, concavity, and Jensen’s inequality

A convex function lies below the straight chord joining two graph points; for a concave function the inequality reverses. Let qⱼ be nonnegative weights that sum to 1, and aⱼ be values in the function’s domain:

f ⁣(∑jqjaj)≤∑jqjf(aj)for convex f.f\!\left(\sum_jq_ja_j\right)\le\sum_jq_jf(a_j)\quad\text{for convex }f.
(89)

For concave f, replace ≤ by ≥. The logarithm is concave because its second derivative is negative on positive inputs.

For the mixture, write positive component contributions as aⱼ. Introduce weights qⱼ and apply Jensen to aⱼ/qⱼ:

log⁡∑jaj=log⁡∑jqjajqj≥∑jqjlog⁡ajqj.\log\sum_j a_j=\log\sum_jq_j\frac{a_j}{q_j}\ge\sum_jq_j\log\frac{a_j}{q_j}.
(90)

The right side is a lower bound: it never exceeds the original log-sum. For positive terms, equality holds when all aⱼ/qⱼ are the same, which occurs at qj=aj/∑ℓaℓq_j=a_j/\sum_\ell a_\ell.

Apply the bound to every observation

For observation i and component j, choose weights qᵢⱼ with ∑jqij=1\sum_jq_{ij}=1. Use aij=πjN(xi∣μj,σj2)a_{ij}=\pi_j\mathcal N(x_i\mid\mu_j,\sigma_j^2):

ℓ(θ)≥F(q,θ)=∑i=1n∑j=1kqijlog⁡πjN(xi∣μj,σj2)qij.\ell(\theta)\ge\mathcal F(q,\theta)=\sum_{i=1}^n\sum_{j=1}^kq_{ij}\log\frac{\pi_j\mathcal N(x_i\mid\mu_j,\sigma_j^2)}{q_{ij}}.
(91)

F is the bound, depending on both auxiliary weights q and model parameters θ. Zero-weight terms are interpreted by a limit. The auxiliary weights are not the global mixture weights π: there is a separate row of q values for each observation.

Why alternating helps

  1. Fix θ and choose q to make the bound touch the current likelihood. These q values become the posterior responsibilities.
  2. Fix q and maximize the bound over θ. The log-sum has become a weighted sum of log terms, so the Gaussian parameters can be updated.
  3. Repeat. Tightening the bound is the E-step; updating the model is the M-step.

Source IDs: S06, S07, S05.

11.3 E-step and M-step

E-step: estimate the hidden assignments

A responsibility rᵢⱼ is the probability that component j generated observed point xᵢ, using the current model. It is a scalar between 0 and 1. For every fixed observation i, its k responsibilities sum to 1.

rij=P(zi=j∣xi,θ)=πjN(xi∣μj,σj2)∑ℓ=1kπℓN(xi∣μℓ,σℓ2).r_{ij}=P(z_i=j\mid x_i,\theta)=\frac{\pi_j\mathcal N(x_i\mid\mu_j,\sigma_j^2)}{\sum_{\ell=1}^{k}\pi_\ell\mathcal N(x_i\mid\mu_\ell,\sigma_\ell^2)}.
(92)

The numerator is component j’s weighted density contribution. The denominator adds the contributions of all components for this same point. The index ℓ is a temporary component index in that sum; it plays the same counting role as j.

Example of an E-step

Suppose a point receives weighted contributions 0.02 and 0.08 from two components. Its responsibilities are 0.02/0.10=0.2 and 0.08/0.10=0.8. It belongs partly to both components; EM does not force an immediate hard label.

M-step: fit using fractional memberships

Define Nⱼ as the effective size of component j: add its responsibilities across all n observations. It can be fractional. Use this same E-step responsibility table for all updates below:

Nj=∑i=1nrij,πjnew=Njn,μjnew=∑irijxiNj.N_j=\sum_{i=1}^{n}r_{ij},\qquad\pi_j^{new}=\frac{N_j}{n},\qquad\mu_j^{new}=\frac{\sum_i r_{ij}x_i}{N_j}.
(93)
(σj2)new=∑irij(xi−μjnew)2Nj.(\sigma_j^2)^{new}=\frac{\sum_i r_{ij}(x_i-\mu_j^{new})^2}{N_j}.
(94)
  • Weight: effective component size divided by total sample count.
  • Mean: weighted average of observations.
  • Variance: weighted average squared distance from the new mean.

The mixture weights still sum to 1 because the responsibility rows sum to 1. In contrast, the sum of responsibilities down one component’s column is Nⱼ, not generally 1.

Complete M-step example

Observations are x=(0,2). Responsibilities for component 1 are (0.8,0.2), and for component 2 are (0.2,0.8).

  1. Effective sizes: N₁=N₂=1, so both mixture weights become 1/2.
  2. Means: μ₁=(0.8×0+0.2×2)/1=0.4; μ₂=(0.2×0+0.8×2)/1=1.6.
  3. Component 1 variance: 0.8(0−0.4)²+0.2(2−0.4)²=0.64. Component 2 also has variance 0.64.

Only after completing this M-step do we recompute responsibilities from the new model.

Gaussian mixture: responsibility · Interactive demonstration

Source IDs: S06, S07, S05.

11.4 EM convergence and comparison with k-means

Run EM

  1. Initialize mixture weights summing to 1, component means, and positive variances.
  2. E-step: compute responsibilities from the current parameters.
  3. M-step: update weights, means, and variances using those responsibilities.
  4. Evaluate log-likelihood and repeat until the increase is small.

Why likelihood does not decrease

The superscript t below counts iterations. qᵗ is the E-step responsibility table computed using θᵗ. The bound touches the likelihood at θᵗ; the M-step improves that bound; the new likelihood is at least as large as the new bound:

Likelihood improvement:

ℓ(θt+1)≥F(qt,θt+1)≥F(qt,θt)=ℓ(θt).\ell(\theta^{t+1})\ge\mathcal F(q^t,\theta^{t+1})\ge\mathcal F(q^t,\theta^t)=\ell(\theta^t).
(95)

Log-likelihood is nondecreasing. Stop when likelihood improvement or parameter change is small. Result depends on initialization; no global-optimum guarantee.

k-means GMM / EM
One hard label per point Soft posterior probabilities
Uses nearest centroid Uses weights, means, and variances
Minimizes squared distortion Maximizes mixture log-likelihood
Convex Voronoi cells in input space Can express unequal spread and curved boundaries

Conditions

Convergence qualification. Unconstrained GMM likelihood can become unbounded when a variance collapses around one observation. Nondecreasing likelihood alone does not ensure a finite maximum. Practical implementations impose a variance floor and handle components with negligible effective size. The example below uses a variance floor.

Equality is possible at a fixed point. A component with Nⱼ=0 cannot use the displayed mean/variance update because it would divide by zero; reinitialize or remove such a component. Initialization and variance safeguards affect the practical result.

Source IDs: S06, S07, S05.

Quiz 1 source questions: ML Techniques

The following 21 questions are transcribed from the supplied MLT_Mock_Quiz_1.md file embedded in the study site. The original question type, options, and available worked explanations are retained.

ML Techniques Quiz 1 browser · Interactive demonstration

ML Techniques Q1

Consider the following kernel:

k:R2×R2→Rk(x,y)=(xTy)2\begin{aligned} k: R^2 \times R^2 \rightarrow R\\ k(x, y) = (x^Ty)^2 \end{aligned}
(96)

Which of the following transformation mapping ϕ\phi may correspond to the kernel kk?

  • A. ϕ([x1,x2]T)=[x1,x1x2,x2]T\phi([x_1, x_2]^T) = [x_1, x_1x_2, x_2]^T
  • B. ϕ([x1,x2]T)=[x12,x1+x2,x22]T\phi([x_1, x_2]^T) = [x_1^2, x_1+x_2, x_2^2]^T
  • C. ϕ([x1,x2]T)=[x1,2x12x22,x2]T\phi([x_1, x_2]^T) = [x_1, \sqrt{2}x_1^2x_2^2, x_2]^T
  • D. ϕ([x1,x2]T)=[x12,2x1x2,x22]T\phi([x_1, x_2]^T) = [x_1^2, \sqrt{2}x_1x_2, x_2^2]^T

Answer and worked solution

Answer: D

  1. Expand the required kernel: (xTy)2=(x1y1+x2y2)2=x12y12+2x1x2y1y2+x22y22(x^Ty)^2=(x_1y_1+x_2y_2)^2=x_1^2y_1^2+2x_1x_2y_1y_2+x_2^2y_2^2.
  2. Option D has ϕ(x)=(x12,2x1x2,x22)T\phi(x)=(x_1^2,\sqrt2x_1x_2,x_2^2)^T. Its dot product with φ(y) gives exactly those three terms.
  3. The √2 factor is necessary: multiplying the two middle features produces coefficient 2. The other maps produce different terms.

ML Techniques Q2

A function kk is defined as

k:R×R→Rk(x1,x2)=x1x2+x12x22+x13x2+1\begin{aligned}k: \mathbb{R} \times \mathbb{R} \rightarrow \mathbb{R}\\ k(x_1, x_2) = x_1x_2 +x_1^2x_2^2+x_1^3x_2+1\end{aligned}
(97)

Is kk a valid kernel?

  • A. Yes
  • B. No

Answer and worked solution

Answer: B: No

  1. A real kernel must be symmetric: k(a,b)=k(b,a) for every pair.
  2. Here k(1,2)=2+4+2+1=9k(1,2)=2+4+2+1=9, while k(2,1)=2+4+8+1=15k(2,1)=2+4+8+1=15.
  3. The asymmetric x₁³x₂ term breaks this requirement; no PSD test is needed after symmetry fails.

ML Techniques Q3

Let XX be a data matrix of shape (d,n)(d, n) for a centered dataset. The first principal component of the dataset is [12,32]T\left[\dfrac{1}{2}, \dfrac{\sqrt{3}}{2}\right]^T. What will the scalar proxy of the point [1,2]T[1, 2]^T be on the first principal component?

  • A. 1+231+2\sqrt{3}
  • B. 1+232\dfrac{1+2\sqrt{3}}{2}
  • C. 1+234\dfrac{1+2\sqrt{3}}{4}
  • D. 1+235\dfrac{1+2\sqrt{3}}{\sqrt{5}}

Answer and worked solution

Answer: B: 1+232\frac{1+2\sqrt3}{2}

  1. A scalar proxy is the coordinate along the unit principal direction: z=wᵀx.
  2. The direction has unit norm since (1/2)2+(3/2)2=1(1/2)^2+(\sqrt3/2)^2=1.
  3. z=(1/2)(1)+(3/2)(2)=1/2+3=(1+23)/2z=(1/2)(1)+(\sqrt3/2)(2)=1/2+\sqrt3=(1+2\sqrt3)/2. This is one number, not the reconstructed vector zw.

ML Techniques Q4

Consider the following data set:

{x1=[02],x2=[20],x3=[00],x4=[0−2],x5=[−20],x6=[01],x7=[0−1]}\left\{ x_1 = \begin{bmatrix} 0 \\ 2 \end{bmatrix}, x_2 = \begin{bmatrix} 2 \\ 0 \end{bmatrix}, x_3 = \begin{bmatrix} 0 \\ 0 \end{bmatrix}, x_4 = \begin{bmatrix} 0 \\ -2 \end{bmatrix}, x_5 = \begin{bmatrix} -2 \\ 0 \end{bmatrix}, x_6 = \begin{bmatrix} 0 \\ 1 \end{bmatrix}, x_7 = \begin{bmatrix} 0 \\ -1 \end{bmatrix} \right\}

For k=3k = 3, assume that the following cluster assignment is given to us which shows the clusters assigned to all data points but x3x_3 : z={1,2,?,3,2,1,3}z = \{1, 2, \textbf{?}, 3, 2, 1, 3\}

What should be the cluster assigned to the data point x3x_3?

  • A. 1
  • B. 2
  • C. 3

Answer and worked solution

Answer: B: Cluster 2

  1. Use the six already assigned points to compute centroids: cluster 1 contains (0,2),(0,1); cluster 2 contains (2,0),(−2,0); cluster 3 contains (0,−2),(0,−1).
  2. Their means are (0,1.5), (0,0), and (0,−1.5).
  3. For x₃=(0,0), squared distances are 2.25, 0, 2.25. The smallest is for cluster 2.

ML Techniques Q5

Consider the scenario where you observe that 8 of your friends {f1,...,f8f_1 , . . . , f_8} have scored the following marks in a quiz: {6, 3, −5, −4, 2, −3, 5, −2} respectively.

Which of the cluster initializations given below will result in clusters where your friends with positive marks are in one cluster and the rest are in another after executing one step of the Lloyd’s algorithm?

I1:z1=z2=z3=z4=z5=z6=z7=2 and z8=1I_1: z_1= z_2 = z_3 = z_4 = z_5 = z_6 = z_7 = 2~\text{and}~ z_8 = 1 I2:z1=1,z2=z3=z4=z5=z6=z7=z8=2I_2: z_1 = 1, z_2= z_3 = z_4 = z_5 = z_6 = z_7 = z_8 = 2

  • A. I1I_1: No, I2I_2: No
  • B. I1I_1: Yes, I2I_2: Yes
  • C. I1I_1: Yes, I2I_2: No
  • D. I1I_1: No, I2I_2: Yes
  • E. Insufficient Information

Answer and worked solution

Answer: C: I₁: Yes; I₂: No

  1. The marks sum to 2. Under I₁, μ₁=−2 and μ2=4/7\mu_2=4/7. The nearest-center boundary is their midpoint (−2+4/7)/2=−5/7(-2+4/7)/2=-5/7. All negative marks lie left of it and all positive marks right.
  2. Under I₂, μ₁=6 and μ2=(2−6)/7=−4/7\mu_2=(2-6)/7=-4/7. The boundary is (6−4/7)/2=19/7≈2.714(6-4/7)/2=19/7\approx2.714.
  3. The positive mark 2 falls on the same side as the negatives under I₂. One Lloyd step here means compute the means from the initial labels, then reassign.

ML Techniques Q6

Consider the data points shown in the following image:

Consider that in the initialization step of K-means with k=2k = 2, the data points x1x_1 and x6x_6 got selected as initial cluster centers. That is, μ10=(0,0)\mu_1^0 = (0, 0) and μ20=(3,0)\mu_2^0 = (3,0). As per these cluster centers, the data points were then assigned to either cluster 1 or cluster 2. After this assignment, what will be the value of the objective function (ObjObj)? Further, as per the assignment of data points, the cluster centers will be re-computed for the next iteration. What will be the value of μ11\mu_1^1 and μ21\mu_2^1?

  • A. Obj=17Obj = 17, μ11=(1,0)\mu_1^1 = (1, 0), μ21=(3.33,0)\mu_2^1 = (3.33, 0)
  • B. Obj=17Obj = 17, μ11=(1,0)\mu_1^1 = (1,0), μ21=(3,0)\mu_2^1 = (3, 0)
  • C. Obj=7Obj = 7, μ11=(0,0)\mu_1^1 = (0, 0), μ21=(3.33,0)\mu_2^1 = (3.33, 0)
  • D. Obj=7Obj = 7, μ11=(0,0)\mu_1^1 = (0, 0), μ21=(3.25,0)\mu_2^1 = (3.25, 0)

Answer and worked solution

Answer: D: Obj=7; new centers (0,0), (3.25,0)

  1. With initial centers (0,0) and (3,0), the five points around the origin join cluster 1; (3,0),(3,1),(3,−1),(4,0) join cluster 2.
  2. Using the initial centers, squared distances sum to 0+1+1+1+1=4 in cluster 1, and 0+1+1+1=3 in cluster 2. Obj=7.
  3. New means: the first cluster sums to (0,0). The second sums to (13,0), so its mean is (13/4,0)=(3.25,0)(13/4,0)=(3.25,0). Do not recompute the requested objective using the new means.

ML Techniques Q7

In the context of EM algorithm, select all true statements from the options given below. There are nn data-points and KK mixtures. The index ii corresponds to the ithi^{th} data-point, the index kk corresponds to the kthk^{th} mixture. ff is the density of a Gaussian. All other symbols have their usual meaning.

  • A. πk=P(zi=k)\pi_k = P(z_i = k)
  • B. ∑i=1nλki=1\sum \limits_{i = 1}^{n} \lambda^{i}_k = 1
  • C. λki=P(zi=k ∣ xi)\lambda_k^{i} = P(z_i = k\ |\ x_i)
  • D. λki=f(xi∣ zi=k)\lambda_k^{i} = f(x_i |\ z_i = k)

Answer and worked solution

Answer: A and C

  1. πₖ=P(zᵢ=k) is the global prior probability of component k. Thus A is true.
  2. λₖⁱ=P(zᵢ=k|xᵢ) is the responsibility after observing xᵢ. Thus C is true.
  3. For each fixed i, ∑kλki=1\sum_k\lambda_k^i=1, not generally ∑iλki=1\sum_i\lambda_k^i=1. The latter is the effective component size Nₖ, so B is false. D is a Gaussian likelihood, not the normalized component posterior.

ML Techniques Q8

Consider a centered dataset of 100100 points in R5\large \mathbb{R}^{5}. Standard PCA is performed on this dataset. Consider the following ratio: θ=variance along the first principal componentsum of variances along all five principal components\theta = \cfrac{\text{variance along the first principal component}}{\text{sum of variances along all five principal components}}

What is the minimum value of θ\theta?

Answer and worked solution

Answer: 0.2

  1. Let the five ordered covariance eigenvalues be λ₁≥…≥λ₅≥0. Their sum is total variance, and θ=λ1/∑jλj\theta=\lambda_1/\sum_j\lambda_j.
  2. Since every eigenvalue is at most λ₁, ∑jλj≤5λ1\sum_j\lambda_j\le5\lambda_1, hence θ≥1/5.
  3. Equality is attained when all five eigenvalues are equal and positive. If total variance is zero, the ratio is undefined.

ML Techniques Q9

Consider a centered dataset of 10001000 points in R10\mathbb{R}^{10}. Standard PCA is performed on this dataset. What is the maximum number of principal components that can be retained so that the compression ratio does not fall below 1.41.4 ? The compression ratio is defined as: size of original datasetsize of reconstructed dataset\cfrac{\text{size of original dataset}}{\text{size of reconstructed dataset}}

Assume that each real number occupies one unit of storage space. Note that we are interested in the reconstructions and not just in the scalar projections. So, the reconstructed dataset will also be in R10\mathbb{R}^{10}.

Answer and worked solution

Answer: 7 components (scores + basis storage)

  1. Original storage is nd=1000×10=10000 numbers. With m components, retain nm scores plus dm basis entries: 1010m numbers. Data are centered, so the mean need not add storage here.
  2. Require 10000/(1010m)≥1.410000/(1010m)\ge1.4, giving m≤7.072m\le7.072. Therefore the largest integer m is 7.
  3. At m=7 the ratio is about 1.414; at m=8 it is about 1.238. If “reconstructed dataset” literally means all 1000 reconstructed 10D vectors stored explicitly, storage is still 10000 and the ratio is 1. The answer 7 uses the compressed representation needed for reconstruction.

ML Techniques Q10

Consider the dataset as shown in the figure. We want to project the dataset into another feature space so that it lives in a linear subspace of a higher-dimension space. We apply the kernel PCA with a polynomial kernel of the appropriate degree to achieve the same. What will be the dimension of transformed feature space?

Answer and worked solution

Answer: Uploaded answer: 3; kernel specification is needed

  1. The plotted samples follow a parabola. A chosen map ϕ(x)=(x1,x2,x12)T\phi(x)=(x_1,x_2,x_1^2)^T has three coordinates; the relation x2≈ax12+bx1+cx_2\approx ax_1^2+bx_1+c becomes planar in these coordinates (a linear subspace after centering the ideal affine relation). This explains the uploaded answer 3.
  2. But this chosen map is not the full feature map of the standard inhomogeneous quadratic kernel (1+xTy)2(1+x^Ty)^2. For 2D inputs that kernel has six features: 1,2x1,2x2,x12,2x1x2,x221,\sqrt2x_1,\sqrt2x_2,x_1^2,\sqrt2x_1x_2,x_2^2.
  3. The question does not specify the polynomial kernel or whether it asks for a selected map, full feature-space dimension, or effective rank. A unique numerical answer cannot be justified as written. This question is review-only rather than automatically scored.

ML Techniques Q11

Consider a dataset with 6060 points in which all points are either 00 or 11. We use a Bernoulli distribution with parameter pp to model this problem. The prior and posterior distributions for the parameter pp are Beta(10,5)\text{Beta}(10, 5) and Beta(30,45)\text{Beta}(30, 45) respectively. How many data-points have the value 00 in this dataset? Note that p=P(x=1)p = P(x = 1) as usual.

Answer and worked solution

Answer: 40 zeros

  1. For Bernoulli data with p=P(x=1), Beta(α,β) updates to Beta(α+ones, β+zeros).
  2. Ones=30−10=20; zeros=45−5=40.
  3. Check: 20+40=60 observations, matching the stated dataset size.

ML Techniques Q12

A GMM is fit for a dataset with 55 points. At some time-step in the EM algorithm, the following are the values of λki\lambda_k^{i} for all points in the dataset for the kthk^{th} mixture after the E-step:

λk1=0.9λk2=0.8λk3=0.7λk4=0.6λk5=0.5\begin{aligned}\lambda_k^{1} = 0.9\\ \lambda_k^{2} = 0.8\\ \lambda_k^{3} = 0.7\\ \lambda_k^{4} = 0.6\\ \lambda_k^{5} = 0.5\end{aligned}
(98)

What is the estimate of πk\pi_k after the M-step?

Answer and worked solution

Answer: 0.7

  1. Effective component size: Nk=∑iλki=0.9+0.8+0.7+0.6+0.5=3.5N_k=\sum_i\lambda_k^i=0.9+0.8+0.7+0.6+0.5=3.5.
  2. The M-step weight is πk=Nk/n=3.5/5=0.7\pi_k=N_k/n=3.5/5=0.7.
  3. Do not normalize this column to sum to 1: responsibilities sum to 1 across components for each individual point.

ML Techniques Q13

Is this dataset centered?

Four points in R2\mathbb{R}^2 lie on a line through the origin:

D={(−2,−6),(−1,−3),(1,3),(2,6)}.D=\{(-2,-6),(-1,-3),(1,3),(2,6)\}.
(99)
  • A. Yes
  • B. No

Answer and worked solution

Answer: A: Yes

  1. Add coordinates separately: x-coordinates −2−1+1+2=0; y-coordinates −6−3+3+6=0.
  2. Divide by four points: mean=(0,0). A dataset is centered when its sample mean is zero.

ML Techniques Q14

Choose all representatives w\mathbf{w} for this dataset such that ∣∣w∣∣=1||\mathbf{w}|| = 1.

Four points in R2\mathbb{R}^2 lie on a line through the origin:

D={(−2,−6),(−1,−3),(1,3),(2,6)}.D=\{(-2,-6),(-1,-3),(1,3),(2,6)\}.
(100)
  • A. 110⋅[13]\cfrac{1}{\sqrt{10}} \cdot \begin{bmatrix} 1\\ 3 \end{bmatrix}
  • B. 110⋅[−1−3]\cfrac{1}{\sqrt{10}} \cdot \begin{bmatrix} -1\\ -3 \end{bmatrix}
  • C. [−1−3]\begin{bmatrix} -1\\ -3 \end{bmatrix}
  • D. [26]\begin{bmatrix} 2\\ 6 \end{bmatrix}

Answer and worked solution

Answer: A and B

  1. All points are scalar multiples of (1,3)ᵀ, so a representative direction must lie along that line.
  2. The length is 12+32=10\sqrt{1^2+3^2}=\sqrt{10}. Dividing by √10 makes a unit vector.
  3. Either sign is valid: it reverses proxy signs but keeps the same line and reconstructions. C and D lie along the line but have lengths √10 and 2√10, not 1.

ML Techniques Q15

If standard PCA is performed on this dataset, what is the variance along the first principal component?

Four points in R2\mathbb{R}^2 lie on a line through the origin:

D={(−2,−6),(−1,−3),(1,3),(2,6)}.D=\{(-2,-6),(-1,-3),(1,3),(2,6)\}.
(101)

Answer and worked solution

Answer: 25

  1. Use w=(1,3)T/10w=(1,3)^T/\sqrt{10}. Coordinates wᵀxᵢ are −210,−10,10,210-2\sqrt{10},-\sqrt{10},\sqrt{10},2\sqrt{10}. Their mean is zero.
  2. Variance under the course convention is average squared coordinate: (40+10+10+40)/4=25(40+10+10+40)/4=25.
  3. Use denominator n=4, consistent with C=XXᵀ/n, rather than the unbiased sample-variance denominator n−1.

ML Techniques Q16

If standard PCA is performed on this dataset, what is the variance along the second principal component?

Four points in R2\mathbb{R}^2 lie on a line through the origin:

D={(−2,−6),(−1,−3),(1,3),(2,6)}.D=\{(-2,-6),(-1,-3),(1,3),(2,6)\}.
(102)

Answer and worked solution

Answer: 0

  1. A unit second direction is perpendicular to (1,3), for example (−3,1)ᵀ/√10.
  2. Every point is on the first-component line, so every projection onto the second direction is zero.
  3. The variance of four zero coordinates is zero; all variance is captured by the first component.

ML Techniques Q17

What is the log-likelihood of this dataset under this distribution?

The four observations x1,x2,x3,x4∈[0,1]x_1,x_2,x_3,x_4\in[0,1] are assumed i.i.d. with density

f(x;θ)={θxθ−1,0≤x≤1,0,otherwise.f(x;\theta)=\begin{cases}\theta x^{\theta-1},&0\le x\le 1,\\0,&\text{otherwise.}\end{cases}
(103)
  • A. ∏i=14θxiθ−1\prod \limits_{i = 1}^{4} \theta x_i^{\theta - 1}
  • B. ∑i=14θxiθ−1\sum \limits_{i = 1}^{4} \theta x_i^{\theta - 1}
  • C. ∑i=14[log⁡θ+(θ−1)log⁡xi]\sum \limits_{i = 1}^{4} \left[ \log \theta + (\theta - 1)\log x_i \right]
  • D. ∏i=14[log⁡θ+(θ−1)log⁡xi]\prod \limits_{i = 1}^{4} \left[ \log \theta + (\theta - 1)\log x_i \right]

Answer and worked solution

Answer: C

  1. For independent observations, L(θ)=∏i=14θxiθ−1L(\theta)=\prod_{i=1}^{4}\theta x_i^{\theta-1}, with θ>0.
  2. Apply log to each factor: ℓ(θ)=∑i=14[log⁡θ+(θ−1)log⁡xi]\ell(\theta)=\sum_{i=1}^{4}[\log\theta+(\theta-1)\log x_i].
  3. A is likelihood, not log-likelihood. B adds densities instead of their logs; D incorrectly multiplies the log terms. The listed positive observations in the next question avoid boundary log issues.

ML Techniques Q18

You are given the actual values of these observations: x1=1e,x2=1e2,x3=1e3,x4=1e4x_1 = \cfrac{1}{e},\quad x_2 = \cfrac{1}{e^2},\quad x_3 = \cfrac{1}{e^3},\quad x_4 = \cfrac{1}{e^4}

What is the maximum likelihood estimate for θ\theta? Use log⁡e\log_e wherever appropriate.

The four observations x1,x2,x3,x4∈[0,1]x_1,x_2,x_3,x_4\in[0,1] are assumed i.i.d. with density

f(x;θ)={θxθ−1,0≤x≤1,0,otherwise.f(x;\theta)=\begin{cases}\theta x^{\theta-1},&0\le x\le 1,\\0,&\text{otherwise.}\end{cases}
(104)

Answer and worked solution

Answer: 0.4

  1. ∑ilog⁡xi=−1−2−3−4=−10\sum_i\log x_i=-1-2-3-4=-10. Hence ℓ(θ)=4log⁡θ−10(θ−1)\ell(\theta)=4\log\theta-10(\theta-1).
  2. Differentiate: ℓ′(θ)=4/θ−10=0\ell\prime(\theta)=4/\theta-10=0, so θ̂=4/10=0.4.
  3. The second derivative −4/θ2-4/\theta^2 is negative for θ>0, confirming the maximum.

ML Techniques Q19

Points: x2,x1x_2, x_1

The data are x1=(0,2)x_1=(0,2), x2=(2,0)x_2=(2,0), x3=(0,0)x_3=(0,0), x4=(0,−2)x_4=(0,-2) and x5=(−2,0)x_5=(-2,0). For k=2k=2, find the k-means++ probability of choosing each listed pair as the initial centers in the specified order. Round to three decimal places.

Answer and worked solution

Answer: 0.044

  1. The ordered event requires x₂ first. The first center is uniform over five points, giving probability 1/5.
  2. Conditional on x₂=(2,0), squared distances to x₁,x₃,x₄,x₅ are 8,4,8,16; total=36. The selected point itself contributes distance 0.
  3. The probability of x₁ second is 8/36. Multiply: P=(1/5)(8/36)=0.044444P=(1/5)(8/36)=0.044444, rounding to 0.044.

ML Techniques Q20

Points x2,x3x_2, x_3

The data are x1=(0,2)x_1=(0,2), x2=(2,0)x_2=(2,0), x3=(0,0)x_3=(0,0), x4=(0,−2)x_4=(0,-2) and x5=(−2,0)x_5=(-2,0). For k=2k=2, find the k-means++ probability of choosing each listed pair as the initial centers in the specified order. Round to three decimal places.

Answer and worked solution

Answer: 0.022

  1. The ordered event requires x₂ first. The first center is uniform over five points, giving probability 1/5.
  2. Conditional on x₂=(2,0), squared distances to x₁,x₃,x₄,x₅ are 8,4,8,16; total=36. The selected point itself contributes distance 0.
  3. The probability of x₃ second is 4/36. Multiply: P=(1/5)(4/36)=0.022222P=(1/5)(4/36)=0.022222, rounding to 0.022.

ML Techniques Q21

Points x2,x5x_2, x_5 (in that order)

The data are x1=(0,2)x_1=(0,2), x2=(2,0)x_2=(2,0), x3=(0,0)x_3=(0,0), x4=(0,−2)x_4=(0,-2) and x5=(−2,0)x_5=(-2,0). For k=2k=2, find the k-means++ probability of choosing each listed pair as the initial centers in the specified order. Round to three decimal places.

Answer and worked solution

Answer: 0.089

  1. The ordered event requires x₂ first. The first center is uniform over five points, giving probability 1/5.
  2. Conditional on x₂=(2,0), squared distances to x₁,x₃,x₄,x₅ are 8,4,8,16; total=36. The selected point itself contributes distance 0.
  3. The probability of x₅ second is 16/36. Multiply: P=(1/5)(16/36)=0.088889P=(1/5)(16/36)=0.088889, rounding to 0.089.

Quiz 1 source questions: ML Foundations

The following 25 questions are transcribed from the supplied mock_quiz_1_with_answers.md file embedded in the study site. The original question type, options, and available worked explanations are retained.

ML Foundations Quiz 1 browser · Interactive demonstration

ML Foundations Q1

Let the function f(x)={ax−3,x<24,x=22x,x>2f(x)= \begin{cases} ax -3, & x < 2 \\ 4, & x=2 \\ 2x, & x>2 \end{cases} be continuous for all x∈Rx \in \mathbb{R}. Then, find the value of aa. Enter the answer correct to one decimal place.

Answer and worked solution

Answer: 3.5

  1. At x=2, the defined value is 4. The right-hand limit is 2×2=4.
  2. The left-hand limit is 2a−3; continuity requires 2a−3=4.
  3. Solve 2a=7 → a=3.5. The linear pieces are already continuous elsewhere.

ML Foundations Q2

Let f:R2→Rf: \mathbb{R}^2 \rightarrow \mathbb{R}, given by f(x,y)=x2+y2f(x, y) = x^2 + y^2. Consider the following algorithm: Xn+1=Xn−h∇f(Xn),    Xi∈R2,i:1,2,…X_{n+1} = X_n -h \nabla f(X_n),~~~~ X_i \in \mathbb{R}^2, i: 1, 2, \ldots and h > 0, where hh is the step size and ∇f(Xn)\nabla f(X_n) is the gradient of ff evaluated at XnX_n. Fix h=0.25h = 0.25 and X0=(1,3)X_0 = (1, 3), which among the following points does the algorithm converge to?

  • A. (1,3)(1, 3)
  • B. (1/2,1/6)(1/2, 1/6)
  • C. (0,0)(0, 0)
  • D. The algorithm does not converge

Answer and worked solution

Answer: C: (0,0)

  1. For f(x,y)=x²+y², the gradient is (2x,2y)ᵀ=2X.
  2. With h=0.25, Xn+1=Xn−0.25(2Xn)=0.5XnX_{n+1}=X_n-0.25(2X_n)=0.5X_n. Thus Xn=2−n(1,3)TX_n=2^{-n}(1,3)^T.
  3. Both coordinates tend to zero because |0.5|<1. This is convergence to (0,0), not just the first update (0.5,1.5).

ML Foundations Q3

Consider the following data set xy [1,0] +1 [2,2] +1 [3,1] +1 [4,5] −1 [5,4] −1 [6,5] −1\begin{array}{ |c| c| } \hline x & y \\ \hline \ [1,0]\ & +1\\ \ [2,2]\ & +1 \\ \ [3,1]\ & +1 \\ \ [4,5]\ & -1\\ \ [5,4]\ & -1\\ \ [6,5]\ & -1\\ \hline \end{array} If sign(x1−3x2)\text{sign}(x_1 - 3x_2) is a classifier that is used to fit the data set, what is the resultant loss? Assume that sign(0)=1.\text{sign}(0) = 1. Enter your answer correct to three decimal places.

Answer and worked solution

Answer: 0.167

  1. Compute scores x₁−3x₂ for the six points: 1,−4,0,−11,−7,−9.
  2. Using sign(0)=+1, predictions are +1,−1,+1,−1,−1,−1. Only the second point disagrees with its true label.
  3. Classification loss=wrong predictions / total=1/6≈0.167. The zero-score point is correct under the specified tie rule.

ML Foundations Q4

For the data set (xi,yi)=[(1,2),(3,4),(4,3),(5,6)],i(x^i,y^i)=[(1,2),(3,4),(4,3),(5,6)], i= 1 to 4, let the regression function be x2−25\dfrac{x^2-2}{5}. The mean squared error loss obtained while fitting this function on the data set is

Answer and worked solution

Answer: 3.4

  1. For x=1,3,4,5, the predictions (x²−2)/5 are −0.2,1.4,2.8,4.6.
  2. Subtract targets 2,4,3,6: errors are −2.2,−2.6,−0.2,−1.4. Their squares are 4.84,6.76,0.04,1.96.
  3. Mean squared error=(4.84+6.76+0.04+1.96)/4=13.6/4=3.4.

ML Foundations Q5

A probability model pX(x)={15,if x∈[0,5]0,otherwisep_X(x)= \begin{cases} \frac{1}{5},& \text{if } x \in [0,5]\\ 0, & \text{otherwise} \end{cases}is obtained by the density estimation algorithm for the data points x1=2.5,x2=1,x3=3,x4=4.5x_1=2.5, x_2=1, x_3=3, x_4=4.5 and x5=4.95x_5=4.95. Compute the (average) negative log likelihood loss of the model. (Note: Use log base 10.)

Answer and worked solution

Answer: 0.69897

  1. All five observations are inside [0,5], so each has model density 1/5.
  2. Average negative log-likelihood is −15∑i=15log⁡10(1/5)=−log⁡10(1/5)=log⁡105-\frac15\sum_{i=1}^{5}\log_{10}(1/5)=-\log_{10}(1/5)=\log_{10}5.
  3. Numerically log₁₀5≈0.69897. Use base 10 as requested, not the natural logarithm.

ML Foundations Q6

The encoder and decoder functions expressed as f(x)=x1−x2+0.5x3f(x)=x_1-x_2+0.5x_3 and g(u)=[0.3u,−u,u]g(u)=[0.3u,-u,u] respectively are used to reduce the dimension of the data set given below. x [−1,1,−1]  [1,2,1]  [1,1,−1]  [1,−1,2]  [0,1,3] \begin{array}{ |c| } \hline x \\ \hline \ [-1,1,-1]\ \\ \ [1,2,1]\ \\ \ [1,1,-1]\ \\ \ [1,-1,2]\ \\ \ [0,1,3]\ \\ \hline \end{array} What is the loss obtained for the model?

Answer and worked solution

Answer: 5.148

  1. Compute each code u=f(x), reconstruct x̂=g(u), then calculate squared Euclidean error: sum the three squared coordinate errors.
  2. Sample u g(u) ‖x−g(u)‖²
    (−1,1,−1) −2.5 (−0.75,2.5,−2.5) 4.5625
    (1,2,1) −0.5 (−0.15,0.5,−0.5) 5.8225
    (1,1,−1) −0.5 (−0.15,0.5,−0.5) 1.8225
    (1,−1,2) 3 (0.9,−3,3) 5.01
    (0,1,3) 0.5 (0.15,−0.5,0.5) 8.5225
  3. The squared errors sum to 25.74. Divide by five samples: loss=5.148. Do not divide again by the three features; this is mean squared vector reconstruction error.

ML Foundations Q7

Let g(x)=ex(sin⁡x+cos⁡x).g(x)=e^x(\sin x+\cos x). Determine the equation of the tangent line at x=0.5x=0.5 and use it to estimate the value of g(0.6)g(0.6). Enter your answer correct to three decimal places.

Answer and worked solution

Answer: 2.527

  1. Product rule: g′(x)=ex(sin⁡x+cos⁡x)+ex(cos⁡x−sin⁡x)=2excos⁡xg\prime(x)=e^x(\sin x+\cos x)+e^x(\cos x-\sin x)=2e^x\cos x.
  2. Tangent at a=0.5: T(x)=g(0.5)+g′(0.5)(x−0.5)T(x)=g(0.5)+g\prime(0.5)(x-0.5). Here g(0.5)≈2.237328 and g′(0.5)≈2.893778.
  3. At x=0.6, displacement=0.1, so T(0.6)≈2.237328+0.289378=2.526706→2.527. Angles are in radians. This is the tangent estimate, not direct evaluation of g(0.6).

ML Foundations Q8

The directional derivative of f(x,y)=xy2+3x2f(x,y)=xy^2+3x^2 at (1,1) in the direction of unit vector along w=[−1,1]w=[-1,1] is

Answer and worked solution

Answer: −5/2≈−3.536-5/\sqrt2\approx-3.536

  1. Partial derivatives: fx=y2+6xf_x=y^2+6x and fy=2xyf_y=2xy. At (1,1), ∇f=(7,2)ᵀ.
  2. Normalize the direction: u=(−1,1)T/2u=(-1,1)^T/\sqrt2.
  3. Directional derivative: ∇fTu=(7(−1)+2(1))/2=−5/2\nabla f^Tu=(7(-1)+2(1))/\sqrt2=-5/\sqrt2. The negative sign means f decreases along that direction.

ML Foundations Q9

Is the system Ax=bAx = b consistent?

Let A=(1−11112),b=(113)A = \begin{pmatrix} 1 & -1\\ 1 & 1\\ 1 & 2 \end{pmatrix}, b = \begin{pmatrix} 1 \\ 1 \\ 3 \end{pmatrix}

  • A. Yes
  • B. No

Answer and worked solution

Answer: B: No

  1. The first two equations are x₁−x₂=1 and x₁+x₂=1. They force x₁=1,x₂=0.
  2. The third equation would then give x₁+2x₂=1, but its required right side is 3.
  3. No vector can satisfy all three equations; b is outside C(A).

ML Foundations Q10

Using the least square approximation, find the length of the projection vector pp of bb onto the column space of AA. Enter the answer correct to two decimal places.

Let A=(1−11112),b=(113)A = \begin{pmatrix} 1 & -1\\ 1 & 1\\ 1 & 2 \end{pmatrix}, b = \begin{pmatrix} 1 \\ 1 \\ 3 \end{pmatrix}

Answer and worked solution

Answer: 3.14

  1. Normal equations: ATA=[3226]A^TA=\begin{bmatrix}3&2\\2&6\end{bmatrix}, ATb=(5,6)TA^Tb=(5,6)^T, so x^=(9/7,4/7)T\hat x=(9/7,4/7)^T.
  2. The projection is p=Ax^=(5,13,17)T/7p=A\hat x=(5,13,17)^T/7.
  3. Take its length, not the coefficient length: ∥p∥=52+132+172/7=483/7≈3.140\|p\|=\sqrt{5^2+13^2+17^2}/7=\sqrt{483}/7\approx3.140, rounding to 3.14.

ML Foundations Q11

Which of the following matrices have eigenvectors as [212]\begin{bmatrix} 2\\ 1\\ 2\\ \end{bmatrix}, [1−20]\begin{bmatrix} 1\\ -2\\ 0\\ \end{bmatrix} and\text{and} [10−1]\begin{bmatrix} 1\\ 0\\ -1\\ \end{bmatrix}?

  • A. [324202423]\begin{bmatrix} 3 & 2 & 4\\ 2 & 0 & 2\\ 4 & 2 & 3\\ \end{bmatrix}
  • B. [648404846]\begin{bmatrix} 6 & 4 & 8\\ 4 & 0 & 4\\ 8 & 4 & 6\\ \end{bmatrix}
  • C. [214404846]\begin{bmatrix} 2 & 1 & 4\\ 4 & 0 & 4\\ 8 & 4 & 6\\ \end{bmatrix}
  • D. [310202423]\begin{bmatrix} 3 & 1 & 0\\ 2 & 0 & 2\\ 4 & 2 & 3\\ \end{bmatrix}

Answer and worked solution

Answer: A and B

  1. Use the test Mv=λv for each of the three vectors, not just one.
  2. Matrix A gives (16,8,16)ᵀ=8(2,1,2)ᵀ, (−1,2,0)ᵀ=−(1,−2,0)ᵀ, and (−1,0,1)ᵀ=−(1,0,−1)ᵀ. Thus all three are eigenvectors.
  3. B=2A preserves those eigenvectors and doubles the eigenvalues. C sends the first vector to (13,16,32)ᵀ; D sends it to (7,8,16)ᵀ. Neither result is a scalar multiple of (2,1,2)ᵀ, so C and D fail.

ML Foundations Q12

Let the matrix A∈Rd×dA \in \mathbb{R}^{d\times d} be diagonalizable, then which of the following statements is/are true for AA?

  • A. AA must be symmetric.
  • B. We can find a basis of eigenvectors for Rd\mathbb{R}^d.
  • C. We can find an orthonormal basis of eigenvectors for Rd\mathbb{R}^d.
  • D. AA can have some repeated eigenvalues but it must have a sufficient number of linearly independent eigenvectors.

Answer and worked solution

Answer: B and D (diagonalizable over ℝ)

  1. Diagonalizability over the real numbers means d independent real eigenvectors exist; they form a basis of ℝᵈ. Thus B is true.
  2. Repeated eigenvalues are allowed if their eigenspaces supply enough independent eigenvectors in total. Thus D is true.
  3. Symmetry and an orthonormal eigenbasis are stronger properties, not guaranteed by diagonalizability. For example [[1,1],[0,2]] has two distinct eigenvalues and is diagonalizable, but is not symmetric. If diagonalization over ℂ were intended, the real-basis claim would need qualification.

ML Foundations Q13

The length of error vector obtained by projecting u=[−142]u= \begin{bmatrix} -1 \\ 4 \\ 2 \\ \end{bmatrix} onto v=[123]v= \begin{bmatrix} 1 \\ 2 \\ 3 \\ \end{bmatrix} is

Answer and worked solution

Answer: 125/14≈2.988\sqrt{125/14}\approx2.988

  1. Compute uTv=−1+8+6=13u^Tv=-1+8+6=13, ∥v∥2=1+4+9=14\|v\|^2=1+4+9=14, and ∥u∥2=1+16+4=21\|u\|^2=1+16+4=21.
  2. The projection is p=(13/14)v. Orthogonality gives ∥u−p∥2=∥u∥2−(uTv)2/∥v∥2=21−169/14=125/14\|u-p\|^2=\|u\|^2-(u^Tv)^2/\|v\|^2=21-169/14=125/14.
  3. The question asks for length, so take the square root: about 2.988. Reporting 125/14 would give squared length instead.

ML Foundations Q14

Consider a line with zero slope and y-intercept of 2. The sum of squared residuals obtained when this line is used to fit the following data set is xy 1 2 2 4 3 1 4 3\begin{array}{ |c| c| } \hline x & y \\ \hline \ 1\ & 2\\ \ 2\ & 4 \\ \ 3\ & 1 \\ \ 4\ & 3\\ \hline \end{array}

Answer and worked solution

Answer: 6

  1. Zero slope and intercept 2 give the horizontal line ŷ=2 at every x.
  2. Observed-minus-predicted residuals are 0,2,−1,1. Square and add: 0+4+1+1=6.
  3. The question asks for the sum, not the mean; dividing by four would answer a different question.

ML Foundations Q15

If the matrix A=[122461236900123]A = \begin{bmatrix} 1 & 2 & 2 & 4 & 6\\ 1 & 2 & 3 & 6 & 9\\ 0 & 0 & 1 & 2 & 3\\ \end{bmatrix} is reduced to its triangular echelon form, the number of free variables is

Answer and worked solution

Answer: 3

  1. Subtract row 1 from row 2: the result equals row 3, (0,0,1,2,3). There are only two independent rows/pivots.
  2. Pivot columns can be 1 and 3. Columns 2,4,5 correspond to free variables.
  3. Five unknowns minus rank 2 gives nullity=3, the number of free variables.

ML Foundations Q16

Find the cardinality of SS or the number of elements in SS.

Let SS be the set of all 2×22\times 2 matrices AA, such that, two entries in AA are equal to 11 and the other two are 00. For example, [1010],[0110]∈S\begin{bmatrix} 1 & 0\\ 1 & 0 \end{bmatrix} ,\begin{bmatrix} 0 & 1\\ 1 & 0 \end{bmatrix} \in S but [1110],[0100],[1120]∉S\begin{bmatrix} 1 & 1\\ 1 & 0 \end{bmatrix}, \begin{bmatrix} 0 & 1\\ 0 & 0 \end{bmatrix}, \begin{bmatrix} 1 & 1\\ 2 & 0 \end{bmatrix} \notin S .

Answer and worked solution

Answer: 6

  1. A 2×2 matrix has four positions. Exactly two must be chosen for ones; the rest become zero.
  2. The number of unordered choices is (42)=4!/(2!2!)=6\binom42=4!/(2!2!)=6.
  3. Order of choosing the positions does not create a different matrix.

ML Foundations Q17

Which of the following is true?

Let SS be the set of all 2×22\times 2 matrices AA, such that, two entries in AA are equal to 11 and the other two are 00. For example, [1010],[0110]∈S\begin{bmatrix} 1 & 0\\ 1 & 0 \end{bmatrix} ,\begin{bmatrix} 0 & 1\\ 1 & 0 \end{bmatrix} \in S but [1110],[0100],[1120]∉S\begin{bmatrix} 1 & 1\\ 1 & 0 \end{bmatrix}, \begin{bmatrix} 0 & 1\\ 0 & 0 \end{bmatrix}, \begin{bmatrix} 1 & 1\\ 2 & 0 \end{bmatrix} \notin S .

  • A. Every matrix in SS is diagonalizable.
  • B. None of the matrices in SS are diagonalizable.
  • C. There exists at least one matrix in SS that is not diagonalizable.

Answer and worked solution

Answer: A: Every matrix in S is diagonalizable

  1. Among the six matrices, four are rank one with trace 1. Their determinant is 0, so their eigenvalues are 0 and 1: distinct eigenvalues guarantee diagonalizability.
  2. The remaining two matrices are I₂ and [[0,1],[1,0]]. The identity is already diagonal; the swap matrix has eigenvalues 1 and −1.
  3. All six therefore have enough independent eigenvectors.

ML Foundations Q18

With the help of the previous question (or otherwise), determine if the following statement is true or false. If a square matrix AA is diagonalizable, then AA is invertible.

Let SS be the set of all 2×22\times 2 matrices AA, such that, two entries in AA are equal to 11 and the other two are 00. For example, [1010],[0110]∈S\begin{bmatrix} 1 & 0\\ 1 & 0 \end{bmatrix} ,\begin{bmatrix} 0 & 1\\ 1 & 0 \end{bmatrix} \in S but [1110],[0100],[1120]∉S\begin{bmatrix} 1 & 1\\ 1 & 0 \end{bmatrix}, \begin{bmatrix} 0 & 1\\ 0 & 0 \end{bmatrix}, \begin{bmatrix} 1 & 1\\ 2 & 0 \end{bmatrix} \notin S .

  • A. True
  • B. False

Answer and worked solution

Answer: B: False

  1. Diagonalizability requires a basis of eigenvectors. Invertibility additionally requires that no eigenvalue be zero.
  2. For example [[1,1],[0,0]] has eigenvalues 1 and 0: it is diagonalizable because they are distinct, but singular because the determinant is zero.
  3. Thus a diagonalizable matrix need not be invertible.

ML Foundations Q19

A row stochastic matrix is a square matrix with non-negative entries in which the sum of the entries in every row is equal to 11. If λ\lambda is a common eigenvalue every row stochastic matrix, then enter the value of λ\lambda.

Answer and worked solution

Answer: 1

  1. Let 1 denote the nonzero all-ones column. Each entry of A1 is the sum of one row of A.
  2. Every row sum is 1, so A1=1=1·1. Hence the eigenvalue 1 occurs in every row-stochastic matrix.
  3. No other value is common to all: the identity matrix is row-stochastic and has only eigenvalue 1.

ML Foundations Q20

Which of the following is/are true?

Consider the matrix A\displaystyle A given below: A=[cos⁡θ−sin⁡θsin⁡θcos⁡θ]A=\begin{bmatrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{bmatrix} where 0<θ<180∘0 < \theta < 180^{\circ}.

  • A. A\displaystyle A is an orthogonal matrix.
  • B. A\displaystyle A is invertible.
  • C. A\displaystyle A is symmetric

Answer and worked solution

Answer: A and B

  1. Multiply: ATA=IA^TA=I because cos⁡2θ+sin⁡2θ=1\cos^2\theta+\sin^2\theta=1 and the off-diagonal terms cancel. Therefore A is orthogonal.
  2. Its inverse is Aᵀ (also det A=1), so A is invertible.
  3. For 0<θ<180°, sin θ is nonzero. The off-diagonal entries −sin θ and +sin θ differ, so A is not symmetric.

ML Foundations Q21

Which of the following is true?

Consider the matrix A\displaystyle A given below: A=[cos⁡θ−sin⁡θsin⁡θcos⁡θ]A=\begin{bmatrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{bmatrix} where 0<θ<180∘0 < \theta < 180^{\circ}.

  • A. A\displaystyle A does not have real eigenvalues.
  • B. A\displaystyle A has two distinct real eigenvalues.
  • C. AA has two real eigenvalues, not necessarily distinct.

Answer and worked solution

Answer: A: No real eigenvalues

  1. The characteristic equation is λ2−2cos⁡θ λ+1=0\lambda^2-2\cos\theta\,\lambda+1=0.
  2. The roots are λ=cos⁡θ±isin⁡θ\lambda=\cos\theta\pm i\sin\theta, where i is the imaginary unit.
  3. Because 0<θ<180°, sin θ≠0, so neither root is real. The endpoints where real roots occur are excluded.

ML Foundations Q22

Which of the following are the eigenvalues of AA?

Consider A=14[3−1−13]A= \cfrac{1}{4} \begin{bmatrix} 3 & -1\\ -1 & 3 \end{bmatrix}.

  • A. 1,121, \cfrac{1}{2}
  • B. 32,0\cfrac{3}{2},0
  • C. 2,−122, \cfrac{-1}{2}

Answer and worked solution

Answer: A: 1,1/21,1/2

  1. Multiply A by (1,−1)ᵀ: 14(4,−4)T=(1,−1)T\frac14(4,-4)^T=(1,-1)^T, giving eigenvalue 1.
  2. Multiply by (1,1)ᵀ: 14(2,2)T=12(1,1)T\frac14(2,2)^T=\frac12(1,1)^T, giving eigenvalue 1/2.
  3. The eigenvalue sum 1.5 equals trace(A), and their product 0.5 equals det(A).

ML Foundations Q23

Consider the eigenvalue decomposition of AA given by A=QDQTA=QDQ^{T}, where QQ is orthogonal and the diagonal elements of DD are arranged in decreasing order on the main diagonal. Which of the following could be QQ?

Consider A=14[3−1−13]A= \cfrac{1}{4} \begin{bmatrix} 3 & -1\\ -1 & 3 \end{bmatrix}.

  • A. 12[11−11]\cfrac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1\\ -1 & 1 \end{bmatrix}
  • B. [1−111]\begin{bmatrix} 1 & -1\\ 1 & 1 \end{bmatrix}
  • C. 15[3−443]\cfrac{1}{5} \begin{bmatrix} 3 & -4\\ 4 & 3 \end{bmatrix}

Answer and worked solution

Answer: A

  1. Decreasing eigenvalue order puts the unit eigenvector for 1 first, then the unit eigenvector for 1/2.
  2. These are (1,−1)T/2(1,-1)^T/\sqrt2 and (1,1)T/2(1,1)^T/\sqrt2. They are perpendicular and have unit length, giving Q in option A.
  3. B is not normalized. C is orthogonal but its columns are not eigenvectors of this A; orthogonality alone is insufficient.

ML Foundations Q24

Two 2×22 \times 2 matrices XX and YY are approximately equal if ∣Xij−Yij∣≈0|X_{ij} - Y_{ij}| \approx 0, for all 1≤i,j≤21 \leq i, j \leq 2, that is, the difference between every pair of corresponding elements is close to zero. Which of the following could be approximately equal to A1000A^{1000}? Choose the most appropriate answer.

Consider A=14[3−1−13]A= \cfrac{1}{4} \begin{bmatrix} 3 & -1\\ -1 & 3 \end{bmatrix}.

  • A. 12[1−1−11]\cfrac{1}{2} \begin{bmatrix} 1 & -1\\ -1 & 1 \end{bmatrix}
  • B. 12[2001]\cfrac{1}{2} \begin{bmatrix} 2 & 0\\ 0 & 1 \end{bmatrix}
  • C. [1111]\begin{bmatrix} 1 & 1\\ 1 & 1 \end{bmatrix}

Answer and worked solution

Answer: A

  1. Write A=Qdiag⁡(1,1/2)QTA=Q\operatorname{diag}(1,1/2)Q^T. Then A1000=Qdiag⁡(1,2−1000)QTA^{1000}=Q\operatorname{diag}(1,2^{-1000})Q^T.
  2. The second factor is negligible; only the eigenvalue-1 direction remains.
  3. Its unit eigenvector is v=(1,−1)T/2v=(1,-1)^T/\sqrt2. The limiting projector is vvT=12[1−1−11]vv^T=\frac12\begin{bmatrix}1&-1\\-1&1\end{bmatrix}, option A.

ML Foundations Q25

Suppose AA is a square matrix of order three with eigenvalues 1,2,41, 2, 4. What is the trace of A2A^2?

Answer and worked solution

Answer: 21

  1. Squaring a matrix squares its eigenvalues, with multiplicities: the eigenvalues of A² are 1,4,16.
  2. Trace equals the sum of eigenvalues, so trace(A²)=1+4+16=21.
  3. Do not square trace(A): (1+2+4)²=49 is not the requested quantity.

Source index

The identifiers below are the source file labels from the uploaded ML Exam Atlas. The original PDFs are not included in this blog package.

ID Source file Collection Week
S01 week_1.pdf archive1 Week 1
S02 Slide 1.pdf archive1 Week 2
S03 Slide 2.pdf archive1 Week 2
S04 slide 1.pdf archive1 Week 3
S05 slide 2.pdf archive1 Week 3
S06 GMM_EM.pdf archive1 Week 4
S07 MLE_Bayesian.pdf archive1 Week 4
S08 1. What is Machine Learning-.pdf archive2 Week 1
S09 2. Data, Models and ML Task.pdf archive2 Week 1
S10 3. Supervised Learning- Regression.pdf archive2 Week 1
S11 4. Supervised Learning- Classification.pdf archive2 Week 1
S12 5. Unsupervised Learning- Dimensionality Reduction.pdf archive2 Week 1
S13 6. Unsupervised Learning- Density Estimation.pdf archive2 Week 1
S14 1. Sets and Functions.pdf archive2 Week 2
S15 2. Univariate Calculus- Continuity and Differentiability.pdf archive2 Week 2
S16 3. Univariate Calculus- Derivatives and Linear Approximations.pdf archive2 Week 2
S17 4. Univariate Calculus- applications and advanced rules.pdf archive2 Week 2
S18 5. Multivariate Calculus- Lines and planes in higher dimensional space.pdf archive2 Week 2
S19 6. Multivariate Calculus- Linear approximation and applications.pdf archive2 Week 2
S20 Week 2 Tutorial.pdf archive2 Week 2
S21 1. Four Fundamental Subspaces.pdf archive2 Week 3
S22 2. Orthogonal Vectors and Subspaces.pdf archive2 Week 3
S23 3. Projections.pdf archive2 Week 3
S24 4. Least Squares and Projections onto a Subspace.pdf archive2 Week 3
S25 5. Example of Least Squares.pdf archive2 Week 3
S26 Week 3 Tutorial 3.1.pdf archive2 Week 3
S27 Week 3 Tutorial 3.2.pdf archive2 Week 3
S28 Week 3 Tutorial 3.3.pdf archive2 Week 3
S29 1. Linear and Polynomial Regression.pdf archive2 Week 4
S30 2. Eigenvalues and Eigenvectors.pdf archive2 Week 4
S31 3. Diagonalization of a matrix.pdf archive2 Week 4
S32 4. Solving Fibonacci Sequence using diagonalization.pdf archive2 Week 4
S33 5. Orthogonally diagonalizable matrices.pdf archive2 Week 4
S34 Week 4 tutorial4.1.pdf archive2 Week 4
S35 Week 4 tutorial4.2.pdf archive2 Week 4
S36 Introduction_to_ML.pptx archive1 Week 1
S37 Week 1 Tutorial-1.docx archive2 Week 1