Artificial neurons: trace one update
人工神经元
Follow a weighted sum, sigmoid response and checked gradient step; distinguish a computational unit from a biological cell.
artificial-neuronA small calculator with an adjustable response
Imagine a sorting machine that receives two measurements. It multiplies each measurement by a weight, adds a bias, then passes the result through a response function. That is the computation of a common artificial neuron. A positive weight increases the score when its input increases; a negative weight decreases it. The bias sets a baseline even when every input is zero.
The word “neuron” is a loose analogy. This scalar calculation does not simulate ion channels, spikes, dendritic dynamics or the physiology of a brain cell. Deep Learning, Chapter 6, opening discussion explicitly treats the biological inspiration as loose. D2L, Section 5.1.1 describes layers built from affine maps and elementwise nonlinearities. Our example isolates one such unit so every number remains visible.
Read dot products and the chain rule first. The perceptron algorithm is a particular threshold-based learning rule; “artificial neuron” names a broader building block.
Separate the score, response and objective
For d inputs, a weight vector w and scalar bias b, define:
Here z is the preactivation and a the activation. We choose the logistic sigmoid for a smooth worked example; other units use other functions. With x=(1,2), w=(2,−1), b=0, the positive and negative weighted inputs cancel: z=0 and a=1/2. A sigmoid value can parameterize a Bernoulli probability, but merely lying between zero and one does not make a model calibrated.
The input dimension is d and the unit has d+1 trainable scalar parameters. Appending a constant input of 1 lets the bias be written as another weight. This is an algebraic convenience, not another measured feature. “Affine” means linear plus a bias; it is strictly linear only when the constant offset vanishes.
One sample, one gradient
For a target y in [0,1], choose half squared error. Applying the chain rule gives:
The three factors in a weight gradient have separate jobs: the prediction error says which direction helps, the sigmoid slope says how responsive the unit is, and xᵢ says how much that weight affects the score. Holding w fixed, the input derivative is δwᵢ. These are derivatives of this specified loss, not of every possible neuron objective.
Set y=1 in the preceding example. Then L=1/8, δ=−1/8, the weight gradient is(−1/8,−1/4), and the bias gradient is−1/8. A simultaneous gradient step with learning rate η is:
At η=1, w becomes(17/8,−3/4), b becomes 1/8, and the new score is 3/4. The response rises toward the target and this sample’s loss decreases. This checked step is not a promise that an arbitrary learning rate decreases every dataset’s loss. Binary classification usually uses Bernoulli cross-entropy; its output derivative differs from the squared-error derivative above. See logistic regression.
Trace one update without a framework
This complete Python 3.12 program returns the score, response, loss and derivatives. It evaluates the exponential only at a nonpositive argument to avoid overflow. The slope is computed from that exponential, avoiding premature subtraction of an activation rounded to one.
from math import exp, isfinite
def neuron(x, weights, bias, target):
x=list(x);weights=list(weights)
if not 1<=len(x)==len(weights)<=32:
raise ValueError('matching nonempty dimensions, at most 32 required')
if any(type(v) not in (int,float) or not isfinite(v) or abs(v)>1e6
for v in x+weights+[bias,target]) or not 0<=target<=1:
raise ValueError('bounded finite inputs and target in [0,1] required')
z=sum(a*b for a,b in zip(x,weights))+bias
e=exp(-abs(z));a=1/(1+e) if z>=0 else e/(1+e)
slope=e/(1+e)**2
delta=(a-target)*slope
return z,a,(a-target)**2/2,[delta*v for v in x],delta
if __name__=='__main__':
x=[1,2];weights=[2,-1];bias=0;target=1
z,a,loss,gradient,db=neuron(x,weights,bias,target)
print('z, activation, half squared loss:',z,a,loss)
print('weight and bias gradients:',gradient,db)
updated=[w-g for w,g in zip(weights,gradient)]
after=neuron(x,updated,bias-db,target)
print('updated weights and bias:',updated,bias-db)
print('new z, activation, loss:',*[f'{v:.9f}' for v in after[:3]])
Actual output:
z, activation, half squared loss: 0 0.5 0.125
weight and bias gradients: [-0.125, -0.25] -0.125
updated weights and bias: [2.125, -0.75] 0.125
new z, activation, loss: 0.750000000 0.679178699 0.051463154
Forward evaluation and all parameter gradients require O(d) arithmetic operations. Returning the gradient takes O(d) memory. The bounds in this teaching program exclude nonfinite inputs and overflow-prone dot products; they are not part of the mathematical definition of a neuron. Floating-point underflow can still make extremely small slopes zero.
To check a derivative independently, perturb one weight by ±10⁻⁵ and divide the loss difference by twice that step. Away from numerical extremes this centered difference should agree with the analytic gradient. Keep the other weights and the bias fixed while doing each check. Our tests also check the rational values at z=0 and the score after the update.
One unit has a narrow view
For a strictly increasing activation such as sigmoid, thresholding the output is equivalent to thresholding an affine score. Its decision boundary is a hyperplane. No choice of weights in this unit can implement XOR on two Boolean inputs. Stacking units with nonlinearities changes the available functions; see multilayer perceptrons.
Input scale affects both the score and the gradient. A large-magnitude feature may dominate because of its units, not its predictive value. Saturated sigmoid units have small activation slopes; the actual training gradient also depends on the loss and surrounding network. Avoid diagnosing all training failures from the activation alone.
The unit does not choose its own data, objective or parameter-update procedure. A useful system needs these decisions, plus validation and an account of errors outside the training examples. A one-step demonstration supplies none of that evidence.
Follow the numbers through the unit
- What are z and a for x=(1,2), w=(2,−1), b=0?
Answer 1: z=0 and a=1/2.
- With target 1 and half squared error, what are the weight and bias gradients?
Answer 2: The weight gradient is(−1/8,−1/4) and the bias gradient is−1/8.
- After the simultaneous η=1 update, what is the new score on the same input?
Answer 3: The weights are(17/8,−3/4), the bias is 1/8, and z=3/4.
- If x₂=0 on one sample, does w₂ receive a data-loss gradient from that sample? What if the objective includes weight decay?
Answer 4: Its gradient from this sample’s stated loss is δx₂=0. An additional regularization term can still contribute a nonzero weight gradient.
A unit is one part of a learning system
The textbook sources explain the computational abstraction and its use inside feedforward networks. This chapter’s numerical example and tests were written for this encyclopedia; they do not reproduce a neuroscience experiment. Historical threshold models belong in the history and perceptron chapters, and modern gradient propagation belongs in backpropagation.
Next compare the same score with sigmoid and tanh, then compose several units. Keep asking three different questions: what can the chosen function represent, how will its parameters be learned, and how will its performance be measured?
Make a prediction, then check
What is the new score after the worked update?
Learning objectives
- Compute an affine score and response.
- Derive and check one weight update.
Prerequisites & connections
Explore related knowledge →References
- Dive into Deep Learning — 5.1 Multilayer Perceptrons
Aston Zhang; Zachary C. Lipton; Mu Li; Alexander J. Smola · 2023 - Deep Learning — Chapter 6: Deep Feedforward Networks
Ian Goodfellow; Yoshua Bengio; Aaron Courville · 2016
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-06 · Codex single-agent authored technical review: cited primary-source scope, explicit assumptions, original calculations and counterexamples, runnable tests and bilingual review; not independent human or second-agent review.
- Single-agent authored technical review: bounded primary-source locations, assumptions, original derivations, exact/literal references and matching bilingual equations/examples/exercises. Not independent human or second-agent review.
- Four focused CPython3.12.4 tests passed per chapter. Neuron gradients, exact XOR/affine composition, sharp interpolation errors and stable activation/loss derivatives are checked against literal references, analytic identities and finite differences. No external runtime dependencies.
- Promoted the full prose, equations, code and exercises. Tests read formal MDX only; removed temporary fallbacks/draft skips and updated review assertion to checked. Algorithm and independent references are unchanged; final record binds both locale hashes.
- Publication navigation points published topics to complete articles and removes corresponding pending wording, retaining directory entries for unwritten targets. Principles, equations, programs and exercises are unchanged; final article SHA values rebound.
- Final copy review restored the proper name D2L after prose spacing; no equations, examples or exercises changed. Final English article SHA rebound.
Source locations checked:
- Dive into Deep Learning — 5.1 Multilayer Perceptrons · Section5.1.1 affine maps and Section5.1.2.2 sigmoid definition/derivative; current page displays1.0.3.
- Deep Learning — Chapter 6: Deep Feedforward Networks · Chapter6 opening pages164–165 loose biological analogy; Section6.2.2.2 pp178–180 sigmoid output and loss choice.
Related topics