Continued from Norms and Spaces.

Orthogonal Vectors

In an inner product space (𝑉,.,.), two vectors 𝒗𝒊 and 𝒗𝒋 are said to be orthogonal if 𝒗𝒊,𝒗𝒋=0
For ex. vectors (1,0,0),(0,1,0) are orthogonal in 3() with the inner product taken as the usual dot product of vectors (we have explicitly defined the inner product to be the dot product here).

Orthogonal complement

Let 𝑉 be an inner product space, and 𝑊𝑉, then the orthogonal complement of W, denoted by 𝑊 is the set of vectors in V that are orthogonal to every element in W.
For all vectors 𝒘𝑊:
𝑊={𝒗𝑉|𝒗𝒘}
Ex. in 3 with the inner product taken as the usual dot product of vectors in 3, if we take 𝑊={(1,0,0),(0,1,0)}, then the orthogonal complement of W is 𝑊=span{(0,0,1)}.

  • There is no requirement on 𝑊 to be a subspace of 𝑉. However, 𝑊 is always a subspace of 𝑉. (WHY?)
  • If 𝑊 is also a subspace of 𝑉, then 𝑉=𝑊𝑊. This means that every vector 𝒗𝑉 can be uniquely written as 𝒗=𝒗𝑊+𝒗𝑊 where 𝒗𝑊𝑊and𝒗𝑊𝑊.

Orthonormal vectors: Two vectors are orthonormal if they are orthogonal and their norms are equal to 1, i.e. the vectors are unit vectors.

Orthogonal matrix

A square matrix 𝑨𝑛×𝑛 is an orthogonal matrix if and only if its columns are orthonormal so that 𝑨𝑨𝑇=𝐼=𝑨𝑇𝑨, which implies that 𝑨1=𝑨𝑇. So the inverse is obtained simply by taking the transpose of the matrix.
Transformations with orthogonal matrices are special because the length of a vector 𝒙 is not changed when transforming it using an orthogonal matrix 𝑨.
For the dot product, we obtain:𝑨𝒙2=(𝑨𝒙)𝑇(𝑨𝒙)=𝒙𝑇𝑨𝑇𝑨𝒙=𝒙2(𝑨𝑩)𝑇=𝑩𝑇𝑨𝑇
Moreover, the angle between two vectors measure via their inner product (see Norms and Spaces for the formula) is also unchanged when transforming (replacing x with Ax for ex.) both of them using an orthogonal matrix.
This means that these matrices define transformations that are rotations.

Orthogonal basis

In an n-dimensional space, we need n basis vectors, i.e. n vectors that are linearly independent. Consider now an n-dimensional vector space 𝑉 and a basis {𝒃1,,𝒃𝑛} of 𝑉. If
𝒃𝑖𝒃𝑗=0for𝑖𝑗
we call it an orthogonal basis. Additionally, if 𝒃𝑖𝒃𝑗=1 we call it an orthonormal basis. In an orthonormal basis, every basis vector has a length/norm = 1.

Orthogonal projection

Let 𝑉 be an inner product space and 𝑊 be a subspace of 𝑉. Also, let {𝒘1,,𝒘𝑛} be an orthogonal basis of 𝑊. (This means that all the vectors in the basis are orthogonal to each other.) Now, the linear mapping

𝑃𝑊:𝑉𝑊𝑃𝑊(𝒗)=𝒗,𝒘1𝒘1𝒘1𝒘1++𝒗,𝒘𝑛𝒘𝑛𝒘𝑛𝒘𝑛

is called the orthogonal projection onto 𝑊.

Think

