Perceptron and Activation Functions Explained: Worked Examples and Exam Traps

Follow one sample through net input, five activations, and a complete perceptron update. Then connect the arithmetic to XOR, gradients, output layers, and common mistakes.

KnowledgeGate Team

Exam prep & CS education

Updated 30 Oct 20265 min read
Perceptron and Activation Functions Explained: Worked Examples and Exam Traps

A perceptron equation looks short, but a question can change the bias sign, activation convention, or update order. One unnoticed change spoils the answer. The reliable sequence is to calculate the net input, compare activation outputs at that fixed value, and apply the perceptron update only after computing the error.

1. What a perceptron computes

With input vector x, weight vector w, and bias b, a perceptron calculates z = w.x + b and produces y = f(z). The hard-step convention is:

  • step(z) = 1 when z >= 0

  • step(z) = 0 when z < 0

State this convention before calculating. Some questions define the output at zero differently.

The bias shifts the decision boundary. Threshold notation may instead say w.x >= theta. It agrees with the bias form when b = -theta. Write that conversion first to prevent a sign mistake.

A classic perceptron applies a hard step for a binary decision. Modern neural networks commonly use differentiable or piecewise differentiable activations so gradients can guide training.

2. Worked example: forward pass and one perceptron update

Use x = (2, 1), target t = 1, initial weights w = (-0.2, 0.1), bias b = -0.3, and learning rate eta = 0.1.

z = (-0.2)(2) + (0.1)(1) - 0.3

z = -0.4 + 0.1 - 0.3 = -0.6

Since z < 0, the step gives y = 0, not the target 1. The sample is misclassified.

The perceptron update is w_new = w + eta(t-y)x and b_new = b + eta(t-y). Here, t-y = 1, so:

w_new = (-0.2, 0.1) + 0.1(1)(2, 1) = (0, 0.2)

b_new = -0.3 + 0.1(1) = -0.2

Now recheck the same sample:

z_new = (0)(2) + (0.2)(1) - 0.2 = 0

Under z >= 0 -> 1, the new output is 1. A convention assigning zero to class 0 would change this label, so the boundary convention is essential.

Two-panel perceptron worked example showing z=-0.6 with output 0, updated weights w1=0 and w2=0.2, and boundaries x2=2x1+3 and x2=1.

3. Feed the same net input through five activation functions

Keep z = -0.6 fixed. That isolates the effect of the activation function.

  • Step: 0, because -0.6 < 0.

  • Sigmoid: 1/(1 + e^0.6), approximately 0.354.

  • Tanh: tanh(-0.6), approximately -0.537.

  • ReLU: max(0, -0.6) = 0.

  • Leaky ReLU with alpha = 0.01: 0.01(-0.6) = -0.006.

Step has range {0,1} for a hard decision. Sigmoid has range (0,1) for a binary output score. Tanh has range (-1,1) for zero-centred signed activations. ReLU has range [0,infinity) for sparse positive hidden activations. Leaky ReLU has range (-infinity,infinity) with a small negative-side slope.

For gradients, step is constant on either side of zero. Sigmoid and tanh can saturate at large input magnitudes. ReLU has zero slope for negative inputs, while this leaky ReLU keeps slope 0.01. No activation is universally best.

Coordinate plot compares step, sigmoid, tanh, ReLU, and leaky ReLU at z=-0.6, with outputs 0, 0.354, -0.537, 0, and -0.006.

4. Why a network needs nonlinearity, and where a single perceptron stops

Suppose one layer computes h = W1x + b1 and the next computes o = W2h + b2, with no activation between them. Substitution gives o = (W2W1)x + (W2b1 + b2). This is still one affine map. Stacking more such layers cannot create nonlinear decision boundaries. Activations let stacked layers represent curved or piecewise relationships.

XOR shows the limit exactly. Its targets are 0 for (0,0) and (1,1), and 1 for (0,1) and (1,0). No single straight line separates the two classes, so one perceptron cannot represent XOR.

The perceptron learning rule converges for linearly separable training data under its standard assumptions. For non-separable data such as XOR, it is not promised to converge to a separating solution.

5. Choosing an activation by the layer's job

Function

Formula

Output range

Typical role

Main caution

Step

1 if z >= 0, else 0

{0,1}

Classic perceptron decision

No useful gradient away from the boundary

Sigmoid

1/(1 + e^-z)

(0,1)

One binary output or non-exclusive labels

Saturates at large magnitudes

Softmax

e^z_i / sum(e^z_j)

Each value in (0,1), sum 1

Mutually exclusive multi-class output

Classes compete through normalisation

Tanh

tanh(z)

(-1,1)

Signed hidden states in some architectures

Can saturate

ReLU

max(0,z)

[0,infinity)

Hidden layers

Zero negative-side slope

Leaky ReLU

max(alpha*z,z)

(-infinity,infinity)

Hidden layers

Negative slope is a chosen hyperparameter

Sigmoid acts independently on one or several logits for non-exclusive labels. Softmax normalises a vector into probabilities summing to 1 for mutually exclusive classes.

For the broader ANN route, Artificial Neural Networks: Complete Guide with Worked Examples for GATE and Interviews adds a sigmoid gradient update and parameter counting to the hard-step rule. Artificial Neural Networks Explained: Forward Pass, Worked Example and Exam Question Patterns then traces a full 2-2-1 forward pass through two hidden neurons and one output. The single-neuron comparison holds z=-0.6 fixed so five activation outputs can be compared directly.

6. Common traps and the correction for each

  • Switching signs silently: w.x + b and w.x - theta are equivalent only after writing b = -theta.

  • Assuming the output at zero: copy the question's convention, or state your own if none is given.

  • Updating only the weights: when bias is trainable, update it with the same error term, as in the worked example.

  • Updating an already correct sample: calculate t-y first. If it is zero, the perceptron update changes nothing.

  • Calling a sigmoid score a class: a hard class still requires a stated decision threshold.

  • Rejecting ReLU because of its kink: optimisation systems use a defined subgradient convention at zero.

7. How exam questions turn these ideas into marks

Common question forms ask you to calculate z, perform one update, match an activation to its graph, identify linear separability, compare gradients, or distinguish sigmoid from softmax. These question forms do not establish official frequency.

Try three rapid checks:

  1. For z = 1.2, ReLU gives 1.2 because ReLU returns a positive input unchanged.

  2. If sigmoid output is a = 0.8, its local derivative is a(1-a) = 0.8(0.2) = 0.16.

  3. The four XOR labels are not linearly separable because no one straight boundary can isolate the two positive points from the two negative points.

Use the UGC NET Computer Science High-Yield Topics article only as a broader revision map. For any exam-specific syllabus or current pattern, verify the details on the relevant conducting body's official website.

8. The short version and the next step

  • Calculate z before applying the activation.

  • State what happens at z = 0.

  • Keep bias and threshold signs consistent through b = -theta.

  • Compute t-y before updating weights and bias.

  • Remember that a single perceptron needs linearly separable data.

For a wider route through related learning, browse the Coding & Skill Development Courses. If you want a structured AI and machine-learning option, continue with AI & ML for Placements.

Finally, redo the worked example with target t = 0 under the same z >= 0 convention. The initial output is already 0, so t-y = 0 and no update occurs. Then sketch the four XOR points and try to draw one separating line. The failed sketch makes the limitation of a single perceptron visible.