Lecture 2 Introduction to Linear Algebra (Part 1)
Lecture 2 Introduction to Linear Algebra (Part 1)
Algebra (Part 1)
1
Week Topic Instructor
1 Data Analytics: An Introduction Jing/Lotto
2 Introduction to Linear Algebra (Part 1) Jing/Lotto
3 Introduction to Linear Algebra (Part 2) Jing/Lotto
4 Introduction to Calculus (Part 1) Jing/Lotto
(+ Quiz 1)
5 Introduction to Calculus (Part 2) Jing/Lotto
Teaching 6
7
In-class Midterm Test
Programming with R (Part 1)
Jing/Lotto
Jibin
Plan 8 Programming with R (Part 2) Jibin
9 Data Visualization Jibin
10 Monto-Carlo Simulation Jibin
11 Linear Regression Jibin
(Assignment out)
12 Time-series Analysis Jibin
(+ Quiz 2)
13 Review and Exam Q&A Jibin & Jing/Lotto
(Assignment due)
Course Structure
Simulation Time-Series
Advanced Data Analytics (3 lectures) Analysis
Regression
3
The roles of
Linear • Understanding Multidimensional Data
Algebra in • The language for describing and manipulating
multidimensional data structures.
Data • Key Concepts
Analytics • Vectors: Data points, features, or even functions
can be represented as vectors.
• Matrices: Datasets are often represented as
matrices, with rows corresponding to individual
records and columns to features.
4
More Examples about data representations
Computer Vision
Product Recommendation
5
Roadmap
• Concepts of the Vector and Matrix
• Vector and Matrix arithmetic
• Addition
• Vector Product
• Matrix Product
• Some special matrices
6
Roadmap
• Concepts of the Vector and Matrix
• Vector and Matrix arithmetic
• Addition
• Vector Product
• Matrix Product
• Some special matrices
7
What is a Vector?
A vector is an ordered list of numbers, such as
−1
Default:
(−1 0 3.6 7.2) or 0 column Elements or entries,
3.6 vectors e.g., the 3rd entry is 3.6
7.2
Seen as a directed line segment in 𝑛-dimensions.
Count of entries: dimension.
Algebra in a
Vector above has dimension 4
y higher dimension.
Vectors of dimension 𝑛: 𝑛-vector.
Numbers are called scalars. v
word 1
in 1 Word
number 0 Count
Dictionary
house 0 Vector
the 0
document 1
9
Vector’s Norm (Length)
The Euclidean norm (or norm) of an 𝑛-vector 𝑥 is:
10
Vectors’ Distance
The Euclidean distance (or distance) of two 𝑛-vectors 𝑥 and 𝑦 is:
𝑥−𝑦 = 𝑥1 − 𝑦1 2 + 𝑥2 − 𝑦2 2 + ⋯ + 𝑥𝑛 − 𝑦𝑛 2
11
Example: Document Distance
5 Wikipedia articles:
Veterans Day, Memorial Day, Academy Awards, Golden
Globe Awards, Super Bowl
Word count vectors with 4,423 words in dictionary.
Pairwise
Distance
12
What is a Matrix?
17
Example: Word Count Vector Addition
Two sentences in a dataset
Each entry of the word count vector is the number of times the
associated dictionary word appears in the document.
word 1 2 3
Dictionary in 1 1 2 Word
number 0 1 1 Count
+ = Vector
house 0 0 0
the 0 4 4 Addition
document 1 1 2 18
Roadmap
• Concepts of the Vector and Matrix
• Vector and Matrix arithmetic
• Addition
• Vector Product
• Matrix Product
• Some special matrices
19
To stretch or shrink the vector's length
Scalar times vector without changing its direction, like pulling or
compressing a spring along its line of action.
20
Product of 2 Vectors
Three ways to multiply
• Element-by-element
• Inner product
• Outer product
21
Element-by-element • Element-wise multiplication
product (Hadamard
• Sometimes written as ⊙
product)
22
Multiplication: A single number that represents
the magnitude of one vector
Dot product (inner product) projected onto the other.
𝑥Ԧ 𝑇 𝑦Ԧ or
𝑦:
Ԧ column vector
𝑥:
Ԧ row vector (transpose,
T, of column vector)
1XN NX1
23
Example: Dot Product
• Pick out the i-th entry: 𝑒𝑖𝑇 𝑎 = 𝑎𝑖
• Sum of entries: 1𝑇 𝑎 = 𝑎1 + 𝑎2 + ⋯ + 𝑎𝑛
• Sum of squares of entries:
• 𝑎𝑇 𝑎 = 𝑎12 + 𝑎22 + ⋯ + 𝑎𝑛2
• More examples.
• 𝑤 is a weight vector, 𝑓 is feature vector,
𝑤 𝑇 𝑓 is weighted score.
• 𝑝 is vector of prices, 𝑞 is vector of
quantities, 𝑝𝑇 𝑞 is total cost.
24
Dot product geometric intuition:
“Overlap” of 2 vectors
25
The angle of two vectors
• Angle 𝜃 between two non-zero vectors 𝑎 and 𝑏
𝑎𝑇 𝑏
• 𝑐𝑜𝑠𝜃 = where 0≤𝜃≤𝜋
𝑎 ⋅| 𝑏 |
• Several cases of 𝜃:
𝜋
• 𝜃 = = 90°: 𝑎 and 𝑏 are orthogonal, i.e., 𝑎 ⊥ 𝑏
2
• 𝜃 = 0: 𝑎 and 𝑏 are aligned. Here 𝑎𝑇 𝑏 = 𝑎 ⋅ | 𝑏 |
• 𝜃 = 𝜋 = 180°: 𝑎 and 𝑏 are anti-aligned. 𝑎𝑇 𝑏 = − 𝑎 ⋅ | 𝑏 |
𝜋
• 𝜃 ∈ (0, ): 𝑎 and 𝑏 make an acute angle. 𝑎𝑇 𝑏 > 0.
2
𝜋
• 𝜃 ∈ ( , 𝜋): 𝑎 and 𝑏 make an obtuse angle. 𝑎𝑇 𝑏 < 0.
2
26
Example: Document Dissimilarity
5 Wikipedia articles:
Veterans Day, Memorial Day, Academy Awards, Golden Globe Awards, Super Bowl
Word count vectors with 4,423 words in dictionary.
Pairwise Angles in
Degrees
27
Example: Dot product and cosine similarity
28
Example: A Bias Problem
with raw dot-product
• Dot product favors long vectors
• Dot product is higher if a vector is longer (has higher values in many
dimension)
• Vector length:
• For example, a document with frequent words (of, the, you) have
long vectors (since these words tend to occur many times)…
• So dot product overly favors document sizes…
29
Dot Product
similarity
30
Input neurons’
Example: Firing rates
linear feed- r1
forward
network r2
Output neuron’s
firing rate
ri
rn
31
Multiplication: Outer product
𝑥Ԧ 𝑦Ԧ 𝑇 or 𝑥Ԧ ⊗ 𝑦Ԧ
• Each element is the product of a pair of elements from the two vectors
• The results measure all possible products between the components of the two vectors.
32
Roadmap
• Concepts of the Vector and Matrix
• Vector and Matrix arithmetic
• Addition
• Vector Product
• Matrix Product
• Some special matrices
33
Matrix times a vector
35
Matrix times a vector:
outer product interpretation
(3,5)
• Note: different
(0,4)
combinations of the
(0,2) columns of M can give you
(3,1) any vector in the plane
(we say the columns of M
“span” the plane)
37
Rank of a Matrix
Are there special matrices whose columns don’t span the full plane?
(1,2)
(-2, -4)
• You can only get vectors along the (1,2) direction (i.e.,
outputs live in 1 dimension, so we call the matrix rank 1)
38
Example: 2-layer linear network
39
Example: 2-layer linear network:
inner product point of view
40
Example: 2-layer linear network:
outer product point of view
•How does cell xj contribute to the pattern of firing of layer 2?
1st column
of W
Contribution
of xj to
network output
41
Product of 2 Matrices
44
Roadmap
• Concepts of the Vector and Matrix
• Vector and Matrix arithmetic
• Addition
• Vector Product
• Matrix Product
• Some special matrices
45
Special matrices: diagonal matrix
This acts like scalar multiplication
46
Special matrices: • for all
identity matrix
47
Special matrices:
inverse matrix
Does the inverse always exist?
We’ll explore in the next class.
48
• A vector is a collection of numbers arranged in
order, representing a point in space with direction
and length, while a matrix is a rectangular array
of numbers arranged in rows and columns, used
to represent and perform operations on linear
transformations and data sets.
• The inner product of vectors is a scalar that
A slide to quantifies the extent to which one vector aligns
with another, whereas the outer product
take away produces a matrix representing all pairwise
multiplications of the elements from two vectors.
• The matrix product combines the inner product
through row-by-column multiplications to
determine each individual element, and can be
viewed as a series of outer products that are
summed to form the final matrix.
49