What does this formula even mean? Let’s see. Whenever we want to imagine many vectors, it’s better to imagine them as points in a space. I know that the inner product is a generalisation of the dot product. For simplicity’s sake let me treat it as the dot product right now. I also know that the 𝒘‘s are just basis vectors in a space 𝑊. Those 𝒘‘s are being summed here. Whenever I take a “linear combination” of basis vectors, the space that the resultant vector lives in is the area “spanned” by the basis vectors, or the span of those vectors. And the numerator in each individual expression is a scalar (because of dot product), the denominator is a scalar too. That means the fractional part is a scalar. What does a scalar being multiplied with a vector 𝒘 do? It literally scales the vector 𝒘 along the direction of 𝒘 itself. This means that we are taking a linear combination of scaled basis vectors to generate another vector. Where does this new vector live? It lives in the area spanned by those basis vectors, which is the subspace 𝑊 itself. Now imagine the vector 𝒗 as a point in space and the subspace 𝑊 as a floor below it. Drop a straight line from 𝒗 to its projection 𝑃𝑊(𝒗). This is the shortest distance from that vector to the space (proof below). The distance between the vector 𝒗 and any general vector 𝒘 is the norm of 𝒗𝒘. Now go read the fifth property below and see what it’s trying to say, It says that the distance between the vector and its projection is always lesser than or equal to the distance between the vector and any random vector in that same subspace.

ex. (plug and chug): Let 𝒘1=(3,0,1) and 𝒘2=(0,1,0). 𝑊=span{𝒘1,𝒘2}. Take a vector 𝒗=(0,3,10)3 and define the inner product to be the usual dot product. Then 𝑃𝑊(𝒗)=𝒗,𝒘1𝒘1𝒘1𝒘1+𝒗,𝒘2𝒘2𝒘2𝒘2 which is equal to 𝑃𝑊(𝒗)=(1010)(3,0,1)+(31)(0,1,0)=(3,3,1).

Some properties; for all 𝒗𝑉,𝒘𝑊:

  1. 𝒗𝑃𝑊(𝒗)𝑊 or 𝒗𝑃𝑊(𝒗)𝑊
  2. 𝑃𝑊(𝒘)=𝒘
  3. 𝑃2𝑊=𝑃𝑊
  4. 𝑃𝑊(𝒗)𝒗
  5. 𝒗𝑃𝑊(𝒗)𝒗𝒘 (see below)

ex. Find the closest point to 𝒗=(2,4,0,2) in 𝑊=span{(1,1,0,0),(0,0,1,1)}.
Let 𝒘1=(1,1,0,0);𝒘2=(0,0,1,1). We choose the inner product to be the dot product here.
𝑃𝑊(𝒗)=(3,3,1,1) (I used a pen and paper for this.) is the closest point to the given vector in 𝑊.

Proof: The closest point to the vector 𝒗 is 𝑃𝑊(𝒗).

  1. How do we determine if it’s the closest point? Let’s imagine this. If 𝒗 is a vector and 𝑃𝑊(𝒗) is its projection in a vector space 𝑊, it is the closest point to that vector if the line joining them is exactly 90 degrees, or the line and the plane are orthogonal. If we imagine the vector 𝒗 as floating above the floor 𝑊, and dropping a straight line at 90 degrees on the floor, the point where it hits the floor is the projection vector.
  2. Now that we know that the line should be 90 degrees, what even is the line. Let’s take a vector 𝒗𝑃𝑊(𝒗) as the vector 𝒆. This “error vector” is the vector of that points from the floor up to the vector floating in the air. Now this error vector’s dot product with the vectors that form the plane below it should be 0 (for it to be orthogonal). What vectors form the plane below? The plane below 𝑊 is just a span of all the different basis vectors. So I can take 𝒘𝑖 where the 𝒘𝑖 is any basis vector. Recall that this is an orthogonal basis, so 𝒘𝟏𝒘𝟐 for example is zero.
  3. (𝒗𝑃𝑊(𝒗))𝒘𝑖=𝒗𝒘𝑖(𝑃𝑊(𝒗)𝒘𝑖)
  4. Let’s expand the second expression a little bit. 𝑃𝑊(𝒗)𝑤1=((𝒗𝒘1𝒘1𝒘1)𝒘1+(𝒗𝒘2𝒘2𝒘2)𝒘2+)𝒘1=(𝒗𝒘1𝒘1𝒘1)𝒘1𝒘1=𝒗𝒘1. This is because of it being an orthogonal basis and the dot product of 𝒘1 with 𝒘‘s other than itself being zero. This holds true for any basis vector 𝒘𝑖.
  5. So on the left expression we get 𝒗𝒘𝑖 and on the right expression we get the same because of all the different 𝒘‘s we multiply 𝑃𝑊(𝒗) with. Hence, their difference is 0.
  6. Because the dot product is zero, the two (sets of) vectors are orthogonal and hence the distance is the shortest.

