Short recapitulation of matrix algebra

advertisement
Short recapitulation of matrix basics
Species
Taxon
Guild
Nanoptilium kunzei (Heer, 1841)
Acrotrichis dispar (Matthews, 1865)
Ptiliidae
Ptiliidae
Necrophagous
Necrophagous
Mean
length
(mm)
0.60
0.65
Acrotrichis silvatica Rosskothen, 1935
Ptiliidae
Necrophagous
Acrotrichis rugulosa Rosskothen, 1935
Ptiliidae
Acrotrichis grandicollis (Mannerheim, 1844)
Acrotrichis fratercula (Matthews, 1878)
Ptiliidae
Ptiliidae
Site 1
Site 2
Site 3
Site 4
0
13
0
0
0
4
0
7
0.80
16
0
2
0
Necrophagous
0.90
0
0
1
0
Necrophagous
0.95
1
0
0
1
Necrophagous
1.00
0
1
0
0
1
0
0
0
13
0
0
8
3
0
5
23
0
5
0
2
5
0
4
0
0
5
6
0
6
9
2
0
0
1
0
0
Carcinops pumilio (Erichson, 1834)
Histeridae
Predator
2.15
Saprinus aeneus (Fabricius, 1775)
Histeridae
Histeridae
Histeridae
Staphylinidae
Histeridae
Histeridae
Histeridae
Predator
Predator
Predator
Predator
Predator
Predator
Predator
3.00
Gnathoncus nannetensis (Marseul, 1862)
Margarinotus carbonarius (Hoffmann, 1803)
Rugilus erichsonii (Fauvel, 1867)
Margarinotus ventralis (Marseul, 1854)
Saprinus planiusculus Motschulsky, 1849
Margarinotus merdarius (Hoffmann, 1803)
3.10
3.60
3.75
4.00
4.45
4.50
A vector can be
interpreted as a
file of data
Handling biological data is most easily done with a matrix approach.
An Excel worksheet is a matrix.
A matrix is a
collection of
vectors and can
be interpreted
as a data base
The red matrix
contain three
column vectors
 a11

A
a
 m1
a1n 


a mn 
 a1 
 
a
V 2
 a3 
 
 a4 
Column
vector
The symmetric matrix is a matrix where
An,m = A m,n.
1

2
A
3

4

2 3 4

4 5 6
5 7 8

6 8 1 
The first subscript denotes rows,
the second columns.
n and m define the dimension of a matrix.
A has m rows and n columns.
V   a1 a 2
a3 a 4 
Row
vector
The diagonal matrix is a square and symmetrical.
1

0
A
0

0

0 0 0

4 0 0
0 7 0

0 0 1 
Λ  3 is a matrix with one row and one column.
It is a scalar (ordinary number).
1

0
A
0

0

0 0 0

1 0 0
0 1 0

0 0 1 
Unit matrix I
For a non-singular square matrix
the inverse is defined as
A  A 1  I
A 1  A  I
(A•B)-1 = B-1 •A-1 ≠ A-1 •B-1
A matrix is singular if it’s
determinant is zero.
a 
a
A   11 12 
 a21 a22 
a 
a
Det A  A   11 12   a11a22  a21a12
 a21 a22 
Singular matrices are those where some rows or
columns can be expressed by a linear
combination of others.
Such columns or rows do not contain additional
information.
They are redundant.
 1 2 3


A   2 4 6
7 8 9


r2=2r1
A linear combination of vectors
V  k1V1  k2 V2  k3V3  ...  kn Vn
A 1 
A matrix is singular if at least one of the
parameters k is not zero.
r3=2r1+r2
The inverse of a 2x2 matrix
 a11
A  
 a12
Det A: determinant of A
1 2 3 


A  4 5 6 
 6 9 12 


a21 

a22 
 a22
1

a11a22  a12a21   a12
Determinant
 a21 

a11 
Scalar product
 b11 ... ... b1m 
Addition and subtraction
 a11  b11

 ...
AB 
...

a  b
 n1 n1
... ... a1m  b1m 

... ...
... 
... ...
... 

... ... anm  bnm 


 ... ... ... ... 
B  
 B
... ... ... ... 


 b ... ... b 
nm 
 n1
The inner or dot product
 a11 ... a1m   b11

 
A  B   ... ... ...    ...
 a ... a   a
nm   m1
 n1
 m
a1i bi1 ...
... b1k   
i 1


... ...    ...
...

... a mk   m
  a ni bi1 ...
 i 1

a
b

1i ik 
A B ... A1Bk 
i 1
  1 1

...    ... ...
... 
 
m
A m B1 ... A m Bk 


a ni bik 

i 1

m
Basic rule of matrix multiplication
A  B  B A
(A  B)  C  A  (B  C)  A  B  C
(A  B)  C  A  C  B  C
A ij B jk C kl Dlm ...Z yz  Ciz
The general solution of a linear system
 1 0 ...

0 1 ...

A 1A  I
Identity matrix I  
... ... ...

X  A 1B
 0 0 ...

