Geometric methods in vector spaces Distributional Semantic Models - - PowerPoint PPT Presentation

geometric methods in vector spaces
SMART_READER_LITE
LIVE PREVIEW

Geometric methods in vector spaces Distributional Semantic Models - - PowerPoint PPT Presentation

Geometric methods in vector spaces Distributional Semantic Models Stefan Evert 1 & Alessandro Lenci 2 1 University of Osnabr uck, Germany 2 University of Pisa, Italy Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 1 / 48


slide-1
SLIDE 1

Geometric methods in vector spaces

Distributional Semantic Models Stefan Evert1 & Alessandro Lenci2

1University of Osnabr¨

uck, Germany

2University of Pisa, Italy Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 1 / 48

slide-2
SLIDE 2

The bad cop is back . . .

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 2 / 48

slide-3
SLIDE 3

Length & distance Introduction

Geometry and meaning

So far: apply vector methods and matrix algebra to DSMs Geometric intuition: distance ≃ semantic (dis)similarity

◮ nearest neighbours ◮ clustering ◮ semantic maps ◮ representation for connectionist models

☞ We need a mathematical notion of distance!

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 3 / 48

slide-4
SLIDE 4

Length & distance Metric spaces

Measuring distance

Distance between vectors u, v ∈ Rn ➜ (dis)similarity

  • f data points

◮ u = (u1, . . . , un) ◮ v = (v1, . . . , vn) x1 v x2

1 2 3 4 5 1 2 3 4 5 6 6

u

d2 ( u, v) = 3.6 d1 ( u, v) = 5

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 4 / 48

slide-5
SLIDE 5

Length & distance Metric spaces

Measuring distance

Distance between vectors u, v ∈ Rn ➜ (dis)similarity

  • f data points

◮ u = (u1, . . . , un) ◮ v = (v1, . . . , vn)

Euclidean distance d2 (u, v)

x1 v x2

1 2 3 4 5 1 2 3 4 5 6 6

u

d2 ( u, v) = 3.6 d1 ( u, v) = 5

d2 (u, v) :=

  • (u1 − v1)2 + · · · + (un − vn)2

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 4 / 48

slide-6
SLIDE 6

Length & distance Metric spaces

Measuring distance

Distance between vectors u, v ∈ Rn ➜ (dis)similarity

  • f data points

◮ u = (u1, . . . , un) ◮ v = (v1, . . . , vn)

Euclidean distance d2 (u, v) “City block” Manhattan distance d1 (u, v)

x1 v x2

1 2 3 4 5 1 2 3 4 5 6 6

u

d2 ( u, v) = 3.6 d1 ( u, v) = 5

d1 (u, v) := |u1 − v1| + · · · + |un − vn|

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 4 / 48

slide-7
SLIDE 7

Length & distance Metric spaces

Measuring distance

Distance between vectors u, v ∈ Rn ➜ (dis)similarity

  • f data points

◮ u = (u1, . . . , un) ◮ v = (v1, . . . , vn)

Euclidean distance d2 (u, v) “City block” Manhattan distance d1 (u, v) Both are special cases of the Minkowski p-distance dp (u, v) (for p ∈ [1, ∞])

x1 v x2

1 2 3 4 5 1 2 3 4 5 6 6

u

d2 ( u, v) = 3.6 d1 ( u, v) = 5

dp (u, v) :=

  • |u1 − v1|p + · · · + |un − vn|p1/p

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 4 / 48

slide-8
SLIDE 8

Length & distance Metric spaces

Measuring distance

Distance between vectors u, v ∈ Rn ➜ (dis)similarity

  • f data points

◮ u = (u1, . . . , un) ◮ v = (v1, . . . , vn)

Euclidean distance d2 (u, v) “City block” Manhattan distance d1 (u, v) Both are special cases of the Minkowski p-distance dp (u, v) (for p ∈ [1, ∞])

x1 v x2

1 2 3 4 5 1 2 3 4 5 6 6

u

d2 ( u, v) = 3.6 d1 ( u, v) = 5

dp (u, v) :=

  • |u1 − v1|p + · · · + |un − vn|p1/p

d∞ (u, v) = max

  • |u1 − v1|, . . . , |un − vn|
  • Evert & Lenci (ESSLLI 2009)

DSM: Matrix Algebra 30 July 2009 4 / 48

slide-9
SLIDE 9

Length & distance Metric spaces

Metric: a measure of distance

A metric is a general measure of the distance d (u, v) between points u and v, which satisfies the following axioms:

◮ d (u, v) = d (v, u) ◮ d (u, v) > 0 for u = v ◮ d (u, u) = 0 ◮ d (u, w) ≤ d (u, v) + d (v, w) (triangle inequality) Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 5 / 48

slide-10
SLIDE 10

Length & distance Metric spaces

Metric: a measure of distance

A metric is a general measure of the distance d (u, v) between points u and v, which satisfies the following axioms:

◮ d (u, v) = d (v, u) ◮ d (u, v) > 0 for u = v ◮ d (u, u) = 0 ◮ d (u, w) ≤ d (u, v) + d (v, w) (triangle inequality)

Metrics form a very broad class of distance measures, some of which do not fit in well with our geometric intuitions

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 5 / 48

slide-11
SLIDE 11

Length & distance Metric spaces

Metric: a measure of distance

A metric is a general measure of the distance d (u, v) between points u and v, which satisfies the following axioms:

◮ d (u, v) = d (v, u) ◮ d (u, v) > 0 for u = v ◮ d (u, u) = 0 ◮ d (u, w) ≤ d (u, v) + d (v, w) (triangle inequality)

Metrics form a very broad class of distance measures, some of which do not fit in well with our geometric intuitions E.g., metric need not be translation-invariant d (u + x, v + x) = d (u, v)

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 5 / 48

slide-12
SLIDE 12

Length & distance Metric spaces

Metric: a measure of distance

A metric is a general measure of the distance d (u, v) between points u and v, which satisfies the following axioms:

◮ d (u, v) = d (v, u) ◮ d (u, v) > 0 for u = v ◮ d (u, u) = 0 ◮ d (u, w) ≤ d (u, v) + d (v, w) (triangle inequality)

Metrics form a very broad class of distance measures, some of which do not fit in well with our geometric intuitions E.g., metric need not be translation-invariant d (u + x, v + x) = d (u, v) Another unintuitive example is the discrete metric d (u, v) =

  • u = v

1 u = v

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 5 / 48

slide-13
SLIDE 13

Length & distance Vector norms

Distance vs. norm

Intuitively, distance d (u, v) should correspond to length u − v of displacement vector u − v

◮ d (u, v) is a metric ◮ u − v is a norm ◮ u = d

  • u, 0
  • x1
  • rigin

v x2

1 2 3 4 5 1 2 3 4 5 6 6

