Implement perceptron neural networks to simulate the function for classifying an image with 2 x 2 pixels as shown below. Your input will be 16 training examples.
Please code in Python with proper indentation.
Example: Perceptron
OUTPUT
CATEGORY
Example calculation: x = -1, x = 1, x = 1, x = -1
S = 0.25 * -1 + 0.25 * 1 + 0.25 * 1 + 0.25 * -1 = 0
0 > -0.1, so the output from the ANN is +1
So the image is categorized as "bright"
Use this training example to update weights:
Here, x1 = -1, x2 = 1, x3 = 1, x4 = -1 as before
Propagate this information through the network:
2 = 1 * 1 + 0 * 1 + 1 * 0 + 1 * -1 + 0 * 1 + 1 * 0 + 1 * -1 = -1
Hence the network outputs oE = -1
But this should have been bright = +1
So tE = +1
When tE is different from oE, add on n * (tE - oE) to weight w;
Where n is the learning rate between 0.0 and 1.0 and x is input
Interpretation:
tE - oE will either be + or -
So we can think of the addition of n * (tE - oE) as the movement of the weight in a direction
Which will improve the network's performance with respect to E
Multiplication by xi moves it more if the input is bigger