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:
.
This activation value is then used in the threshold function:
.
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:
.
This is then repeated with the new weight values until an acceptable error level is reached:
.
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.
![[Graphics:Images/perceptron-2d-example-1.0_gr_5.gif]](Images/perceptron-2d-example-1.0_gr_5.gif)
![[Graphics:Images/perceptron-2d-example-1.0_gr_6.gif]](Images/perceptron-2d-example-1.0_gr_6.gif)
![[Graphics:Images/perceptron-2d-example-1.0_gr_7.gif]](Images/perceptron-2d-example-1.0_gr_7.gif)
![[Graphics:Images/perceptron-2d-example-1.0_gr_8.gif]](Images/perceptron-2d-example-1.0_gr_8.gif)
![[Graphics:Images/perceptron-2d-example-1.0_gr_9.gif]](Images/perceptron-2d-example-1.0_gr_9.gif)
![[Graphics:Images/perceptron-2d-example-1.0_gr_10.gif]](Images/perceptron-2d-example-1.0_gr_10.gif)
![[Graphics:Images/perceptron-2d-example-1.0_gr_11.gif]](Images/perceptron-2d-example-1.0_gr_11.gif)
![[Graphics:Images/perceptron-2d-example-1.0_gr_12.gif]](Images/perceptron-2d-example-1.0_gr_12.gif)
![[Graphics:Images/perceptron-2d-example-1.0_gr_13.gif]](Images/perceptron-2d-example-1.0_gr_13.gif)
![[Graphics:Images/perceptron-2d-example-1.0_gr_14.gif]](Images/perceptron-2d-example-1.0_gr_14.gif)
![[Graphics:Images/perceptron-2d-example-1.0_gr_15.gif]](Images/perceptron-2d-example-1.0_gr_15.gif)
![[Graphics:Images/perceptron-2d-example-1.0_gr_16.gif]](Images/perceptron-2d-example-1.0_gr_16.gif)
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 . 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 .
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]](Images/perceptron-2d-example-1.0_gr_19.gif)
![[Graphics:Images/perceptron-2d-example-1.0_gr_20.gif]](Images/perceptron-2d-example-1.0_gr_20.gif)
![[Graphics:Images/perceptron-2d-example-1.0_gr_21.gif]](Images/perceptron-2d-example-1.0_gr_21.gif)
![[Graphics:Images/perceptron-2d-example-1.0_gr_22.gif]](Images/perceptron-2d-example-1.0_gr_22.gif)
![[Graphics:Images/perceptron-2d-example-1.0_gr_23.gif]](Images/perceptron-2d-example-1.0_gr_23.gif)
![[Graphics:Images/perceptron-2d-example-1.0_gr_24.gif]](Images/perceptron-2d-example-1.0_gr_24.gif)
![[Graphics:Images/perceptron-2d-example-1.0_gr_25.gif]](Images/perceptron-2d-example-1.0_gr_25.gif)
![[Graphics:Images/perceptron-2d-example-1.0_gr_26.gif]](Images/perceptron-2d-example-1.0_gr_26.gif)
![[Graphics:Images/perceptron-2d-example-1.0_gr_27.gif]](Images/perceptron-2d-example-1.0_gr_27.gif)
Table (Activation values Weights}
![[Graphics:Images/perceptron-2d-example-1.0_gr_28.gif]](Images/perceptron-2d-example-1.0_gr_28.gif)
Table (Activation values Weights}
![[Graphics:Images/perceptron-2d-example-1.0_gr_31.gif]](Images/perceptron-2d-example-1.0_gr_31.gif)
Error Graph
![[Graphics:Images/perceptron-2d-example-1.0_gr_34.gif]](Images/perceptron-2d-example-1.0_gr_34.gif)
Region Graph
![[Graphics:Images/perceptron-2d-example-1.0_gr_37.gif]](Images/perceptron-2d-example-1.0_gr_37.gif)
The Seperation
![[Graphics:Images/perceptron-2d-example-1.0_gr_40.gif]](Images/perceptron-2d-example-1.0_gr_40.gif)
The progression of the seperation
![[Graphics:Images/perceptron-2d-example-1.0_gr_43.gif]](Images/perceptron-2d-example-1.0_gr_43.gif)