Products & Services Solutions Academia Support User Community Company

Creating a Perceptron (newp)

A perceptron can be created with the newp function:

where input arguments are as follows:

Commonly, the hardlim function is used in perceptrons, so it is the default.

The following commands create a perceptron network with a single one-element input vector with the values 0 and 2, and one neuron with outputs that can be either 0 or 1:

You can see what network has been created by executing the following command:

which yields

The default learning function is learnp, which is discussed in Perceptron Learning Rule (learnp). The net input to the hardlim transfer function is dotprod, which generates the product of the input vector and weight matrix and adds the bias to compute the net input.

The default initialization function initzero is used to set the initial values of the weights to zero.

Similarly,

gives

You can see that the default initialization for the bias is also 0.

Simulation (sim)

This section shows how sim works using a simple problem.

Suppose that you take a perceptron with a single two-element input vector, such as discussed in the decision boundary figure on page 3-4. This perceptron outputs the values 0 and 1.

Define the network using the following commands:

The network includes zero weights and biases. If you want weights and biases with values other than zero, you have to create them.

Set the two weights and the one bias to -1, 1, and 1, as they were in the decision boundary figure using the following commands:

To make sure that these parameters were set correctly, check them with

Now see if the network responds to two signals, one on each side of the perceptron boundary:

and for

Sure enough, the perceptron classified the two inputs correctly.

You could present the two inputs in a sequence and get the outputs in a sequence as well:

Initialization (init)

You can use the function init to reset the network weights and biases to their original values. Suppose, for instance, that you start with the network

Now check the weights using the following command:

which gives, as expected,

In the same way, you can verify that the bias is 0 with

which gives

Now set the weights to the values 3 and 4 and the bias to the value 5 with

Recheck the weights and bias as shown above to verify that the change has been made. Sure enough,

Now use init to reset the weights and bias to their original values:

You can check as shown above to verify that

You can change the way that a perceptron is initialized with init. For instance, you can redefine the network input weights and bias initFcns as rands, and then apply init:

Now check the weights and bias:

You can see that the weights and bias are assigned random numbers.


 Provide feedback about this page 

Previous page Perceptron Architecture Learning Rules Next page

Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS