Professional Documents
Culture Documents
You
Transposing Vectors
If u is a row vector…
u=[12345]
…then u’ (“u-transpose”) is a column vector
1
2
u’ = 3 Answer: It’ll matter
4 when we come to
5 vector multiplication.
… and vice-versa.
Transposing Vectors
If u is a row vector…
u=[12345]
…then u’ (“u-transpose”) is a column vector
1
2
u’ = 3 OK.
4
5
… and vice-versa.
Vectors, Matrices & Neural Nets
Vectors, Matrices & Neural Nets
j1 j2 j3 Input units, j
Vectors, Matrices & Neural Nets
i1 i2 Output units, i
j1 j2 j3 Input units, j
Vectors, Matrices & Neural Nets
i1 i2 Output units, i
w11
w23 Connection
w12 w22 w13 weights, wij
w21
j1 j2 j3 Input units, j
Vectors, Matrices & Neural Nets
i1 i2 Output units, i
w11
w23 Connection
w12 w22 w13 weights, wij
w21
w11
w23 Connection
w12 w22 w13 weights, wij
w21
j1 j2 j3 Input units, j
i1 i2 Output units, i
w11
0.1
w23 Connection
w12
1.0 w22 0.2
w13 weights, wij
w21
j1 j2 j3 Input units, j
i1 i2 Output units, i
w11
0.1
w23
-0.9 Connection
w12
1.0 w22
0.1 0.2
w13 weights, wij
w21
1.0
j1 j2 j3 Input units, j
i1 i2 Output units, i
w11
0.1
w23
-0.9 Connection
w12
1.0 w22
0.1 0.2
w13 weights, wij
w21
1.0
Why in the world
j1 j2 j3 Input
would units, j
I care??
x2 .3
.5 x2
.5
.2
x3 x3
.2
x1 x1
.3
Vector as a point Vector as arrow
Geometric Analysis of Vectors
Dimensionality: The number of numbers in a vector
x2 .3
.5 x2
.5
.2
x3 x3
.2
x1 x1
.3
Vector as a point Vector as arrow
Geometric Analysis of Vectors
Implications for neural networks
• Auto-associative nets
• State of activation at time t is a vector (a point in a space)
• As activations change, vector moves through that space
• Will prove invaluable in understanding Hopfield nets
[5 4]*2=
Multiplying a Vector by a Scalar
5 10
[ 5 4 ] * 2 = [ 10 8 ]
Lengthens the vector but does not change its orientation
Adding a Vector to a Scalar
[5 4]+2=
Adding a Vector to a Scalar
[ 5 4 ] + 2 = NAN
Is Illegal.
Adding a Vector to a Vector
6
4
3 5
[5 4]+[3 6]=
Adding a Vector to a Vector
10
6
4
3 5 8
[ 5 4 ] + [ 3 6 ] = [ 8 10 ]
Forms a parallelogram.
Multiplying a Vector by a Vector 1:
The Inner Product (aka “Dot Product”)
?
Multiplying a Vector by a Vector 1:
The Inner Product (aka “Dot Product”)
v · u’ = 32
The Inner (“Dot”) Product
• In scalar notation…
u v’
d 1 4 4
u v' u i v i 5
2 10
i 1
3 6 18
32
The Inner (“Dot”) Product
• In scalar notation…
d
u v' u i v i
i 1
• In vector notation…
n w a
What Does the Dot Product “Mean”?
What Does the Dot Product “Mean”?
• Consider u u’
What Does the Dot Product “Mean”?
• Consider u u’
u = [ 3, 4 ]
3
What Does the Dot Product “Mean”?
u u’
• Consider u u’
3 3 9
u = [ 3, 4 ]
4 4 16
25
3
What Does the Dot Product “Mean”?
u u’
• Consider u u’
3 3 9
u = [ 3, 4 ]
4 4 16
25
u u u'
5
u ui 2
4
3
What Does the Dot Product “Mean”?
u u’
• Consider u u’
3 3 9
u = [ 3, 4 ]
4 4 16
25
u u u'
5
u ui 2
4
True for vectors of any
3 dimensionality
What Does the Dot Product “Mean”?
• So: u u u'
What Does the Dot Product “Mean”?
u v
Well… cos( uv )
u v
What Does the Dot Product “Mean”?
u v
Well… cos( uv )
u v
… and cos(uv) is a length-invariant measure of the
similarity of u and v
What Does the Dot Product “Mean”?
U = [ 1, 0 ]
What Does the Dot Product “Mean”?
1
cos( uv )
u v
What Does the Dot Product “Mean”?
1
cos( uv )
u v
What Does the Dot Product “Mean”?
1
cos( uv ) .707
1*1.414
What Does the Dot Product “Mean”?
V’ = [ 0, 1 ]
uv = 90º; cos(uv) = 0
U = [ 1, 0 ]
What Does the Dot Product “Mean”?
V’ = [ 0, -1 ]
What Does the Dot Product “Mean”?
uv = 180º; cos(uv) = -1
U = [ 1, 0 ]
V’ = [ -1,0 ]
What Does the Dot Product “Mean”?
uv = 0º; cos(uv) = 1
U = [ 1, 0 ]
V’ = [ 2.2,0 ]
What Does the Dot Product “Mean”?
In general…
cos(uv) -1…1
True regardless of dimensionality
What Does the Dot Product “Mean”?
cos( uv )
u v i i
u v2
i
2
i
What Does the Dot Product “Mean”?
cos( uv )
u v i i
r(u,v)
(u u )(v v )
i i
u v2
i
2
i (u u ) (v v )
i
2
i
2
What Does the Dot Product “Mean”?
cos( uv )
u v i i
r(u,v)
(u u )(v v )
i i
u v2
i
2
i (u u ) (v v )
i
2
i
2
What Does the Dot Product “Mean”?
cos( uv )
u v i i
r(u,v)
(u u )(v v )
i i
u v2
i
2
i (u u ) (v v )
i
2
i
2
The cosine is a special case of the correlation coefficient!
What Does the Dot Product “Mean”?
u v
cos( uv )
u v
What Does the Dot Product “Mean”?
u v
cos( uv )
u v
If u and v have lengths of 1, then the dot product is equal to the cosine.
What Does the Dot Product “Mean”?
u v
cos( uv )
u v
If u and v have lengths of 1, then the dot product is equal to the cosine.
The dot product is a special case of the cosine, which is a special case of
the correlation coefficient, which is a measure of vector similarity!
What Does the Dot Product “Mean”?
ni wij a j w i a
j
• The most common input rule is a dot product between unit i’s
vector of weights and the activation vector on the other end
• Such a unit is computing the (biased) similarity between what
it expects (wi) and what it’s getting (a).
• It’s activation is a positive function of this similarity
What Does the Dot Product “Mean”?
ni wij a j w i a
j
• The most common input rule is a dot product between unit i’s
vector of weights and the activation vector on the other end
• Such a unit is computing the (biased) similarity between what
it expects (wi) and what it’s getting (a).
• It’s activation is a positive function of this similarity
ai asymptotic
ni
What Does the Dot Product “Mean”?
ni wij a j w i a
j
• The most common input rule is a dot product between unit i’s
vector of weights and the activation vector on the other end
• Such a unit is computing the (biased) similarity between what
it expects (wi) and what it’s getting (a).
• It’s activation is a positive function of this similarity
ai Step (BTU)
ni
What Does the Dot Product “Mean”?
ni wij a j w i a
j
• The most common input rule is a dot product between unit i’s
vector of weights and the activation vector on the other end
• Such a unit is computing the (biased) similarity between what
it expects (wi) and what it’s getting (a).
• It’s activation is a positive function of this similarity
ai logistic
ni
Multiplying a Vector by a Vector 2:
The Outer Product
The two vectors need not have the same dimensionality.
Same Mantra: Rows by Columns.
This time, multiply a column vector by a row vector:
Multiplying a Vector by a Vector 2:
The Outer Product
The two vectors need not have the same dimensionality.
Same Mantra: Rows by Columns.
This time, multiply a column vector by a row vector:
M = u’ * v
1
u’ = v=[4 5 6]
2
Multiplying a Vector by a Vector 2:
The Outer Product
The two vectors need not have the same dimensionality.
Same Mantra: Rows by Columns.
This time, multiply a column vector by a row vector:
M = u’ * v
1
u’ = v=[4 5 6] M=
2
Multiplying a Vector by a Vector 2:
The Outer Product
The two vectors need not have the same dimensionality.
Same Mantra: Rows by Columns.
This time, multiply a column vector by a row vector:
M = u’ * v
1
u’ = v=[4 5 6] M=
2
Row 1
Multiplying a Vector by a Vector 2:
The Outer Product
The two vectors need not have the same dimensionality.
Same Mantra: Rows by Columns.
This time, multiply a column vector by a row vector:
M = u’ * v
1
u’ = v=[4 5 6] M=
2
M = u’ * v
1 4
u’ = v=[4 5 6] M=
2
M = u’ * v
1 4 5
u’ = v=[4 5 6] M=
2
M = u’ * v
1 4 5 6
u’ = v=[4 5 6] M=
2
M = u’ * v
1 4 5 6
u= v=[4 5 6] M=
2 8
M = u’ * v
1 4 5 6
u’ = v=[4 5 6] M=
2 8 10
M = u’ * v
1 4 5 6
u’ = v=[4 5 6] M=
2 8 10 12
M = u’ * v
A better way to visualize it…
v=[4 5 6]
u’ = 1 4 5 6
=M
2 8 10 12
Multiplying a Vector by a Vector 2:
The Outer Product
Outer product is not exactly commutative…
M = u’ * v M = v’ * u
v=[4 5 6] u=[1 2]
1 4 5 6 4 4 8
u’ = =M v’ = 5
2 8 10 12 5 10
6 6 12
Multiplying a Vector by a Matrix
• Same Mantra: Rows by Columns
Rows by Columns
A row vector:
[ .2 .6 .3 .7 .9 .4 .3 ]
Rows by Columns
A row vector: A matrix:
[ .2 .6 .3 .7 .9 .4 .3 ] .3 .4 .8 .1 .2 .3
.5 .2 0 .1 .5 .2
.1 .1 .9 .2 .5 .3
.2 .4 .1 .7 .8 .5
.9 .9 .2 .5 .3 .5
.4 .1 .2 .7 .8 .2
.1 .2 .2 .5 .7 .2
Rows by Columns
A row vector: A matrix:
[ .2 .6 .3 .7 .9 .4 .3 ] .3 .4 .8 .1 .2 .3
.5 .2 0 .1 .5 .2
.1 .1 .9 .2 .5 .3
Multiply rows
.2 .4 .1 .7 .8 .5
.9 .9 .2 .5 .3 .5
.4 .1 .2 .7 .8 .2
.1 .2 .2 .5 .7 .2
Rows by Columns
A row vector: A matrix:
[ .2 .6 .3 .7 .9 .4 .3 ] .3 .4 .8 .1 .2 .3
.5 .2 0 .1 .5 .2
.1 .1 .9 .2 .5 .3
Multiply rows by columns
.2 .4 .1 .7 .8 .5
.9 .9 .2 .5 .3 .5
.4 .1 .2 .7 .8 .2
.1 .2 .2 .5 .7 .2
Each such multiplication is a simple dot product
1 2
1 2 3
1 2
1 2 3
1 2
Row 1 X Column 1
A 2 X 3 matrix A 3 X 2 matrix
1 1 2 Column 1
Row 1 1 2 3
2 1 2
1 2 3
3 1 2
(proxy)
Row 1 X Column 1
A 2 X 3 matrix A 3 X 2 matrix
1 1 2 Column 1
Row 1 1 2 3
2 1 2
1 2 3
3 1 2
Result = 6
Row 1 X Column 1
A 2 X 3 matrix A 3 X 2 matrix
1 1 2 Column 1
Row 1 1 2 3
2 1 2
1 2 3
3 1 2
Result = 6
1 1 2 Column 1
Row 1 1 2 3
2 1 2
1 2 3
3 1 2
Result = 6
1 1 2 Column 1
Row 1 1 2 3
2 1 2
1 2 3
3 1 2
Result = 6
1 1 2 Column 2
Row 1 1 2 3
2 1 2
1 2 3
3 1 2
Result = 12
6
Row 1 X Column 2
A 2 X 3 matrix A 3 X 2 matrix
1 1 2 Column 2
Row 1 1 2 3
2 1 2
1 2 3
3 1 2
Result = 12
1 1 2 Column 1
1 2 3
Row 2 2 1 2
1 2 3
3 1 2
Result = 6
6 12
Row 2 X Column 1
A 2 X 3 matrix A 3 X 2 matrix
1 1 2 Column 1
1 2 3
Row 2 2 1 2
1 2 3
3 1 2
Result = 6
1 1 2 Column 2
1 2 3
Row 2 2 1 2
1 2 3
3 1 2
Result = 12
6 12
6
Row 2 X Column 2
A 2 X 3 matrix A 3 X 2 matrix
1 1 2 Column 2
1 2 3
Row 2 2 1 2
1 2 3
3 1 2
Result = 12
1 2
1 2 3
1 2 3 * 1 2
1 2
6 12
=
6 12
A 2 X 2 matrix
So…
A 2 X 3 matrix A 3 X 2 matrix
1 2
1 2 3
1 2 3 * 1 2
1 2
The result has
the same
number of
6 12
rows as the
first matrix… =
6 12
A 2 X 2 matrix
So…
A 2 X 3 matrix A 3 X 2 matrix
1 2
1 2 3
1 2 3 * 1 2
1 2
The result has …and the same
the same number of columns
number of as the second.
6 12
rows as the
first matrix… =
6 12
A 2 X 2 matrix
…and…
A 2 X 3 matrix A 3 X 2 matrix
1 2
1 2 3
1 2 3 * 1 2
1 2
…and the
number of
columns in the
6 12
first matrix…
=
6 12
A 2 X 2 matrix
…and…
A 2 X 3 matrix A 3 X 2 matrix
1 2
1 2 3
1 2 3 * 1 2
1 2
…and the …must be equal to
number of the number of rows
columns in the in the second.
6 12
first matrix…
=
6 12
A 2 X 2 matrix
This is basic (default) matrix
multiplication.
There’s other more complicated stuff, too.
You (probably) won’t need it for this class.