Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.A light switch
The step activation is a light switch: below the threshold it is off (0), above it on (1). The sign activation is a switch between −1 and +1. They are the simplest possible decisions, and they were the first activations used in artificial neurons. A switch has no “a little more on”, though, and that turns out to make learning hard.
Hard-threshold units are back in edge AI: binarised neural networks replace multiplications with bit operations and use 32× less memory, and spiking neuromorphic chips fire all-or-nothing pulses. Both are attractive for low-power satellites and drones, and both must deal with the step function’s missing gradient.
- 1. The step function outputs…
- 2. The sign function outputs…
- 3. Why are step units hard to train with backpropagation?
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.Definitions by hand
- Step: H(z) = 1 if z > 0, else 0. For z = (−2, −0.3, 0, 0.3, 2), H = (0, 0, 0, 1, 1).
- Sign: sgn(z) = +1 if z ≥ 0, else −1 (one common convention for z = 0). For the same z, sgn = (−1, −1, 1, 1, 1).
- Derivative: H′(z) = 0 for z ≠ 0, and it does not exist at 0. Finite differences at −0.7, 0.4 and 1.3 all give 0.
Perceptron rule. w ← w + (t − H(w·x))x, with x extended by a constant 1 for the bias. It changes w only on mistakes and needs no derivative. From w = 0 with x = (1, 1, 1) and target 1, the prediction 0 is wrong, so w becomes (1, 1, 1).
Straight-through estimator (STE). In the forward pass use sgn(z); in the backward pass use ∂sgn/∂z ≈ 1 when |z| ≤ 1 and 0 otherwise (the derivative of hard-tanh). For upstream gradients (0.5, −2, 3) at z = (0.2, −0.9, 1.7), it passes (0.5, −2, 0).
Binary weights. Approximating a weight matrix by α·sgn(W) with α equal to the mean |w| gives the best single-scale binary fit (XNOR-Net). For W = [[0.5, −1.5], [2, −1]] that is ±1.25.
- 1. sgn(−0.01) =
- 2. The perceptron changes its weights only when…
- 3. The STE passes the gradient where…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Learning without a derivative
Exercise 1. Step and sign had a finite-difference derivative of 0 at every tested point. The perceptron rule nevertheless learned AND (w = (2, 1, −2)) and OR within a few epochs, and never learned XOR, which is not linearly separable (E0-1).
Multi-layer step networks. The perceptron rule trains a single layer. For hidden step or sign units there is no error signal to push back, since the chain rule multiplies by H′ = 0. Historically this blocked multilayer training until smooth activations (sigmoid, tanh) arrived in the 1980s. The STE (Hinton, 2012 lectures; Bengio, Léonard and Courville, 2013) is a pragmatic fix: use the threshold in the forward pass and a surrogate slope in the backward pass. The surrogate gradient is biased, but it points roughly the right way.
class SignSTE(torch.autograd.Function):
@staticmethod
def forward(ctx, z): ctx.save_for_backward(z); return torch.where(z >= 0, 1.0, -1.0)
@staticmethod
def backward(ctx, g): (z,) = ctx.saved_tensors; return g * (z.abs() <= 1)- 1. The perceptron rule learned…
- 2. The STE's gradient is…
- 3. Hidden step units block backpropagation because…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Threshold logic. Networks of threshold units are universal for Boolean functions (McCulloch and Pitts, 1943). A single unit computes exactly the linearly separable functions. The perceptron convergence theorem (E6-2) guarantees convergence in at most (R/γ)² updates when the data are separable with margin γ.
Why the STE works. For sgn(z) the “ideal” gradient is a delta at 0. The STE replaces it by a box of width 2, which is a smoothed, biased estimate. Yin et al. (2019) analysed it as a coarse gradient that is still a descent direction under conditions. In practice it trains binarised networks (BinaryConnect, Courbariaux et al., 2015; XNOR-Net, Rastegari et al., 2016) to competitive accuracy with full-precision latent weights.
Alternatives.
- Smooth relaxations (sigmoid with growing slope, Gumbel-softmax).
- Stochastic binary neurons with REINFORCE-style estimators.
- Surrogate gradients in spiking networks (Neftci, Mostafa and Zenke, 2019).
Costs and benefits. A binary activation and binary weights turn multiply–accumulate operations into XNOR and popcount, about 32× less memory and much less energy. The price is lower accuracy, and training needs full-precision latent weights.
Interview questions.
- Why did the sigmoid replace the step? It is differentiable, with a nonzero slope everywhere, so backpropagation can train hidden layers.
- What is the STE’s main risk? Gradient mismatch: the surrogate can point in poor directions, and training can stall or oscillate near thresholds.
- 1. Binarised networks replace multiply–accumulate with…
- 2. Spiking networks are trained with…
- 3. Perceptron convergence needs…
Level 4: Expert
★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.Training a network of sign units
History.
- W. McCulloch and W. Pitts (1943) introduced threshold units.
- F. Rosenblatt (1958) introduced the perceptron.
- D. Rumelhart, G. Hinton and R. Williams (1986) replaced the step with the sigmoid for backpropagation.
- Y. Bengio, N. Léonard and A. Courville (2013) analysed the straight-through estimator.
- M. Courbariaux et al. (2015, 2016) and M. Rastegari et al. (2016) introduced binarised networks.
Exercise 2. A 2 → 16 → 16 → 3 network on 3-arm spirals (600 training and 2000 test points), with full-batch gradient descent for 800 steps.
| hidden activation and backward rule | test accuracy per seed | mean |
|---|---|---|
| tanh (smooth) | 0.985, 0.989, 0.980 | 0.984 |
| sign, straight-through gradient | 0.938, 0.839, 0.864 | 0.880 |
| sign, true gradient (zero) | 0.584, 0.574, 0.562 | 0.573 |
- With the true gradient, the sign network’s hidden layers never learned. Only the output layer trained, on top of fixed random binary features, so it reached only 57%.
- The straight-through estimator trained the hidden layers and reached 88%, recovering most of the gap.
- Smooth tanh units remained best and most consistent. The STE runs varied from 84% to 94%: its biased gradient makes training noisier.
- The lesson matches history: thresholds are cheap at inference, but learning through them needs either smooth activations or a surrogate gradient.
Step and sign units in AI, robotics and aerospace
- Ultra-low-power inference: binarised networks on microcontrollers and FPGAs for always-on sensing (wake-word, anomaly triggers) on small satellites and drones.
- Neuromorphic computing: spiking chips (Loihi, TrueNorth) fire threshold events, and are trained with surrogate gradients similar to the STE.
- Hybrid systems: a learned score followed by a threshold is how many detectors make their final decision. The threshold is tuned after training, not trained through.
References
- F. Rosenblatt (1958). “The perceptron: a probabilistic model for information storage and organization in the brain.” Psychological Review 65(6).
- Y. Bengio, N. Léonard, A. Courville (2013). “Estimating or propagating gradients through stochastic neurons for conditional computation.” arXiv:1308.3432.
- M. Courbariaux, I. Hubara, D. Soudry, R. El-Yaniv, Y. Bengio (2016). “Binarized neural networks.” Advances in NeurIPS 29.
- M. Rastegari, V. Ordonez, J. Redmon, A. Farhadi (2016). “XNOR-Net: ImageNet classification using binary convolutional neural networks.” Proc. ECCV.
- E. O. Neftci, H. Mostafa, F. Zenke (2019). “Surrogate gradient learning in spiking neural networks.” IEEE Signal Processing Magazine 36(6).