Only possible if A is not singular.
IX  XI  X
If A is singular the system has no solution.
AX  B  A 1AX  A 1B
3 x  2 y  4 z  10
 3 x  3 y  8 z  12
9 x  0 .5 y  2 . 3 z  1
0

0
... 

1 
Systems with a unique solution
The number of independent equations
equals the number of unknowns.
2
4 
 3


3
8 
3
 9  0.5 2.3 


2
4 10 
 3


3
8 12 
3
 9  0.5 2.3 1 


X: Not singular
2
4 
 3


3
8 
3
 9  0.5 2.3 


1
10   x   0.3819 
    

12    y    4.5627 
 1   z    0.0678 
    

The general solution of a linear system
Species
1981
1982
1983
1984
1985
1986
1987
Aspilota sp2 Aspilota sp5
3.8
0.7
3.5
0.5
6.6
0
5.8
2.3
0.8
0
26.8
13.4
18.3
5.8
Aspilota sp2
DN
N
-N2
-0.3
3.8
-14.44
3.1
3.5
-12.25
-0.8
6.6
-43.56
-5
5.8
-33.64
26
0.8
-0.64
-8.5
26.8
-718.24
Transpose
3.8
3.5
6.6
5.8
0.8
26.8
-14.44 -12.25 -43.56 -33.64 -0.64 -718.24
𝑟
∆𝑁 = 𝑟𝑁 − 𝑁 2
𝐾
𝑌 = 𝑋𝑎
XTX
822.77
-19829.7
𝑋 𝑇 𝑌 = 𝑋 𝑇 𝑋𝑎
(𝑋 𝑇 𝑋)−1 𝑋 𝑇 𝑌 = (𝑋 𝑇 𝑋)−1 𝑋 𝑇 𝑋𝑎=IA=A
DN
-0.2
-0.5
2.3
-2.3
13.4
-7.6
Aspilota sp5
N
-N2
0.7
-0.49
0.5
-0.25
0
0
2.3
-5.29
0
0
13.4
-179.56
XTY
-231.57
6257.805
Both species have low reproductive rate r.
They are prone to fast extinction.
-19829.7
519256.8
Aspilota
sp2
Aspilota
sp5
(XTX)-1
0.015267
0.000583
0.000583
2.42E-05
r/K
r
K
0.11308 6.90785
0.01637
r/K
r
K
-1.0019 30.9025
-0.03242
Orthogonal vectors
Y=
0
1
XY=
X=
1
0
0
=0
1
The dot product of two orthogonal vectors is zero.
If the orthogonal vectors have unity length they are called
orthonormal.
1
0
A system of n orthogonal vectors spans an n-dimensional
hypervolume (a Cartesian system)
In ecological modelling orthogonal vectors are of particular importance. They define
linearly independent variables.
Orthogonal matrix
𝐴=
𝐴′ 𝐴 =
𝑐𝑜𝑠𝛼
−𝑠𝑖𝑛𝛼
𝑐𝑜𝑠𝛼
𝑠𝑖𝑛𝛼
𝑠𝑖𝑛𝛼
𝑐𝑜𝑠𝛼
−𝑠𝑖𝑛𝛼
𝑐𝑜𝑠𝛼
𝐴𝑇 =
𝑐𝑜𝑠𝛼
−𝑠𝑖𝑛𝛼
𝑐𝑜𝑠 2 𝛼 + 𝑠𝑖𝑛2 𝛼
=
𝑐𝑜𝑠𝛼 𝑠𝑖𝑛𝛼 − 𝑐𝑜𝑠𝛼 𝑠𝑖𝑛𝛼
𝑐𝑜𝑠𝛼
𝑠𝑖𝑛𝛼
−𝑠𝑖𝑛𝛼
𝑐𝑜𝑠𝛼
V=
𝑠𝑖𝑛𝛼
𝑐𝑜𝑠𝛼
𝑐𝑜𝑠𝛼 𝑠𝑖𝑛𝛼 − 𝑐𝑜𝑠𝛼 𝑠𝑖𝑛𝛼 = 1
0
𝑐𝑜𝑠 2 𝛼 + 𝑠𝑖𝑛2 𝛼
𝑠𝑖𝑛𝛼
𝑐𝑜𝑠𝛼
d=1
X=cos(a)
0
1
Multiplying an orthogonal matrix with its transpose gives the identity matrix.
𝐴𝑇 𝐴 =
1 0
0 1
𝐴−1 𝐴 =
1 0
0 1
𝐴−1 = 𝐴𝑇
The transpose of an orthogonal system is identical to its inverse.
Y=sin(a)
Eigenvalues and eigenvectors
Y
How to transform
vector A into vector B?
XA  B
2  1   7 
 1

    