u

  • u = d
  • u,
  • d (

u, v) = u − v

  • v = d
  • v,
  • Evert & Lenci (ESSLLI 2009)

DSM: Matrix Algebra 30 July 2009 6 / 48

slide-14
SLIDE 14

Length & distance Vector norms

Distance vs. norm

Intuitively, distance d (u, v) should correspond to length u − v of displacement vector u − v

◮ d (u, v) is a metric ◮ u − v is a norm ◮ u = d

  • u, 0
  • Such a metric is always

translation-invariant

x1

  • rigin

v x2

1 2 3 4 5 1 2 3 4 5 6 6

u

  • u = d
  • u,
  • d (

u, v) = u − v

  • v = d
  • v,
  • Evert & Lenci (ESSLLI 2009)

DSM: Matrix Algebra 30 July 2009 6 / 48

slide-15
SLIDE 15

Length & distance Vector norms

Distance vs. norm

Intuitively, distance d (u, v) should correspond to length u − v of displacement vector u − v

◮ d (u, v) is a metric ◮ u − v is a norm ◮ u = d

  • u, 0
  • Such a metric is always

translation-invariant dp (u, v) = v − up

x1

  • rigin

v x2

1 2 3 4 5 1 2 3 4 5 6 6

u

  • u = d
  • u,
  • d (

u, v) = u − v

  • v = d
  • v,
  • Minkowski p-norm for p ∈ [1, ∞]:

up :=

  • |u1|p + · · · + |un|p1/p

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 6 / 48

slide-16
SLIDE 16

Length & distance Vector norms

Norm: a measure of length

A general norm u for the length of a vector u must satisfy the following axioms:

◮ u > 0 for u = 0 ◮ λu = |λ| · u (homogeneity, not req’d for metric) ◮ u + v ≤ u + v (triangle inequality) Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 7 / 48

slide-17
SLIDE 17

Length & distance Vector norms

Norm: a measure of length

A general norm u for the length of a vector u must satisfy the following axioms:

◮ u > 0 for u = 0 ◮ λu = |λ| · u (homogeneity, not req’d for metric) ◮ u + v ≤ u + v (triangle inequality)

every norm defines a translation-invariant metric d (u, v) := u − v

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 7 / 48

slide-18
SLIDE 18

Length & distance Vector norms

Norm: a measure of length

−1.0 −0.5 0.0 0.5 1.0 −1.0 −0.5 0.0 0.5 1.0

Unit circle according to p−norm

x1 x2 p = 1 p = 2 p = 5 p = ∞

Visualisation of norms in R2 by plotting unit circle for each norm, i.e. points u with u = 1 Here: p-norms ·p for different values of p

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 8 / 48

slide-19
SLIDE 19

Length & distance Vector norms

Norm: a measure of length

−1.0 −0.5 0.0 0.5 1.0 −1.0 −0.5 0.0 0.5 1.0

Unit circle according to p−norm

x1 x2 p = 1 p = 2 p = 5 p = ∞

Visualisation of norms in R2 by plotting unit circle for each norm, i.e. points u with u = 1 Here: p-norms ·p for different values of p Triangle inequality ⇐ ⇒ unit circle is convex This shows that p-norms with p < 1 would violate the triangle inequality

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 8 / 48

slide-20
SLIDE 20

Length & distance Vector norms

Norm: a measure of length

−1.0 −0.5 0.0 0.5 1.0 −1.0 −0.5 0.0 0.5 1.0

Unit circle according to p−norm

x1 x2 p = 1 p = 2 p = 5 p = ∞

Visualisation of norms in R2 by plotting unit circle for each norm, i.e. points u with u = 1 Here: p-norms ·p for different values of p Triangle inequality ⇐ ⇒ unit circle is convex This shows that p-norms with p < 1 would violate the triangle inequality Consequence for DSM: p ≫ 2 “favours” small differences in many coordinates, p ≪ 2 differences in few coordinates

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 8 / 48

slide-21
SLIDE 21

Length & distance Vector norms

Operator and matrix norm

The norm of a linear map (or “operator”) f : U → V between normed vector spaces U and V is defined as f := max {f (u) | u ∈ U, u = 1}

◮ f depends on the norms chosen in U and V ! Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 9 / 48

slide-22
SLIDE 22

Length & distance Vector norms

Operator and matrix norm

The norm of a linear map (or “operator”) f : U → V between normed vector spaces U and V is defined as f := max {f (u) | u ∈ U, u = 1}

◮ f depends on the norms chosen in U and V !

The definition of the operator norm implies f (u) ≤ f · u

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 9 / 48

slide-23
SLIDE 23

Length & distance Vector norms

Operator and matrix norm

The norm of a linear map (or “operator”) f : U → V between normed vector spaces U and V is defined as f := max {f (u) | u ∈ U, u = 1}

◮ f depends on the norms chosen in U and V !

The definition of the operator norm implies f (u) ≤ f · u Norm of a matrix A = norm of corresponding map f

◮ NB: this is not the same as a p-norm of A in Rk·n ◮ spectral norm induced by Euclidean vector norms

in U and V = largest singular value of A (➜ SVD)

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 9 / 48

slide-24
SLIDE 24

Length & distance Vector norms

Which metric should I use?

Choice of metric or norm is one of the parameters of a DSM

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 10 / 48

slide-25
SLIDE 25

Length & distance Vector norms

Which metric should I use?

Choice of metric or norm is one of the parameters of a DSM Measures of distance between points:

◮ intuitive Euclidean norm ·2 ◮ “city-block” Manhattan distance ·1 ◮ maximum distance ·∞ ◮ general Minkowski p-norm ·p ◮ and many other formulae . . . Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 10 / 48

slide-26
SLIDE 26

Length & distance Vector norms

Which metric should I use?

Choice of metric or norm is one of the parameters of a DSM Measures of distance between points:

◮ intuitive Euclidean norm ·2 ◮ “city-block” Manhattan distance ·1 ◮ maximum distance ·∞ ◮ general Minkowski p-norm ·p ◮ and many other formulae . . .

Measures of the similarity of arrows:

◮ “cosine distance” ∼ u1v1 + · · · + unvn ◮ Dice coefficient (matching non-zero coordinates) ◮ and, of course, many other formulae . . .

☞ these measures determine angles between arrows

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 10 / 48

slide-27
SLIDE 27

Length & distance Vector norms

Which metric should I use?

Choice of metric or norm is one of the parameters of a DSM Measures of distance between points:

◮ intuitive Euclidean norm ·2 ◮ “city-block” Manhattan distance ·1 ◮ maximum distance ·∞ ◮ general Minkowski p-norm ·p ◮ and many other formulae . . .

Measures of the similarity of arrows:

