Download presentation

Presentation is loading. Please wait.

Published byHaleigh Crosby Modified about 1 year ago

1
Matrix Algebra (and why it’s important!) Methods for Dummies FIL October 2007 Steve Fleming & Verity Leeson

2
Sources and further information Jon Machtynger & Jen Marchant’s slides! Human Brain Function textbook (for GLM) SPM course http://www.fil.ion.ucl.ac.uk/spm/course/ http://www.fil.ion.ucl.ac.uk/spm/course/ Web Guides –http://mathworld.wolfram.com/LinearAlgebra.html http://mathworld.wolfram.com/LinearAlgebra.html –http://www.maths.surrey.ac.uk/explore/emmaspages/opt ion1.html http://www.maths.surrey.ac.uk/explore/emmaspages/opt ion1.htmlhttp://www.maths.surrey.ac.uk/explore/emmaspages/opt ion1.html –http://www.inf.ed.ac.uk/teaching/courses/fmcs1/ http://www.inf.ed.ac.uk/teaching/courses/fmcs1/ (Formal Modelling in Cognitive Science course) –http://www.wikipedia.org http://www.wikipedia.org

3
Scalars, vectors and matrices Scalar: Variable described by a single number – e.g. Image intensity (pixel value) Vector: Variable described by magnitude and direction – e.g. Image intensity at a particular time Matrix: Rectangular array of vectors defined by number of rows and columns Square (3 x 3)Rectangular (3 x 2) d r c : r th row, c th column 3 2 (Roman Catholic)

4
Matrices in Matlab Vector formation: Vector formation: [1 2 3] Matrix formation: X = [1 2 3; 4 5 6; 7 8 9] = Subscripting – each element of a matrix can be addressed with a pair of numbers; row first, column second (Roman Catholic) e.g. X(2,3) = 6 X(3, :) = X( [2 3], 2) = ‘;’ is used to signal end of a row ‘:’ is used to signify all rows or columns “Special” matrix commands: zeros(3,1) = ones(2) = magic(3) more to come…

5
Addition (matrix of same size) –Commutative: A+B=B+A –Associative: (A+B)+C=A+(B+C) Subtraction (consider as the addition of a negative matrix) Matrix addition

6
Matrix multiplication a 11 a 12 a 13 b 11 b 12 a 21 a 22 a 23 X b 21 b 22 a 31 a 32 a 33 b 31 b 32 a 41 a 42 a 43 Scalar multiplication: Rule for multiplication of vectors/matrices: b 11 b 12 a 11 a 12 a 13 b 21 b 22 x a 21 a 22 a 23 b 31 b 32 a 31 a 32 a 33 a 41 a 42 a 43 Matrix multiplication rule: “ “When A is a mxn matrix & B is a kxl matrix, AB is only viable if n=k. The result will be an mxl matrix” nl m k

7
Sum over product of respective rows and columns For larger matrices, following method might be helpful: Multiplication method m l m l X= = = Define output matrix Sum over c rc Matlab does all this for you! Simply type: C = A * B N.B. If you want to do element-wise multiplication, use: A.* B rc

8
Transposition column → row row → column M rc = M cr In Matlab: A T = A’

9
Outer product = matrix Inner product = scalar Two vectors: Outer and inner products of vectors (1xn)(nx1) (1X1) (nx1)(1xn) (nXn)

10
Identity matrices Is there a matrix which plays a similar role as the number 1 in number multiplication? Consider the nxn matrix: Consider the nxn matrix: A square nxn matrix A has one A I n = I n A = A An nxm matrix A has two!! I n A = A & A I m = A 1231001+0+00+2+00+0+3 456 X010=4+0+00+5+00+0+6 7890017+0+00+8+00+0+9 Worked example A In = A for a 3x3 matrix: In Matlab: eye(r, c) produces an r x c identity matrix