Think

Take a vector 𝒗 floating in space. Take its projection 𝑃𝑊(𝒗) and drop a line from the vector to its projection. Now take an arbitrary vector along the plane (floor) of the projection (the subspace 𝑊) and call that vector 𝒘. Now connect the projection with this vector, and the floating point with this vector. Now you have a right angled (just proved) triangle. Take the distance from the vector to the projection to be 𝑎, the distance from the projection to be 𝑏 and the distance between the vectors 𝒗 and 𝒘 to be 𝑐. (Note that 𝑎,𝑏,𝑐 are norms here but I am omitting the because I don’t want to be that verbose here.) Now consider the Pythagorean theorem: 𝑎2+𝑏2=𝑐2
The distance between the projection and the arbitrary vector was 𝑏 and norm squared can be 0. So the distance 𝑐𝑎0 or 𝑎𝑐, which is exactly what property 5 says above.

General projection

A linear mapping 𝜋:𝑉𝑊 that satisfies 𝜋2=𝜋𝜋=𝜋 is called a projection. Such linear mappings are expressed by transformation matrices, the projection matrices 𝑷𝜋 where 𝑷2𝜋=𝑷𝜋.

Projection onto one-dimensional subspaces (lines)

If we are given a line (1D subspace) through the origin with a basis vector 𝒃𝑛, the line is a one dimensional subspace 𝑈𝑛 spanned by 𝒃. When we project 𝒙𝑛 onto 𝑈, we seek the vector 𝜋𝑈(𝒙)𝑈 that is closest to 𝒙. This figure is useful for visualizing such projections.

Using geometric arguments,

  • the projection is closest to 𝒙 when the distance 𝒙𝜋𝑈(𝒙) is minimal. The segment 𝜋𝑈(𝒙)𝒙 from 𝜋𝑈(𝒙) to 𝒙 is orthogonal to 𝑈 and therefore the basis vector 𝒃 of 𝑈. The orthogonality condition yields 𝜋𝑈(𝒙)𝒙,𝒃=0 since angles between vectors are defined via the inner product.
  • the projection 𝜋𝑈(𝒙) must be an element of 𝑈 and therefore a multiple of the basis vector; hence 𝜋𝑈(𝒙)=𝜆𝒃.

Step A: Finding the coordinate 𝜆
Since 𝜋𝑈(𝒙)𝒙,𝒃=0 we can have 𝜆𝒙𝒙,𝒃=0 and then we can use the billinearity of the inner product to have 𝜆𝒃,𝒃𝒙,𝒃=0. (If you are confused about billinearity just choose the inner product to be the dot product and solve the first equation with the dot product.) Thus we have 𝜆=𝒙,𝒃𝒃,𝒃=𝒙,𝒃𝒃2

Step B: Finding the projection point 𝜋𝑈(𝒙)
Since 𝜋𝑈(𝒙)=𝜆𝒃 we can have 𝜋𝑈(𝒙)=𝒙,𝒃𝒃2𝒃=𝒃𝑇𝒙𝒃2𝒃 where the last equality holds true if the inner product is chosen to be the dot product. If we choose the inner product to be the dot product, the following relation holds: 𝜋𝑈(𝒙)=|cos𝜔|𝒙, where 𝜔 is the angle between the vectors 𝒙 and 𝒃. An illustration is shown in (b) of above figure.

Step C: Finding the projection matrix 𝑷𝜋
since 𝜋𝑈(𝒙)=𝜆(𝒃)=𝒃𝜆=𝒃(𝒃𝑇𝒙𝒃2) if we set the inner product to be the dot product. We see that:
𝑷𝜋=𝒃𝒃𝑇𝒃2

Projections onto general subspaces

