+ - 0:00:00
Notes for current slide
Notes for next slide

Geometry of Matrices

High Dimensional Data Analysis

Anastasios Panagiotelis & Ruben Loaiza-Maya

Lecture 9

1

Why?

2

Why vectors and matrices?

  • Nearly all the methods we cover involve vectors and matrices.
3

Why vectors and matrices?

  • Nearly all the methods we cover involve vectors and matrices.
  • The earlier lecture on matrices may have felt like it involved remembering many seemingly arbitrary rules.
3

Why vectors and matrices?

  • Nearly all the methods we cover involve vectors and matrices.
  • The earlier lecture on matrices may have felt like it involved remembering many seemingly arbitrary rules.
  • The aim of this lecture is to understand the geometric interpretation of vectors which is crucial in making the connection between data, data analysis and visualisation.
3

Why vectors and matrices?

  • Nearly all the methods we cover involve vectors and matrices.
  • The earlier lecture on matrices may have felt like it involved remembering many seemingly arbitrary rules.
  • The aim of this lecture is to understand the geometric interpretation of vectors which is crucial in making the connection between data, data analysis and visualisation.
  • Matrices are important to gain a deep understanding about dimension reduction.
3

Vectors

  • We will think of a 2-dimensional vector in one of three ways:
4

Vectors

  • We will think of a 2-dimensional vector in one of three ways:
    • A point in 2-dimensional space
4

Vectors

  • We will think of a 2-dimensional vector in one of three ways:
    • A point in 2-dimensional space
    • An arrow pointing to that point in 2-dimensional space
4

Vectors

  • We will think of a 2-dimensional vector in one of three ways:
    • A point in 2-dimensional space
    • An arrow pointing to that point in 2-dimensional space
    • An array of 2 numbers
4

Vectors

  • We will think of a 2-dimensional vector in one of three ways:
    • A point in 2-dimensional space
    • An arrow pointing to that point in 2-dimensional space
    • An array of 2 numbers
  • All of these ideas work for n-dimensional vectors where n can be 3,4 or any number
4

Vectors

  • We will think of a 2-dimensional vector in one of three ways:
    • A point in 2-dimensional space
    • An arrow pointing to that point in 2-dimensional space
    • An array of 2 numbers
  • All of these ideas work for n-dimensional vectors where n can be 3,4 or any number
  • By convention all vectors in this lecture are column vectors.
4

Vectors as points

5

Vectors as points

6

Vectors as arrows

7

Vectors as arrows

8

Vectors as numbers

In general a vector is:

v=[xy]

For our two examples.

v1=[12]andv2=[31]

9

Data as a vector

  • Consider two examples:
10

Data as a vector

  • Consider two examples:
    • The vector v corresponds to a cage where x measures the number of chickens and y measures the number of rabbits.
10

Data as a vector

  • Consider two examples:
    • The vector v corresponds to a cage where x measures the number of chickens and y measures the number of rabbits.
    • The vector v corresponds to a country where x measures the trade deficit in 2016 and y measures trade deficit in 2017.
10

Data as a vector

  • Consider two examples:
    • The vector v corresponds to a cage where x measures the number of chickens and y measures the number of rabbits.
    • The vector v corresponds to a country where x measures the trade deficit in 2016 and y measures trade deficit in 2017.
  • Notice that if we have many cages or countries and plot each of these vectors as points we get a scatterplot
10

Vectors as points

11

Vector Operations

  • There are two fundamental operations that we can do with vectors
12

Vector Operations

  • There are two fundamental operations that we can do with vectors
    • Vector addition
12

Vector Operations

  • There are two fundamental operations that we can do with vectors
    • Vector addition
    • Scalar multiplication
12

Vector Operations

  • There are two fundamental operations that we can do with vectors
    • Vector addition
    • Scalar multiplication
  • We will look at each of these:
12

Vector Operations

  • There are two fundamental operations that we can do with vectors
    • Vector addition
    • Scalar multiplication
  • We will look at each of these:
    • Geometrically (with pictures) and
12

Vector Operations

  • There are two fundamental operations that we can do with vectors
    • Vector addition
    • Scalar multiplication
  • We will look at each of these:
    • Geometrically (with pictures) and
    • Algebraically (with numbers)
12

Vector Addition

13

The other way

14

Vector Addition: Geometry

  • The operation of adding two vectors is simply to slide one along the other.
15

Vector Addition: Geometry

  • The operation of adding two vectors is simply to slide one along the other.
  • This is called translation
15

Vector Addition: Geometry

  • The operation of adding two vectors is simply to slide one along the other.
  • This is called translation
  • The order of adding vectors does not matter v1+v2=v2+v1
15

Vector Addition: Geometry

  • The operation of adding two vectors is simply to slide one along the other.
  • This is called translation
  • The order of adding vectors does not matter v1+v2=v2+v1
  • This property is called commutativity
15

With lots of points

16

Vector Additions: Numbers

Vector addition is as simple as adding up the corresponding numbers

[12]+[31]=[1+32+1]=[43]

17

Vector Additions: Numbers

Vector addition is as simple as adding up the corresponding numbers

[12]+[31]=[1+32+1]=[43]

18

Vector Additions: Numbers

Vector addition is as simple as adding up the corresponding numbers

[12]+[31]=[1+32+1]=[43]

19

Vector Additions: Numbers

Vector addition is as simple as adding up the corresponding numbers

[12]+[31]=[1+32+1]=[43]

20

Vector Addition and Data

  • Vector addition can be meaningful for data.
21

Vector Addition and Data

  • Vector addition can be meaningful for data.
  • If I add a cage with 1 chicken and 3 rabbits to another cage with 2 chickens and 1 rabbits what do I get?
21

Vector Addition and Data

  • Vector addition can be meaningful for data.
  • If I add a cage with 1 chicken and 3 rabbits to another cage with 2 chickens and 1 rabbits what do I get?
    • A cage with 3 chickens and 4 rabbits.
21

Vector Addition and Data

  • Suppose Australia had a trade deficit of $US1bn in 2016 and $US3bn in 2017 and New Zealand had a trade deficit of $US2bn in 2016 and $US1bn in 2017.
22

Vector Addition and Data

  • Suppose Australia had a trade deficit of $US1bn in 2016 and $US3bn in 2017 and New Zealand had a trade deficit of $US2bn in 2016 and $US1bn in 2017.
  • Australia and New Zealand merge to form a currency union and the trade deficit statistics need to be updated.
22

Vector Addition and Data

  • Suppose Australia had a trade deficit of $US1bn in 2016 and $US3bn in 2017 and New Zealand had a trade deficit of $US2bn in 2016 and $US1bn in 2017.
  • Australia and New Zealand merge to form a currency union and the trade deficit statistics need to be updated.
    • The new currency union had a trade deficit of $US3bn in 2016 and $US4bn in 2017.
22

Scalar multiplication

  • If we add a number c times we call that multiplication
23

Scalar multiplication

  • If we add a number c times we call that multiplication
  • We do something similar with vectors.
23

Scalar multiplication

  • If we add a number c times we call that multiplication
  • We do something similar with vectors.
  • If we add a vector to itself c times this is called scalar multiplication.
23

Scalar multiplication

  • If we add a number c times we call that multiplication
  • We do something similar with vectors.
  • If we add a vector to itself c times this is called scalar multiplication.
  • We are multiplying a vector by a single number and NOT by another vector.
23

Scalar multiplication

  • If we add a number c times we call that multiplication
  • We do something similar with vectors.
  • If we add a vector to itself c times this is called scalar multiplication.
  • We are multiplying a vector by a single number and NOT by another vector.
  • This is very different from matrix multiplication.
23

Scalar multiply by 2

24

Scalar multiply by 0.5

25

Scalar multiplication by 2

26

Scalar multiplication by 0.5

27

Scalar multiplication by 2

2v1=2[12]=[2×12×2]=[24]

28

Scalar multiplication by 0.5

0.5v2=0.5[31]=[0.5×30.5×1]=[1.50.5]

29

Scalar multiplication and data

  • How might scalar multiplication be relevant to data?
30

Scalar multiplication and data

  • How might scalar multiplication be relevant to data?
  • Suppose trade deficit is measured in Chinese Yuan instead of $US where 6 Yuan = $US1.
30

Scalar multiplication and data

  • How might scalar multiplication be relevant to data?
  • Suppose trade deficit is measured in Chinese Yuan instead of $US where 6 Yuan = $US1.
  • Then we can get the trade defcit in Yuan by multiplying by the scalar 6.
30

Scalar multiplication and data

  • How might scalar multiplication be relevant to data?
  • Suppose trade deficit is measured in Chinese Yuan instead of $US where 6 Yuan = $US1.
  • Then we can get the trade defcit in Yuan by multiplying by the scalar 6.
  • Suppose Australia had a trade deficit of $US1bn in 2016 and $US3bn in 2017.
30

Scalar multiplication and data

  • How might scalar multiplication be relevant to data?
  • Suppose trade deficit is measured in Chinese Yuan instead of $US where 6 Yuan = $US1.
  • Then we can get the trade defcit in Yuan by multiplying by the scalar 6.
  • Suppose Australia had a trade deficit of $US1bn in 2016 and $US3bn in 2017.
    • This is equivalent to a trade deficit of 6bn Yuan in 2016 and 18bn Yuan in 2017.
30

Basis vector

  • Every vector can be created using
31

Basis vector

  • Every vector can be created using
    • Scalar multiplication
    • Vector addition
    • Two basis vectors
31

Basis vector

  • Every vector can be created using
    • Scalar multiplication
    • Vector addition
    • Two basis vectors
  • The basis vectors we use are:

b1=[10]andb2=[01]

31

How the basis works

  • Suppose we want the vector [xy]
  • This is given by

xb1+yb2 or x[10]+y[01]

32

Build a vector

33

Matrices

34

Matrices

  • You have learnt about matrices before as an array of numbers.
35

Matrices

  • You have learnt about matrices before as an array of numbers.
  • Today think about matrices as transforming points in space.
35

Matrices

  • You have learnt about matrices before as an array of numbers.
  • Today think about matrices as transforming points in space.
  • By multiplying a vector by a matrix, points in space are stetched, rotated and flipped around
35

Matrices

  • You have learnt about matrices before as an array of numbers.
  • Today think about matrices as transforming points in space.
  • By multiplying a vector by a matrix, points in space are stetched, rotated and flipped around
  • But what does this have to do with an array of numbers?
35

Example of a matrix

  • Consider the following matrix M=[5124]
  • Think of this as something that moves all the points in space to a new address.
  • It encodes where b1 and b2 get moved to.
36

Change of basis

Multiplying by the matrix M=[5124] will:

Move the vector b1=[10] to b1=[52]

Move the vector b2=[01] to b2=[14]

Matrix multiplication is a very different type of multiplication than scalar multiplication.

37

Change of basis

38

Old Basis

v=xb1+yb2=x[10]+y[01]=[xy]

39

New Basis

v=xb1+yb2=x[52]+y[14]=[5x+y2x+4y]

40

In general

Multiplying by the matrix M moves all vectors v to v

We can write this as:

v=Mv=[5124][xy]=[5x+y2x+4y]

Another way to think of it is as multiplying the rows of M by the column v

41

Matrix Multiplication in General

42

Matrix Multiplication and Data

An simple application of matrix multiplication is to create new variables.

  • Suppose we want a matrix to transform :
    • The number of chickens and number of rabbits to...
43

Matrix Multiplication and Data

An simple application of matrix multiplication is to create new variables.

  • Suppose we want a matrix to transform :
    • The number of chickens and number of rabbits to...
    • The number of heads and the number of feet.
43

Answer

  • First basis vector is the number of heads and feet of each chicken.
  • Second basis vector is the number of heads and feet of each rabbit.

[1124]

44

