1 Vectors
1 Vectors
1 Vectors
Vectors
Examples
Inner product
Complexity
1: Vectors 2/29
Vectors via symbols 1
• other conventions (that you should not use in this course): g, "a
• if a = (5, 7, 1, 4, 6) then, a3 = 1
• in ai , i is the index
• two vectors a and b of the same size are equal if ai = bi for all i
1: Vectors 3/29
Block vectors 2
• a has size m + n + p
a = (b1 , b2 , . . . , bm , c1 , c2 , . . . , cn , d1 , d2 , . . . , dp )
1: Vectors 4/29
Zero, ones, and unit vectors 3,4
1: Vectors 5/29
Sparsity 5
1: Vectors 6/29
Outline
Vectors
Examples
Inner product
Complexity
1: Vectors 7/29
Location or displacement in 2-D or 3-D 6
1: Vectors 8/29
Images, video
1: Vectors 9/29
Portfolio vector
Portfolio
• n-vector represents stock portfolio or investment in n assets
1: Vectors 10/29
Resource vector
Resource vector
• elements of n-vector represent quantities of n resources or commodities
r = ( −2, 1, 0, −1)
1: Vectors 11/29
Feature vectors
Examples
• age, weight, blood pressure, gender, . . . of patients
Area (m2 ) Bedrooms Bathrooms Cars Pets Weekly rental price ($)
252 3 2 2 1 1400
Note
• vector elements can represent very different quantities, in different units
1: Vectors 12/29
Word count vectors 7
• a short document:
1: Vectors 13/29
Polynomials 8
a polynomial of degree n − 1
f (t) = c1 + c2 t + c3 t2 + · · · + cn tn−1
Example
f (t) = 3 + t − 5t2 + 2t3
would be represented by the n-vector (3, 1, −5, 2)
1: Vectors 14/29
Outline
Vectors
Examples
Inner product
Complexity
1: Vectors 15/29
Vector addition 9
• subtraction is similar
• associative: (a + b) + c = a + (b + c)
(so we can write both as a + b + c)
• a+0=0+a=a
• a−a=0
1: Vectors 16/29
Scalar-vector multiplication 10
βa = (βa1 , . . . , βan )
• also denoted aβ
• example:
! $ ! $
1 −2
(−2) # 9 & = # −18 &
6 −12
1: Vectors 17/29
Linear combinations 11
β1 a 1 + · · · + βm a m
b = b1 e 1 + · · · + bn e n
1: Vectors 18/29
Outline
Vectors
Examples
Inner product
Complexity
1: Vectors 19/29
Inner product 12
aT b = a1 b1 + a2 b2 + · · · + an bn
• other notation used (that you should not use in this course):
〈a, b〉, 〈a|b〉, (a, b), a · b
• example:
! $T ! $
−1 1
# 2 & # 0 & = (−1)(1) + (2)(0) + (2)(−3) = −7
2 −3
1: Vectors 20/29
Properties of inner product 12
• aT a = 0 if and only if a = 0
• commutative: aT b = bT a
(a + b)T (c + d) = aT c + aT d + bT c + bT d
1: Vectors 21/29
Simple examples
• eTi a = ai (inner product with ith unit vector picks out ith entry)
• (ei − ej )T a = ai − aj (differencing)
• 1 T a = a1 + · · · + an (sum of entries)
1: Vectors 22/29
Example: Weighted sum
• w is vector of weights
• f is vector of features
Example
1: Vectors 23/29
Example: Cost
1: Vectors 24/29
Example: Portfolio return
pfinal
i − pinit
i
ri = , i = 1, . . . , n
pinit
i
where pinit
i and pfinal
i are the prices of asset i at the beginning and end of
the period
1: Vectors 25/29
Example: Portfolio return
Example: We have two companies we have invested in. We invested $200 into
company 1 and $100 into company 2. This means that:
h = (200, 100)
pfinal
1 − pinit
1 27.10 − 54.20
r1 = init
= = −0.5
p1 54.20
pfinal
2 − pinit
2 50.00 − 40.00
r2 = = = 0.25
pinit
2 40.00
Our fractional returns are then:
r = (−0.5, 0.25)
Our total returns are then:
rT h = −0.5 × 200 + 0.25 × 100 = −100 + 25 = −75
1: Vectors 26/29
Outline
Vectors
Examples
Inner product
Complexity
1: Vectors 27/29
Flop counts
1: Vectors 28/29
Complexity