A practical Time-Series Tutorial with MATLAB MATLAB 实用时间序列教程_第1页
A practical Time-Series Tutorial with MATLAB MATLAB 实用时间序列教程_第2页
A practical Time-Series Tutorial with MATLAB MATLAB 实用时间序列教程_第3页
A practical Time-Series Tutorial with MATLAB MATLAB 实用时间序列教程_第4页
A practical Time-Series Tutorial with MATLAB MATLAB 实用时间序列教程_第5页
已阅读5页,还剩91页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

PAGE

1

Tutorial|PKDD2005

ApracticalTime-SeriesTutorialwithMATLAB

MichalisVlachos

IBMT.J.WatsonResearchCenterHawthorne,NY,10532

Tutorial|Time-SerieswithMatlab

Aboutthistutorial

Thegoalofthistutorialistoshowyouthattime-seriesresearch(orresearchingeneral)canbemadefun,whenitinvolvesvisualizingideas,thatcanbeachievedwithconciseprogramming.

Matlabenablesustodothat.

WillIbeable Iamdefinately

tousethis smarterthanher,

MATLAB butIamnotatime-rightawayseriesperson,per-se.afterthe IwonderwhatIgaintutorial? fromthistutorial…

2

PAGE

2

Tutorial|Time-SerieswithMatlab

Disclaimer

IamnotaffiliatedwithMathworksinanyway

…butIdolikeusingMatlabalot–sinceitmakesmylifeeasier

Errorsandbugsaremostlikelycontainedinthistutorial.

Imightberesponsibleforsomeofthem.

3

Tutorial|Time-SerieswithMatlab

Timelineoftutorial

Matlabintroduction

IwilltrytoconvinceyouthatMatlabiscool

Briefintroductiontoitsmanyfeatures

Time-serieswithMatlab

Introduction

Time-SeriesRepresentations

DistanceMeasures

LowerBounding

Clustering/Classification/Visualization

Applications

4

Tutorial|Time-SerieswithMatlab

WhatthistutorialisNOTabout

Movingaverages

OOhh...b.buuyy

Autoregressivemodels mmyybbooookkss

Forecasting/Prediction LLeett’s’snnootteessccaappeeininttoo ttoooo!!

mmaatthheemmaatticicss..LLeett’s’s

Stationarity sstticickkwwitithhrreeaaliltityy..

Seasonality

..oraboutcomplexmathematicalformulas

MichaelCrichton

5

Tutorial|Time-SerieswithMatlab

PARTI:MatlabIntroduction

6

PAGE

4

Tutorial|Time-SerieswithMatlab

WhydoesanyoneneedMatlab?

Matlabenablestheefficient

ExploratoryDataAnalysis(EDA)

“Scienceprogressesthroughobservation”

--IsaacNewton

IsaacNewton

“Thegreatestvalueofapictureisthatisforcesustonoticewhatweneverexpectedtosee”

--JohnTukey

JohnTukey

7

Tutorial|Time-SerieswithMatlab

Matlab

InterpretedLanguage

Easycodemaintenance(codeisverycompact)

Veryfastarray/vectormanipulation

SupportforOOP

Easyplottingandvisualization

EasyIntegrationwithotherLanguages/OS’s

InteractwithC/C++,COMObjects,DLLs

BuildinJavasupport(andcompiler)

Abilitytomakeexecutablefiles

Multi-PlatformSupport(Windows,Mac,Linux)

ExtensivenumberofToolboxes

Image,Statistics,Bioinformatics,etc

8

Tutorial|Time-SerieswithMatlab

HistoryofMatlab(MATrixLABoratory)

“Themostimportantthingintheprogramminglanguageisthename.IhaverecentlyinventedaverygoodnameandnowIamlookingforasuitablelanguage”.--R.Knuth

ProgrammedbyCleveMolerasaninterfaceforEISPACK&LINPACK

CleveMoler

1957:MolergoestoCaltech.StudiesnumericalAnalysis

1961:GoestoStanford.WorkswithG.ForsytheonLaplacianeigenvalues.

1977:FirsteditionofMatlab;2000linesofFortran

–80functions(nowmorethan8000functions)

1979:MetwithJackLittleinStanford.StartedworkingonportingittoC

1984:Mathworksisfounded

Video:

/company/aboutus/founders/origins_of_matlab_wm.html

9

Tutorial|Time-SerieswithMatlab

