The following shows steps to create a Perceptron Neural
Network model to solve linear classification problems using MATLAB.
1. Define the input e.g. x[0 0 1 1;0 1 0 1];
2. Define the target e.g. t=[0 0 0 1]; % This target shows that we are solving the AND
problem.
3. Define the network architecture i.e.
net=perceptron;
OR i.e. net = newp([0 1;0 1],[0 1]); % That is, inputs will
be 2-element column vectors in which values for each element are 0 or 1, and
output will be 1-element "vector" that has values of 0 or 1.
4. Train the
network i.e. net= train(net,x,t);
5. View the network i.e. view(net);
6 Simulate the
network with a new input to obtain the output e.g. y=sim(net,[0;0])
or y=sim(net,[0;1]).
In step 3 above, if the "newp" function is used, we can set the initial set of weights, bias, learning parameter and other parameters (e.g. number of epochs) as follows.
3a. Set initial set of weights and bias
For example,
w = [1 -0.8]; %i.e. w1=1, w2=-0.8
net.IW{1,1} = w;
net.b{1} = [0]; %i.e.
w0=0
3b. Set learning rate
net.trainParam.lr=0.1;
3c. Set the number of epochs for training
net.trainParam.epochs=10;
7. Find out the final weights and bias after training the
network.
w = net.iw{1,1}
b = net.b{1}
Note: patternnet should be used to solve non-linearly separable problems.
II. Perceptron architecture
References
MATLAB 2010b Help Documentation
No comments:
Post a Comment