The Mathematics of Machine Intelligence

Chapter 3

Keeping What Matters

Spend a few distinguishable signal steps where the world is crowded, and see what that rule does not say.

7 guided illustrations. Move a slider or choose a value, watch the mathematics change, and check your prediction. Each illustration includes its full calculation.

01 / 07

How many bits can ten steps carry, and when do they carry them all?

From Chapter 3, A cell spent its few steps where the world was crowded

A cell can signal ten distinguishable levels. If most readings crowd into a narrow band, how much of the 3.32 bits does an evenly spaced layout waste?

A level that is used rarely adds little to what the signal can tell you, and a level that is used all the time cannot tell you which of the crowded readings occurred. Entropy averages the surprise of each level weighted by its share, and it is largest when the shares are equal. The ceiling log2 M is therefore a statement about use, not about how many levels there are.

Predict first: With 800 of 1,000 readings in a band that evenly spaced steps cover with only 2 of the 10 steps, predict to the nearest bit how many of the 3.32 possible bits the signal carries.

18
Bars of the share of readings in each of ten steps, and a curve of bits carried against the number of steps covering the band.
Ten levels can carry 3.32 bits only if they are used equally often; crowding the readings into a few of them wastes the rest.
Steps covering the narrow band: 2 · Readings in the band (of 1,000): 800

With the band covering 2 steps, the busiest step holds 40 percent of the readings and the ten levels carry 2.12 of a possible 3.32 bits. Placement of the steps, not their number, set the shortfall.

Bits carried
2.12
Most possible, log2 10
3.32
Share of the most
64 percent
Busiest step
40 percent of readings
Why it matters

A sensor or code with a fixed number of levels has a ceiling set by its level count and a shortfall set by how its levels are placed. Placement is the part a designer or a cell can change.

In brains and behavior

Laughlin measured contrast in outdoor scenes and the response of fly cells; the ten-level drawing in his note is an illustration, and no bits were counted in a real cell.

In machines

Any quantizer or code with M levels has the same ceiling, log2 M bits, and reaches it only when its levels are used equally often.

Show the calculation

Shares: band steps 0.4 each, tail steps 0.025 each. H = -sum p log2 p = 2.12 bits against log2 10 = 3.32.

The equations and symbols

Hmax=log⁡2M,H=−∑i=1Mpilog⁡2pi≤log⁡2M H_{\max}=\log_2 M,\qquad H=-\sum_{i=1}^{M}p_i\log_2 p_i\le\log_2 M

M
number of distinguishable levels (10 here)
p_i
share of readings that land in level i
H
bits actually carried per signal, on average
H_max
the most any use of M levels can carry, reached when all p_i equal 1/M
Where the conclusion applies

Ten equally distinguishable levels, no noise, and readings spread evenly within the band steps and within the tail steps. This is the capacity of an idealized signal, not a measurement of the fly cell.

Check your understanding: How many bits can 16 equally used levels carry, and how many levels do 5 bits need?
log2 16 = 4 bits. Five bits need 2^5 = 32 equally used levels.

Book source: Chapter 3, A cell spent its few steps where the world was crowded. Illustration C03-D01. Formula. Book formula and the chapter's constructed 1,000-reading example (800 in a narrow band, 100 in each tail). Laughlin did not count ten steps in a real cell; the ten levels are an illustration. Spreading band and tail readings evenly inside their steps is this companion's simplification. The layouts where the band covers 1 to 9 evenly spaced steps, and the 500 and 950 band shares, are the companion's constructions; the chapter gives only the 800, 100, 100 split with eight band steps and one step per tail.

02 / 07

What does the share-at-or-below rule buy over evenly spaced steps?

From Chapter 3, A cell spent its few steps where the world was crowded

If contrast is mostly small, how does a response built from the share of readings at or below each contrast compare with one spaced evenly across the range?

Where readings crowd, a small change in contrast passes many readings, so the share at or below climbs fast and the response with it. Each response step then catches the same share of readings. A straight-line response gives the middle of the range the same number of steps as the far tails, which almost nothing visits.

