Lab (1)
Neural Network – Perceptron Architecture

Objective: Learn to create Perceptron networks

You will use Matlab's Neural Network Toolbox to complete this lab.   The manual for Neural Network Toolbox is available under the resource page.

A Perceptron can be created using the newp function, usually, by running a command like this:

net = newp(PR,S,TF,LF)

Perceptrons are used to solve simple (i.e. linearly separable) classification problems.

Use the Matlab help on newp to explain what each parameter of the function mean:



S :



To answer this question, you can either use the help command at the Matlab prompt; help newp, or use the online help for Neural network Toolbox.

The following command creates a Perceptron network with a single one-element input vector and one neuron.  The range for the input is [0 2].

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

To see everything that will be created, you can run the above command without the ";".  At this time the weights and biases are set to the default values. The default learning function is learnp. The net input to the hardlim transfer function is dotprod.  Thus, the DOT product of the input vector and weight matrix will be computed then the bias will be added to compute the net input. The default initialization function, initzero, is used to set the initial values of the weights to zero.

To check the weights and biases, we can run:

inputweights = net.inputweights{1, 1}

biases = net.biases{1}

Simulation (sim)

When a network is created, that does not necessary mean it is ready for use.  A network should be trained for the given cases, and then be used for other inputs. Here we will try an example in which we set the weights and biases manually.  This means, we set the values and will run the network.  If we are happy with the outcome, then we will keep those weights and the biases. If we are no happy, we make some changes, and will try again.


Suppose we want to create a network with a single-neuron, one bias, and two inputs.  This network will separate some patterns from each other.  The limit for the inputs are [-1 and 1].  As we mentioned before, when you create a perceptron network (all networks in Matlab), the weights and the bias are set to 0 by default.
net = newp([-1 1; -1 1], 1);
Let’s set the weights to: w11 = -1, w12 = 1, and bias = 1.
net.IW{1,1} = [-1 1];
net.b{1} = [1];
Note: at anytime of the process, if you want to check the outcome, just ignore the ; at the end of the command.  Now, let's create an inputs.  Each input matrix in our case should have two values, a pair.
p = [1; 1];
You can run a simulation of this network using:

a1 = sim(net, p)

What is the output?

What is the output for p_new = [1 –1]?

Can you confirm the answer by hand?

Find out how you can run the network for both p and p_new together, then run the network for both inputs. What is the output?

Note:  Just in case you want to reset the weights and biases back to the default values (0), you can use the init command. For example in the network that we just created, we can type:

net= init(net).

to reset them back to 0 again.

Sometimes, one may want to assign the weights and biases randomly. There is a function that does this:

net.inputweights{1,1}.initFcn = ‘rands’;

net.biases{1}.initFcn = ‘rands’;
net = init(net);
Let’s check it out:
wts = net.IW{1,1}
What do you have for the weights and the bias?
Try your network with these parameter for the two inputs and see what you will get this time?
You can use the nntool command to create neural networks using a Graphical Interface.  Try to see if you can create the above network using that tool.
Lab Assignment - Due at the end of the lab
Now that you learned to set up a Perceptron network, design a network to separate apples and oranges using the weights and biases given in class, .
Thus, the input parameter for an apple and orange, respectively, are:
The network produces [1] for orange and [-1] for apple.
Once your network is trained, try the following inputs:and then 
What did your network produce for these two cases?
What to submit?
The list of all commands that you have used following by the outcome of Matlab run. You can create a blank file and cut an paste your commands as you will progress. Then print that file or send it as an e-mail attachment.  You can also send the file in the body of your e-mail.