◮ “cosine distance” ∼ u1v1 + · · · + unvn ◮ Dice coefficient (matching non-zero coordinates) ◮ and, of course, many other formulae . . .

☞ these measures determine angles between arrows

Similarity and distance measures are equivalent!

☞ I’m a fan of the Euclidean norm because of its intuitive geometric properties (angles, orthogonality, shortest path, . . . )

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 10 / 48

slide-28
SLIDE 28

Length & distance with R

Norms & distance measures in R

# We will use the cooccurrence matrix M from the last session > print(M)

eat get hear kill see use boat 59 4 39 23 cat 6 52 4 26 58 4 cup 1 98 2 14 6 dog 33 115 42 17 83 10 knife 3 51 20 84 pig 9 12 2 27 17 3

# Note: you can save selected variables with the save() command, # and restore them in your next session (similar to saving R’s workspace) > save(M, O, E, M.mds, file="dsm_lab.RData") # load() restores the variables under the same names! > load("dsm_lab.RData")

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 11 / 48

slide-29
SLIDE 29

Length & distance with R

Norms & distance measures in R

# Define functions for general Minkowski norm and distance; # parameter p is optional and defaults to p = 2 > p.norm <- function (x, p=2) (sum(abs(x)^p))^(1/p) > p.dist <- function (x, y, p=2) p.norm(x - y, p) > round(apply(M, 1, p.norm, p=1), 2)

boat cat cup dog knife pig 125 150 121 300 158 70

> round(apply(M, 1, p.norm, p=2), 2)

boat cat cup dog knife pig 74.48 82.53 99.20 152.83 100.33 35.44

> round(apply(M, 1, p.norm, p=4), 2)

boat cat cup dog knife pig 61.93 66.10 98.01 122.71 86.78 28.31

> round(apply(M, 1, p.norm, p=99), 2)

boat cat cup dog knife pig 59 58 98 115 84 27

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 12 / 48

slide-30
SLIDE 30

Length & distance with R

Norms & distance measures in R

# Here’s a nice trick to normalise the row vectors quickly > normalise <- function (M, p=2) M / apply(M, 1, p.norm, p=p) # dist() function also supports Minkowski p-metric # (must normalise rows in order to compare different metrics) > round(dist(normalise(M, p=1), method="minkowski", p=1), 2)

boat cat cup dog knife cat 0.58 cup 0.69 0.97 dog 0.55 0.45 0.89 knife 0.73 1.01 1.01 1.00 pig 1.03 0.64 1.29 0.71 1.28

# Try different p-norms: how do the distances change? > round(dist(normalise(M, p=2), method="minkowski", p=2), 2) > round(dist(normalise(M, p=4), method="minkowski", p=4), 2) > round(dist(normalise(M, p=99), method="minkowski", p=99), 2)

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 13 / 48

slide-31
SLIDE 31

Length & distance with R

Why it is important to normalise vectors

before computing a distance matrix

  • 20

40 60 80 100 120 20 40 60 80 100 120

Two dimensions of English V−Obj DSM

get use

cat dog knife boat

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 14 / 48

slide-32
SLIDE 32

Orientation Euclidean geometry

Euclidean norm & inner product

The Euclidean norm u2 =

  • u, u is special because it can

be derived from the inner product: u, v := xTy = x1y1 + · · · + xnyn where u ≡E x and v ≡E y are the standard coordinates of u and v (certain other coordinate systems also work)

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 15 / 48

slide-33
SLIDE 33

Orientation Euclidean geometry

Euclidean norm & inner product

The Euclidean norm u2 =

  • u, u is special because it can

be derived from the inner product: u, v := xTy = x1y1 + · · · + xnyn where u ≡E x and v ≡E y are the standard coordinates of u and v (certain other coordinate systems also work) The inner product is a positive definite and symmetric bilinear form with the following properties:

◮ λu, v = u, λv = λ u, v ◮ u + u′, v = u, v + u′, v ◮ u, v + v′ = u, v + u, v′ ◮ u, v = v, u (symmetric) ◮ u, u = u2 > 0 for u = 0 (positive definite) ◮ also called dot product or scalar product Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 15 / 48

slide-34
SLIDE 34

Orientation Euclidean geometry

Angles and orthogonality

The Euclidean inner product has an important geometric interpretation ➜ angles and orthogonality

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 16 / 48

slide-35
SLIDE 35

Orientation Euclidean geometry

Angles and orthogonality

The Euclidean inner product has an important geometric interpretation ➜ angles and orthogonality Cauchy-Schwarz inequality:

  • u, v
  • ≤ u · v

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 16 / 48

slide-36
SLIDE 36

Orientation Euclidean geometry

Angles and orthogonality

The Euclidean inner product has an important geometric interpretation ➜ angles and orthogonality Cauchy-Schwarz inequality:

  • u, v
  • ≤ u · v

Angle φ between vectors u, v ∈ Rn: cos φ := u, v u · v

◮ cos φ is the “cosine similarity” measure Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 16 / 48

slide-37
SLIDE 37

Orientation Euclidean geometry

Angles and orthogonality

The Euclidean inner product has an important geometric interpretation ➜ angles and orthogonality Cauchy-Schwarz inequality:

  • u, v
  • ≤ u · v

Angle φ between vectors u, v ∈ Rn: cos φ := u, v u · v

◮ cos φ is the “cosine similarity” measure

u and v are orthogonal iff u, v = 0

◮ the shortest connection between a point u and a subspace U

is orthogonal to all vectors v ∈ U

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 16 / 48

slide-38
SLIDE 38

Orientation Euclidean geometry

Cosine similarity in R

The dist() function does not calculate the cosine measure (because it is a similarity rather than distance value), but:

M · MT =       · · · u(1) · · · · · · u(2) · · · · · · u(n) · · ·       ·     . . . . . . . . . u(1) u(2) u(n) . . . . . . . . .    

  • M · MT

ij =

  • u(i), u(j)

# Matrix of cosine similarities between rows of M: > M.norm <- normalise(M, p=2) # only works with Euclidean norm! > M.norm %*% t(M.norm)

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 17 / 48

slide-39
SLIDE 39

Orientation Euclidean geometry

Euclidean distance or cosine similarity?

Which is better, Euclidean distance or cosine similarity?

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 18 / 48

slide-40
SLIDE 40

Orientation Euclidean geometry

Euclidean distance or cosine similarity?

Which is better, Euclidean distance or cosine similarity? They are equivalent: if vectors are normalised (u2 = 1), both lead to the same neighbour ranking

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 18 / 48

slide-41
SLIDE 41

Orientation Euclidean geometry

Euclidean distance or cosine similarity?

Which is better, Euclidean distance or cosine similarity? They are equivalent: if vectors are normalised (u2 = 1), both lead to the same neighbour ranking d2 (u, v) =

  • u − v2 =
  • u − v, u − v