1.5 2.5  3   9 
B
Multiplication of a vector with
a square matrix defines a new
vector that points to a
different direction.
The matrix defines a
transformation in space
A
X
The vectors that don’t change
during transformation are the
eigenvectors.
𝑿𝑨 = 𝑨
In general we define
Y
𝑿𝑼 = 𝝀𝑼
B
A
U is the eigenvector and  the
eigenvalue of the square matrix X
XA  B
Image transformation
X
X contains all the information
necesssary to transform the image
𝑿𝑼 = 𝝀𝑼 → 𝑿𝑼 − 𝝀𝑼 = 𝟎
[X − 𝝀𝑰]𝑼 = 𝟎
[X − 𝜦]𝑼 = 𝟎
A matrix with n columns has n
eigenvalues and n eigenvectors.
Some properties of eigenvectors
If  is the diagonal matrix
of eigenvalues:
The eigenvectors of symmetric
matrices are orthogonal
ΛU  UΛ
A( symmetric) :
U' U  0
AU  UΛ  AUU 1  A  UU 1
Eigenvectors do not change after a
matrix is multiplied by a scalar k.
Eigenvalues are also multiplied by k.
The product of all
eigenvalues equals the
determinant of a
matrix.
[ A  I ]u  [kA  kI ]u  0
det A  i 1 i
n
The determinant is zero if
at least one of the
eigenvalues is zero.
In this case the matrix is
singular.
If A is trianagular or diagonal the
eigenvalues of A are the diagonal
entries of A.
A
2
3
3
-1
2
4
3
-6
-5
5
Eigenvalues
2
3
4
5
Matrix M
A
B
C
D
E
A
1
2
3
4
5
B
2
1
4
3
2
Eigenvalues of M
C
3
4
1
3
4
D
4
3
3
1
4
E
5
2
4
4
1
A
B
C
D
E
-4.37578
-3.49099
-2.20138
0.347457
14.72069
Eigenvectors U of M
A
B
C
D
E
A
0.438984
-0.29098
0.435137
0.127886
-0.71898
B
0.629065
0.442618
-0.37779
-0.50284
-0.11313
C
0.007298
-0.25089
0.56955
-0.71251
0.323958
D
0.443962
-0.72095
-0.37455
0.121699
0.357809
E
0.46305
0.369735
0.450844
0.456425
0.487132
The largest eigenvalue is
associated with the left
(dominant) eigenvector
UTU
A
A
B
C
D
E
1
1.39E-17
6.11E-16
3.89E-16
1.22E-15
B
C
D
E
1.39E-17 6.11E-16 3.89E-16 1.22E-15
1 2.29E-16 -3.5E-16 1.25E-16
2.29E-16
1 1.39E-16
-5E-16
-3.5E-16 1.39E-16
1 -6.1E-16
1.25E-16
-5E-16 -6.1E-16
1
UTU = I
Y
8.299247
6.668841
4.655068
10.10163
3.759326
0.14555
9.83781
4.885297
4.35569
1.044779
6.69628
1.591056
6.500477
4.208492
5.697605
1.499851
8.562652
7.354506
1.532767
2.285576
0.052058
A geometrical interpretation of eigenvalues
𝑿𝑼 = 𝝀𝑼
10
8
2
6
Y
X
7.492729
3.794709
7.188977
5.192209
3.358493
0.543067
8.105676
3.094105
7.392673
2.225443
9.748683
2.831838
8.602463
2.977185
3.5781
2.730209
7.122361
5.771215
2.740751
5.741111
0.301084
Ymean
4
2
0
0
2
Xmean
4
X
Y
6
8
10
X
Correlation matrix
X
Y
1 0.7218
0.7218 1
1
Eigenvalues
0.2782
1.7218
EV1
0.707
-0.707
EV2
0.707
0.707
The eigenvectors define the
major axes of the data.
The eigenvalues define the
length of the eigenvalues
Correlation matrix
X
Y
X
Y
1 0.7218
0.7218 1
1 − 𝜆1
𝑟
Eigenvalues
0.2782
1.7218
1 − 𝜆1 1 − 𝜆1 = 𝑟 2
1 − 2𝜆1 + 𝜆1 2 = 𝑟 2
[R − 𝜦]𝑼 = 𝟎
𝜆
1 𝑟
− 1
0
𝑟 1
10
(𝜆1 − 1)2 = 𝑟 2
0
=0
𝜆1
𝜆1 = +𝑟 + 1
8
Y
6
4
2
𝐴 = 𝜋𝜆1 𝜆2 = 𝜋(1 + 𝑟)(1 − 𝑟)
0
2
Xmean
4
X
6
𝜆2 = −𝑟 + 1
The eigenvalues of a correlation
similarity matrix are linearly
linked to the coefficients of
correlation.
The eigenvector ellipse
0
𝑟
= 0`
1 − 𝜆1
8
10
Eigenvectors and information content
𝑿𝑼 = 𝝀𝑼
A matrix is a data base that
contains an amount of
information.
Left and right sides of
an equation contain the
same amount of
information
The eigenvectors take
over the information
content of the data base
(the matrix)
The eigenvalues define ow much information contains each eigenvector.
The eigenvalue is a measure of correlation.
The squared eigenvalue is therefore a measure of the variance explained by the
associated eigenvector.
The eigenvector of the largest eigenvalue is called the dominant eigenvector and contains
the largest part of information of the associated data base.
Download