16
SS 2008 Maschinelles Lernen und Neural Computation 1 Maschinelles Lernen und Neural Computation Übung: Grundlagen von Matlab und Netlab Georg Dorffner / Achim Lewandowski

Maschinelles Lernen und Neural Computation Übung: Grundlagen von Matlab und Netlab

  • Upload
    ayanna

  • View
    55

  • Download
    4

Embed Size (px)

DESCRIPTION

Maschinelles Lernen und Neural Computation Übung: Grundlagen von Matlab und Netlab. Georg Dorffner / Achim Lewandowski. Matlab – Nützliches I. Zugriff auf die Daten: Per Hand eingeben: >> a=4 %Skalar >> Vektor=[3; 5; 7] >> bmat=[2 3 4 5; 3 4 5 6; 11 1 2 1] Aus Ascii-Datei: - PowerPoint PPT Presentation

Citation preview

Page 1: Maschinelles Lernen und Neural Computation   Übung: Grundlagen von Matlab und Netlab

SS 2008 Maschinelles Lernen und Neural Computation

1

Maschinelles Lernen und Neural Computation Übung: Grundlagen von Matlab und Netlab

Georg Dorffner / Achim Lewandowski

Page 2: Maschinelles Lernen und Neural Computation   Übung: Grundlagen von Matlab und Netlab

SS 2008 Maschinelles Lernen und Neural Computation

2

Matlab – Nützliches I

• Zugriff auf die Daten:– Per Hand eingeben:

>> a=4 %Skalar>> Vektor=[3; 5; 7]>> bmat=[2 3 4 5; 3 4 5 6; 11 1 2 1]

– Aus Ascii-Datei:>> load beispiel.datVariable (oder Array) heißt nun beispiel

– Aus Matlab-Datei (Endung .mat):>> load class.matclass.mat kann mehrere Variablen, arrays,… auch mit anderen Namen enthalten

Page 3: Maschinelles Lernen und Neural Computation   Übung: Grundlagen von Matlab und Netlab

SS 2008 Maschinelles Lernen und Neural Computation

3

Matlab – Nützliches II

• Welche Daten sind im Arbeitsspeicher?>> whos Name Size Bytes Class

Vektor 3x1 24 double array a 1x1 8 double array bmat 3x4 96 double array

• Daten abspeichern, alles löschen, neu laden>>save daten Ve* bmat %legt daten.mat an>>clear %loescht alles>>load daten %Vektor und bmat sind wieder geladen

Page 4: Maschinelles Lernen und Neural Computation   Übung: Grundlagen von Matlab und Netlab

SS 2008 Maschinelles Lernen und Neural Computation

4

Matlab – Nützliches III

>>a*bmat %Multiplikationans =

8 12 16 20 12 16 20 24 44 4 8 4

>>c=bmat' %Transponiertec = 2 3 11 3 4 1 4 5 2 5 6 1

Page 5: Maschinelles Lernen und Neural Computation   Übung: Grundlagen von Matlab und Netlab

SS 2008 Maschinelles Lernen und Neural Computation

5

Matlab – Nützliches IV

>>d=a*bmatd =

8 12 16 20 12 16 20 24 44 4 8 4

>>d=a*bmat; %ruhiger Modus ohne Bildschirmausgabe

>> help befehl %Hilfe zu befehl >> c=zeros(1,3) ergibt c=[0 0 0] (1x3)>> d=ones(3,1) ergibt d=[1;1;1] (3x1)

Page 6: Maschinelles Lernen und Neural Computation   Übung: Grundlagen von Matlab und Netlab

SS 2008 Maschinelles Lernen und Neural Computation

6

Matlab – Nützliches V

Matrizen zusammenfügen: >>a=[2 3 4]

>>b=[5 6 7]>>c=[a b]c = 2 3 4 5 6 7>>c=[a;b]

c = 2 3 4 5 6 7

Page 7: Maschinelles Lernen und Neural Computation   Übung: Grundlagen von Matlab und Netlab

SS 2008 Maschinelles Lernen und Neural Computation

7

Netlab – Grundsätzliches

http://www.ncrg.aston.ac.uk/netlab/

netlab.zip, nethelp.zip und foptions.m (ab Matlab 7.0) entpackt und dann in den Pfad aufgenommen:

Menupunkt: File – SetPath – Add with Subfolders

Verzeichnisse mit Netlab und den Daten aufnehmen

Netlab-Befehle stehen nun zur Verfügung Daten werden gefunden

Page 8: Maschinelles Lernen und Neural Computation   Übung: Grundlagen von Matlab und Netlab

SS 2008 Maschinelles Lernen und Neural Computation

8

Netlab – GLM

glm (General Linear Model)

1. Initialisieren: net=glm(nin,nout,outfunc)• Brauche also

1. nin: Dimension der Inputs

2. nout: Dimension der Outputs

3. outfunc: Ausgabefunktion, die eins von den folgenden sein kann: 'linear', 'logistic' oder 'softmax'