=

  • u, u + v, v − 2 u, v

=

  • u2 + v2 − 2 u, v

=

  • 2 − 2 cos φ

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 18 / 48

slide-42
SLIDE 42

Orientation Euclidean geometry

Euclidean distance and cosine similarity

  • 20

40 60 80 100 120 20 40 60 80 100 120

Two dimensions of English V−Obj DSM

get use

cat dog knife boat

α α

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 19 / 48

slide-43
SLIDE 43

Orientation Euclidean geometry

Cartesian coordinates

A set of vectors b(1), . . . , b(n) is called orthonormal if the vectors are pairwise orthogonal and of unit length:

b(j), b(k) = 0 for j = k

b(k), b(k) =

  • b(k)

2 = 1

An orthonormal basis and the corresponding coordinates are called Cartesian

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 20 / 48

slide-44
SLIDE 44

Orientation Euclidean geometry

Cartesian coordinates

A set of vectors b(1), . . . , b(n) is called orthonormal if the vectors are pairwise orthogonal and of unit length:

b(j), b(k) = 0 for j = k

b(k), b(k) =

  • b(k)

2 = 1

An orthonormal basis and the corresponding coordinates are called Cartesian Cartesian coordinates are particularly intuitive, and the inner product has the same form wrt. every Cartesian basis B: for u ≡B x′ and v ≡B y′, we have u, v = (x′)Ty′ = x′

1y′ 1 + · · · + x′ ny′ n

NB: the column vectors of the matrix B are orthonormal

◮ recall that the columns of B specify the standard coordinates

  • f the vectors b(1), . . . , b(n)

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 20 / 48

slide-45
SLIDE 45

Orientation Euclidean geometry

Orthogonal projection

Cartesian coordinates u ≡B x can easily be computed:

  • u, b(k)

= n

  • j=1

xjb(j), b(k)

  • =

n

  • j=1

xj

  • b(j), b(k)
  • =δjk

= xk

◮ Kronecker delta: δjk = 1 for j = k and 0 for j = k Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 21 / 48

slide-46
SLIDE 46

Orientation Euclidean geometry

Orthogonal projection

Cartesian coordinates u ≡B x can easily be computed:

  • u, b(k)

= n

  • j=1

xjb(j), b(k)

  • =

n

  • j=1

xj

  • b(j), b(k)
  • =δjk

= xk

◮ Kronecker delta: δjk = 1 for j = k and 0 for j = k

Orthogonal projection PV : Rn → V to subspace V := sp

  • b(1), . . . , b(k)

(for k < n) is given by PV u :=

k

  • j=1

b(j) u, b(j)

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 21 / 48

slide-47
SLIDE 47

Orientation Normal vector

Hyperplanes & normal vectors

A hyperplane is the decision boundary of a linear classifier!

A hyperplane U ⊆ Rn through the origin 0 can be characterized by the equation U =

  • u ∈ Rn

u, n = 0

  • for a suitable n ∈ Rn with n = 1

n is called the normal vector of U

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 22 / 48

slide-48
SLIDE 48

Orientation Normal vector

Hyperplanes & normal vectors

A hyperplane is the decision boundary of a linear classifier!

A hyperplane U ⊆ Rn through the origin 0 can be characterized by the equation U =

  • u ∈ Rn

u, n = 0

  • for a suitable n ∈ Rn with n = 1

n is called the normal vector of U The orthogonal projection PU into U is given by PUv := v − n v, n

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 22 / 48

slide-49
SLIDE 49

Orientation Normal vector

Hyperplanes & normal vectors

A hyperplane is the decision boundary of a linear classifier!

A hyperplane U ⊆ Rn through the origin 0 can be characterized by the equation U =

  • u ∈ Rn

u, n = 0

  • for a suitable n ∈ Rn with n = 1

n is called the normal vector of U The orthogonal projection PU into U is given by PUv := v − n v, n An arbitrary hyperplane Γ ⊆ Rn can analogously be characterized by Γ =

  • u ∈ Rn

u, n = a

  • where a ∈ R is the (signed) distance of Γ from 0

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 22 / 48

slide-50
SLIDE 50

Orientation Isometric maps

Orthogonal matrices

A matrix A whose column vectors are orthonormal is called an orthogonal matrix AT is orthogonal iff A is orthogonal

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 23 / 48

slide-51
SLIDE 51

Orientation Isometric maps

Orthogonal matrices

A matrix A whose column vectors are orthonormal is called an orthogonal matrix AT is orthogonal iff A is orthogonal The inverse of an orthogonal matrix is simply its transpose: A−1 = AT if A is orthogonal

◮ it is easy to show ATA = I by matrix multiplication,

since the columns of A are orthonormal

◮ since AT is also orthogonal, it follows that

AAT = (AT)TAT = I

◮ side remark: the transposition operator ·T is called

an involution because (AT)T = A

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 23 / 48

slide-52
SLIDE 52

Orientation Isometric maps

Isometric maps

An endomorphism f : Rn → Rn is called an isometry iff f (u), f (v) = u, v for all u, v ∈ Rn Geometric interpretation: isometries preserve angles and distances (which are defined in terms of ·, ·)

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 24 / 48

slide-53
SLIDE 53

Orientation Isometric maps

Isometric maps

An endomorphism f : Rn → Rn is called an isometry iff f (u), f (v) = u, v for all u, v ∈ Rn Geometric interpretation: isometries preserve angles and distances (which are defined in terms of ·, ·) f is an isometry iff its matrix A is orthogonal

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 24 / 48

slide-54
SLIDE 54

Orientation Isometric maps

Isometric maps

An endomorphism f : Rn → Rn is called an isometry iff f (u), f (v) = u, v for all u, v ∈ Rn Geometric interpretation: isometries preserve angles and distances (which are defined in terms of ·, ·) f is an isometry iff its matrix A is orthogonal Coordinate transformations between Cartesian systems are isometric (because B and B−1 = BT are orthogonal)

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 24 / 48

slide-55
SLIDE 55

Orientation Isometric maps

Isometric maps

An endomorphism f : Rn → Rn is called an isometry iff f (u), f (v) = u, v for all u, v ∈ Rn Geometric interpretation: isometries preserve angles and distances (which are defined in terms of ·, ·) f is an isometry iff its matrix A is orthogonal Coordinate transformations between Cartesian systems are isometric (because B and B−1 = BT are orthogonal) Every isometric endomorphism of Rn can be written as a combination of planar rotations and axial reflections in a suitable Cartesian coordinate system R(1,3)

φ

= cos φ

− sin φ 1 sin φ cos φ

  • ,

Q(2) = 1

−1 1

  • Evert & Lenci (ESSLLI 2009)

DSM: Matrix Algebra 30 July 2009 24 / 48

slide-56
SLIDE 56

