【Study Notes】Mathematics for Machine Learning: Linear Algebra (Week 2)

Introduction

This is a study note of the course Mathematics for Machine Learning: Linear Algebra on the coursera. In week 2 section, we will look at vector’s modulus, and look at a way to combine vectors together to get the dot product, which can take us on to find the scalar and vector projections. In addition, basis vector and vector space will be defined in this section, and we will learn how to prove linear independence and linear combination.

Modulus

Modulus is length of a vector, so if a vector is given r=ai^+bj^=[ab]r=a\hat i+b\hat j = \begin{bmatrix} a\\b\\ \end{bmatrix}, the modulus of vector rr is equal to r=a2+b2|r| = \sqrt{a^2+b^2} . In addition, we also use dot product to get the modulus of a vector, i.e. we can get the modulus of a vector by the vector dotted by itself, r2=rr=[ab][ab]=a2+b2|r|^2=r\cdot r= \begin{bmatrix} a\\b\\ \end{bmatrix}\cdot \begin{bmatrix} a\\b\\ \end{bmatrix}=a^2+b^2 .
在這裏插入圖片描述

Dot Product

The dot product is a scalar number given by multiplying the components of the vector in turn, and adding those up. e.g. given two vector r=[r1r2rn]r = \begin{bmatrix}r_1\\r_2\\ \vdots \\r_n\\ \end{bmatrix} and s=[s1s2sn]s = \begin{bmatrix}s_1\\s_2\\\vdots\\s_n\\ \end{bmatrix}, we can find the dot product is rs=r1s1+r2s2++rnsnr\cdot s =r_1s_1+r_2s_2+\cdots+r_ns_n .

  • commutative: rsr\cdot s is equal to srs\cdot r .
  • distributive: r(s+t)r\cdot (s+t) is equal to rs+rtr\cdot s+r\cdot t .
  • associative: r(as)r\cdot(as) is equal to a(rs)a(r\cdot s), where aa is a scalar.

Interestingly, if we take the dot product of a vector with itself, we can get the square of its size of its modulus. i.e. r2=rr=[ab][ab]=a2+b2|r|^2=r\cdot r= \begin{bmatrix} a\\b\\ \end{bmatrix}\cdot \begin{bmatrix} a\\b\\ \end{bmatrix}=a^2+b^2.

Cosine & Dot Product

Let’s start from a right triangle. For a right triangle, it have 3 egdes, respectively called legs if the side adjacent to the right angle, and called hypotenuse if the side oppsite the right angle.
在這裏插入圖片描述
According consine rule, we get a equation.
c2=a2+b22abcosθc^2=a^2+b^2-2ab\cos\theta
Then we define a vector ss and a vector rr as the following figure.
在這裏插入圖片描述
rs2=r2+s22rscosθ(1)|r-s|^2=|r|^2+|s|^2-2|r||s|\cos\theta \tag{1}
Let’s make dot product of rsr-s with itself.
(rs)(rs)=rrsrsr+ss=r22sr+s2(2)\begin{aligned} (r-s)\cdot(r-s)&=r\cdot r-s\cdot r-s\cdot r+s\cdot s\\ &=|r|^2-2s\cdot r + |s|^2\tag{2}\\ \end{aligned}
Then, we do that comparison between (1)(1) and (2)(2).
rs=rscosθr\cdot s=|r||s|\cos\theta

  • rs=rscosθr\cdot s=|r||s|\cos\theta
  • θ=90\theta=90^\circ, rs=rscosθ=0r\cdot s=|r||s|\cos\theta=0.
  • θ=0\theta=0^\circ, rs=rscosθ=rsr\cdot s=|r||s|\cos\theta=|r||s|
  • θ=180\theta=180^\circ, rs=rscosθ=rsr\cdot s=|r||s|\cos\theta=-|r||s|

Vector Projection

Given two vector as following figure, we can make the projection of the vector ss onto the vector rr.
在這裏插入圖片描述
Obviously, we can get cosθ=adjhyp=adjs\cos\theta={\text{adj}\over{\text{hyp}}}={{\text{adj}}\over{|s|}} in the right triangle.
In addition, we use dot product to get a equation rs=rscosθr\cdot s = |r||s|\cos\theta.
So, scosθ=rsr|s|\cos\theta={{r\cdot s}\over{|r|}} is used to take the scalar projection of vetor ss onto the vector rr.
We also can get the vector projection by using rsrr×r=rsrr×r{{r\cdot s} \over {|r||r|}}\times r={{r\cdot s} \over {r\cdot r}}\times r.

  • scalar projection: scosθ=rsr|s|\cos\theta={{r\cdot s}\over{|r|}}
  • vector projection: rsrr×r=rsrr×r{{r\cdot s} \over {|r||r|}}\times r={{r\cdot s} \over {r\cdot r}}\times r

Linear Dependence & Independence

Linear Dependence

Vectors are linearly dependent if it is possible to write one vector as a linear combination of the others. For example, the vectors aa, bb and cc are linearly dependent if a=q1b+q2ca=q_1b+q_2c where q1q_1 and q2q_2 are scalars.

Linear Independence

We say that two vectors are linearly independent if they are not linearly dependent, that is, we cannot write one of the vectors as a linear combination of the others.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章