2 Dimensional Perceptron Computer

by Chad Rempp
This is a perceptron simulator. A perceptron takes a set of inputs usually {-1,1} and uses them to evaluate an activation function:
    [Graphics:Images/perceptron-2d-example-1.0_gr_1.gif].
This activation value is then used in the threshold function:
    [Graphics:Images/perceptron-2d-example-1.0_gr_2.gif].
This output is compared against the desired output for that input pair and if it is not correct an error function adjusts the weights according to this equation:
    [Graphics:Images/perceptron-2d-example-1.0_gr_3.gif].
This is then repeated with the new weight values until an acceptable error level is reached:
    [Graphics:Images/perceptron-2d-example-1.0_gr_4.gif].

This examples uses two inputs and a set of 10 data triples (the third value is the bias, β). The graphs section shows the error and the linear seperation of the two classes. In this example I use the terms vector and list interchangably. This is because where the algorithm calls for vectors I use Mathematica list data types. I also use the list data type to store data for error computation and other uses.

Compute Perceptron

Initialize Variables

Reset Variables
[Graphics:Images/perceptron-2d-example-1.0_gr_5.gif]
Set the input vector values
[Graphics:Images/perceptron-2d-example-1.0_gr_6.gif]
Set the initial weight vector
[Graphics:Images/perceptron-2d-example-1.0_gr_7.gif]
Set the weight record vector to an empty list
[Graphics:Images/perceptron-2d-example-1.0_gr_8.gif]
Set the output vector to an empty list
[Graphics:Images/perceptron-2d-example-1.0_gr_9.gif]
Set the net activation vector to an empty list
[Graphics:Images/perceptron-2d-example-1.0_gr_10.gif]
Set the region 1 vector to an empty list
[Graphics:Images/perceptron-2d-example-1.0_gr_11.gif]
Set the region 2 vector to an empty list
[Graphics:Images/perceptron-2d-example-1.0_gr_12.gif]
Set the desired output vector
[Graphics:Images/perceptron-2d-example-1.0_gr_13.gif]

Set the error vector to an empty list

[Graphics:Images/perceptron-2d-example-1.0_gr_14.gif]
Set the learning constant
[Graphics:Images/perceptron-2d-example-1.0_gr_15.gif]
Set the number of times to loop throught the network during training.
      Note that the total training iterations = loops * sets of input values
[Graphics:Images/perceptron-2d-example-1.0_gr_16.gif]

Compute

The perceptron algorithm.
Line 1 - Go through the input vector loop times.
Line 2 - Reset the output vector to an empty list for another pass through.
Line 3 - Reset the activation vector to an empty list for another pass through.
Line 4 - Loop through each of the input values. --TODO-- Change the hard coded value to a length function of the input vector.
Line 5 - The net activation level, net, is calculated using the activation function [Graphics:Images/perceptron-2d-example-1.0_gr_17.gif]. For this algorithm I substituted a dot product for the summation for computational convenience.
Line 6 - The activation level is added to a storage list.
Line 7 - The activation value is used to produce and output value using the bipolar threshold function [Graphics:Images/perceptron-2d-example-1.0_gr_18.gif].
Line 8 - The output value is added to a storage list.
Line 9 - Calculate the weight adjustment if necessary and store it to the weight vector, else store the same weight to the weight vector since the out put was correct.
Line 13 - Calculate the error for this loop through the data set and store it to the error list.
Line 14 - Store this loops weight vector to a list of weight vectors for later use.
Line 15 - Reset the weight vector to the last set of weight values for use in the next loop.
   

[Graphics:Images/perceptron-2d-example-1.0_gr_19.gif]

Results

Preprocessing

Create Tables
[Graphics:Images/perceptron-2d-example-1.0_gr_20.gif]
Create equation for linear seperation
[Graphics:Images/perceptron-2d-example-1.0_gr_21.gif]
Create data regions for graphing
[Graphics:Images/perceptron-2d-example-1.0_gr_22.gif]
Create error graph
[Graphics:Images/perceptron-2d-example-1.0_gr_23.gif]
Create seperation line graph
[Graphics:Images/perceptron-2d-example-1.0_gr_24.gif]
Create region 1 graph
[Graphics:Images/perceptron-2d-example-1.0_gr_25.gif]
Create region 2 graph
[Graphics:Images/perceptron-2d-example-1.0_gr_26.gif]
Create a list of graphs that represent the linear seperation at the end of each loop
[Graphics:Images/perceptron-2d-example-1.0_gr_27.gif]

Results

Show tables

Table (Activation values Weights}

[Graphics:Images/perceptron-2d-example-1.0_gr_28.gif]

[Graphics:Images/perceptron-2d-example-1.0_gr_29.gif]

[Graphics:Images/perceptron-2d-example-1.0_gr_30.gif]

Table (Activation values Weights}

[Graphics:Images/perceptron-2d-example-1.0_gr_31.gif]

[Graphics:Images/perceptron-2d-example-1.0_gr_32.gif]

[Graphics:Images/perceptron-2d-example-1.0_gr_33.gif]
Show graphs

Error Graph

[Graphics:Images/perceptron-2d-example-1.0_gr_34.gif]

[Graphics:Images/perceptron-2d-example-1.0_gr_35.gif]

[Graphics:Images/perceptron-2d-example-1.0_gr_36.gif]

Region Graph

[Graphics:Images/perceptron-2d-example-1.0_gr_37.gif]

[Graphics:Images/perceptron-2d-example-1.0_gr_38.gif]

[Graphics:Images/perceptron-2d-example-1.0_gr_39.gif]

The Seperation

[Graphics:Images/perceptron-2d-example-1.0_gr_40.gif]

[Graphics:Images/perceptron-2d-example-1.0_gr_41.gif]

[Graphics:Images/perceptron-2d-example-1.0_gr_42.gif]

The progression of the seperation

[Graphics:Images/perceptron-2d-example-1.0_gr_43.gif]

[Graphics:Images/perceptron-2d-example-1.0_gr_44.gif]

[Graphics:Images/perceptron-2d-example-1.0_gr_45.gif]


Converted by Mathematica      December 8, 2003