matlab nn intro
DESCRIPTION
A gentle introduction to neural networks and nn tool box inmatlabTRANSCRIPT
![Page 1: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/1.jpg)
MATLABAn Introduction
Imthias Ahamed T. P.Dept. of Electrical Engineering,T.K.M.College of Engineering,
Kollam – 691005,[email protected]
![Page 2: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/2.jpg)
A Glorified Calculator• >> 2*3
• ans =
• 6
• >> 2.5*400
• ans =
• 1000
• >> 2^3
• ans =
• 8
![Page 3: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/3.jpg)
A Glorified Calculator Contd..
>> exp(1)ans = 2.7183>> sin(pi/4)ans = 0.7071
>> exp(-1)*sin(pi/4)ans = 0.2601
![Page 4: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/4.jpg)
• Command window• workspace
![Page 5: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/5.jpg)
plot
• x= [0 1 2 3 4 5 6 7 8 9 10];• d = [0 1 2 3 4 3 2 1 2 3 4];• plot(x,d)
![Page 6: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/6.jpg)
MATrix LABoratory
a=[10 0 0; 0 20 0; 0 0 100];b=[ 1 20 -3; 0.2 100 -4; 25 10 0]c= a+b• d= a-b• e=a*b
![Page 7: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/7.jpg)
MATRIX contd…
• F= inv(a)• H=a*f• Eig(a)
![Page 8: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/8.jpg)
Useful functions
• sin• cos • tan PlotEigInvExp
![Page 9: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/9.jpg)
A PROGRAMMING LANGUAGE
clearclfx= [0 1 2 3 4 5 6 7 8 9 10];d = [0 1 2 3 4 3 2 1 2 3 4];plot(x,d,'x')
![Page 10: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/10.jpg)
X=0:.1:10
clearclfx= 0:.1:.4;y=sin(x)plot(x,y)
![Page 11: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/11.jpg)
hold
clearclfx= 0:.1:10;y1=sin(x);plot(x,y1);y2=cos(x);plot(x,y2);
![Page 12: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/12.jpg)
help
• >> help
• HELP topics:
• matlab\general - General purpose commands.• matlab\ops - Operators and special characters.• matlab\lang - Programming language constructs.• matlab\elmat - Elementary matrices and matrix
manipulation.
![Page 13: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/13.jpg)
help general• >> help general
• General purpose commands.• MATLAB Toolbox Version 6.1 (R12.1) 18-May-2001• • General information• helpbrowser - Bring up the help browser.• doc - Complete on-line help, displayed in the help
browser.• help - M-file help, displayed at the command line. • helpwin
![Page 14: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/14.jpg)
help plot
• PLOT Linear plot. • PLOT(X,Y) plots vector Y versus vector X. If X
or Y is a matrix,• then the vector is plotted versus the rows or
columns of the matrix,• whichever line up. If X is a scalar and Y is a
vector, length(Y)• disconnected points are plotted.
![Page 15: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/15.jpg)
• Command window• Workspace• Edit window• Figer window
![Page 16: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/16.jpg)
Model of a Simple Perceptron
wk1
wk2
wkm
x1
x2
xm
......
S
Biasbk
Summing junction
Synaptic weights
Input signals j(×)
Activation function
vkOutputyk
m
jjkjk xwv
0and ( )kk vy jLet bk=wk0 and x0=+1
![Page 17: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/17.jpg)
Multi Layer Perceptron
![Page 18: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/18.jpg)
18
Back-propagation Algorithm:Summary
1. Initialization. Pick all of
the wji from a uniform
distribution.
2. Presentations of
Training Examples.
3. Forward Computation.
4. Backward
Computation.
5. Iteration.
![Page 19: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/19.jpg)
NN commands
• net = newff([rangep1; rangep2],[8 1],{'logsig' 'logsig'});• Y = sim(net,P)• net = train(net,P,T);• Y = sim(net,P);
![Page 20: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/20.jpg)
![Page 21: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/21.jpg)
![Page 22: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/22.jpg)
Pattern classification problem
• %defines inputs• P = [ 0.8903 0.9574 0.8031 0.9523 0.9517 0.0662 0.1129 0.1560 0.1604 0.0406• 0.8391 0.9237 0.9782 0.9814 0.8761 0.1008 0.1534 0.0968 0.0942 0.1159]• T =[ 0 0 0 0 0 1 1 1 1 1]
![Page 23: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/23.jpg)
creates a feed forward network
• net = newff([-1 1; -1 1],[4 1],{'logsig' 'logsig'});• %creates a feed forward network • %[-1 1;-1 1] represents min and max of
inputs• %[4 1] 4 represents size of hidden layer and
1 size of the output layer• %('logsig' 'logsig') represents transfer
function of output and hidden layer
![Page 24: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/24.jpg)
training
• ybeforetrain = sim(net,P)• % simulates network net.trainParam.epochs = 50;• %network is trained for 50 epochs • net = train(net,P,T);
![Page 25: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/25.jpg)
Testing
• Y = sim(net,P);• plotpv(P,Y)
![Page 26: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/26.jpg)
A function approximation example
• P1=[32.7 43.3 19 5;• 2.3 84.7 11 2;• 0.9 86.1 10 3;• 4.7 83.8 10.5 1;• 42.5 34.3 16.8 6;• 1.1 85.9 11 2;• 5.88 68.7 22.5 3;• 47.6 31.7 11.7 9;• 9.3 61.2 25.5 4;• 13.8 75.6 9.6 1;• 0.3 74.5 23.2 2;
![Page 27: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/27.jpg)
• 0.3 90.9 7.8 1;• 0.3 87.9 10.8 1;• 1.5 91.7 6.3 0.5;• 34.9 28.5 27.6 9;• 8.4 82.7 6.9 2;• 4.5 71 18.5 6;• 3.9 75.9 17.2 3];
![Page 28: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/28.jpg)
target• T1=[0.00025;• 0.009;• 0.009;• 0.025;• 0.00025;• 0.009;• 0.00049;• 0.00009;• 0.00025;• 0.049;• 0.00064;• 0.081;• 0.025;• 0.1;• 0.0000484;• 0.1;• 0.00016;• 0.001];
![Page 29: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/29.jpg)
Initialising the net
• P=P1' T=T1'• net = newff([0 50; 25 95;5 30;0 10],[8 1],
{'logsig' 'logsig'});• Y = sim(net,P)
![Page 30: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/30.jpg)
training
• net.trainParam.epochs = 500;• net.trainParam.goal = 1e-8;• net = train(net,P,T);• save result net• Y = sim(net,P);
![Page 31: Matlab Nn Intro](https://reader033.vdocuments.net/reader033/viewer/2022061207/54876091b4af9f7d0d8b53ba/html5/thumbnails/31.jpg)
testing
• clear• load result % read net from file result.mat
• ptest= [27.5; 44.5; 20; 8]• ytest = sim(net,ptest)•