+ReviewofLinearAlgebraIntroductiontoMatlabMachineLearningGroupFall2014+OutlineLinearAlgebraBasicsMatrixCalculusSingularValueDecomposition(SVD)EigenvalueDecompositionLow-rankMatrixInversionMatlabessentialsBasicconceptsVectorinRnisanorderedsetofnrealnumbers.e.g.v=(1,6,3,4)isinR4Acolumnvector:Arowvector:m-by-nmatrixisanobjectinRmxnwithmrowsandncolumns,eachentryfilledwitha(typically)realnumber:436143612396784821BasicconceptsVectornorms:Anormofavector||x||isinformallyameasureofthe“length”ofthevector.–Commonnorms:L1,L2(Euclidean)–LinfinityBasicconceptsVectordot(inner)product:Vectorouterproduct:WewilluselowercaselettersforvectorsTheelementsarereferredbyxi.Ifu•v=0,||u||2!=0,||v||2!=0uandvareorthogonalIfu•v=0,||u||2=1,||v||2=1uandvareorthonormalBasicconceptsMatrixproduct:222212212122112122121211211211112221121122211211,babababababababaABbbbbBaaaaAWewilluseuppercaselettersformatrices.TheelementsarereferredbyAi,j.e.g.Specialmatricesfedcba000cba000000jihgfedcba000000fedcba000diagonalupper-triangulartri-diagonallower-triangular100010001I(identitymatrix)BasicconceptsTranspose:Youcanthinkofitas“flipping”therowsandcolumnsOR“reflecting”vector/matrixonlinebabaTdbcadcbaTe.g.+Linearindependence000||||||321321cccvvv(u,v)=(0,0),i.e.thecolumnsarelinearlyindependent.•Asetofvectorsislinearlyindependentifnoneofthemcanbewrittenasalinearcombinationoftheothers.•Vectorsv1,…,vkarelinearlyindependentifc1v1+…+ckvk=0impliesc1=…=ck=0000313201vue.g.x3=−2x1+x2+Spanofavectorspace•Ifallvectorsinavectorspacemaybeexpressedaslinearcombinationsofasetofvectorsv1,…,vk,thenv1,…,vkspansthespace.•Thecardinalityofthissetisthedimensionofthevectorspace.•Abasisisamaximalsetoflinearlyindependentvectorsandaminimalsetofspanningvectorsofavectorspace100201020012222(0,0,1)(0,1,0)(1,0,0)e.g.+RankofaMatrixrank(A)(therankofam-by-nmatrixA)isThemaximalnumberoflinearlyindependentcolumns=Themaximalnumberoflinearlyindependentrows=Thedimensionofcol(A)=Thedimensionofrow(A)IfAisnbym,thenrank(A)=min(m,n)Ifn=rank(A),thenAhasfullrowrankIfm=rank(A),thenAhasfullcolumnrank+InverseofamatrixInverseofasquarematrixA,denotedbyA-1istheuniquematrixs.t.AA-1=A-1A=I(identitymatrix)IfA-1andB-1exist,then(AB)-1=B-1A-1,(AT)-1=(A-1)TFororthonormalmatricesFordiagonalmatrices+DimensionsByThomasMinka.OldandNewMatrixAlgebraUsefulforStatistics+Examples(SVD)AnymatrixAcanbedecomposedasA=UDVT,whereDisadiagonalmatrix,withd=rank(A)non-zeroelementsThefistdrowsofUareorthogonalbasisforcol(A)ThefistdrowsofVareorthogonalbasisforrow(A)ApplicationsoftheSVDMatrixPseudoinverseLow-rankmatrixapproximation+EigenValueDecompositionAnysymmetricmatrixAcanbedecomposedasA=UDUT,whereDisdiagonal,withd=rank(A)non-zeroelementsThefistdrowsofUareorthogonalbasisforcol(A)=row(A)Re-interpretingAbFirststretchbalongthedirectionofu1byd1timesThenfurtherstretchitalongthedirectionofu2byd2times+Low-rankMatrixInversionInmanyapplications(e.g.linearregression,Gaussianmodel)weneedtocalculatetheinverseofcovariancematrixXTX(eachrowofn-by-mmatrixXisadatasample)Ifthenumberoffeaturesishuge(e.g.eachsampleisanimage,#samplen#featurem)invertingthem-by-mXTXmatrixbecomesanproblemComplexityofmatrixinversionisgenerallyO(n3)Matlabcancomfortablysolvematrixinversionwithm=thousands,butnotmuchmorethanthat+Low-rankMatrixInversionWiththehelpofSVD,weactuallydoNOTneedtoexplicitlyinvertXTXDecomposeX=UDVTThenXTX=VDUTUDVT=VD2VTSinceV(D2)VTV(D2)-1VT=IWeknowthat(XTX)-1=V(D2)-1VTInvertingadiagonalmatrixD2istrivial+BasicsDerivativesDecompositionsDistributions…+MATrixLABoratoryMostlyusedformathematicallibrariesVeryeasytodomatrixmanipulationinMatlabIfthisisyourfirsttimeusingMatlabStronglysuggestyougothroughthe“GettingStarted”partofMatlabhelpManyusefulbasicsyntax+MakingArrays%Asimplearray[12345]ans:12345[1,2,3,4,5]ans:12345v=[1;2;3;4;5]v=12345v’ans:123451:5ans:123451:2:5ans:1355:-2:1ans:531rand(3,1)ans:0.03180.27690.0462+MakingMatrices%Allthefollowingareequivalent[123;456;789][1,2,3;4,5,6;7,8,9][[12;45;78][3;6;9]][[123;456];[789]]ans:123456789+MakingMatrices%Creatingallones,zeros,identity,diagonalmatriceszeros(rows,cols)ones(rows,cols)eye(rows)diag([123])%CreatingRandommatricesrand(rows,cols)%Unif[0,1]randn(rows,cols)%N(0,1)%Make3x5withN(1,4)entries2*randn(3,5)+1%Getthesize[rows,cols]=size(matrix);+AccessingElementsUnlikeC-likelanguages,indicesstartfrom1(NOT0)A=[123;456;789]ans:123456789%AccessIndividualElementsA(2,3)ans:6%Access2ndcolumn(:meansallelements)A(:,2)ans:258+AccessingElementsA=123456789Matlabhascolumn-orderA([1,3,5])ans:175A([1,3],2:end)ans:2389A(A5)=-1ans:12345-1-1-1-1A(A5)=-1ans:7869[ij]=find(A5)i=3j=1322333+MatrixOperatio