11
Inverse matrices Definition. A matrix A is nonsingular or invertible if there exists a matrix B such that: worked example: Common notation for the inverse of a matrix A is A -1 If A is an invertible matrix, then (A T ) -1 = (A -1 ) T The inverse matrix A -1 is unique when it exists. If A is invertible, A -1 is also invertible A is the inverse matrix of A -1.11X 23232323 -1 3 = 2 + 1 3 3 -1 + 1 3 3 =102 13131313 13131313 -2+ 2 3 3 1 + 2 3 3 01 In Matlab: A -1 = inv(A) Matrix division: A/B = AB -1

12
Determinants Determinant is a function: –Input is nxn matrix –Output is a single number (real or complex) called the determinant In Matlab: det(A) = det(A) A matrix A has an inverse matrix A -1 if and only if det(A)≠0 (see next slide)

13
Calculation of inversion using determinants More complex matrices can be inverted using methods such as the Gauss-Jordan elimination, Gaussian elimination or LU decomposition thus Note: det(A)≠0 Or you can just type inv(A) !

14
Applications

15
SEM http://www.maths.soton.ac.uk/~jav/soton/MATH1007/workbook_8/8_2_inv _mtrx_sim_lin_eqnpdf.pdf Neural Networks http://csn.beckman.uiuc.edu/k12/nn_matrix.pdf SPM http://imaging.mrc-cbu.cam.ac.uk/imaging/PrinciplesStatistics

16
Solving simultaneous equations For one linear equation ax=b where the unknown is x and a and b are constants 3 possibilities

17
With >1 equation and >1 unknown Can use solution from the single equation to solve For example In matrix form AX = B

18
Need to find determinant of matrix A (because X =A -1 B) From earlier (2 x -2) – (3 x 1) = -4 – 3 = -7 So determinant is -7 To find A -1

19
if B is So

20
Neural Networks Neural networks create a mathematical model of the connections in a neural system Connections are the excitatory and inhibitory synapses between neurons Excitatory ConnectionInhibitory Connection Input Neuron Output Neuron

21
Scenario 1 Input Neuron Output Neuron If then

22
Scenario 2 + = The combination of both an active excitatory and active inhibitory input will cancel outThe combination of both an active excitatory and active inhibitory input will cancel out No net activityNo net activity

23
Matrix Representations of Neural Connections –Scenario 2 again #1#3 #2 += +1 11 Excitatory = positive influence on post synaptic cell Inhibitory = negative influence With the synapses labelled (1-3) and activity level specified we can translate this information into a set of vectors (1 row matrices)

24
Input vector = (1 1) relates to activity (#1 #2) Weight vector = (1 -1) relates to connection weight (#1 #2) #1#3 #2 += +1 11 Activity of Neuron 3 Input x weight With varying input (activity) and weight, neuron 3 can take on a wide range of values

25
How are matrices relevant to fMRI data? Consider that data measured includes –Response variable e.g BOLD signal at a particular voxel Many scalars for this one voxel –Explanatory variables These are assumed to be measured without error May be continuous May be dummy indicating levels of an experimental factor

26
With a single explanatory variable Y = X. β + ε Observed = Predictors * Parameters + Error BOLD = Design Matrix * Betas + Error

27
Y is a matrix of BOLD signals Each column represents a single voxel sampled at successive time points. Each voxel is considered as independent observation Each voxel is considered as independent observation Analysis of individual voxels over time, not groups over space Analysis of individual voxels over time, not groups over space Preprocessing... Intensity Time Y Y = X. β + ε

28
Design Matrix Matrix Rows : values of X for a single predictor Columns : different predictors Y X 1 X 2 X 1 X 2 Y = X. β + ε Most –ve nearest black, most +ve nearest white

29
A complex version + = + YX data vector (Voxel) design matrix parameters error vector × = Solve equation for β – tells us how much of the BOLD signal is explained by X

30
The End… Any (easy) questions?!

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google