Orientation Isometric maps

Summary: orthogonal matrices

The column vectors of an orthogonal n × n matrix B form a Cartesian basis b(1), . . . , b(n) of Rn

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 25 / 48

slide-57
SLIDE 57

Orientation Isometric maps

Summary: orthogonal matrices

The column vectors of an orthogonal n × n matrix B form a Cartesian basis b(1), . . . , b(n) of Rn B−1 = BT, i.e. we have BTB = BBT = I

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 25 / 48

slide-58
SLIDE 58

Orientation Isometric maps

Summary: orthogonal matrices

The column vectors of an orthogonal n × n matrix B form a Cartesian basis b(1), . . . , b(n) of Rn B−1 = BT, i.e. we have BTB = BBT = I The coordinate transformation BT into B-coordinates is an isometry, i.e. all distances and angles are preserved

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 25 / 48

slide-59
SLIDE 59

Orientation Isometric maps

Summary: orthogonal matrices

The column vectors of an orthogonal n × n matrix B form a Cartesian basis b(1), . . . , b(n) of Rn B−1 = BT, i.e. we have BTB = BBT = I The coordinate transformation BT into B-coordinates is an isometry, i.e. all distances and angles are preserved The first k < n columns of B form a Cartesian basis of a subspace V = sp

  • b(1), . . . , b(k)
  • f Rn

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 25 / 48

slide-60
SLIDE 60

Orientation Isometric maps

Summary: orthogonal matrices

The column vectors of an orthogonal n × n matrix B form a Cartesian basis b(1), . . . , b(n) of Rn B−1 = BT, i.e. we have BTB = BBT = I The coordinate transformation BT into B-coordinates is an isometry, i.e. all distances and angles are preserved The first k < n columns of B form a Cartesian basis of a subspace V = sp

  • b(1), . . . , b(k)
  • f Rn

The corresponding rectangular matrix ˆ B =

  • b(1), . . . , b(k)

performs an orthogonal projection into V : PV u ≡B ˆ BTx (for u ≡E x) ≡E ˆ Bˆ BTx ➥ These properties will become important later today!

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 25 / 48

slide-61
SLIDE 61

Orientation General inner product

General inner products

Can we also introduce geometric notions such as angles and

  • rthogonality for other metrics, e.g. the Manhattan distance?

☞ norm must be derived from appropriate inner product

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 26 / 48

slide-62
SLIDE 62

Orientation General inner product

General inner products

Can we also introduce geometric notions such as angles and

  • rthogonality for other metrics, e.g. the Manhattan distance?

☞ norm must be derived from appropriate inner product

General inner products are defined by u, vB := (x′)Ty′ = x′

1y′ 1 + · · · + x′ yy′ n

  • wrt. non-Cartesian basis B (u ≡B x′, v ≡B y′)

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 26 / 48

slide-63
SLIDE 63

Orientation General inner product

General inner products

Can we also introduce geometric notions such as angles and

  • rthogonality for other metrics, e.g. the Manhattan distance?

☞ norm must be derived from appropriate inner product

General inner products are defined by u, vB := (x′)Ty′ = x′

1y′ 1 + · · · + x′ yy′ n

  • wrt. non-Cartesian basis B (u ≡B x′, v ≡B y′)

·, ·B can be expressed in standard coordinates u ≡E x, v ≡E y using the transformation matrix B: u, vB = (x′)Ty′ =

  • B−1x

T B−1y

  • = xT(B−1)TB−1y =: xTCy

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 26 / 48

slide-64
SLIDE 64

Orientation General inner product

General inner products

The coefficient matrix C := (B−1)TB−1 of the general inner product is symmetric CT = (B−1)T((B−1)T)T = (B−1)TB−1 = C

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 27 / 48

slide-65
SLIDE 65

Orientation General inner product

General inner products

The coefficient matrix C := (B−1)TB−1 of the general inner product is symmetric CT = (B−1)T((B−1)T)T = (B−1)TB−1 = C and positive definite xTCx =

  • B−1x

T B−1x

  • = (x′)Tx′ ≥ 0

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 27 / 48

slide-66
SLIDE 66

Orientation General inner product

General inner products

The coefficient matrix C := (B−1)TB−1 of the general inner product is symmetric CT = (B−1)T((B−1)T)T = (B−1)TB−1 = C and positive definite xTCx =

  • B−1x

T B−1x

  • = (x′)Tx′ ≥ 0

It is (relatively) easy to show that every positive definite and symmetric bilinear form can be written in this way.

☞ i.e. every norm that is derived from an inner product can be expressed in terms of a coefficient matrix C or basis B

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 27 / 48

slide-67
SLIDE 67

Orientation General inner product

General inner products

An example: b(1) = (3, 2), b(2) = (1, 2) B = 3 1 2 2

  • B−1 =

1

2

−1

4

−1

2 3 4

  • C =

.5 −.5 −.5 .625

  • Graph shows unit circle
  • f the inner product C,

i.e. points x with xTCx = 1

x1 x2

  • 3
  • 2
  • 1

1 2

  • 3
  • 2
  • 1

1 2 3 3

b1 b2

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 28 / 48

slide-68
SLIDE 68

Orientation General inner product

General inner products

C is a symmetric matrix There is always an

  • rthonormal basis such

that C has diagonal form “Standard” dot product with additional scaling factors (wrt. this

  • rthonormal basis)

Intuition: unit circle is a squashed and rotated disk

x1 x2

  • 3
  • 2
  • 1

1 2

  • 3
  • 2
  • 1

1 2 3 3

c2 c1

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 29 / 48

slide-69
SLIDE 69

Orientation General inner product

General inner products

C is a symmetric matrix There is always an

  • rthonormal basis such

that C has diagonal form “Standard” dot product with additional scaling factors (wrt. this

  • rthonormal basis)

Intuition: unit circle is a squashed and rotated disk

x1 x2

  • 3
  • 2
  • 1

1 2

  • 3
  • 2
  • 1

1 2 3 3

c2 c1

➥ Every “geometric” norm is equivalent to the Euclidean norm except for a rotation and rescaling of the axes

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 29 / 48

slide-70
SLIDE 70

PCA Motivation and example data

Motivating latent dimensions: example data

Example: term-term matrix V-Obj cooc’s extracted from BNC

◮ targets = noun lemmas ◮ features = verb lemmas

feature scaling: association scores (modified log Dice coefficient) k = 111 nouns with f ≥ 20 (must have non-zero row vectors) n = 2 dimensions: buy and sell

noun buy sell bond 0.28 0.77 cigarette

  • 0.52

0.44 dress 0.51

  • 1.30

freehold

  • 0.01
  • 0.08

land 1.13 1.54 number

  • 1.05
  • 1.02

per

  • 0.35
  • 0.16

