Skip to content
AriadneTechnology

The Outer Ring · Chamber 3 of 9

Span, Basis and Dimension

Which points can you reach? Linear independence, bases and the true dimension of your data.

40 min 60 XP + 12 questions + 1 challengeMathVideoPapersProofsCodeLab

In this chamber you will

  • Describe the span of a set of vectors
  • Test vectors for linear independence
  • Find coordinates in a basis and state the dimension of a subspace
  • Read the intrinsic-dimension experiments on neural networks
DiscoverLearnRead beyondPapers & lecturesYour turn

Discover: how many numbers does a network really need?

A small network that classifies handwritten digits (the MNIST dataset), with layers of 784, 200, 200 and 10 neurons, has 199,210 parameters. Normal training adjusts every one of them. In 2018 four researchers at Uber AI Labs asked an odd question: what if we only let the network move in a few directions? They froze a random starting point and a random matrix, and trained a much shorter vector instead:

Spotted in the wild

θ(D)=θ0(D)+P θ(d)\theta^{(D)} = \theta^{(D)}_0 + P\,\theta^{(d)}
Li, Farkhoor, Liu & Yosinski (2018), “Measuring the Intrinsic Dimension of Objective Landscapes”, Eq. (2)

Read it aloud: “theta D equals theta-nought D plus P times theta d.” The bracketed superscripts are labels, not powers (Mathematics for ML, Chamber 1): they say which space each vector lives in. θ(D)\theta^{(D)} is the full list of DD parameters, θ0(D)\theta^{(D)}_0 is a random starting point, PP is a random matrix with DD rows and dd columns, and θ(d)\theta^{(d)} is a short vector of just dd numbers. Only θ(d)\theta^{(d)} is trained.

With d=750d = 750, the digit classifier already reached 90% of the accuracy of the normally trained network. Out of 199,210 directions, 750 random ones were enough. That raises questions this chamber answers. Which settings of the weights can such a network actually reach? What exactly is a “direction”, and when do 750 of them really give 750 different ones? And why 750, not 10 or 100,000? The words for these ideas are span, independence and dimension.

Quick check +20 XP

Take a guess before reading on. In θ(D)=θ0(D)+P θ(d)\theta^{(D)} = \theta^{(D)}_0 + P\,\theta^{(d)}, the matrix PP has DD rows and dd columns, and only θ(d)\theta^{(d)} is trained. For the MNIST network, D=199,210D = 199{,}210 and d=750d = 750. How many numbers does training adjust?

DiscoverLearnRead beyondPapers & lecturesYour turn

Learn: the span of a set of vectors

In Chamber 1 you built linear combinations: scale some vectors, then add them up. The span asks the natural next question: what are all the vectors you can build that way?

The set-builder braces are the ones from Mathematics for ML, Chamber 2. The coefficients cic_i are free: positive, negative, zero, fractions, anything real. Now picture the geometry:

  • One non-zero vector v\mathbf{v}: its span is every multiple cvc\mathbf{v}, a line through the origin.
  • Two vectors in R2\mathbb{R}^2 that don't lie along the same line: their span is the whole plane.
  • Two such vectors in R3\mathbb{R}^3: a plane through the origin, a flat sheet inside space.
  • The zero vector alone: its span is {0}\{\mathbf{0}\}, the single point at the origin.
Span and independence
  • span{v1,…,vk}\mathrm{span}\{\mathbf{v}_1, \ldots, \mathbf{v}_k\}“the span of v one to v k”
    Every linear combination c1v1+⋯+ckvkc_1\mathbf{v}_1 + \cdots + c_k\mathbf{v}_k with real coefficients: all the points these vectors can reach.
    (3,6)∈span{(1,2)}(3, 6) \in \mathrm{span}\{(1, 2)\}
  • {0}\{\mathbf{0}\}“the zero subspace”
    The set whose only element is the zero vector. The smallest subspace there is, and the span of 0\mathbf{0} alone.
    span{0}={0}\mathrm{span}\{\mathbf{0}\} = \{\mathbf{0}\}
  • c1v1+⋯+ckvk=0c_1\mathbf{v}_1 + \cdots + c_k\mathbf{v}_k = \mathbf{0}“a dependency relation”
    A combination that lands on 0\mathbf{0}. If one exists with some ci≠0c_i \neq 0, the vectors are dependent; if only all-zero coefficients work, they are independent.
    2(1,2)−(2,4)=02(1, 2) - (2, 4) = \mathbf{0}
  • det⁡[u v]\det[\mathbf{u}\ \mathbf{v}]“the determinant of u and v”
    For two vectors in the plane, u1v2−u2v1u_1v_2 - u_2v_1: the signed area of the parallelogram they span. Zero exactly when they are dependent. Chamber 5 builds determinants in general.
    det⁡[2112]=3\det\begin{bmatrix} 2 & 1 \\ 1 & 2 \end{bmatrix} = 3