Another one

  • Suppose we want a matrix to transform:
    • The trade deficit in 2016 and trade deficit in 2017 to...
45

Another one

  • Suppose we want a matrix to transform:
    • The trade deficit in 2016 and trade deficit in 2017 to...
    • The average trade deficit from 2016 to 2017 and the change in the trade deficit between 2016 and 2017
45

Another one

  • Suppose we want a matrix to transform:
    • The trade deficit in 2016 and trade deficit in 2017 to...
    • The average trade deficit from 2016 to 2017 and the change in the trade deficit between 2016 and 2017

What does this matrix look like? Try yourselves.

45

Answer

  • First basis vector average and change if trade deficit was $1 in 2016 and $0 in 2017.
  • Second basis vector average and change if trade deficit was $0 in 2016 and $1 in 2017.

[0.50.511]

46

Non-Square Matrices

  • So far we have only considered 2×2 matrices.
  • These move every point in 2D space to another point in 2D space
  • However we can have a matrix with 3 rows and 2 columns (or 3×2 matrix).

M=[123456]

47

Non-square Matrices

Mz=[123456][xy]=x[135]+y[246]=[x+2y3x+4y5x+6y]

48

Non-square matrices

  • Matrix multiplication works in the same way
49

Non-square matrices

  • Matrix multiplication works in the same way
  • However the input is a 2-dimensional vector but the output is a 3-dimensional vector
49

Non-square matrices

  • Matrix multiplication works in the same way
  • However the input is a 2-dimensional vector but the output is a 3-dimensional vector
  • Multiplying by a non-square matrix changes the dimension
49

Non-square matrices

  • Matrix multiplication works in the same way
  • However the input is a 2-dimensional vector but the output is a 3-dimensional vector
  • Multiplying by a non-square matrix changes the dimension
  • The points will still lie in a two-dimensional subspace of three-dimensional space.
49

In factor analysis

  • For an example of this consider the factor model and in particular the component Λfi.
50

In factor analysis

  • For an example of this consider the factor model and in particular the component Λfi.
  • This takes a low-dimensional set of factors and maps them to a high-dimensional vector of data.
50

In factor analysis

  • For an example of this consider the factor model and in particular the component Λfi.
  • This takes a low-dimensional set of factors and maps them to a high-dimensional vector of data.
  • What about multiplying by a 2×3 matrix?
50

Dimension reduction

  • Multiplying by a 2×3 matrix takes a 3-dimensional vector and maps it to a point in 2-dimensional space.
51

Dimension reduction

  • Multiplying by a 2×3 matrix takes a 3-dimensional vector and maps it to a point in 2-dimensional space.
  • This is an example of dimension reduction
51

Dimension reduction

  • Multiplying by a 2×3 matrix takes a 3-dimensional vector and maps it to a point in 2-dimensional space.
  • This is an example of dimension reduction
  • For instance taking the first two principal component of data is the same as multiplying the data by a 2×p matrix
51

Matrix composition

  • What does it mean to multiply matrices?
52

Matrix composition

  • What does it mean to multiply matrices?
  • What does FG when G is a 4×2 matrix and F a 3×4 matrix?
52

Matrix composition

  • What does it mean to multiply matrices?
  • What does FG when G is a 4×2 matrix and F a 3×4 matrix?
  • It is as a composition of transformations:
52

Matrix composition

  • What does it mean to multiply matrices?
  • What does FG when G is a 4×2 matrix and F a 3×4 matrix?
  • It is as a composition of transformations:
    • Transform a 2-dimensional vector v into a 4-dimensional vector by multiplying by the 4×2 matrix G
52

Matrix composition

  • What does it mean to multiply matrices?
  • What does FG when G is a 4×2 matrix and F a 3×4 matrix?
  • It is as a composition of transformations:
    • Transform a 2-dimensional vector v into a 4-dimensional vector by multiplying by the 4×2 matrix G
    • Transorm the result into a 3-dimensional vector by multiplying by a 3×4 matrix F
52

Mathematically

  • When reading below go from right to left:

H(3×2)×v(2×1)==F(3×4)×G(4×2)×v(2×1)

  • The matrix H=FG is a composition of doing G and then F
53

Matrix multiplication

  • What happens if you try to multiply GFv?
54

Matrix multiplication

  • What happens if you try to multiply GFv? G(4×2)×F(3×4)×v(2×1)
54

Matrix multiplication

  • What happens if you try to multiply GFv? G(4×2)×F(3×4)×v(2×1)
  • Going from right to left, F will try to transform a 4-dimensional vector to a 3-dimensional vector and cannot take the is a 2-dimensional vector v as its input!
54

Matrix multiplication

  • What happens if you try to multiply GFv? G(4×2)×F(3×4)×v(2×1)
  • Going from right to left, F will try to transform a 4-dimensional vector to a 3-dimensional vector and cannot take the is a 2-dimensional vector v as its input!
  • Also G transforms a 2-dimensional vector to a 4-dimensional vector so cannot take the 3-dimensional output of F as its input.
54

Matrix Multiplication

  • Although it is possible to get FG it is impossible to get GF.
55

Matrix Multiplication

  • Although it is possible to get FG it is impossible to get GF.
  • In general, for matrix multiplication ABBA even for square matrices.
55

Matrix Multiplication

  • Although it is possible to get FG it is impossible to get GF.
  • In general, for matrix multiplication ABBA even for square matrices.
  • Matrix multiplication is non-commutative.
55

Inner products and rotations

56

Inner product

  • One final operation with vectors is called the inner product.
57

Inner product

  • One final operation with vectors is called the inner product.
  • The inner product of two vectors x and y is defined as xy.
57

Inner product

  • One final operation with vectors is called the inner product.
  • The inner product of two vectors x and y is defined as xy.
  • The inner product of a vector with itself xx is the length of the vector squared.
57

Orthogonality

  • An interesting case is when the inner product between two vectors is zero.
    • xy=0
  • In this case, the vectors x and y are at a 90 degree angle to one another.
  • This is also called orthogonality.
58

Rotation matrix

  • Another important matrix is known as a orthogonal rotation matrix.
59

Rotation matrix

  • Another important matrix is known as a orthogonal rotation matrix.
  • It spins all the points around keeping them the same distance from the origin and from each other.
59

Rotation matrix

  • Another important matrix is known as a orthogonal rotation matrix.
  • It spins all the points around keeping them the same distance from the origin and from each other.
  • The word orthogonal means that the new basis vectors are at right angles to one another.
59

Rotation Matrix

  • In matrix algebra rotation can be defined in any dimension.
  • It is easiest to understand in two dimensions.
  • An example of a rotation matrix in two dimensions is: R=[0.80.60.60.8]
60

Rotation Matrix

61

Rotation matrix

  • The new basis vectors should have a length of 1 therefore riri=1 where ri are the columns of R.
62

Rotation matrix

  • The new basis vectors should have a length of 1 therefore riri=1 where ri are the columns of R.
  • The new basis vectors should be at right angles rirj=0
62

Rotation matrix

  • The new basis vectors should have a length of 1 therefore riri=1 where ri are the columns of R.
  • The new basis vectors should be at right angles rirj=0
  • A rotation matrix R has the property RR=I
62

Rotations in PCA

  • In PCA the weights of the principal components have two properties
    • wiwi=1
    • wiwj=0
  • All p principal components can be obtained by multiplying by a rotation matrix by p-dimensional data.
  • Taking principal components rotates the data.
63

Rotations in Factor Analysis

  • In factor analysis rotation was used to obtain more interpretable factors.
  • This was a r-dimensional rotation of the factors rather than the data.
  • Again this involved multiplying by a rotation matrix.
64

Conclusion

  • Understand the geometry of matrix algebra assists in understanding PCA and Factor analysis in particular.
  • PCA forms new variables as linear combinations of old variables.
    • This corresponds to matrix multiplication.
  • The role of rotation should now also be understood.
  • The next step is to understand the importance of matrix decompositions in the methods covered so far.
65

Why?

2
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow