25
INTRODUCTION TO NEURAL NETWORK TOOLBOX IN MATLAB

Neural tool box

Embed Size (px)

Citation preview

Page 1: Neural tool box

INTRODUCTION TO NEURAL NETWORK

TOOLBOX IN MATLAB

Page 2: Neural tool box

NEURAL NETWORK TOOLBOXNEURAL NETWORK TOOLBOX• The Matlab neural network toolbox provides a complete set of functions and a graphical user interface for the design, implementation, visualization, and simulation of neural networks.

• It supports the most commonly used supervised and unsupervised network architectures and a comprehensive set of training and learning functions.

Page 3: Neural tool box

KEY FEATURESKEY FEATURES•Graphical user interface (GUI) for creating, training, and simulating your neural networks

•Support for the most commonly used supervised and unsupervised network architectures

•A comprehensive set of training and learning functions

•A suite of Simulink blocks, as well as documentation and demonstrations of control system applications

•Automatic generation of Simulink models from neural network objects

•Routines for improving generalization

Page 4: Neural tool box

GENERAL CREATION OF NETWORKGENERAL CREATION OF NETWORKnet = network

net= network(numInputs,numLayers,biasConnect,inputConnect,layerConnect,outputConnect,targetConnect)

Description

NETWORK creates new custom networks. It is used to create networks that are then customized by functions such as NEWP, NEWLIN, NEWFF, etc.

Page 5: Neural tool box

NETWORK takes these optional arguments (shown with default values):

numInputs - Number of inputs, 0.

numLayers - Number of layers, 0.

biasConnect - numLayers-by-1 Boolean vector, zeros.

inputConnect - numLayers-by-numInputs Boolean matrix, zeros.

layerConnect - numLayers-by-numLayers Boolean matrix, zeros.

outputConnect - 1-by-numLayers Boolean vector, zeros.

targetConnect - 1-by-numLayers Boolean vector, zeros. and returns,

NET - New network with the given property values.

Page 6: Neural tool box

TRAIN AND ADAPTTRAIN AND ADAPT1. Incremental training : updating the weights after the

presentation of each single training sample.

2. Batch training : updating the weights after each presenting the complete data set.

When using adapt, both incremental and batch training can be used . When using train on the other hand, only batch training will be used, regardless of the format of the data. The big plus of train is that it gives you a lot more choice in training functions (gradient descent, gradient descent w/ momentum, Levenberg-Marquardt, etc.) which are implemented very efficiently .

Page 7: Neural tool box

The difference between train and adapt: the difference between passes and epochs. When using adapt, the property that determines how many times the complete training data set is used for training the network is called net.adaptParam.passes. Fair enough. But, when using train, the exact same property is now called net.trainParam.epochs.

>> net.trainFcn = 'traingdm';>> net.trainParam.epochs = 1000;>> net.adaptFcn = 'adaptwb';>> net.adaptParam.passes = 10;

Page 8: Neural tool box

TRAINING FUNCTIONSTRAINING FUNCTIONSThere are several types of training functions:

1. Supported training functions

2. Supported learning functions

3. Transfer functions

4. Transfer derivative functions

5. Weight and bias initialize functions

6. Weight derivative functions

Page 9: Neural tool box

SUPPORTED TRAINING FUNCTIONSSUPPORTED TRAINING FUNCTIONStrainb – Batch training with weight and bias learning rules trainbfg – BFGS quasi-Newton backpropagation trainbr – Bayesian regularization trainc – Cyclical order incremental update traincgb – Powell-Beale conjugate gradient backpropagation traincgf – Fletcher-Powell conjugate gradient backpropagation

traincgp – Polak-Ribiere conjugate gradient backpropagation traingd – Gradient descent backpropagation traingda – Gradient descent with adaptive learning rate backpropagation traingdm – Gradient descent with momentum backpropagation traingdx – Gradient descent with momentum & adaptive linear backpropagation trainlm – Levenberg-Marquardt backpropagation trainoss – One step secant backpropagations trainr – Random order incremental update trainrp – Resilient backpropagation (Rprop) trains – Sequential order incremental update trainscg – Scaled conjugate gradient backpropagation

Page 10: Neural tool box

SUPPORTED LEARNING FUNCTIONSSUPPORTED LEARNING FUNCTIONSlearncon – Conscience bias learning function learngd – Gradient descent weight/bias learning function learngdm – Gradient descent with momentum weight/bias learning function learnh – Hebb weight learning function learnhd – Hebb with decay weight learning rule learnis – Instar weight learning function learnk – Kohonen weight learning function learnlv1 – LVQ1 weight learning function learnlv2 – LVQ2 weight learning function learnos – Outstar weight learning function learnp – Perceptron weight and bias learning function learnpn – Normalized perceptron weight and bias learning function learnsom – Self-organizing map weight learning function learnwh – Widrow-Hoff weight and bias learning rule

Page 11: Neural tool box

TRANSFER FUNCTIONSTRANSFER FUNCTIONS compet - Competitive transfer function.

hardlim - Hard limit transfer function.

hardlims - Symmetric hard limit transfer function.