pub

  • 0.08
  • 1.30

share 1.92 1.99 system

  • 1.63
  • 0.70

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 30 / 48

slide-71
SLIDE 71

PCA Motivation and example data

Motivating latent dimensions & subspace projection

1 2 3 4 1 2 3 4 buy sell

acre advertising amount arm asset bag beer bill bit bond book bottle box bread building business car card carpet cigarette clothe club coal collection company computer copy couple currency dress drink drug equipment estate farm fish flat flower food freehold fruit furniture good home horse house insurance item kind land licence liquor lot machine material meat milk mill newspaper number

  • il
  • ne

pack package packet painting pair paper part per petrol picture piece place plant player pound product property pub quality quantity range record right seat security service set share shoe shop site software stake stamp stock stuff suit system television thing ticket time tin unit vehicle video wine work year

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 31 / 48

slide-72
SLIDE 72

PCA Motivation and example data

Motivating latent dimensions & subspace projection

The latent property of being a commodity is “expressed” through associations with several verbs: sell, buy, acquire, . . . Consequence: these DSM dimensions will be correlated

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 32 / 48

slide-73
SLIDE 73

PCA Motivation and example data

Motivating latent dimensions & subspace projection

The latent property of being a commodity is “expressed” through associations with several verbs: sell, buy, acquire, . . . Consequence: these DSM dimensions will be correlated Identify latent dimension by looking for strong correlations (or weaker correlations between large sets of features)

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 32 / 48

slide-74
SLIDE 74

PCA Motivation and example data

Motivating latent dimensions & subspace projection

The latent property of being a commodity is “expressed” through associations with several verbs: sell, buy, acquire, . . . Consequence: these DSM dimensions will be correlated Identify latent dimension by looking for strong correlations (or weaker correlations between large sets of features) Projection into subspace V of k < n latent dimensions as a “noise reduction” technique ➜ LSA Assumptions of this approach:

◮ “latent” distances in V are semantically meaningful ◮ other “residual” dimensions represent chance co-occurrence

patterns, often particular to the corpus underlying the DSM

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 32 / 48

slide-75
SLIDE 75

PCA Motivation and example data

The latent “commodity” dimension

1 2 3 4 1 2 3 4 buy sell

acre advertising amount arm asset bag beer bill bit bond book bottle box bread building business car card carpet cigarette clothe club coal collection company computer copy couple currency dress drink drug equipment estate farm fish flat flower food freehold fruit furniture good home horse house insurance item kind land licence liquor lot machine material meat milk mill newspaper number

  • il
  • ne

pack package packet painting pair paper part per petrol picture piece place plant player pound product property pub quality quantity range record right seat security service set share shoe shop site software stake stamp stock stuff suit system television thing ticket time tin unit vehicle video wine work year

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 33 / 48

slide-76
SLIDE 76

PCA Calculating variance

The variance of a data set

Rationale: find the dimensions that give the best (statistical) explanation for the variance (or “spread”) of the data Definition of the variance of a set of vectors

☞ you remember the equations for one-dimensional data, right?

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 34 / 48

slide-77
SLIDE 77

PCA Calculating variance

The variance of a data set

Rationale: find the dimensions that give the best (statistical) explanation for the variance (or “spread”) of the data Definition of the variance of a set of vectors

☞ you remember the equations for one-dimensional data, right?

σ2 = 1 k − 1

k

  • i=1

x(i) − µ2 µ = 1 k

k

  • i=1

x(i) Easier to calculate if we center the data so that µ = 0

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 34 / 48

slide-78
SLIDE 78

PCA Calculating variance

Centering the data set

Uncentered data set Centered data set Variance of centered data

−2 2 4 −2 2 4 buy sell

  • Evert & Lenci (ESSLLI 2009)

DSM: Matrix Algebra 30 July 2009 35 / 48

slide-79
SLIDE 79

PCA Calculating variance

Centering the data set

Uncentered data set Centered data set Variance of centered data

−2 2 4 −2 2 4 buy sell

  • Evert & Lenci (ESSLLI 2009)

DSM: Matrix Algebra 30 July 2009 35 / 48

slide-80
SLIDE 80

PCA Calculating variance

Centering the data set

Uncentered data set Centered data set Variance of centered data σ2 =

1 k−1 k

  • i=1

x(i)2

−2 −1 1 2 −2 −1 1 2 buy sell

  • variance = 1.26

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 35 / 48

slide-81
SLIDE 81

PCA Projection

Principal components analysis (PCA)

We want to project the data points to a lower-dimensional subspace, but preserve distances as well as possible

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 36 / 48

slide-82
SLIDE 82

PCA Projection

Principal components analysis (PCA)

We want to project the data points to a lower-dimensional subspace, but preserve distances as well as possible Insight 1: variance = average squared distance 1 k(k − 1)

k

  • i=1

k

  • j=1

x(i) − x(j)2 = 2 k − 1

k

  • i=1

x(i)2 = 2σ2

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 36 / 48

slide-83
SLIDE 83

PCA Projection

Principal components analysis (PCA)

We want to project the data points to a lower-dimensional subspace, but preserve distances as well as possible Insight 1: variance = average squared distance 1 k(k − 1)

k

  • i=1

k

  • j=1

x(i) − x(j)2 = 2 k − 1

k

  • i=1

x(i)2 = 2σ2 Insight 2: orthogonal projection always reduces distances

➜ difference in squared distances = loss of variance

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 36 / 48

slide-84
SLIDE 84

PCA Projection

Principal components analysis (PCA)

We want to project the data points to a lower-dimensional subspace, but preserve distances as well as possible Insight 1: variance = average squared distance 1 k(k − 1)

k

  • i=1

k

  • j=1

x(i) − x(j)2 = 2 k − 1

k

  • i=1

x(i)2 = 2σ2 Insight 2: orthogonal projection always reduces distances

➜ difference in squared distances = loss of variance

If we reduced the data set to just a single dimension, which dimension would still have the highest variance? Mathematically, we project the points onto a line through the

  • rigin and calculate one-dimensional variance on this line

◮ we’ll see in a moment how to compute such projections ◮ but first, let us look at a few examples Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 36 / 48

slide-85
SLIDE 85

PCA Projection

Projection and preserved variance: examples

−2 −1 1 2 −2 −1 1 2 buy sell

  • Evert & Lenci (ESSLLI 2009)

DSM: Matrix Algebra 30 July 2009 37 / 48

slide-86
SLIDE 86

PCA Projection

Projection and preserved variance: examples

−2 −1 1 2 −2 −1 1 2 buy sell

  • variance = 0.36

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 37 / 48

slide-87
SLIDE 87

PCA Projection

Projection and preserved variance: examples

−2 −1 1 2 −2 −1 1 2 buy sell

  • Evert & Lenci (ESSLLI 2009)