Here we will look at projections of vectors 𝒙𝑛 onto lower dimensional subspaces 𝑈𝑛 with dim(𝑈)1. The illustration for this projection is given below.

Assume that (𝒃1,,𝒃𝑛) is an ordered basis of 𝑈. Any projection 𝜋𝑈(𝒙) onto 𝑈 is necessarily an element of 𝑈. Therefore, it can be represented as a linear combination of the basis vectors such that 𝜋𝑈(𝒙)=𝑛𝑖=1𝜆𝑖𝒃𝑖.
We can follow a three step procedure again to find the projection and the projection matrix. Note that 𝑩=[𝒃1,,𝒃𝑛] is a matrix whose columns are the vectors 𝒃1,,𝒃𝑛. And also remember that the vector 𝝀 represents the coordinate.

  1. Find the coordinates 𝜆1,,𝜆𝑛 of the projection (with respect to the basis of 𝑈) such that the linear combination 𝜋𝑈(𝒙)=𝑛𝑖=1𝜆𝑖𝒃𝑖=𝑩𝝀 (where 𝑩,𝝀 are matrices and 𝑩=[𝒃1,,𝒃𝑛]𝑛×𝑚, 𝝀=[𝜆1,,𝜆𝑛]𝑇𝑚) is closest to 𝒙𝑛. Closest means minimum distance again, which implies that the vector connecting the projection to the original vector, 𝒙𝜋𝑈(𝒙) is orthogonal to all basis vectors of 𝑈. We can thus say that 𝒃1,𝒙𝜋𝑈(𝒙)=0;;𝒃𝑛,𝒙𝜋𝑈(𝒙)=0 for which we get n simultaneous conditions. Now let’s choose the inner product to be the dot product, and we obtain 𝒃𝑇1(𝒙𝜋𝑈(𝒙))=0;;𝒃𝑇𝑛(𝒙𝜋𝑈(𝒙))=0 following the dot product. Using the aforementioned equation, we can write 𝒃𝑇1(𝒙𝑩𝝀)=0;;𝒃𝑇𝑛(𝒙𝑩𝝀)=0. And since this is of the form 𝒃𝑇1(𝒙𝑩𝝀)=0𝒃𝑇𝑛(𝒙𝑩𝝀)=0(𝒃𝑇1𝒃𝑇𝑛)(𝒙𝑩𝝀)=𝟎𝑩𝑇(𝒙𝑩𝝀)=𝟎𝑩𝑇𝑩𝝀=𝑩𝑇𝒙 This allows us to solve for the coefficients or coordinates, 𝝀=(𝑩𝑇𝑩)1𝑩𝑇𝒙.
  2. Find the projection. We have already established that 𝜋𝑈(𝒙)=𝑩𝝀. Thus, 𝜋𝑈(𝒙)=𝑩(𝑩𝑇𝑩)1𝑩𝑇𝒙.
  3. Find the projection matrix. 𝑷𝜋=𝑩(𝑩𝑇𝑩)1𝑩𝑇.

Projections allow us to look at situations where we have a linear system 𝑨𝒙=𝒃 without a solution. This means that 𝒃 does not lie in the span of 𝑨, i.e. the vector 𝒃 does not lie in the subspace spanned by the columns of 𝑨. In these cases we need an approximate solution. The idea is to find the vector in the subspace spanned by columns of 𝑨 that is closest to 𝒃, i.e. we compute the orthogonal projection of 𝒃 onto the subspace spanned by columns of 𝑨. The solution here is called the least-squares solution of an overdetermined system, as we assume the dot product to be the inner product.

A teaser for machine learning

In that floor analogy above, think of the subspace 𝑊 now, or the floor, as the space of all possible predictions of a machine learning model. Think of the vector 𝒗 as the “true” feature vector we want to have a prediction of. In some models, we use this and we want to find out the most accurate prediction. The most accurate prediction geometrically is the closest point on that floor or plane to the feature vector. This is also the reason we briefly called 𝒗𝑃𝑊(𝒗) as the “error” vector, because it represents how off the model is from the prediction.