10

PAGE

6

Tutorial|Time-SerieswithMatlab

CurrentStateofMatlab/Mathworks

Matlab,Simulink,Stateflow

Matlabversion7,servicepack2

Usedinvarietyofindustries

Aerospace,defense,computers,communication,biotech

Mathworksstillisprivatelyowned

Usedin>3,500Universities,with>500,000usersworldwide

2004Revenue:300M.

2004Employees:1,000

Pricing:

~2000$(Commercialuse),

~100$(StudentEdition)

Moneyisbetterthanpoverty,ifonlyforfinancialreasons.–WoodyAllen 11

Tutorial|Time-SerieswithMatlab

WhoneedsMatlab?

R&Dcompaniesforeasyapplicationdeployment

Professors

Labassignments

Matlaballowsfocusonalgorithmsnotonlanguagefeatures

Students

Batchprocessingoffiles

Nomoreincomprehensibleperlcode!

Greatenvironmentfortestingideas

Quickcodingofideas,thenportingtoC/Javaetc

Easyvisualization

It’scheap!(forstudentsatleast…)

12

PAGE

7

13

Tutorial|Time-SerieswithMatlab

StartingupMatlab

PersonallyI'malwaysreadytolearn,althoughIdonotalwayslikebeingtaught.

SirWinstonChurchill

Dos/Unixlikedirectorynavigation

Commandslike:

cd

pwd

mkdir

Fornavigationitiseasiertojustcopy/pastethepathfromexplorerE.g.:

cd‘c:\documents\’

MatlabEnvironment

14

Tutorial|Time-SerieswithMatlab

Workspace:

LoadedVariables/Types/Size

CommandWindow:

typecommands

loadscripts

PAGE

8

Tutorial|Time-SerieswithMatlab

MatlabEnvironment

CommandWindow:

typecommands

loadscripts

Workspace:

LoadedVariables/Types/Size

Helpcontainsacomprehensiveintroductiontoallfunctions

15

-type

-load

Tutorial|Time-SerieswithMatlab

MatlabEnvironment

CommandWindow:

commandsscripts

Workspace:

LoadedVariables/Types/Size

Excellentdemosandtutorialofthevariousfeaturesandtoolboxes

16

Tutorial|Time-SerieswithMatlab

StartingwithMatlab

Everythingisarrays

Manipulationofarraysisfasterthanregularmanipulationwithfor-loops

a=[1234567910]%defineanarray

17

Tutorial|Time-SerieswithMatlab

Populatingarrays

Plotsinusoidfunction

a=[0:0.3:2*pi]%generatevaluesfrom0to2pi(withstepof0.3)

b=cos(a)%accesscosatpositionscontainedinarray[a]

plot(a,b)%plota(x-axis)againstb(y-axis)

Related:

linspace(-100,100,15);%generate15valuesbetween-100and100

18

PAGE

10

Tutorial|Time-SerieswithMatlab

ArrayAccess

Accessarrayelements

>>a(1) >>a(1:3)

ans= ans=

0 0.3000 0.6000

0

Setarrayelements

>>a(1)=100 >>a(1:3)=[100100100]

19

Tutorial|Time-SerieswithMatlab

2DArrays

Canaccesswholecolumnsorrows

–Let’sdefinea2Darray

>>a=[123;456] >>a(1,:) Row-wiseaccess

a=

ans=

1 2 3

4 5 6 1 2 3

>>a(2,2) >>a(:,1) Column-wiseaccess

ans= ans=

5 1

4

Agoodlistenerisnotonlypopulareverywhere,butafterawhilehegetstoknowsomething.–WilsonMizner20

PAGE

11

Tutorial|Time-SerieswithMatlab

Column-wisecomputation

Forarraysgreaterthan1D,allcomputationshappencolumn-by-column

>>a=[123;321] >>max(a)

a=

ans=

1 2 3

3 2 1 3 2 3

>>mean(a) >>sort(a)

ans= ans=

2.0000 2.0000 2.0000 1 2 1

3 2 3

21

>>a=[123];

>>b=[456];

>>c=[ab]

Rownexttorow

>>a=[1;2];

c=

1

2

3

4

5

6

>>a=[123];

>>a=[1;2];

22

>>b=[3;4];

>>c=[a;b]c=

1

2

3

4

3

6

2

5

1

4

>>b=[456];

>>c=[a;b]

c=

Columnbelowcolumn

Rowbelowtorow

3

4

1

2

>>b=[3;4];

>>c=[ab]c=

Columnnexttocolumn

Concatenatingarrays

Column-wiseorrow-wise

Tutorial|Time-SerieswithMatlab

Tutorial|Time-SerieswithMatlab

Initializingarrays

Createarrayofones[ones]

>>a=ones(1,3)a=

1 1 1

>>a=ones(1,3)*infa=

InfInfInf

>>a=ones(2,2)*5;a=

5 5

5 5

Createarrayofzeroes[zeros]

–Goodforinitializingarrays

>>a=zeros(1,4)a=

0 0 0 0

>>a=zeros(3,1)+[123]’

a=

1

2

3

23

Tutorial|Time-SerieswithMatlab

ReshapingandReplicatingArrays

Changingthearrayshape[reshape]

–(eg,foreasiercolumn-wisecomputation)

>>a=[123456]’;%makeitintoacolumn reshape(X,[M,N]):

>>reshape(a,2,3) [M,N]matrixof

columnwiseversion

ans= ofX

1 3 5

2 4 6

Replicatinganarray[repmat]

>>a=[123]; repmat(X,[M,N]):

>>repmat(a,1,2) make[M,N]tilesofX

ans= 1 2 3 1 2 3

>>repmat(a,2,1)ans=

1 2 3

1 2 3

24

PAGE

13

UsefulArrayfunctions

Lastelementofarray[end]

Lengthofarray[length]

Length=4

a= 1 3 2 5

Dimensionsofarray[size]

columns=4

1 2 3 5

25

Tutorial|Time-SerieswithMatlab

>>[rows,columns]=size(a)rows=1

columns=4

>>length(a)ans=

4

>>a=[1325];

>>a(end-1)ans=

2

>>a=[1325];

>>a(end)ans=

5

rows=1

Tutorial|Time-SerieswithMatlab

UsefulArrayfunctions

Findaspecificelement[find]**

>>a=[132510523];

>>b=find(a==2)b=

3 7

Sorting[sort]***

>>a=[1325];

>>[s,i]=sort(a) a= 1 3 2 5

s=

1 2 3 5

s= 1 2 3 5

i=

1324 i=1324Indicatestheindexwheretheelementcamefrom

26

PAGE

14

Tutorial|Time-SerieswithMatlab

VisualizingDataandExportingFigures

UseFisher’sIrisdataset

>>loadfisheriris

4dimensions,3species

Petallength&width,sepallength&width

Iris:

virginica/versicolor/setosa

meas(150x4array):

Holds4Dmeasurements

...

'versicolor''versicolor''versicolor''versicolor'

'versicolor'species(150x1cellarray):

'virginica'Holdsnameofspeciesfor'virginica'thespecificmeasurement'virginica'

'virginica‘

...

27

VisualizingData(2D)

idx_setosa

...1

1

1

0

0

0

...

28

Theworldisgovernedmorebyappearancesratherthanrealities…--DanielWebster

Anarrayofzerosandonesindicatingthepositionswherethekeyword‘setosa’wasfound

strcmp,scatter,holdon

Tutorial|Time-SerieswithMatlab

>>idx_setosa=strcmp(species,‘setosa’);%rowsofsetosadata

>>idx_virginica=strcmp(species,‘virginica’);%rowsofvirginica

>>

>>setosa=meas(idx_setosa,[1:2]);

>>virgin=meas(idx_virginica,[1:2]);

>>scatter(setosa(:,1),setosa(:,2));%plotinbluecirclesbydefault

>>holdon;

>>scatter(virgin(:,1),virgin(:,2),‘rs’);%red[r]squares[s]forthese

Tutorial|Time-SerieswithMatlab

scatter3

VisualizingData(3D)

>>idx_setosa=strcmp(species,‘setosa’);%rowsofsetosadata

>>idx_virginica=strcmp(species,‘virginica’);%rowsofvirginica

>>idx_versicolor=strcmp(species,‘versicolor’);%rowsofversicolor

>>setosa=meas(idx_setosa,[1:3]);

>>virgin=meas(idx_virginica,[1:3]);

>>versi=meas(idx_versicolor,[1:3]);

>>scatter3(setosa(:,1),setosa(:,2),setosa(:,3));%plotinbluecirclesbydefault

>>holdon;