Predict first: An evenly spaced response clips the extremes if its range is too narrow and leaves its end steps idle if too wide. Predict which half-range, from 0.5 to 8, carries the most bits.

0.58
Share-at-or-below and straight-line response curves over a gold contrast density, and bits carried against the straight-line half-range.
Making the response follow the share of readings at or below each contrast uses every step equally often, so it carries log2 M bits for any scale of world; an evenly spaced response must be tuned to the scale and still falls short.
Half-range of the evenly spaced response: 3 · Number of response steps: 10

With a half-range of 3 the evenly spaced response carries 3 of 3.32 bits, neither heavily clipped nor leaving its end steps idle. The share-at-or-below curve uses every step 10 percent of the time for any scale of world.

Bits, evenly spaced
3
Bits, share rule
3.32
Readings clipped at an end
5 percent
Levels
10
Why it matters

The rule turns a measured world into a predicted response curve, which Laughlin could then check against a cell. A machine can do the same with a measured input distribution, which is how a photo's brightness values are spread across the available range.

In brains and behavior

Laughlin's cell curve and his cumulative curve were both S shapes that matched by eye in six cells of one class; no fit statistic or bits were reported.

In machines

Histogram equalization applies the same share-at-or-below curve to spread an image's brightness values. The match is in the curve alone, and it does not mean the cell computes like an image program.

Show the calculation

Clipped fraction = exp(-3) = 0.0498. Entropy of the 10 step probabilities = 3 bits; the rule gives log2 10 = 3.32.

The equations and symbols

r(c)=rmaxF(c),F(c)=P(C≤c) r(c)=r_{\max}\,F(c),\qquad F(c)=P(C\le c)

c
one contrast, a change as a fraction of its surroundings
C
the contrast the world hands the cell at random
F(c)
share of readings at or below c, a number from 0 to 1
r_max, r(c)
the top response, and the response to contrast c
Where the conclusion applies

Continuous input, zero response floor, equal-sized response steps, equally steady response at every level and information as the only goal; these are the rule's assumptions, not findings of Laughlin's. The linear comparison clips contrasts beyond its half-range into the end steps.

Check your understanding: For F(c) = c^2 on the unit interval, what share of readings fall in each of four equal response steps?
Each step has probability 1/4, so 0.25 each and entropy 2 bits. A response r = rmax F(C) is uniform whatever F is, as long as F is the input's own cumulative curve.

Book source: Chapter 3, A cell spent its few steps where the world was crowded. Illustration C03-D02. Constructed example. Book formula. The world here is a constructed Laplace distribution of contrast with scale 1 (the shape the chapter uses for a later example), not Laughlin's 15,000 readings, which the chapter does not tabulate. The evenly spaced comparison is the companion's own.

03 / 07

Does telling inputs apart give the same layout as rebuilding them?

From Chapter 3, Counting information says nothing about what the fly needs

If a later stage must rebuild each contrast closely, where should the step boundaries go compared with the equal-use layout?

When a miss costs its size squared, a rare large contrast that lands in a wide step is expensive, so the layout gives it finer steps than equal use would. The cost is that the middle steps get wider than they need to be to tell commonplace readings apart, and the code carries fewer bits.

Predict first: Predict whether squared-error boundaries sit nearer to the middle or farther out than the equal-use boundaries, and by about how much the squared error of a ten-step code changes.

416
Step boundaries for equal-use and squared-error layouts under a Laplace density, and squared error of each layout against the number of steps.
Telling inputs apart and rebuilding them closely are two goals, and they give two layouts; a third goal, serving a task, would need its own cost.
Number of steps: 10 · Layout highlighted: equal use

With 10 steps, the equal use layout puts its outermost boundary at 1.61 and has squared error 0.213, against 0.0731 for the other layout. Equal use carries 3.32 bits; the squared-error layout trades some of that for a smaller miss on large contrasts.

Outermost boundary
1.61
Bits carried
3.32
Squared error
0.213
Squared error of the other layout
0.0731
Why it matters

A code is good or bad relative to what the next stage does with it. Equal use maximizes information; it does not minimize the cost of a large miss.