logsig - Log sigmoid transfer function.

poslin - Positive linear transfer function.

purelin - Linear transfer function.

radbas - Radial basis transfer function.

satlin - Saturating linear transfer function.

satlins - Symmetric saturating linear transfer function.

softmax - Soft max transfer function.

tansig - Hyperbolic tangent sigmoid transfer function.

tribas - Triangular basis transfer function.

Page 12: Neural tool box

TRANSFER DERIVATIVE FUNCTIONSTRANSFER DERIVATIVE FUNCTIONS dhardlim - Hard limit transfer derivative function.

dhardlms - Symmetric hard limit transfer derivative function

dlogsig - Log sigmoid transfer derivative function.

dposlin - Positive linear transfer derivative function.

dpurelin - Hard limit transfer derivative function.

dradbas - Radial basis transfer derivative function.

dsatlin - Saturating linear transfer derivative function.

dsatlins - Symmetric saturating linear transfer derivative function.

dtansig - Hyperbolic tangent sigmoid transfer derivative function.

dtribas - Triangular basis transfer derivative function.

Page 13: Neural tool box

WEIGHT AND BIAS INITIALIZATION WEIGHT AND BIAS INITIALIZATION FUNCTIONSFUNCTIONS

initcon - Conscience bias initialization function.

initzero - Zero weight/bias initialization function.

midpoint - Midpoint weight initialization function.

randnc - Normalized column weight initialization function.

randnr - Normalized row weight initialization function.

rands - Symmetric random weight/bias initialization function.

WEIGHT DERIVATIVE FUNCTIONSWEIGHT DERIVATIVE FUNCTIONS ddotprod - Dot product weight derivative function.

Page 14: Neural tool box

NEURAL NETWORK TOOLBOX GUINEURAL NETWORK TOOLBOX GUI1. The graphical user interface (GUI) is designed to be simple and

user friendly.This tool lets you import potentially large and complex data sets.

2. The GUI also enables you to create, initialize, train, simulate, and manage the networks. It has the GUI Network/Data Manager window.

3. The window has its own work area, separate from the more familiar command line workspace. Thus, when using the GUI, one might "export" the GUI results to the (command line) workspace. Similarly to "import" results from the command line workspace to the GUI.

4. Once the Network/Data Manager is up and running, create a network, view it, train it, simulate it and export the final results to the workspace. Similarly, import data from the workspace for use in the GUI.

Page 15: Neural tool box
Page 16: Neural tool box
Page 17: Neural tool box
Page 18: Neural tool box
Page 19: Neural tool box
Page 20: Neural tool box

clc

clear all

%net = newp(P,T,TF,LF) ------ Create Perceptron Network

%P ------ R x Q1 matrix of Q1 input vectors with R elements

%T ------ S x Q2 matrix of Q2 target vectors with S elements

%TF ----- Transfer function (default = 'hardlim')

%LF ----- Learning function (default = 'learnp')

net = newp([0 1; 0 1],[0 1]);

P1 = [0 0 1 1; 0 1 0 1];

T1 = [0 1 1 1];

net = init(net);

Y1 = sim(net,P1)

net.trainParam.epochs = 20;

net = train(net,P1,T1);

Y2 = sim(net,P1)

Page 21: Neural tool box

A graphical user interface can thus be used to

1. Create networks

2. Create data

3. Train the networks

4. Export the networks

5. Export the data to the command line workspace

Page 22: Neural tool box

Sample Programmes

%Creating a Neural Network in MATLAB

net = network;

net.numInputs = 1;

net.inputs{1}.size = 2;

net.numLayers = 2;

net.layers{1}.size = 3;

net.layers{2}.size = 1;

net.inputConnect(1) = 1

net.layerConnect(2, 1) = 1

net.outputConnect(2) = 1

net.targetConnect(2) = 1

net.layers{1}.transferFcn = 'logsig'

net.layers{2}.transferFcn = 'purelin'

net.biasConnect = [ 1 ; 1]

Page 23: Neural tool box

%Design and Train a feedforward network for the following problem: Parity: Consider a 4-input and 1-output problem, where the output should be 'one' if there are odd number of 1s in the input pattern and 'zero' other-wise.

clearinp=[0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1; 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1; 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1; 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1];out=[0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0];network=newff([0 1;0 1; 0 1; 0 1],[6 1],{'logsig','logsig'});network=init(network);y=sim(network,inp);figure,plot(inp,out,inp,y,'o'),title('Before Training');axis([-5 5 -2.0 2.0]);network.trainParam.epochs = 500;network=train(network,inp,out);

- Continue…

Page 24: Neural tool box

y=sim(network,inp);figure,plot(inp,out,inp,y,'o'),title('After Training');axis([-5 5 -2.0 2.0]);Layer1_Weights=network.iw{1};Layer1_Bias=network.b{1};Layer2_Weights=network.lw{2};Layer2_Bias=network.b{2};Layer1_WeightsLayer1_BiasLayer2_WeightsLayer2_BiasActual_Desired=[y' out'];Actual_Desiredgensim(network)

- Continue…

Page 25: Neural tool box