>>scatter3(virgin(:,1),virgin(:,2),virgin(:,3),‘rs’);%red[r]squares[s]forthese

>>scatter3(versi(:,1),virgin(:,2),versi(:,3),‘gx’);%greenx’s

7

6

5

>>gridon;%showgridonaxis

4

>>rotate3Don;%rotatewithmouse

3

2

1

4.5

4 8

3.5 77.5

3 66.5

2.5 55.5

4.5

24

29

Tutorial|Time-SerieswithMatlab

ChangingPlotsVisually

Zoomout

Zoomin

Createline

CreateArrow

SelectObject Addtext

Computersareuseless.Theycanonlygiveyouanswers.–PabloPicasso 30

PAGE

16

Tutorial|Time-SerieswithMatlab

ChangingPlotsVisually

Addtitles

Addlabelsonaxis

Changeticklabels

Addgridstoaxis

Changecolorofline

Changethickness/Linestyle

etc

31

Tutorial|Time-SerieswithMatlab

ChangingPlotsVisually(Example)

Changecolorandwidthofaline

A

Rightclick

C

B

32

PAGE

17

Tutorial|Time-SerieswithMatlab

ChangingPlotsVisually(Example)

Theresult…

OtherStyles:

3

2

1

0

-1

-2

-3

0

10

20

30

40

50

60

70

80

90 100

3

2

1

0

-1

-2

-3

0

33

10

20

30

40

50

60

70

80

90 100

Tutorial|Time-SerieswithMatlab

ChangingFigurePropertieswithCode

GUI’sareeasy,butsoonerorlaterwerealizethatcodingisfaster

>>a=cumsum(randn(365,1));%randomwalkof365values

Ifthisrepresentsayear’sworthofmeasurementsofanimaginaryquantity,wewillchange:

x-axisannotationtomonths

Axislabels

Puttitleinthefigure

Includesomegreeklettersinthetitlejustforfun

Realmendoitcommand-line…--Anonymous 34

PAGE

18

Tutorial|Time-SerieswithMatlab

ChangingFigurePropertieswithCode

Axisannotationtomonths

>>axistight;%irrelevantbutuseful...

>>xx=[15:30:365];

>>set(gca,‘xtick’,xx) Theresult…

Realmendoitcommand-line…--Anonymous 35

Tutorial|Time-SerieswithMatlab

ChangingFigurePropertieswithCode

Axisannotationtomonths

>>set(gca,’xticklabel’,[‘Jan’;...

‘Feb’;‘Mar’])

Theresult…

Realmendoitcommand-line…--Anonymous 36

PAGE

19

37

Realmendoitcommand-line…--Anonymous

>>xlabel(‘Monthof2005’)

>>ylabel(‘ImaginaryQuantity’)

Tutorial|Time-SerieswithMatlab

>>title(‘Mymeasurements(\epsilon/\pi)’)

ChangingFigurePropertieswithCode

Axislabelsandtitle

Otherlatexexamples:

\alpha,\beta,e^{-\alpha}etc

Tutorial|Time-SerieswithMatlab

SavingFigures

Matlaballowstosavethefigures(.fig)forlaterprocessing

.figcanbelateropenedthroughMatlab

Youcanalwaysput-offfortomorrow,whatyoucandotoday.-Anonymous 38

PAGE

20

Tutorial|Time-SerieswithMatlab

ExportingFigures

Exportto:emf,eps,jpg,etc

39

Tutorial|Time-SerieswithMatlab

Exportingfigures(code)

YoucanalsoachievethesameresultwithMatlabcode

Matlabcode:

%extracttocoloreps

print-depscmyImage.eps;%fromcommand-line

print(gcf,’-depsc’,’myImage’)%usingvariableasname

40

PAGE

21

Tutorial|Time-SerieswithMatlab

VisualizingData-2DBars

colormap

bars

time=[1001208070];%ourdata

h=bar(time);%gethandle

cmap=[100;010;001;.501];%colors

colormap(cmap);%createcolormap

cdata=[1234];%assigncolors

set(h,'CDataMapping','direct','CData',cdata);

41

1

2

3

4

Tutorial|Time-SerieswithMatlab

VisualizingData-3DBars

data colormap

10

108 7 0 0 0

8 9 6 5 0.01980.01240.0079

6 8 6 4 0.03970.02480.0158

4 6 5 4 0.05950.03720.0237