In brains and behavior

The note does not say what a fly's later stages need, so nothing here says which layout the fly uses.

In machines

A quantizer designer picks the layout by the cost to be minimized: equal use for telling inputs apart, squared-error design for rebuilding them.

Show the calculation

Equal-use boundaries are the quantiles F^-1(k / M), where F^-1(u) = ln(2u) for u below 0.5 and -ln(2(1 - u)) above. Squared-error boundaries sit midway between neighboring centroids at convergence.

The equations and symbols

equal use: bk=F−1(k/M),rebuild: min⁡∑i∫step i(c−qi)2f(c)dc \text{equal use: } b_k=F^{-1}(k/M),\qquad \text{rebuild: } \min \sum_{i}\int_{\text{step } i}(c-q_i)^2 f(c)\,dc

b_k
the k-th boundary between steps, chosen so each step holds 1/M of the readings
q_i
the contrast the receiver assumes when step i is signaled
f(c)
the input density; here Laplace with scale 1, f(c) = exp(-|c|) / 2
M
number of steps
Where the conclusion applies

Laplace contrast with scale 1, squared error as the cost, and each step's rebuilt value set to the mean of the readings in it. The result is not claimed for other distributions or costs, and it says nothing about what a fly's later stages need.

Check your understanding: For four equal-use steps on a Laplace density with scale 1, what are the three boundaries? Use F^-1(u) = ln(2u) for u below 0.5.
The quantiles at 0.25, 0.5 and 0.75: ln(0.5) = -0.693, 0, and 0.693.

Book source: Chapter 3, Counting information says nothing about what the fly needs. Illustration C03-D03. Constructed example. The chapter's own ten-step Laplace example: equal-use boundaries at plus or minus 0.22, 0.51, 0.92 and 1.61 and squared-error boundaries at plus or minus 0.60, 1.35, 2.37 and 3.97. The companion recomputes these and adds other step counts. The chapter calls the comparison this book's calculation for one distribution and one cost.

04 / 07

Why must a response curve stretch when the spread of its input changes?

From Chapter 3, A motion cell stretched its curve when motion changed

If a cell's velocity input doubles in spread, what does it do to a curve that was best before?

Stretching the input and the curve together changes nothing about which response step each reading lands in. So the bits carried are a function of one number, the width divided by the spread, and the best width scales with the spread. The three curves on the right lie exactly on top of each other for that reason.

Predict first: A curve of width 2 is close to best when the velocity spread is 4. If the spread doubles to 8 and the curve stays put, predict whether it loses a little or a lot of the 3.32 bits.

0.512
Response curves over a gold velocity density, and bits carried against curve width over spread, with three spreads lying on one curve.
Only the ratio of curve width to input spread matters, so keeping information high across spreads means stretching the curve in proportion, which is what H1 was reported to do.
Velocity spread: 4 · Width of the cell's curve: 2

At spread 4 a curve of width 2 carries 3.29 bits, against 3.32 at the best width, 2.37. The best width is 0.592 times the spread whatever the spread, so the curve must stretch in proportion.

Bits carried
3.29
Bits at the best width
3.32
Width / spread
0.5
Best width / spread
0.592
Why it matters

A code fitted to one spread is mismatched when the spread changes, and the fix is to rescale it. A machine whose inputs change scale faces the same question; the chapter notes that neither the sparse-coding model nor the mammography software was tested for it.

In brains and behavior

H1, a blowfly motion cell that fires spikes, widened its response curve when the velocity spread widened; curves nearly coincided once velocity was in units of its spread and firing rate in units of its own average. This is one cell type in one species.

In machines

Normalizing an input by its own spread before a fixed code is the machine counterpart of a curve that stretches; this is an engineering practice, not a claim about cells.

Show the calculation

Boundaries in velocity are width x ln(k/(10 - k)); each step's probability is a difference of normal cumulative values at boundary / 4. Width / spread = 0.5 gives 3.29 bits.

The equations and symbols

