Artificial neural networks (ANN) are models loosely inspired by the brain, built from many simple units that are connected together. The simplest is the single layer perceptron.
The Artificial Neuron
A biological neuron receives signals through dendrites, sums them in the cell body and fires along its axon when the total is large enough. The artificial neuron mimics this. It receives inputs x₁, ..., xₙ, each multiplied by a weight wᵢ, adds a bias b, and passes the sum z = Σ wᵢxᵢ + b through an activation function f to produce the output y = f(z). Weights show the importance of each input and are what the network learns.
Activation Functions
The step function gives 1 if z > 0 and 0 otherwise and is used by the classic perceptron. The sigmoid gives a smooth value between 0 and 1. tanh gives values between −1 and 1. ReLU, max(0, z), is the usual choice in deep networks because it is simple and trains well.
Single Layer Perceptron
A single layer perceptron (Rosenblatt, 1957) has one layer of weights connecting the inputs directly to the output neuron with a step activation. It is a linear classifier: it draws the line w₁x₁ + w₂x₂ + b = 0 and puts the two classes on its two sides. It can learn any linearly separable function, such as AND and OR, but cannot learn XOR, because no single straight line separates the XOR classes. This limit, pointed out by Minsky and Papert in 1969, is overcome by multi-layer networks with hidden layers.
Definition: Perceptron. A single artificial neuron that computes a weighted sum of its inputs plus a bias and applies a step function to give a binary output; it is a linear classifier.
Table 3.6: Common activation functions
| Function | Formula | Range | Typical use |
|---|---|---|---|
| Step | 1 if z > 0, else 0 | 0 or 1 | Classic perceptron |
| Sigmoid | 1 / (1 + e⁻ᶻ) | 0 to 1 | Probability output |
| tanh | (eᶻ − e⁻ᶻ) / (eᶻ + e⁻ᶻ) | −1 to 1 | Hidden layers |
| ReLU | max(0, z) | 0 to ∞ | Deep networks |
Example 3.6: A perceptron computing AND
Problem: A perceptron has weights w₁ = 2, w₂ = 1 and bias b = −2, with a step activation (output 1 when z > 0). Show that it computes the AND function.
Solution:
- For (0, 0): z = −2, output 0.
- For (0, 1): z = 1 − 2 = −1, output 0.
- For (1, 0): z = 2 − 2 = 0, which is not greater than 0, so output 0.
- For (1, 1): z = 2 + 1 − 2 = 1, output 1.
- The outputs 0, 0, 0, 1 are the AND truth table. The boundary is the line 2x₁ + x₂ = 2.
Result: The perceptron with w = (2, 1) and b = −2 implements AND.
w, b = (2, 1), -2
for x1 in (0, 1):
for x2 in (0, 1):
z = w[0] * x1 + w[1] * x2 + b
print(x1, x2, "z =", z, "output", 1 if z > 0 else 0)
Output
0 0 z = -2 output 0
0 1 z = -1 output 0
1 0 z = 0 output 0
1 1 z = 1 output 1
Common mistakes
- Expecting a single perceptron to learn XOR.
- Forgetting the bias, which shifts the boundary away from the origin.
- Confusing the step activation (hard 0 or 1) with the sigmoid (smooth).
- Thinking the weights are set by hand; they are learned.
Key takeaways
- Neuron: y = f(Σ wᵢxᵢ + b).
- Step, sigmoid, tanh and ReLU are common activations.
- A single layer perceptron is a linear classifier.
- It solves AND and OR but not XOR; hidden layers fix this.
Practice questions
- What are the parts of an artificial neuron?
- Why can a single perceptron not learn XOR?
- What is the role of the bias?
Answers to the practice questions
- Inputs, weights, bias, a summation and an activation function.
- XOR is not linearly separable by one straight line.
- It shifts the decision boundary.
Sources
- Official BCA syllabus Introduction to Machine Learning, course code 26BCA404DSE21, Unit III