2 6 3 2 0.07940.04960.0316

3 2 1 64 0.09920.06200.0395

0

...

1 1.00000.74400.4738

2

3 1.00000.75640.4817

5 1.00000.76880.4896

6 3

7 2 1.00000.78120.4975

1

3

data=[1087;965;864;654;632;321];

bar3([123567],data);

c=colormap(gray);%getcolorsofcolormapc=c(20:55,:);%getsomecolorscolormap(c);%newcolormap

42

Tutorial|Time-SerieswithMatlab

VisualizingData-Surfaces

data

10

9 123… 10

8

1

7

6

5 910

4 1 10

3

2

1

10 Thevalueatposition

8 10 x-yofthearray

6 8

4 6 indicatestheheightof

4

2 2 thesurface

00

data=[1:10];

data=repmat(data,10,1);%createdata

surface(data,'FaceColor',[111],'Edgecolor',[001]);%plotdata

view(3);gridon;%changeviewpointandputaxislines

43

Tutorial|Time-SerieswithMatlab

Creating.mfiles

Standardtextfiles

Script:AseriesofMatlabcommands(noinput/outputarguments)

Functions:Programsthatacceptinputandreturnoutput

Rightclick

44

PAGE

23

46

Tutorial|Time-SerieswithMatlab

Creating.mfiles

Meditor

Doubleclick

45

Creating.mfiles

Thefollowingscriptwillcreate:

Anarraywith10randomwalkvectors

Willsavethemundertextfiles:1.dat,…,10.dat

myScript.m SampleScript

Acumsum(A)

1 1

2 3

3 6

4 10

Writethisinthe 5

Arandomwalktime-series Meditor…

10

5

0 …andexecutebytypingthe

nameontheMatlab

-5 commandline

0 10 20 30 40 50 60 70 80 90100

cumsum,num2str,save

Tutorial|Time-SerieswithMatlab

15

a=cumsum(randn(100,10));%10randomwalkdataoflength100

fori=1:size(a,2), %numberofcolumns

data=a(:,i);

fname=[num2str(i)‘.dat’];%astringisavectorofcharacters!

save(fname,’data’,’-ASCII’);%saveeachcolumninatextfile

end

PAGE

24

Tutorial|Time-SerieswithMatlab

Functionsin.mscripts

Whenweneedto:

Organizeourcode

Frequentlychangeparametersinourscripts

keywordoutputargumentfunctionname

inputargument

functiondataN=zNorm(data)

%ZNORMzNormalizationofvector HelpText

%subtractmeananddividebystd (helpfunction_name)

if(nargin<1),%checkparameters

error(‘Notenougharguments’);

end

data=data–mean(data);%subtractmean FunctionBody

data=data/std(data);%dividebystd

dataN=data;

function[a,b]=myFunc(data,x,y)%pass&returnmorearguments

Seealso:varargin,varargout

47

Tutorial|Time-SerieswithMatlab

CellArrays

CellsthatholdotherMatlabarrays

–Let’sreadthefilesofadirectory

>>f=dir(‘*.dat’)%readfilecontents

f=

15x1structarraywithfields:name

date StructArray

bytes name

isdir 1 date

fori=1:length(f), bytes

isdir

a{i}=load(f(i).name); 2

N=length(a{i});

plot3([1:N],a{i}(:,1),a{i}(:,2),... 3

‘r-’,‘Linewidth’,1.5);

gridon; 4

pause; 600 5

cla; 500

end 400

300

200

100

0

1000

1500

500 1000 48

500

Tutorial|Time-SerieswithMatlab

Reading/WritingFiles

Load/SavearefasterthanCstyleI/Ooperations

–Butfscanf,fprintfcanbeusefulforfileformattingorreadingnon-Matlabfiles

fid=fopen('fischer.txt','wt');fori=1:length(species),

fprintf(fid,'%6.4f%6.4f%6.4f%6.4f%s\n',meas(i,:),species{i});

endfclose(fid);

Outputfile: ■Elementsareaccessedcolumn-wise(again…)

x=0:.1:1;y=[x;exp(x)];

fid=fopen('exp.txt','w');fprintf(fid,'%6.2f%12.8f\n',y);fclose(fid);

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7

11.10521.22141.34991.49181.64871.8221 2.0138

49

Tutorial|Time-SerieswithMatlab

FlowControl/Loops

if(else/elseif),switch