pk=Φ(wln⁡kM−kσ)−Φ(wln⁡k−1M−k+1σ),H=−∑kpklog⁡2pk p_k=\Phi\!\left(\frac{w\,\ln\frac{k}{M-k}}{\sigma}\right)-\Phi\!\left(\frac{w\,\ln\frac{k-1}{M-k+1}}{\sigma}\right),\qquad H=-\sum_k p_k\log_2 p_k

sigma
spread of the input velocity (normal, mean 0)
w
width of the cell's S-shaped curve, in velocity units
p_k
share of the time response step k is used, for M = 10 equal response steps
Phi
the standard normal cumulative curve
H
bits carried per signal; it depends only on w / sigma
Where the conclusion applies

Noiseless response read out in ten equal steps, normal velocity with mean zero, and a logistic curve family. The paper's own information test was a calculation on the measured H1 curve for the measured input, not this one, and the other stretches were simulated, not recorded. The paper reports the rescaling broke down at very large spreads.

Check your understanding: The best width is about 2.37 at spread 4. What is the best width at spread 8, and at spread 2?
Best width / spread is fixed at about 0.59, so the best widths are about 4.73 at spread 8 and 1.18 at spread 2: they scale with the spread.

Book source: Chapter 3, A motion cell stretched its curve when motion changed. Illustration C03-D04. Model. Companion calculation in the spirit of the chapter's description of Brenner and colleagues (2000). The chapter reports no formula, no curve family and no bit values; the logistic curve, the normal velocity and the ten equal response steps are made up here.

05 / 07

When does a less exact rebuild beat a more exact one?

From Chapter 3, A model told to use few elements grew detectors like those in cortex

One code rebuilds a patch more exactly but uses many elements; another is less exact but sparse. Which does the objective prefer?

The first term wants an exact rebuild, and the second wants few or weak elements. A code that is cheap on one is dear on the other, so the weight lambda decides. With a lambda of zero the second term vanishes, and the more exact code wins.

Predict first: At lambda 0 the exact rebuild wins. Predict the value of lambda above which the sparse rebuild (error 2, penalty 1) starts to win.

04
Stacked cost bars for the exact and sparse rebuilds, and two cost lines against lambda crossing at one third.
Changing the weight on the penalty changes which code the same arithmetic favors.
Penalty weight lambda: 1 · Squared error of the sparse code: 2

At lambda 1 the exact rebuild costs 5 and the sparse rebuild costs 3, so the model prefers the sparse rebuild. The two cost the same at lambda = 0.333; the less exact code wins above that.

Cost, exact rebuild
5
Cost, sparse rebuild
3
Cheaper
sparse rebuild
Crossover lambda
0.333
Why it matters

Any objective that mixes accuracy with a cost on complexity has a weight that decides what counts as good. That weight is a design choice, not a measurement.

In brains and behavior

In the study, a demand to be accurate and sparse was enough to make learned elements that looked like simple cells, judged by eye and by two averages; this is partial evidence that such a demand could shape the cells, not proof that it does.

In machines

The arithmetic is dictionary learning: a set of elements is built from data under a cost like E. The model's objective is a specification, not a model of behavior.

Show the calculation

Exact: 1 + 1 x 4 = 5. Sparse: 2 + 1 x 1 = 3. Crossover: 1 + 4 L = 2 + L gives L = 0.333.

The equations and symbols

E=∥I−∑iaiϕi∥2+λ∑iS(ai) E=\left\|I-\sum_i a_i\phi_i\right\|^2+\lambda\sum_i S(a_i)

I
the image patch
phi_i, a_i
learned image element i and how strongly it is used
S
the penalty on element use
lambda
nonnegative weight on the penalty
Where the conclusion applies

Two made-up codes with stated squared errors and penalties. Olshausen and Field set the balance between the two terms themselves, and the paper had no new recordings from cortex.

Check your understanding: With sparse error 2 and penalty 1, and exact error 1 and penalty 4, which code wins at lambda 0.25?
Exact: 1 + 0.25 x 4 = 2. Sparse: 2 + 0.25 x 1 = 2.25. The exact rebuild still wins because 0.25 is below the crossover 1/3.