• Brauche (noch) nicht die Daten

• z.B. net=glm(5,3, 'linear')

Page 9: Maschinelles Lernen und Neural Computation   Übung: Grundlagen von Matlab und Netlab

SS 2008 Maschinelles Lernen und Neural Computation

9

Netlab – GLM II

net= type: 'glm' nin: 5 nout: 3 nwts: 18 outfn: 'linear' w1: [5x3 double] b1: [0.6909 0.2414 -0.2627]

Page 10: Maschinelles Lernen und Neural Computation   Übung: Grundlagen von Matlab und Netlab

SS 2008 Maschinelles Lernen und Neural Computation

10

Netlab – GLM III

Modell an Daten anpassen:[netneu, options] = netopt(net, options, x, t, alg)

• net eben definiert• options=foptions erzeugt den Optionenvektor (1x18)• options(1)=1 %Fehler anzeigen• options(14)=30 %Anzahl der Iterationen• Daten bestehen aus n Beobachtungen (jeweils Input- und

Outputvektor), bspw. n=300• x 300x5-Matrix, t 300x3-Matrix• alg= 'scg'‚ (Scaled Conjugate Gradient)• netneu=netopt(net, options, x, t, ‚scg')

netneu =

type: 'glm' nin: 5 nout: 3 nwts: 18 outfn: 'linear' w1: [5x3 double] b1: [0.4566 0.3357 0.5434]

Page 11: Maschinelles Lernen und Neural Computation   Übung: Grundlagen von Matlab und Netlab

SS 2008 Maschinelles Lernen und Neural Computation

11

Netlab – GLM IV

Outputvektor für neue Daten vorhersagen:

tvor = glmfwd(netneu,xneu)• netneu eben angepasst• bspw. xneu 2x5-Matrix• xneu=[1 1 1 1 1; -1 -1 -1 -1 -1]

tvor =

2.1326 0.2828 1.1488 -0.8870 1.4671 -1.7579

Page 12: Maschinelles Lernen und Neural Computation   Übung: Grundlagen von Matlab und Netlab

SS 2008 Maschinelles Lernen und Neural Computation

12

Netlab – MLP I

Multilayer-Perceptron:1. Initialisieren: net=mlp(nin,nhidden,nout,outfunc)

z.B. net=mlp(1,4,1, 'linear') type: 'mlp'

nin: 1 nhidden: 4 nout: 1 nwts: 13 %number of weights outfn: 'linear' w1: [0.2400 -0.0927 0.3431 0.4234] b1: [-0.0608 0.2300 -0.2370 -0.2280] w2: [4x1 double] b2: -0.2587

Page 13: Maschinelles Lernen und Neural Computation   Übung: Grundlagen von Matlab und Netlab

SS 2008 Maschinelles Lernen und Neural Computation

13

Netlab – MLP II

Multilayer-Perceptron:

2. Trainieren mit x Inputmatrix und t Targetmatrix:

bspw. x=5*rand(100,1); t=sin(x)+0.1*rand(100,1);

netneu=netopt(net, options, x, t,'scg')

3. Vorhersagen auf Trainingsinput:

tfitted=mlpfwd(netneu,x)

tfitinitial=mlpfwd(net,x) %ohne Training plot(x,[t tfitted tfitinitial],'.')

Page 14: Maschinelles Lernen und Neural Computation   Übung: Grundlagen von Matlab und Netlab

SS 2008 Maschinelles Lernen und Neural Computation

14

Netlab – GMM I

Gauss‘sches Mischmodell:1. Initialisieren: mix = gmm(dim, ncentres,covartype)

covartype: 'spherical', 'full', 'diag',

z.B. mix=gmm(3,10,'diag')2. Vortrainieren (k-means)

mix2 = gmminit(mix, x,options) 3. Parameter anpassen:

mix3=gmmem(mix2, x,options)

Page 15: Maschinelles Lernen und Neural Computation   Übung: Grundlagen von Matlab und Netlab

SS 2008 Maschinelles Lernen und Neural Computation

15

Netlab – GMM II

Gauss‘sches Mischmodell Beispielx1=randn(100,1);x2=randn(50,1)*2+4;x3=randn(50,1)*2+12;x=[x1;x2;x3]

1.Initialisieren: mix = gmm(1, 3, 'diag')

2. Vortrainieren (k-means)

mix2 = gmminit(mix, x,options) 3. Parameter anpassen:

mix3=gmmem(mix2, x,options)

Page 16: Maschinelles Lernen und Neural Computation   Übung: Grundlagen von Matlab und Netlab

SS 2008 Maschinelles Lernen und Neural Computation

16

Netlab – GMM III

Gauss‘sches Mischmodell Beispielangepasste Dichte anzeigen lassen:

xv=[-2:0.1:15]'

yv=gmmprob(mix3,xv) yv2=gmmprob(mix2,xv)

plot(xv,[yv yv2])