Checklogicalconditions

while

Executestatementsinfinitenumberoftimes

for

Executestatementsafixednumberoftimes

break,continue

return

Returnexecutiontotheinvokingfunction

Lifeispleasant.Deathispeaceful.It’sthetransitionthat’stroublesome.–IsaacAsimov 50

PAGE

26

Tutorial|Time-SerieswithMatlab

tic,toc,clearall

For-Looporvectorization?

clearall; elapsed_time=

tic;

fori=1:50000 5.0070

a(i)=sin(i);

endtoc

clearall; elapsed_time=

a=zeros(1,50000);

tic; 0.1400

fori=1:50000

a(i)=sin(i);

endtoc

clearall;

tic; elapsed_time=

i=[1:50000];

a=sin(i); 0.0200

toc;

Pre-allocatearraysthat

storeoutputresults

–NoneedforMatlabto

resizeeverytime

Functionsarefasterthan

scripts

–Compiledintopseudo-

code

Load/Savefasterthan

MatlabI/Ofunctions

Afterv.6.5ofMatlabthere

isfor-loopvectorization

(interpreter)

Vectorizationshelp,but

notsoobvioushowto

achievemanytimes

Timenotimportant…onlylifeimportant.–TheFifthElement

51

Tutorial|Time-SerieswithMatlab

MatlabProfiler

Findwhichportionsofcodetakeupmostoftheexecutiontime

Identifybottlenecks

Vectorizeoffendingcode

Timenotimportant…onlylifeimportant.–TheFifthElement 52

Tutorial|Time-SerieswithMatlab

Hints&Tips

Thereisalwaysaneasier(andfaster)way

Typicallythereisaspecializedfunctionforwhatyouwanttoachieve

Learnvectorizationtechniques,by‘peaking’attheactualMatlabfiles:

edit[fname],eg

editmean

editprincomp

MatlabHelpcontainsmanyvectorizationexamples

53

Tutorial|Time-SerieswithMatlab

Debugging Bewareofbugsintheabovecode;Ihaveonlyproveditcorrect,nottriedit

--R.Knuth

NotasfrequentlyrequiredasinC/C++

–Setbreakpoints,step,stepin,checkvariablesvalues

Setbreakpoints

54

Tutorial|Time-SerieswithMatlab

Debugging

Fullcontrolovervariablesandexecutionpath

–F10:step,F11:stepin(visitfunctions,aswell)

A

B

F10

C

Eitherthismanisdeadormywatchhasstopped.–GrouchoMarx 55

Tutorial|Time-SerieswithMatlab

AdvancedFeatures–3Dmodeling/VolumeRendering

Veryeasyvolumemanipulationandrendering

56

Tutorial|Time-SerieswithMatlab

AdvancedFeatures–MakingAnimations(Example)

Createanimationbychangingthecameraviewpoint

3 3

2 2

1 1

3 0 0

2 -1

-1

1 -2

-2

0 -3

0 -3

0

-1 0

-2 50 3

50 50 2

-3 1

-1 0 1 2 100 0

3 4 100 1 2 3 4 100-1

-1 0

azimuth=[50:10099:-1:50];%azimuthrangeofvalues

fork=1:length(azimuth),

plot3(1:length(a),a(:,1),a(:,2),'r','Linewidth',2);gridon;

view(azimuth(k),30);%changenew

M(k)=getframe;%savetheframe

end

movie(M,20);%playmovie20times

4

Seealso:movie2avi

57

Tutorial|Time-SerieswithMatlab

AdvancedFeatures–GUI’s

Built-inDevelopmentEnvironment

–Buttons,figures,Menus,sliders,etc

SeveralExamplesinHelp

Directorylisting

Addressbookreader

GUIwithmultipleaxis

58

Tutorial|Time-SerieswithMatlab

AdvancedFeatures–UsingJava

MatlabisshippedwithJavaVirtualMachine(JVM)

AccessJavaAPI(egI/Oornetworking)

ImportJavaclassesandconstructobjects

PassdatabetweenJavaobjectsandMatlabvariables

59

Tutorial|Time-SerieswithMatlab

AdvancedFeatures–UsingJava(Example)

StockQuoteQuery

ConnecttoYahooserver

/matlabcentral/fileexchange/loadFile.do?

objectId=4069&objectType=file

disp('ContactingYAHOOserverusing...');disp(['url=.URL('urlString')']);