Book source: Chapter 3, A model told to use few elements grew detectors like those in cortex. Illustration C03-D05. Constructed example. The chapter's constructed comparison: squared error 1 with penalty 4 against squared error 2 with penalty 1, costs 5 and 3 at lambda 1. The companion adds other lambda values and other errors for the sparse code. The equation is a simplified form of the model's objective, not an established equation for cortex.

06 / 07

What does the sparsity penalty do to a patch's coefficients?

From Chapter 3, A model told to use few elements grew detectors like those in cortex

Given the strength each element would need to rebuild a patch exactly, how many elements stay active as the penalty grows?

With an orthonormal dictionary, each coefficient can be chosen on its own. The derivative of (c - a)^2 + lambda |a| is zero at a = c - lambda/2 for a positive c, so a coefficient smaller than lambda/2 is best set to zero and a larger one shrinks by lambda/2. The squared penalty has a derivative that vanishes at zero, so it never forces zeros.

Predict first: With the absolute-value penalty, predict how many of the eight elements stay active at lambda 2, and which ones.

010
Bars of needed and used coefficients for eight elements, and squared error against number of elements in use for two penalty shapes.
A penalty that treats small strengths harshly zeroes them out, and a penalty that grows with the square only shrinks them, so the shape of the penalty decides whether the code is sparse.
Penalty weight lambda: 2 · Penalty shape S: absolute value

With the absolute-value penalty and lambda 2, every coefficient smaller than lambda/2 = 1 is dropped and the rest shrink by that amount. 3 of 8 elements stay active at a squared error of 4.34.

Elements active
3
Squared error
4.34
Total cost E
11.5
Energy in the patch
17.1
Why it matters

Few active elements is a goal that has to be written into the cost. Which shape of penalty is used decides whether the result has exact zeros or only small values.

In brains and behavior

Most learned elements in the study sat in one place, ran along one direction and picked one size of detail, as simple cortical cells do; the likeness was judged by looking, and the model's elements were about 1.3 times longer than wide against about 2 for the cited cells.

In machines

The toy is the coding step of dictionary learning with a fixed dictionary: a specification, not a model of any trained system.

Show the calculation

Squared error = 4.34, penalty term = 2 x 3.6, total E = 11.5.

The equations and symbols

ai=sign⁡(ci)max⁡(|ci|−λ2,0)forS(a)=|a|,ai=ci1+λforS(a)=a2 a_i=\operatorname{sign}(c_i)\max\!\left(|c_i|-\tfrac{\lambda}{2},\,0\right)\ \text{for}\ S(a)=|a|,\qquad a_i=\frac{c_i}{1+\lambda}\ \text{for}\ S(a)=a^2

c_i
strength element i needs to rebuild the patch exactly (made-up values)
a_i
strength the code actually uses
lambda
weight on the penalty
S
the penalty shape, absolute value or square
Where the conclusion applies

A fixed orthonormal dictionary, so minimizing E splits into one-number problems. The paper learned 192 elements from 16 by 16 patches of natural images; this toy fixes an orthonormal dictionary and learns nothing. The chapter does not state the paper's penalty function, and the paper did not require the other coefficients to be exactly zero.

Check your understanding: With the absolute-value penalty and lambda 4, which coefficients of 3.0, -2.2, 1.4 survive and how strong are they?
The threshold is lambda/2 = 2, so 3.0 becomes 1.0 and -2.2 becomes -0.2, and 1.4 is dropped: two of the three survive.

Book source: Chapter 3, A model told to use few elements grew detectors like those in cortex. Illustration C03-D06. Model. The companion's own toy built on the chapter's objective. The chapter does not state a penalty shape and does not give this closed form. The eight coefficients are made up, and the dictionary is taken as orthonormal so the elements do not overlap. No learning of elements is done here, only the coding step.

07 / 07

What do reported sensitivity and specificity mean in counts?

From Chapter 3, Software marks on mammograms of 300,000 women were not linked to better readings

As a what-if, if marks on a mammogram changed sensitivity by 2 points and specificity by 3 (a combination neither study reported), how many cancers and how many recalls would change per 100,000 exams?