Is a given vector in the span? That's a question about finding coefficients. Is x=(4,7)\mathbf{x} = (4, 7) in the span of u=(1,2)\mathbf{u} = (1, 2) and v=(1,1)\mathbf{v} = (1, 1)? We need numbers c1,c2c_1, c_2 with

c1(12)+c2(11)=(47)⟺{c1+c2=42c1+c2=7.c_1 \begin{pmatrix} 1 \\ 2 \end{pmatrix} + c_2 \begin{pmatrix} 1 \\ 1 \end{pmatrix} = \begin{pmatrix} 4 \\ 7 \end{pmatrix} \quad\Longleftrightarrow\quad \begin{cases} c_1 + c_2 = 4 \\ 2c_1 + c_2 = 7. \end{cases}

Subtracting the first equation from the second gives c1=3c_1 = 3, and then c2=1c_2 = 1. Check: 3(1,2)+1(1,1)=(4,7)3(1, 2) + 1(1, 1) = (4, 7). So yes, it's in the span.

Now try x=(1,2,4)\mathbf{x} = (1, 2, 4) with u=(1,0,1)\mathbf{u} = (1, 0, 1) and v=(0,1,1)\mathbf{v} = (0, 1, 1) in R3\mathbb{R}^3. Any combination is c1u+c2v=(c1,c2,c1+c2)c_1\mathbf{u} + c_2\mathbf{v} = (c_1, c_2, c_1 + c_2). The first two entries force c1=1c_1 = 1 and c2=2c_2 = 2, and then the third entry is 33, not 44. No coefficients work, so (1,2,4)(1, 2, 4) is not in the span. The span of u\mathbf{u} and v\mathbf{v} is a plane (the points whose third entry is the sum of the first two), and (1,2,4)(1, 2, 4) floats just above it.

Quick check +20 XP

Which vector lies in span{(1,0,1),(0,1,1)}\mathrm{span}\{(1, 0, 1), (0, 1, 1)\}?

Learn: subspaces, and a first proof

Lines and planes through the origin share a property: you can't escape them by adding or scaling. Add two vectors on a line through the origin and you land on the same line. Stretch one and you stay on it. Sets with that property get a name.

In R2\mathbb{R}^2 the subspaces are exactly {0}\{\mathbf{0}\}, the lines through the origin, and the whole plane. The line y=x+1y = x + 1 is not a subspace, because it misses the origin. Neither is a disc around the origin: scale any point by 100 and you leave it.

Here's a theorem with a complete proof. It says a span is always one of these well-behaved sets.

Claim. For any vectors v1,…,vk\mathbf{v}_1, \ldots, \mathbf{v}_k in Rn\mathbb{R}^n, the set S=span{v1,…,vk}S = \mathrm{span}\{\mathbf{v}_1, \ldots, \mathbf{v}_k\} is a subspace.

Proof. We check the three conditions in turn.

Zero. Choose every coefficient to be 00: 0 v1+⋯+0 vk=00\,\mathbf{v}_1 + \cdots + 0\,\mathbf{v}_k = \mathbf{0}. So 0∈S\mathbf{0} \in S.

Addition. (You met this step in Chamber 1's proof puzzle: combinations of combinations are combinations.) Take any x,y∈S\mathbf{x}, \mathbf{y} \in S. By the definition of span, there are numbers a1,…,aka_1, \ldots, a_k and b1,…,bkb_1, \ldots, b_k with x=a1v1+⋯+akvk\mathbf{x} = a_1\mathbf{v}_1 + \cdots + a_k\mathbf{v}_k and y=b1v1+⋯+bkvk\mathbf{y} = b_1\mathbf{v}_1 + \cdots + b_k\mathbf{v}_k. (Two different lists of letters, because x\mathbf{x} and y\mathbf{y} may need different coefficients.) Adding, and grouping the terms for each vi\mathbf{v}_i,

x+y=(a1+b1) v1+⋯+(ak+bk) vk,\mathbf{x} + \mathbf{y} = (a_1 + b_1)\,\mathbf{v}_1 + \cdots + (a_k + b_k)\,\mathbf{v}_k,

which is again a linear combination of the vi\mathbf{v}_i. So x+y∈S\mathbf{x} + \mathbf{y} \in S.

Scaling. For x\mathbf{x} as above and any c∈Rc \in \mathbb{R}, we have c x=(ca1) v1+⋯+(cak) vkc\,\mathbf{x} = (c a_1)\,\mathbf{v}_1 + \cdots + (c a_k)\,\mathbf{v}_k, another linear combination. So c x∈Sc\,\mathbf{x} \in S.

All three conditions hold, so SS is a subspace. ■\blacksquare

Notice the rhythm of the argument: unpack the definition (“in the span” means “equals some combination”), do a line of algebra, then repack the definition. Most proofs in linear algebra move to this beat.

Learn: linear independence

Some lists of vectors carry dead weight. In the list u=(1,2)\mathbf{u} = (1, 2), v=(2,4)\mathbf{v} = (2, 4), the second vector is just 2u2\mathbf{u}, so including it reaches nothing new: span{u,v}=span{u}\mathrm{span}\{\mathbf{u}, \mathbf{v}\} = \mathrm{span}\{\mathbf{u}\}, a line. Linear independence is the precise way to say “no dead weight”.

Why does this capture dead weight? Suppose c1v1+⋯+ckvk=0c_1\mathbf{v}_1 + \cdots + c_k\mathbf{v}_k = \mathbf{0} with some coefficient non-zero; renumber so that it's ck≠0c_k \neq 0. Divide by ckc_k and rearrange:

vk=−c1ck v1−⋯−ck−1ck vk−1.\mathbf{v}_k = -\frac{c_1}{c_k}\,\mathbf{v}_1 - \cdots - \frac{c_{k-1}}{c_k}\,\mathbf{v}_{k-1}.

So vk\mathbf{v}_k is a combination of the others, and dropping it doesn't shrink the span. Dependent means redundant; independent means every vector pulls its weight. For (1,2)(1, 2) and (2,4)(2, 4) the witness is 2(1,2)−1(2,4)=(0,0)2(1, 2) - 1(2, 4) = (0, 0).

Two consequences are worth remembering. Any list that contains 0\mathbf{0} is dependent, because 1⋅0=01 \cdot \mathbf{0} = \mathbf{0} uses a non-zero coefficient. And two vectors are dependent exactly when one is a multiple of the other, which means they lie on a common line through the origin.

A test for two vectors in the plane

In Chamber 1 you solved au+bv=ta\mathbf{u} + b\mathbf{v} = \mathbf{t} by elimination and met the number D=u1v2−u2v1D = u_1v_2 - u_2v_1. Chamber 1 left you a claim to check: D=0D = 0 exactly when the two vectors share a line. Now we can prove it, and turn DD into a complete test for independence. Write u=(u1,u2)\mathbf{u} = (u_1, u_2) and v=(v1,v2)\mathbf{v} = (v_1, v_2), set the target to 0\mathbf{0}, and look for coefficients with c1u+c2v=0c_1\mathbf{u} + c_2\mathbf{v} = \mathbf{0}. That's one equation per entry:

c1u1+c2v1=0(1)c1u2+c2v2=0(2)\begin{aligned} c_1 u_1 + c_2 v_1 &= 0 \qquad (1) \\ c_1 u_2 + c_2 v_2 &= 0 \qquad (2) \end{aligned}

Eliminate exactly as in Chamber 1. Multiply (1) by v2v_2 and (2) by v1v_1, then subtract the second result from the first. The c2c_2 terms cancel, leaving

c1 (u1v2−u2v1)=0.c_1\,(u_1 v_2 - u_2 v_1) = 0.

To eliminate c1c_1 instead, multiply (1) by u2u_2 and (2) by u1u_1, then subtract the first result from the second:

c2 (u1v2−u2v1)=0.c_2\,(u_1 v_2 - u_2 v_1) = 0.

The same number appears in both. Chamber 1 promised that it would come back as the determinant, and here it is, a little early, written for the pair as

det⁡[u v]=u1v2−u2v1.\det[\mathbf{u}\ \mathbf{v}] = u_1 v_2 - u_2 v_1.

If det⁡[u v]≠0\det[\mathbf{u}\ \mathbf{v}] \neq 0, divide both equations by it: c1=0c_1 = 0 and c2=0c_2 = 0. The only combination giving 0\mathbf{0} is the trivial one, so the vectors are independent.

If det⁡[u v]=0\det[\mathbf{u}\ \mathbf{v}] = 0, they are dependent, and we can write down a witness. Take c1=v2c_1 = v_2 and c2=−u2c_2 = -u_2. Equation (1) becomes v2u1−u2v1=det⁡[u v]=0v_2 u_1 - u_2 v_1 = \det[\mathbf{u}\ \mathbf{v}] = 0, and equation (2) becomes v2u2−u2v2=0v_2 u_2 - u_2 v_2 = 0. Both hold. That witness is non-zero unless u2=v2=0u_2 = v_2 = 0; in that case both vectors lie on the xx-axis and c1=v1c_1 = v_1, c2=−u1c_2 = -u_1 works instead (or c1=1c_1 = 1, c2=0c_2 = 0 if both vectors are 0\mathbf{0}).

So, for two vectors in the plane:

u,v are independent  ⟺  u1v2−u2v1≠0.\mathbf{u}, \mathbf{v} \text{ are independent} \iff u_1 v_2 - u_2 v_1 \neq 0.

For example, (2,3)(2, 3) and (4,6)(4, 6) give 2⋅6−3⋅4=02 \cdot 6 - 3 \cdot 4 = 0: dependent, and indeed (4,6)=2(2,3)(4, 6) = 2(2, 3). But (2,3)(2, 3) and (4,5)(4, 5) give 10−12=−210 - 12 = -2: independent.

Geometrically, det⁡[u v]\det[\mathbf{u}\ \mathbf{v}] is the signed area of the parallelogram with sides u\mathbf{u} and v\mathbf{v}. A flat parallelogram has zero area, and that's exactly when the vectors are dependent. Chamber 5 builds determinants for matrices of any size. For now, it's your independence meter.

Quick check +20 XP

Which pair of vectors is linearly dependent?

Now play with it. Drag the two vectors and watch the span. The lab asks you to hit a target with a combination au+bva\mathbf{u} + b\mathbf{v}, and then to make the span collapse.

Interactive lab

Span explorer

Drag the heads of u and v (or focus one and use the arrow keys). The teal region is their span: every point a·u + b·v can reach. The meter shows det[u v]: zero means the vectors are dependent.
span{u, v} = ℝ²uvt

u and v are independent, so their span is the whole plane. Slide a and b to land on the target.

u= (,)
v= (,)

Independence meterdet[u v] = 3

Independent: the parallelogram on u and v has area |det|.

a·u + b·v

(3, 3)

target t

(1, 5)

  • Land a·u + b·v on the target (within 0.2).
  • Make the span collapse to a line, with u and v both non-zero.
Challenge: Span explorerHit the target, then find a pair of vectors whose span is only a line.+40 XP

Learn: bases and coordinates

Span tells you how much you can reach, and independence tells you there's no waste. Put them together and you get the most useful idea in the chamber.

The standard basis e1=(1,0)\mathbf{e}_1 = (1, 0), e2=(0,1)\mathbf{e}_2 = (0, 1) from Chamber 1 is a basis of R2\mathbb{R}^2, but far from the only one. b1=(1,1)\mathbf{b}_1 = (1, 1) and b2=(1,−1)\mathbf{b}_2 = (1, -1) form another: det⁡[b1 b2]=1⋅(−1)−1⋅1=−2≠0\det[\mathbf{b}_1\ \mathbf{b}_2] = 1 \cdot (-1) - 1 \cdot 1 = -2 \neq 0, so they are independent, and two independent vectors in the plane span all of it.

The pay-off of a basis is coordinates. Every x\mathbf{x} in UU can be written as x=c1b1+⋯+cnbn\mathbf{x} = c_1\mathbf{b}_1 + \cdots + c_n\mathbf{b}_n (because the basis spans), and in only one way (because it's independent). Chamber 1 proved this for the standard basis; you'll assemble the proof for any basis in Your turn. Those unique coefficients are the coordinates of x\mathbf{x} in the basis B\mathcal{B}, written

[x]B=(c1,…,cn),[\mathbf{x}]_{\mathcal{B}} = (c_1, \ldots, c_n),

and read “the coordinates of x in basis B”.

Worked example: find the coordinates of x=(5,1)\mathbf{x} = (5, 1) in B=((1,1),(1,−1))\mathcal{B} = ((1, 1), (1, -1)). We need c1(1,1)+c2(1,−1)=(5,1)c_1(1, 1) + c_2(1, -1) = (5, 1), that is, c1+c2=5c_1 + c_2 = 5 and c1−c2=1c_1 - c_2 = 1. Adding the equations gives 2c1=62c_1 = 6, so c1=3c_1 = 3 and c2=2c_2 = 2:

[x]B=(3,2),because3(11)+2(1−1)=(51).[\mathbf{x}]_{\mathcal{B}} = (3, 2), \qquad \text{because} \quad 3\begin{pmatrix} 1 \\ 1 \end{pmatrix} + 2\begin{pmatrix} 1 \\ -1 \end{pmatrix} = \begin{pmatrix} 5 \\ 1 \end{pmatrix}.

In the standard basis the same vector has coordinates (5,1)(5, 1). One arrow, two descriptions. The vector didn't move; only the ruler changed.

Bases, coordinates and dimension
  • B=(b1,…,bn)\mathcal{B} = (\mathbf{b}_1, \ldots, \mathbf{b}_n)“the basis B”
    An ordered list of vectors that is linearly independent and spans the space. Bases usually get calligraphic letters.
    B=((1,1),(1,−1))\mathcal{B} = ((1, 1), (1, -1))
  • [x]B[\mathbf{x}]_{\mathcal{B}}“the coordinates of x in basis B”
    The unique coefficients (c1,…,cn)(c_1, \ldots, c_n) with x=c1b1+⋯+cnbn\mathbf{x} = c_1\mathbf{b}_1 + \cdots + c_n\mathbf{b}_n. Same arrow, different ruler.
    [(5,1)]B=(3,2)[(5, 1)]_{\mathcal{B}} = (3, 2)
  • dim⁡U\dim U“the dimension of U”
    The number of vectors in any basis of the subspace UU. All bases of UU have the same size.
    dim⁡Rn=n\dim \mathbb{R}^n = n
  • dintd_{\text{int}}“d int, the intrinsic dimension”
    From Li et al. (2018): the number of directions that actually matter for solving a problem, D−sD - s, where ss is the dimension of the solution set.
    D=dint+sD = d_{\text{int}} + s

Every spanning list contains a basis. Walk through the list in order, and throw away each vector that's already in the span of the vectors you've kept. What survives still spans the same set, since you only threw away redundant vectors. And it's independent: if some combination of the survivors gave 0\mathbf{0} with a non-zero coefficient, the last survivor with a non-zero coefficient would be a combination of earlier survivors, and you would have thrown it away. Problem 3 below asks you to run this sifting algorithm on a table of features.

Learn: dimension

A plane through the origin has infinitely many bases, but every one of them has exactly two vectors. That's no accident.

The proof that all bases have the same size takes a page of careful bookkeeping (it's in Axler's Chapter 2, listed below), so we'll take it on trust here. What it buys us is a single number that measures how big a subspace is:

SubspaceA basisDimension
{0}\{\mathbf{0}\}the empty list00
a line through 0\mathbf{0}any non-zero vector on it11
a plane through 0\mathbf{0} in R3\mathbb{R}^3any two independent vectors in it22
Rn\mathbb{R}^ne1,…,en\mathbf{e}_1, \ldots, \mathbf{e}_nnn

Three rules of thumb follow, and they're worth more than their size. In Rn\mathbb{R}^n, more than nn vectors are always dependent: three vectors in the plane always carry dead weight. Fewer than nn vectors never span: two vectors can't fill space. And dim⁡span{v1,…,vk}≤k\dim \mathrm{span}\{\mathbf{v}_1, \ldots, \mathbf{v}_k\} \le k, with equality exactly when the vectors are independent.

A worked example: the plane U={(x,y,z):x+y+z=0}U = \{(x, y, z) : x + y + z = 0\}. You can choose xx and yy freely, and then z=−x−yz = -x - y is forced. So every vector in UU has the form

(xy−x−y)=x(10−1)+y(01−1).\begin{pmatrix} x \\ y \\ -x - y \end{pmatrix} = x\begin{pmatrix} 1 \\ 0 \\ -1 \end{pmatrix} + y\begin{pmatrix} 0 \\ 1 \\ -1 \end{pmatrix}.

The two vectors on the right span UU, and they're independent (look at their first two entries). So they form a basis and dim⁡U=2\dim U = 2. One linear equation in R3\mathbb{R}^3 removed one dimension. Keep that pattern in mind: it's exactly how Li et al. count.

Quick check +20 XP

What is the dimension of U={(x,y,z,w)∈R4:x+y+z+w=0}U = \{(x, y, z, w) \in \mathbb{R}^4 : x + y + z + w = 0\}?

Back to the paper: intrinsic dimension

Before touching a network, Li et al. warm up with a toy problem that you can now solve in your head. Take D=1000D = 1000 parameters, split them into 10 groups of 100, and require that the first group sums to 1, the second to 2, and so on up to 10. Each requirement is one linear equation, and just like x+y+z=0x + y + z = 0 above, each removes one dimension. The solutions form a flat set of dimension s=990s = 990. The paper defines the intrinsic dimension as what's left over:

Spotted in the wild

D=dint+sD = d_{\text{int}} + s
Li, Farkhoor, Liu & Yosinski (2018), “Measuring the Intrinsic Dimension of Objective Landscapes”, Eq. (1)

Here dint=1000−990=10d_{\text{int}} = 1000 - 990 = 10. Out of a thousand numbers, only ten things need to be got right. Now train in a random dd-dimensional subspace, as in Eq. (2). The dd columns of PP are random, so they are independent (with probability 1) and the subspace really has dimension dd. With d<10d < 10 the subspace (almost surely) misses the solution set; with d≥10d \ge 10 it meets it. So sweep dd upwards and watch for the first success: it happens at d=10d = 10, and it measures dintd_{\text{int}}.

For real networks nobody can count the equations, so the authors sweep dd and call a subspace successful when it reaches 90% of the performance of normal training. They call the first such dd the intrinsic dimension dint90d_{\text{int90}}. Some of their measurements (Table 1):

Task and networkParameters DDdint90d_{\text{int90}}
MNIST digits, fully connected199,210750
MNIST digits, LeNet (convolutional)44,426290
CIFAR-10 images, fully connected656,8109,000
CIFAR-10 images, LeNet62,0062,900
Inverted pendulum (reinforcement learning)5624

Two things stand out. The numbers are small, and making the MNIST network wider or deeper barely changed dint90d_{\text{int90}}. In the paper's words, every extra parameter “just ends up adding one dimension to the redundancy of the solution, ss”. Bigger networks have bigger solution sets, not harder problems, and the authors suggest this may be one reason large models are easy to train.

DiscoverLearnRead beyondPapers & lecturesYour turn

Read beyond the course

Book · free online · ~60 min

Linear Algebra Done Right (4th edition)

Sheldon Axler · Chapter 2: sections 2A (span and linear independence), 2B (bases) and 2C (dimension)

The cleanest treatment of this chamber's ideas, free under an open licence. Section 2C contains the proof that every basis has the same length, which this chamber took on trust. Read the definitions and examples first and the proofs second.

Book · free online · ~40 min

Mathematics for Machine Learning

Marc Peter Deisenroth, A. Aldo Faisal & Cheng Soon Ong · Sections 2.4.3 (vector subspaces), 2.5 (linear independence) and 2.6.1 (generating set and basis)

The same ideas in machine-learning notation, with worked examples that test independence using Gaussian elimination. Read it now for the definitions, then return after Chamber 5 when the elimination steps will feel natural.

Lecture notes · free online · ~50 min

Lecture 9: Independence, basis, and dimension

Gilbert Strang, MIT 18.06 · MIT OpenCourseWare, 18.06 Spring 2010

A classic lecture that covers this chamber in one sitting, with the video, a summary and a problem set. Strang connects independence to null spaces straight away, which is a preview of Chamber 6.

Interactive · free online · ~20 min

Immersive Linear Algebra: Vectors

J. Ström, K. Åström & T. Akenine-Möller · Section 2.5: vector bases and coordinates

Interactive figures where you drag basis vectors and watch coordinates change. A good way to make “same arrow, different ruler” feel physical.

DiscoverLearnRead beyondPapers & lecturesYour turn

Papers and lectures

The intrinsic-dimension paper is unusually readable, and you can get most of it today. Read the abstract. Then read Section 2 up to the end of Section 2.1, about two pages: the toy problem, Eq. (1), Eq. (2), and the paragraph on how PP is built (its columns are scaled to length 1 but not made exactly orthogonal). Look at Figure 1, then read the first two paragraphs of Section 3.1 and Table 1. Skip Section 2.2's thresholds, the reinforcement-learning section and the supplementary material for now. The short discussion of compressing a network to 750 numbers in Section 3.1 is a fun bonus.

Measuring the Intrinsic Dimension of Objective LandscapesChunyuan Li, Heerad Farkhoor, Rosanne Liu, Jason Yosinski · ICLR, 2018

Trains networks in random subspaces of growing dimension to measure how many directions a problem really needs. Span, independence and dimension, applied to the weights of a neural network.

Intrinsic Dimensionality Explains the Effectiveness of Language Model Fine-TuningArmen Aghajanyan, Sonal Gupta, Luke Zettlemoyer · ACL, 2021

Applies the same measurement to fine-tuning BERT and RoBERTa, and finds intrinsic dimensions as low as a few hundred for models with hundreds of millions of parameters. Section 3 opens by restating Li et al.'s method as a single equation, and Table 1 has the numbers; the rest can wait until after Chamber 6.

Decode the paper · Eq. (2), Section 2.1

Measuring the Intrinsic Dimension of Objective Landscapes

Chunyuan Li, Heerad Farkhoor, Rosanne Liu, Jason Yosinski · ICLR, 2018

+30 XP
θ(D)=θ0(D)+P θ(d)\theta^{(D)} = \theta^{(D)}_0 + P\,\theta^{(d)}

The paper's recipe for training a network in a random subspace. Two of the three pieces on the right are random and frozen; only one is trained. Match each symbol to its job.

θ(D)\theta^{(D)}
θ0(D)\theta^{(D)}_0
PP
θ(d)\theta^{(d)}
DD
dd

Options

Watch

Linear combinations, span, and basis vectors | Chapter 2, Essence of linear algebra3Blue1Brown · 10 min

Grant Sanderson animates exactly the picture from the lab: two vectors whose combinations sweep out the plane, until they line up and the span collapses to a line. Watch for the three-dimensional case in the second half, where a third vector either adds a new direction or stays trapped in the plane of the first two.

DiscoverLearnRead beyondPapers & lecturesYour turn

Your turn

You've met span, independence, bases and dimension. Now use them: match sets of vectors to their spans and notation to code, assemble a proof and write one, then solve three problems in code.

Match · Vectors ↔ Their span

What does the span look like?

+25 XP

Match each set of vectors to the shape of its span. Watch for vectors that add nothing new.

{(0,0)}\{(0, 0)\}
{(2,1)}\{(2, 1)\}
{(1,3),(2,6)}\{(1, 3), (2, 6)\}
{(1,0),(1,1)}\{(1, 0), (1, 1)\}
{(1,0,0),(0,0,1)}\{(1, 0, 0), (0, 0, 1)\}
{(1,1,0),(0,0,1),(1,1,1)}\{(1, 1, 0), (0, 0, 1), (1, 1, 1)\}
{(1,0,0),(0,1,0),(0,0,1),(1,2,3)}\{(1, 0, 0), (0, 1, 0), (0, 0, 1), (1, 2, 3)\}

Options

Match · Maths ↔ Python

From symbols to NumPy

+25 XP

Match each piece of notation to the code that computes it. In the code, B holds the basis vectors as its columns, A holds a1,…,ak\mathbf{a}_1, \ldots, \mathbf{a}_k as its columns, and c is a coordinate vector.

c1v1+c2v2c_1\mathbf{v}_1 + c_2\mathbf{v}_2
det⁡[u v]≠0\det[\mathbf{u}\ \mathbf{v}] \neq 0
x=B [x]B\mathbf{x} = B\,[\mathbf{x}]_{\mathcal{B}}
[x]B[\mathbf{x}]_{\mathcal{B}}
dim⁡span{a1,…,ak}\dim \mathrm{span}\{\mathbf{a}_1, \ldots, \mathbf{a}_k\}
θ(D)=θ0(D)+P θ(d)\theta^{(D)} = \theta^{(D)}_0 + P\,\theta^{(d)}
the columns of PP scaled to length 1

Options

Proofs

The first proof explains why coordinates in a basis are well defined: put its lines in order and leave out the two that don't belong. The second you write yourself.

Proof puzzle

Coordinates in a basis are unique

+25 XP

Claim

Let B=(b1,…,bn)\mathcal{B} = (\mathbf{b}_1, \ldots, \mathbf{b}_n) be a basis of a subspace UU. Then every x∈U\mathbf{x} \in U can be written as c1b1+⋯+cnbnc_1\mathbf{b}_1 + \cdots + c_n\mathbf{b}_n in only one way.

Tap lines in the order they should appear. Not every line belongs. Tap a line in your proof to send it back.

Your proof

  1. Pick the first line below.

Available lines

Prove it yourself

Sum and difference stay independent

+40 XP

Claim

If u\mathbf{u} and v\mathbf{v} are linearly independent, then so are u+v\mathbf{u} + \mathbf{v} and u−v\mathbf{u} - \mathbf{v}.

Preview

Your typeset proof appears here.

Code it up

Three problems in the Project Euler style: each has a single answer. The second applies the intrinsic-dimension paper's toy problem, and the third runs the sifting algorithm from this chamber.

Problem 7·Warm-up

Independent pairs on a small grid

+20 XP

Let S={−2,−1,0,1,2}S = \{-2, -1, 0, 1, 2\}. Consider every ordered pair of vectors (u,v)(\mathbf{u}, \mathbf{v}) with u=(u1,u2)\mathbf{u} = (u_1, u_2) and v=(v1,v2)\mathbf{v} = (v_1, v_2), where each of the four entries u1,u2,v1,v2u_1, u_2, v_1, v_2 is chosen from SS. There are 54=6255^4 = 625 such pairs, including pairs with u=v\mathbf{u} = \mathbf{v} and pairs where a vector is 0\mathbf{0}.

How many of the 625 pairs are linearly independent, so that span{u,v}=R2\mathrm{span}\{\mathbf{u}, \mathbf{v}\} = \mathbb{R}^2?

An exact integer (or a fraction like 7/12)

Problem 8·Standard

Unfreezing one weight at a time

+35 XP

Li et al. (2018) warm up with a toy problem. There are D=1000D = 1000 parameters θ1,…,θ1000\theta_1, \ldots, \theta_{1000}, split into 10 groups of 100 consecutive ones: group gg holds θ100(g−1)+1,…,θ100g\theta_{100(g-1)+1}, \ldots, \theta_{100g}. A parameter vector is a solution when, for every g=1,…,10g = 1, \ldots, 10, the parameters in group gg add up to exactly gg.

The paper trains in a dense random subspace, θ=θ0+Pθ(d)\theta = \theta_0 + P\theta^{(d)}. Try a cheaper-looking alternative instead: unfreeze individual parameters one at a time. Start from θ0=0\theta_0 = \mathbf{0}. At step k=1,2,3,…k = 1, 2, 3, \ldots unfreeze parameter number jk=xk+1j_k = x_k + 1, where

x0=0,xk=(61 xk−1+13) mod 1000.x_0 = 0, \qquad x_k = (61\,x_{k-1} + 13) \bmod 1000.

This sequence visits all 1000 indices without repeating, so after dd steps exactly dd parameters are free, and training may only move within the dd-dimensional subspace θ0+span{ej1,…,ejd}\theta_0 + \mathrm{span}\{\mathbf{e}_{j_1}, \ldots, \mathbf{e}_{j_d}\}, where ej\mathbf{e}_j is the jj-th standard basis vector of R1000\mathbb{R}^{1000}.

What is the smallest dd for which this subspace contains a solution?

An exact integer (or a fraction like 7/12)

Problem 9·Challenge

Sifting redundant features

+50 XP

A dataset has 8 examples, indexed by t=1,2,…,8t = 1, 2, \ldots, 8. An eager engineer computes 15 features for each one. Feature fif_i gives the vector (fi(1),fi(2),…,fi(8))∈R8(f_i(1), f_i(2), \ldots, f_i(8)) \in \mathbb{R}^8, where

f1=1f2=tf3=t mod 2f4=⌊t/2⌋f5=(−1)tf6=t2f7=(t−4)2f8=t mod 3f9=2tf10=∏k=18(t−k)f11=⌊t/3⌋f12=t3f13=2t+t2f14=t mod 4f15=t4\begin{array}{lll} f_1 = 1 & f_2 = t & f_3 = t \bmod 2 \\ f_4 = \lfloor t/2 \rfloor & f_5 = (-1)^t & f_6 = t^2 \\ f_7 = (t - 4)^2 & f_8 = t \bmod 3 & f_9 = 2^t \\ f_{10} = \prod_{k=1}^{8} (t - k) & f_{11} = \lfloor t/3 \rfloor & f_{12} = t^3 \\ f_{13} = 2^t + t^2 & f_{14} = t \bmod 4 & f_{15} = t^4 \end{array}

Many of them are secretly redundant. Run the sifting algorithm from this chamber: go through f1,f2,…,f15f_1, f_2, \ldots, f_{15} in order, and keep fif_i if it is not in the span of the features kept so far (so f1f_1 is kept unless it is the zero vector). Otherwise discard it.

What is the sum of the indices ii of the features you keep?

An exact integer (or a fraction like 7/12)

Key takeaways

  • The span of some vectors is every linear combination of them. It's always a subspace: a point, a line, a plane or more, through the origin.
  • Independent vectors have no dead weight: only the all-zero combination gives 0\mathbf{0}. For two vectors in the plane, that's u1v2−u2v1≠0u_1v_2 - u_2v_1 \neq 0.
  • A basis is independent and spanning, so every vector has unique coordinates [x]B[\mathbf{x}]_{\mathcal{B}} in it. Changing basis changes the ruler, not the vector.
  • Dimension is the size of any basis. In Rn\mathbb{R}^n, more than nn vectors are dependent and fewer than nn can't span, and each independent linear equation removes one dimension.
  • Networks have small intrinsic dimension: Li et al. trained in random subspaces θ0+Pθ(d)\theta_0 + P\theta^{(d)} and found that a few hundred directions often suffice, an idea that led to LoRA.

Checkpoint

Prove it to the labyrinth

Answer every question to clear this chamber. First-try answers earn the most XP.

0/8
Question 1 of 8 +20 XP

In the basis B=((1,1),(1,−1))\mathcal{B} = ((1, 1), (1, -1)), the vector x=(7,1)\mathbf{x} = (7, 1) has coordinates [x]B=(c1,c2)[\mathbf{x}]_{\mathcal{B}} = (c_1, c_2). What is c1c_1?

Question 2 of 8 +20 XP

For which number kk are (2,3)(2, 3) and (4,k)(4, k) linearly dependent?

Question 3 of 8 +20 XP

Which list is a basis of R2\mathbb{R}^2?

Question 4 of 8 +20 XP

Which of these sets is not a subspace of R3\mathbb{R}^3?

Question 5 of 8 +20 XP

You have four vectors in R3\mathbb{R}^3. What can you conclude for certain?

Question 6 of 8 +20 XP

A list of vectors includes the zero vector 0\mathbf{0}. Can the list be linearly independent?

Question 7 of 8 +20 XP

Li et al. write D=dint+sD = d_{\text{int}} + s. A model has D=5000D = 5000 parameters, and its solution set is a flat set of dimension s=4968s = 4968. What is its intrinsic dimension dintd_{\text{int}}?

Question 8 of 8 +20 XP

In the toy problem (D=1000D = 1000, ten group-sum constraints, dint=10d_{\text{int}} = 10), Li et al. train in random subspaces θ=θ0+Pθ(d)\theta = \theta_0 + P\theta^{(d)} of increasing dimension dd. What do they observe?

End of the chamber

Clear this chamber

+60 XPSpanLinear IndependenceBasisDimension