end;

url=.URL(urlString);

try

stream=openStream(url);

ireader=java.io.InputStreamReader(stream);breader=java.io.BufferedReader(ireader);connect_query_data=1;%connectmade;

catch

connect_query_data=-1;%couldnotconnectcase;

disp(['URL:'urlString]);

error(['Couldnotconnecttoserver.Itmaybeunavailable.Tryagainlater.']);

stockdata={};return;

end

60

PAGE

31

Tutorial|Time-SerieswithMatlab

MatlabToolboxes

YoucanbuymanyspecializedtoolboxesfromMathworks

ImageProcessing,Statistics,Bio-Informatics,etc

Therearemanyequivalentfreetoolboxestoo:

SVMtoolbox

http://theoval.sys.uea.ac.uk/~gcc/svm/toolbox/

Wavelets

/~ojanen/wavekit/

SpeechProcessing

http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html

BayesianNetworks

http://www.cs.ubc.ca/~murphyk/Software/BNT/bnt.html

61

62

Tutorial|Time-SerieswithMatlab

IncaseIgetstuck…

help[command](onthecommandline)eg.helpfft

Menu:help->matlabhelp

Excellentintroductiononvarioustopics

Matlabwebinars

II’v’veehhaaddaawwoonnddeerrffuulleevveenniningg..BBuutttthhisiswwaassnn’t’titit……

/company/events/archived_webinars.html?fp

Googlegroups

comp.soft-sys.matlab

Youcanfind*anything*here

Someoneelsehadthesameproblembeforeyou!

Tutorial|Time-SerieswithMatlab

PARTII:TimeSeriesAnalysis

EEigighhttppeerrcceennttooffssuucccceessssisissshhoowwiningguupp..

63

Definition:Asequenceofmeasurementsovertime

Tutorial|Time-SerieswithMatlab

Whatisatime-series

Definition:Asequenceofmeasurementsovertime

ECG

Medicine 64.0

StockMarket 62.8

62.0

Meteorology 66.0

Geology 62.0

32.0

Astronomy 86.4 Sunspot

...

Chemistry 21.6

Biometrics 45.2

43.2

Robotics 53.0

43.2 Earthquake

42.8

43.2

36.4

16.9

10.0

time

64

Tutorial|Time-SerieswithMatlab

Applications(ImageMatching)

Cluster1

Manytypesofdatacanbeconvertedtotime-series

Image

ColorHistogram

600

400 Cluster2

200

0

50100150200250

400

200

0

50100150200250

800

600

400

200

0

50100150200250

Time-Series

65

Tutorial|Time-SerieswithMatlab

Applications(Shapes)

Recognizetypeofleafbasedonitsshape

Ulmuscarpinifolia Acerplatanoides Salixfragilis Tilia Quercusrobur

Convertperimeterintoasequenceofvalues

SpecialthankstoA.Ratanamahatana&

E.Keoghfortheleafvideo.

66

PAGE

34

Tutorial|Time-SerieswithMatlab

Applications(MotionCapture)

Motion-Capture(MOCAP)Data(Movies,Games)

Trackpositionofseveraljointsovertime

3*17joints=51parametersperframe

MMOOCCAAPPddaattaa……

……mmyypprreeccioiouuss……

67

Tutorial|Time-SerieswithMatlab

Applications(Video)

Video-tracking/Surveillance

Visualtrackingofbodyfeatures(2Dtime-series)

SignLanguagerecognition(3Dtime-series)

VideoTrackingofbodyfeatureovertime(Athens1,Athens2)

68

PAGE

35

Tutorial|Time-SerieswithMatlab

Time-SeriesandMatlab

Time-seriescanberepresentedasvectorsorarrays

Fastvectormanipulation

Mostlinearoperations(egeuclideandistance,correlation)canbetriviallyvectorized

Easyvisualization

Manybuilt-infunctions

SpecializedToolboxes

69

Tutorial|Time-SerieswithMatlab

BBeeccoommiinnggssuuffffiicciieennttllyyffaammiilliiaarrwwiitthhssoommeetthhiinnggiissaassuubbssttiittuutteeffoorruunnddeerrssttaannddiinnggiitt..

PARTII:TimeSeriesMatchingIntroduction

70

PAGE

36

Tutorial|Time-SerieswithMatlab

BasicData-Miningproblem