Sensitivity applies to the small group with cancer, and specificity applies to the large group without. A 2-point change on about 505 cancers is about 10; a 3-point change on about 99,495 exams without cancer is about 2,985. With the Lehman cancer rate and sensitivity 87.3, the arithmetic recall rates at specificity 90.2 and 87.2 are 10.2 and 13.2 percent. They land near the recalls Fenton reported (about 10 and about 13 in 100) because recalls are dominated by women without cancer; that is expected from the arithmetic and is not a validation of it, and the two studies are not pooled.

Predict first: Lehman's sensitivity gap is 2 points. Predict whether it is worth more cancers or fewer than 100 per 100,000 exams, and how it compares with the recall change from Fenton's specificity drop of 3 points.

Bars of cancers found, missed and recalled without cancer per 100,000 exams, and a scatter of changes in finds against changes in recalls.
A few points of sensitivity move counts of cancers by tens per 100,000 exams, while a few points of specificity move recalls by thousands, because exams without cancer vastly outnumber the rest.
Sensitivity (percent): 85.3 · Specificity (percent): 91.0

At sensitivity 85.3 and specificity 91, about 431 cancers found and 8,955 women without cancer recalled per 100,000 exams. Against Lehman's no-software baseline (sensitivity 87.3, specificity 91), finds change by -10 and recalls by 0. Lehman's 2-point gap was not significant and both studies are observational: arithmetic, not an effect.

Cancers found
431
Cancers missed
74
Recalled with no cancer
8,955
Recall rate
9.4 percent
Why it matters

A rate that looks small can be a large count, and a mark that asks for a second look costs attention whether or not it helps. The chapter's studies did not measure that cost; it is an inference.

In brains and behavior

The reader is the brain side: a radiologist who must review and dismiss marks, with limited attention. The studies did not measure attention.

In machines

The software is the machine side: marks built to flag what a reader might drop. In Lehman's data they were not linked to better accuracy overall.

Show the calculation

Cancer rate = 3,159 / 625,625 = 0.00505. Cancers per 100,000 = 505. Found = 505 x 0.853 = 431. No-cancer recalls = 99,495 x 0.09 = 8,955.

The equations and symbols

found=Nπse,no-cancer recalls=N(1−π)(1−sp) \text{found}=N\,\pi\,s_e,\qquad \text{no-cancer recalls}=N\,(1-\pi)\,(1-s_p)

N
number of screening exams (100,000 here)
pi
cancer rate, 3,159 of 625,625 = 0.00505, from the chapter's counts
s_e
sensitivity, the share of cancers a reading finds
s_p
specificity, the share of examinations without a cancer diagnosis whose reading was negative
Where the conclusion applies

The rates are observational, model-derived estimates from two studies that differ in years and design and are not pooled. Applying one study's cancer rate to the other's specificity is arithmetic for illustration. The studies do not show why marks did not help, and this is not advice about any screening decision.

Check your understanding: At a cancer rate of 3,159 per 625,625, about how many cancers are there per 100,000 exams, and how many does a sensitivity of 85.3 percent find?
3,159 / 625,625 x 100,000 = 505 cancers per 100,000 exams. At 85.3 percent, about 431 are found and 74 are missed.

Book source: Chapter 3, Software marks on mammograms of 300,000 women were not linked to better readings. Illustration C03-D07. Constructed example. Rates from Lehman and colleagues (2015): sensitivity 85.3 percent with the software and 87.3 without, specificity about 91 percent either way, 3,159 cancers in 625,625 exams. Specificity values 87.2 and 90.2 are Fenton and colleagues' (2007), a different study; the values 80, 90 and 93 are dial settings chosen here. The counts are arithmetic, not results from either study.

Mathematical illustrations use the book's formulas with disclosed small examples. Each interactive choice shows a result computed from the same calculations as the chapter notebook. A simulation is not a measurement, and for a brain the mathematics is a model: a picture illustrates a result, and the assumptions determine its scope. Review copy, brain-computer partnership revision of 1 november 2026.