| Neural Network Toolbox | ![]() |
Simulation (sim)
To show how sim works we examine a simple problem.
Suppose we take a perceptron with a single two-element input vector, like that discussed in the decision boundary figure. We define the network with
net = newp([-2 2;-2 +2],1);
As noted above, this gives us zero weights and biases, so if we want a particular set other than zeros, we have to create them. We can set the two weights and the one bias to -1, 1 and 1 as they were in the decision boundary figure with the following two lines of code.
net.IW{1,1}= [-1 1];
net.b{1} = [1];
To make sure that these parameters were set correctly, we check them with
net.IW{1,1}
ans =
-1 1
net.b{1}
ans =
1
Now let us see if the network responds to two signals, one on each side of the perceptron boundary.
p1 = [1;1];
a1 = sim(net,p1)
a1 =
1
p2 = [1;-1]
a2 = sim(net,p2)
a2 =
0
Sure enough, the perceptron classified the two inputs correctly.
Note that we could present the two inputs in a sequence and get the outputs in a sequence as well.
p3 = {[1;1] [1;-1]};
a3 = sim(net,p3)
a3 =
[1] [0]
You may want to read more about sim in Advanced Topics in Chapter 12.
| Creating a Perceptron (newp) | Initialization (init) | ![]() |