DSM: Matrix Algebra 30 July 2009 37 / 48

slide-88
SLIDE 88

PCA Projection

Projection and preserved variance: examples

−2 −1 1 2 −2 −1 1 2 buy sell

  • variance = 0.72

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 37 / 48

slide-89
SLIDE 89

PCA Projection

Projection and preserved variance: examples

−2 −1 1 2 −2 −1 1 2 buy sell

  • Evert & Lenci (ESSLLI 2009)

DSM: Matrix Algebra 30 July 2009 37 / 48

slide-90
SLIDE 90

PCA Projection

Projection and preserved variance: examples

−2 −1 1 2 −2 −1 1 2 buy sell

  • variance = 0.9

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 37 / 48

slide-91
SLIDE 91

PCA Projection

The mathematics of projections

Line through origin given by unit vector v = 1 For a point x and the corresponding unit vector x′ = x/x, we have cos ϕ = x′, v

.

ϕ

  • v 1
  • x
  • x′
  • x
  • x

P

v

x x, v v

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 38 / 48

slide-92
SLIDE 92

PCA Projection

The mathematics of projections

Line through origin given by unit vector v = 1 For a point x and the corresponding unit vector x′ = x/x, we have cos ϕ = x′, v

.

ϕ

  • v 1
  • x
  • x′
  • x
  • x

P

v

x x, v v

Trigonometry: position of projected point on the line is x · cos ϕ = x · x′, v = x, v Preserved variance = one-dimensional variance on the line (note that data set is still centered after projection) σ2

v =

1 k − 1

k

  • i=1

xi, v2

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 38 / 48

slide-93
SLIDE 93

PCA Covariance matrix

The covariance matrix

Find the direction v with maximal σ2

v, which is given by:

σ2

v = 1 k−1 k

  • i=1

xi, v2

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 39 / 48

slide-94
SLIDE 94

PCA Covariance matrix

The covariance matrix

Find the direction v with maximal σ2

v, which is given by:

σ2

v = 1 k−1 k

  • i=1

xi, v2 =

1 k−1 k

  • i=1
  • xT

i v

T ·

  • xT

i v

  • Evert & Lenci (ESSLLI 2009)

DSM: Matrix Algebra 30 July 2009 39 / 48

slide-95
SLIDE 95

PCA Covariance matrix

The covariance matrix

Find the direction v with maximal σ2

v, which is given by:

σ2

v = 1 k−1 k

  • i=1

xi, v2 =

1 k−1 k

  • i=1
  • xT

i v

T ·

  • xT

i v

  • =

1 k−1 k

  • i=1

vT xixT

i

  • v

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 39 / 48

slide-96
SLIDE 96

PCA Covariance matrix

The covariance matrix

Find the direction v with maximal σ2

v, which is given by:

σ2

v = 1 k−1 k

  • i=1

xi, v2 =

1 k−1 k

  • i=1
  • xT

i v

T ·

  • xT

i v

  • =

1 k−1 k

  • i=1

vT xixT

i

  • v

= vT

  • 1

k−1 k

  • i=1

xixT

i

  • v

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 39 / 48

slide-97
SLIDE 97

PCA Covariance matrix

The covariance matrix

Find the direction v with maximal σ2

v, which is given by:

σ2

v = 1 k−1 k

  • i=1

xi, v2 =

1 k−1 k

  • i=1
  • xT

i v

T ·

  • xT

i v

  • =

1 k−1 k

  • i=1

vT xixT

i

  • v

= vT

  • 1

k−1 k

  • i=1

xixT

i

  • v

= vTCv

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 39 / 48

slide-98
SLIDE 98

PCA Covariance matrix

The covariance matrix

C is the covariance matrix of the data points

◮ C is a square n × n matrix (2 × 2 in our example)

Preserved variance after projection onto a line v can easily be calculated as σ2

v = vTCv

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 40 / 48

slide-99
SLIDE 99

PCA Covariance matrix

The covariance matrix

C is the covariance matrix of the data points

◮ C is a square n × n matrix (2 × 2 in our example)

Preserved variance after projection onto a line v can easily be calculated as σ2

v = vTCv

The original variance of the data set is given by σ2 = tr(C) = C11 + C22 + · · · + Cnn C =           σ2

1

C12 · · · C1n C21 σ2

2

... . . . . . . ... ... Cn−1,n Cn1 · · · Cn,n−1 σ2

n

         

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 40 / 48

slide-100
SLIDE 100

PCA The PCA algorithm

Maximizing preserved variance

In our example, we want to find the axis v1 that preserves the largest amount of variance by maximizing vT

1 Cv1

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 41 / 48

slide-101
SLIDE 101

PCA The PCA algorithm

Maximizing preserved variance

In our example, we want to find the axis v1 that preserves the largest amount of variance by maximizing vT

1 Cv1

For higher-dimensional data set, we also want to find the axis v2 with the second largest amount of variance, etc.

☞ Should not include variance that has already been accounted for: v2 must be orthogonal to v1, i.e. v1, v2 = 0

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 41 / 48

slide-102
SLIDE 102

PCA The PCA algorithm

Maximizing preserved variance

In our example, we want to find the axis v1 that preserves the largest amount of variance by maximizing vT

1 Cv1

For higher-dimensional data set, we also want to find the axis v2 with the second largest amount of variance, etc.

☞ Should not include variance that has already been accounted for: v2 must be orthogonal to v1, i.e. v1, v2 = 0

Orthogonal dimensions v(1), v(2), . . . partition variance: σ2 = σ2

v(1) + σ2 v(2) + . . .

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 41 / 48

slide-103
SLIDE 103

PCA The PCA algorithm

Maximizing preserved variance

In our example, we want to find the axis v1 that preserves the largest amount of variance by maximizing vT

1 Cv1

For higher-dimensional data set, we also want to find the axis v2 with the second largest amount of variance, etc.

☞ Should not include variance that has already been accounted for: v2 must be orthogonal to v1, i.e. v1, v2 = 0

Orthogonal dimensions v(1), v(2), . . . partition variance: σ2 = σ2

v(1) + σ2 v(2) + . . .

Useful result from linear algebra: every symmetric matrix C = CT has an eigenvalue decomposition with orthogonal eigenvectors a1, a2, . . . , an and corresponding eigenvalues λ1 ≥ λ2 ≥ · · · ≥ λn

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 41 / 48

slide-104
SLIDE 104

PCA The PCA algorithm

Eigenvalue decomposition

The eigenvalue decomposition of C can be written in the form C = U · D · UT where U is an orthogonal matrix of eigenvectors (columns) and D = Diag(λ1, . . . , λn) a diagonal matrix of eigenvalues

U =           . . . . . . . . . . . . . . . . . . a1 a2 · · · an . . . . . . . . . . . . . . . . . .           D =         λ1 λ2 ... ... λn        

