The perceptron is a fundamental building block of neural networks used to solve binary classification problems. It consists of input values, weights and bias, net sum, and an activation function.
The perceptron takes input vectors, multiplies them by corresponding weight vectors, adds bias, and passes the result through an activation function.
The Perceptron Algorithm outputs binary values (0 or 1) and can only classify linearly separable vector sets.
from numpy import array, random, dot
from random import choice
from pylab import ylim, plot
from matplotlib import pyplot as plt
step_function = lambda x: 0 if x < 0 else 1
training_dataset = [
(array([0,0,1]), 0),
(array([0,1,1]), 1),
(array([1,0,1]), 1),
(array([1,1,1]), 1),
]
weights = random.rand(3)
error = []
learning_rate = 0.2
n = 100
for j in range(n):
x, expected = choice(training_dataset)
result = dot(weights, x)
err = expected - step_function(result)
error.append(err)
weights += learning_rate * err * x
for x, _ in training_dataset:
result = dot(x, weights)
print('{}: {} -> {}'.format(x[:2], result, step_function(result)))
ylim([-1,1])
plot(error)
plt.show()
The perceptron algorithm, implemented using Python, is the simplest form of artificial neural networks. It can create a single Neuron model to solve binary classification problems by taking input vectors, multiplying them by corresponding weight vectors, adding bias, and passing the result through an activation function.