Today’sdatabasesarebecomingtoolarge.Searchisdifficult.

Howcanweovercomethisobstacle?

Basicstructureofdata-miningsolution:

Representdatainanewformat

Searchfewdatainthenewrepresentation

Examineevenfeweroriginaldata

Provideguaranteesaboutthesearchresults

Providesometypeofdata/resultvisualization

71

Databasewithtime-series:

– Medicalsequences

– Images,etc

SequenceLength:100-1000ptsDBSize:1TByte

Tutorial|Time-SerieswithMatlab

BasicTime-SeriesMatchingProblem

Distance

query

D=7.3

LinearScan: D=10.2

Objective:ComparethequerywithallsequencesinDBandreturn

thekmostsimilarsequencesto D=11.8

thequery.

Databasewithtime-series: D=17

Medicalsequences

Images,etc D=22

SequenceLength:100-1000ptsDBSize:1TByte

72

PAGE

37

Tutorial|Time-SerieswithMatlab

Whatotherproblemscanwesolve?

Clustering:“Placetime-seriesinto‘similar’groups”

Classification:“Towhichgroupisatime-seriesmost‘similar’to?”

query

? ?

?

73

HierarchicalClustering

Verygeneric&powerfultool

Providesvisualdatagrouping

Pairwisedistances

74

Mergeobjectswithsmallestdistance

Reevaluatedistances

Repeatprocess

Tutorial|Time-SerieswithMatlab

Z=linkage(D);

H=dendrogram(Z);

D1,1

D2,1

DM,N

PAGE

38

1.4

1.2

1

0.8

0.6

0.4

0.2

0

-0.2

-0.4

-0.5 0 0.5 1 1.5

1.4

1.2

1

0.8

0.6

0.4

0.2

0

-0.2

-0.4

-0.5 0 0.5 1 1.5

1.4

1.2

1

0.8

0.6

0.4

0.2

0

-0.2

-0.4

-0.5 0 0.5 1 1.5

1.4

1.2

1

0.8

0.6

0.4

0.2

0

-0.2

-0.4

-0.5 0 0.5 1 1.5

1.4

1.2

1

0.8

0.6

0.4

0.2

0

-0.2

-0.4

-0.5 0 0.5 1 1.5

1.4

1.2

1

0.8

0.6

0.4

0.2

0

-0.2

-0.4

-0.5 0 0.5 1 1.5

1.4

1.2

1

0.8

0.6

0.4

0.2

0

-0.2

-0.4

-0.5 0 0.5 1 1.5

1.4

1.2

1

0.8

0.6

0.4

0.2

0

-0.2

-0.4

-0.5 0 0.5 1 1.5

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

00.10.20.30.40.50.60.70.8 0.9

75

See:kmeans

K-MeansAlgorithm:

Initializekclusters(kspecifiedbyuser)randomly.

Repeatuntilconvergence

Assigneachobjecttothenearestclustercenter.

Re-estimateclustercenters.

PartitionalClustering

Fasterthanhierarchicalclustering

Typicallyprovidessuboptimalsolutions(localminima)

Notgoodperformanceforhighdimensions

Tutorial|Time-SerieswithMatlab

K-MeansDemo

1.4

1.2

1

0.8

0.6

0.4

0.2

0

-0.2

-0.4

-0.5

0

0.5

1

1.5

76

Tutorial|Time-SerieswithMatlab

PAGE

39

Tutorial|Time-SerieswithMatlab

K-MeansClusteringforTime-Series

SohowiskMeansappliedforTime-Seriesthatarehigh-dimensional?

PerformkMeansonacompresseddimensionality

Original Compressed Clustering

sequences sequences space

0.4

0.2

0

-0.2

-0.4

-0.6

-0.6-0.4-0.200.20.40.6 0.8

77

Tutorial|Time-SerieswithMatlab

Classification

TypicallyclassificationcanbemadeeasierifwehaveclusteredtheobjectsClassA

0.4

Q 0.2

0

-0.2

Projectqueryinthe -0.4 So,queryQismore

newspaceandfind -0.6 similartoclassB

itsclosestcluster -0.6-0.4-0.200.20.40.6 0.8

ClassB

78

PAGE

40

NearestNeighborClassification

Weneednotperformclusteringbeforeclassification.Wecanclassifyanobjectbasedontheclassmajorityofitsnearestneighbors/matches.

Elfs

Hobbits 10

9

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论