◮ note that both U and D are n × n square matrices Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 42 / 48

slide-105
SLIDE 105

PCA The PCA algorithm

The PCA algorithm

With the eigenvalue decomposition of C, we have σ2

v = vTCv = vTUDUTv = (UTv)TD(UTv) = yTDy

where y = UTv = [y1, y2, . . . , yn]T are the coordinates of v in the Cartesian basis formed by the eigenvectors of C

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 43 / 48

slide-106
SLIDE 106

PCA The PCA algorithm

The PCA algorithm

With the eigenvalue decomposition of C, we have σ2

v = vTCv = vTUDUTv = (UTv)TD(UTv) = yTDy

where y = UTv = [y1, y2, . . . , yn]T are the coordinates of v in the Cartesian basis formed by the eigenvectors of C y = 1 since UT is an isometry (orthogonal matrix) We therefore want to maximize vTCv = λ1(y1)2 + λ2(y2)2 · · · + λn(yn)2 under the constraint (y1)2 + (y2)2 + · · · + (yn)2 = 1

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 43 / 48

slide-107
SLIDE 107

PCA The PCA algorithm

The PCA algorithm

With the eigenvalue decomposition of C, we have σ2

v = vTCv = vTUDUTv = (UTv)TD(UTv) = yTDy

where y = UTv = [y1, y2, . . . , yn]T are the coordinates of v in the Cartesian basis formed by the eigenvectors of C y = 1 since UT is an isometry (orthogonal matrix) We therefore want to maximize vTCv = λ1(y1)2 + λ2(y2)2 · · · + λn(yn)2 under the constraint (y1)2 + (y2)2 + · · · + (yn)2 = 1 Solution: y = [1, 0, . . . , 0]T (since λ1 is the largest eigenvalue) This corresponds to v = a1 (the first eigenvector of C) and a preserved amount of variance given by σ2

v = aT 1 Ca1 = λ1

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 43 / 48

slide-108
SLIDE 108

PCA The PCA algorithm

The PCA algorithm

In order to find the dimension of second highest variance, we have to look for an axis v orthogonal to a1

☞ UT is orthogonal, so the coordinates y = UTv must be

  • rthogonal to first axis [1, 0, . . . , 0]T, i.e. y = [0, y2, . . . , yn]T

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 44 / 48

slide-109
SLIDE 109

PCA The PCA algorithm

The PCA algorithm

In order to find the dimension of second highest variance, we have to look for an axis v orthogonal to a1

☞ UT is orthogonal, so the coordinates y = UTv must be

  • rthogonal to first axis [1, 0, . . . , 0]T, i.e. y = [0, y2, . . . , yn]T

In other words, we have to maximize vTCv = λ2(y2)2 · · · + λn(yn)2 under constraints y1 = 0 and (y2)2 + · · · + (yn)2 = 1

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 44 / 48

slide-110
SLIDE 110

PCA The PCA algorithm

The PCA algorithm

In order to find the dimension of second highest variance, we have to look for an axis v orthogonal to a1

☞ UT is orthogonal, so the coordinates y = UTv must be

  • rthogonal to first axis [1, 0, . . . , 0]T, i.e. y = [0, y2, . . . , yn]T

In other words, we have to maximize vTCv = λ2(y2)2 · · · + λn(yn)2 under constraints y1 = 0 and (y2)2 + · · · + (yn)2 = 1 Again, solution is y = [0, 1, 0, . . . , 0]T, corresponding to the second eigenvector v = a2 and preserved variance σ2

v = λ2

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 44 / 48

slide-111
SLIDE 111

PCA The PCA algorithm

The PCA algorithm

In order to find the dimension of second highest variance, we have to look for an axis v orthogonal to a1

☞ UT is orthogonal, so the coordinates y = UTv must be

  • rthogonal to first axis [1, 0, . . . , 0]T, i.e. y = [0, y2, . . . , yn]T

In other words, we have to maximize vTCv = λ2(y2)2 · · · + λn(yn)2 under constraints y1 = 0 and (y2)2 + · · · + (yn)2 = 1 Again, solution is y = [0, 1, 0, . . . , 0]T, corresponding to the second eigenvector v = a2 and preserved variance σ2

v = λ2

Similarly for the third, fourth, . . . axis

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 44 / 48

slide-112
SLIDE 112

PCA The PCA algorithm

The PCA algorithm

The eigenvectors ai of the covariance matrix C are called the principal components of the data set The amount of variance preserved (or “explained”) by the i-th principal component is given by the eigenvalue λi Since λ1 ≥ λ2 ≥ · · · ≥ λn, the first principal component accounts for the largest amount of variance etc. Coordinates of a point x in PCA space are given by UTx (note: these are the projections on the principal components) For the purpose of “noise reduction”, only the first n′ < n principal components (with highest variance) are retained, and the other dimensions in PCA space are dropped

☞ i.e. data points are projected into the subspace V spanned by the first n′ column vectors of U

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 45 / 48

slide-113
SLIDE 113

PCA The PCA algorithm

PCA example

−2 −1 1 2 −2 −1 1 2 buy sell

  • Evert & Lenci (ESSLLI 2009)

DSM: Matrix Algebra 30 July 2009 46 / 48

slide-114
SLIDE 114

PCA The PCA algorithm

PCA example

−2 −1 1 2 −2 −1 1 2 buy sell

  • book

bottle good house packet part stock system advertising arm asset car clothe collection copy dress food insurance land liquor number

  • ne

pair pound product property share suit ticket time year Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 46 / 48

slide-115
SLIDE 115

PCA with R

PCA in R

> pca <- prcomp(M) # for the buy/sell example data > summary(pca)

Importance of components: PC1 PC2 Standard deviation 0.947 0.599 Proportion of Variance 0.715 0.285 Cumulative Proportion 0.715 1.000

> print(pca)

Standard deviations: [1] 0.9471326 0.5986067 Rotation: PC1 PC2 buy

  • 0.5907416

0.8068608 sell -0.8068608 -0.5907416

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 47 / 48

slide-116
SLIDE 116

PCA with R

PCA in R

# Coordinates in PCA space > pca$x[c("house","book","arm","time"), ]

PC1 PC2 house -2.1390957 0.5274687 book

  • 1.1864783

0.3797070 arm 0.9141092 -1.3080504 time 1.8036445 0.1387165

# Transformation matrix U > pca$rotation

PC1 PC2 buy

  • 0.5907416

0.8068608 sell -0.8068608 -0.5907416

# Eigenvalues of the covariance matrix C > (pca$sdev)^2

[1] 0.8970602 0.3583299

Evert & Lenci (ESSLLI 2009) DSM: Matrix Algebra 30 July 2009 48 / 48