In this C++ video lesson, we implement the perceptron training algorithm. Bringing together material from the previous C++ lessons and the last three, in particular, along with the first neural networks lesson, we present the simplest example of perceptron training; we use one-dimensional data and only two data points. Our example trains in four correction steps. So, it is easy to follow the execution of the code.
To make the algorithm clearer, we graphed our one-dimensional data in the plane, using a simple embedding. Then the weight vector is generated as a linear combination of the two vectors from the origin to the points. In fact, the weight vector is a positive integer multiple of the green vector and a negative integer multiple of the red vector. This corresponds to the vectors having class values one and negative one, respectively. Running the algorithm generates our linear combination:
We can write this in an equation like this:
Here, the white vector is the weight vector and is denoted by w. The green and red vectors are denoted by the letters r and g. The integer multipliers, m and n, are equal to 3 and 2 for the image above. Notice that the weight vector is perpendicular to the line and points in the positive direction.