Codebook Quantisation
We may need to replace a continuous vector with a compact ID. A codebook provides a fixed set of representative vectors, letting us choose a nearby entry and measure how much the replacement changes the input.
15 sections · 14 questions · 4 coding challenges
The arrow keys move between sections too.
Could We Store the Nearest Representative Instead of Every Number?
BOTIE
Vector quantisation developed around this compression problem. Linde, Buzo and Gray's 1980 work described an iterative algorithm for designing a codebook of representative vectors. Assignment and representative updates were used together to reduce distortion.
The encoder finds the nearest codebook entry and records its index. The decoder retrieves that entry. Many different inputs can share the same code, so reconstruction loses detail. More representatives can reduce that loss while requiring more storage. The method makes the tradeoff explicit: the code identifies a representative region, not an exact copy of the original vector.
Sources for this history
Replace Many Possible Vectors with a Small Set of Representatives
Imagine storing a picture using a limited palette. Each original colour is replaced by the nearest available colour, and the stored record can name that palette entry.
Vector quantisation extends this idea to groups of numbers. A codebook contains representative vectors, and each input is assigned to one of them.
Start with values that vary continuously
Inputs may be colours, image patches, or learned feature vectors. Many slightly different inputs would require different exact records if we preserved every coordinate.
Vertical: Second coordinate
Horizontal: First coordinate
A discrete code names a representative, not the exact input
The full example learns or inspects the codebook, assigns inputs, and reconstructs them so the approximation is visible.
These codes are different from arbitrary text vocabulary IDs: assignment here depends on distance to numerical representatives.
Explore the full example
Compare an input vector with its selected codebook entry and reconstruction. Increase the codebook size and inspect both the error and the number of entries used.
…
Part 1. A Picture Is Already Numbers
1. Why this page changes the example
Every other page in this section carries one sentence, Dr. Alvarez didn’t expect the low-cost re-analysis. It is there because it breaks things, and none of the things it breaks are things this method can meet. The method here is vector quantisation, and it reads vectors rather than writing, so a sentence would have to be turned into vectors before it arrived, and every interesting decision would then have been taken by whatever did the turning. So this page carries a picture instead, and says so plainly rather than pretending the sentence still fits.
The picture is sixteen pixels down and sixteen across, each pixel a brightness between 0 and 1. That is 256 numbers, and we will cut them into 128 pieces of two, each piece being a pixel and the pixel to its right. Two numbers per piece is a small piece by the standards of anything that codes real images, where sixteen or sixty-four is ordinary, and it is chosen here because a piece of two numbers is a point in the plane and can therefore be drawn on a page and checked with a pencil.
Keep in mind
2. The four pictures, and what each is for
Four pictures run through the whole page, and they are not four illustrations of one thing. Each one makes the same measurement come out differently, and the differences are where most of the argument lives. The photograph is smooth, so a pixel and the pixel beside it are nearly equal almost everywhere. The poster is four flat bands of tone.
The printed chart is hard-edged stripes. The speckled square has every pixel drawn independently of every other, which is the case with no structure in it at all and is the control the other three are measured against.
| picture | pieces | different pieces | what it is there to show |
|---|---|---|---|
| photograph | 128 | 53 | the ordinary case, where neighbouring pixels agree |
| poster | 128 | 93 | content with a natural number of parts |
| printed chart | 128 | 5 | very little variety, and hard edges |
| speckled square | 128 | 127 | no structure, as a control |
Every picture has the same 128 pieces; what differs is how many of them are different from each other.
The playground above quantises any of the four at any table size. It is worth turning the table size down to 2 on the photograph and watching the reconstruction beside it, before reading any of the arithmetic below.
Keep in mind
3. The contract, asked of something that was never text
A model reads whole numbers and nothing else, and that is as true of a model reading a picture as of one reading a sentence. The vocabulary page sets out what has to be settled before a stream of numbers means anything, which is what the pieces are, how they are found, what happens at a piece the table has never seen, and whether the round trip is exact. Those four questions do not stop applying when the pieces stop being writing.
What changes is the answer to the last of them. A character vocabulary that has met every character in a text reproduces that text exactly, so the round trip loses nothing and the fourth question has a clean yes. Here the answer is no, always, and the interesting part is that it is a number rather than a yes or a no, which is what the middle of this page measures.
Keep in mind
4. Why the brightnesses cannot be the vocabulary
The obvious thing to try first is to skip the vocabulary altogether and let the pieces be their own numbers. It fails for a reason that has nothing to do with this picture. A vocabulary is a finite list, and every number in it names one entry, so a scheme that hands the pieces over as they are is claiming there is a finite list of pieces to name. A brightness is a real number, so there is no such list.
Rounding brightness to two decimal places still leaves 101 possible values per pixel. A two-pixel piece can combine any of them.
possible two-pixel pieces = 101 × 101 = 10,201The photograph uses only fifty-three of those possibilities. Enumerating every possible piece spends most of the table on combinations absent from this picture.
›Why the count grows with the coordinates too
The number of possible pieces grows exponentially with the number of pixels per piece.
two pixels: 101² = 10,201 possibilities
sixteen pixels: 101¹⁶ ≈ 1.17 × 10³² possibilitiesA useful codebook therefore records representative pieces from the data instead of trying to list every possible combination.
Keep in mind
Part 2. A Table of Positions, and the Nearest One Wins
5. The rule, in one line
Keep a fixed list of vectors. Each one owns the number that is its position in the list, counting from zero. To give a new vector a number, measure how far it is from every entry and answer with the position of the nearest. That is the whole method, and everything else on this page is a consequence of it or a cost of it.
number of v = the position i minimising ||v − entryᵢ||²The square is there for convenience rather than for meaning. Squaring is increasing on non-negative numbers, so the entry that minimises the squared distance is the entry that minimises the distance, and the square saves a square root that would change no answer.
Keep in mind
6. Four vectors against three entries
Before any picture, the smallest instance that shows every part of the rule. Three entries in the plane, at (0, 0), (4, 0) and (0, 3), owning the numbers 0, 1 and 2. Four vectors to quantise, at (1, 0), (3, 1), (1, 2) and (2, 0). The table below is every squared distance, with the winner in each row marked, and it is small enough that a reader can check any cell of it.
…
One row, by hand
Compare the vector (3, 1) with each of the three codebook entries. Squared Euclidean distance is enough to rank them.
entry 0 at (0, 0): 3² + 1² = 10
entry 1 at (4, 0): (−1)² + 1² = 2
entry 2 at (0, 3): 3² + (−2)² = 13Entry 1 is nearest. Encoding stores the ID one; decoding returns its representative vector, (4, 0).
Keep in mind
7. The tie, and the rule that settles it
The last of the four vectors, (2, 0), is 4 away in squared distance from entry 0 and 4 away from entry 1. Nothing in the rule says which of them it should get, because the rule says nearest and there are two of those. Something has to decide, and whatever decides is arbitrary in the strict sense that a different choice would be equally correct.
The convention taken here is the lower position, which means the entry that comes first in the table rather than the entry that is smaller as a vector. That distinction is not idle. Writing the same three entries down in a different order, with (4, 0) first, sends the tied vector to the other one, and every other answer and the total cost stay exactly where they were.
…
Keep in mind
8. This table has been met before, under another name
A short list of positions, each standing for whatever is nearest to it, chosen so that the things nearest to it are close to it. That is the description of a codebook, and it is also, word for word, the description of the centres the k-means page finds. The two are the same object. Cluster k becomes entry k, the assign step of k-means is exactly the lookup described in section 5, and the quantity k-means calls inertia is the total this page is about to call the rounding error, before it is divided by the number of pieces.
Naming that connection is not a nicety. It settles where the table comes from, which is Part 6, and it settles what the table is good at, which is being close to whatever it was chosen from and nothing else. Every warning the clustering page gives about a grouping being a property of the rows it was fitted on transfers here without a word changed, and lands harder, because a grouping is usually inspected by somebody before it is used, while a table of codes is read straight into a model with no way of reporting a poor match.
In a model
The speech units a model like HuBERT reads are made this way. Frames of speech features are grouped by k-means, the centres become the table, and a frame’s unit is the number of the centre nearest to it. There is no separate machinery; the clustering is the vocabulary.
Keep in mind
9. Reading the numbers back again
Going the other way is a lookup and nothing more. Number 1 means the vector sitting at position 1 of the table, so a run of numbers becomes a run of vectors by reading them off, and the picture is reassembled by putting those vectors back where their pieces came from. A number outside the table has no meaning at all, exactly as a number past the end of a word list does, and there is nothing to give back for it.
What comes back is the entry, not the piece. That sentence is short and is the whole of the next Part, because it is the point at which this method parts company with a vocabulary of characters, where what comes back is the character that went in.
Keep in mind
Part 3. The Round Trip Is Lossy, and the Loss Is a Number
10. What a piece loses on the way through
Send a piece through and back. The piece (0.35, 0.39) of the photograph, under a table of four entries, becomes the number 0, and the number 0 means the vector (0.4490, 0.5119). The piece did not survive. What survives is the entry it was nearest to, and the difference between the two is gone in the sense that nothing downstream holds it.
That is not a defect to be repaired by a better implementation. A table of four entries can distinguish four things, and the photograph has 53 different pieces, so at least 49 of them have to arrive somewhere they did not start. What is worth asking is how much is lost rather than whether anything is, and the answer to that is a number.
Keep in mind
11. The rounding error, defined
Take each piece, subtract the entry it became, square the result coordinate by coordinate, add those up, and average over the pieces. That average is the rounding error of the whole collection under that table, and it is what a coder calls the distortion.
error = (1 / n) × Σᵢ ||pieceᵢ − entry(pieceᵢ)||²On the four vectors of section 6 the squared gaps are 1, 2, 2 and 4, so the error is their mean, 2.25. Every number this page quotes for a picture is that same average, and because it is a mean of squares its units are the square of a brightness, which is awkward to read. Taking the square root of the error divided by the two coordinates gives a figure in brightness again, and that is the typical miss on a single pixel.
›Why this is the quantity, rather than some other measure of miss
The choice of squares is not neutral, and it is the same choice the update rule makes. The point minimising the total squared distance to a set of points is their mean, which is why the step that moves an entry to the mean of the pieces that chose it is the step that lowers this number.
Measure the miss some other way, by the sum of the coordinate gaps for instance, and the minimising point is no longer the mean and the procedure that chooses the table is no longer guaranteed to improve. The measure of loss and the way the table is chosen are one decision taken twice.
Keep in mind
12. The photograph at sixteen entries
Now the measurement. The photograph’s 128 pieces against a table of sixteen entries chosen from those same pieces give a rounding error of 0.000418, which is a typical miss of 0.0145 on a pixel whose brightness runs from 0 to 1. The furthest any piece had to travel is a squared gap of 0.00243, which is 0.0493 in the plane. Every one of the sixteen entries wins at least one piece.
…
Turn the table size down and watch two things at once. The points in the plane are the pieces and the marked positions are the entries, and at two entries the picture visibly becomes two tones while the error goes up by a factor of nearly sixty. The pieces lie in a narrow band along the diagonal, because a pixel and its neighbour are nearly equal in a smooth picture, and that band is what makes a small table do as well as it does here.
Keep in mind
13. What the numbers cost to write down
A table of sixteen entries owns the numbers 0 to 15, so each number takes four bits, and the whole picture becomes 128 numbers of four bits, which is 512 bits. The original was 256 brightnesses. Whether that is a saving depends entirely on what a brightness was costing, and at any ordinary precision it is a large one.
The codebook must travel with the IDs, or the receiver cannot reconstruct their meaning. This example uses sixteen entries with two coordinates each.
codebook = 16 × 2 = 32 brightness values
encoded picture = 128 IDs + 32 codebook values
original picture = 256 brightness valuesThese are counts of stored values, not equal-sized bytes: an ID and a brightness value may use different representations. Sharing the same table across many pictures amortizes the codebook cost.
| entries | bits per number | bits for the picture | numbers in the table | rounding error |
|---|---|---|---|---|
| 1 | 0 | 0 | 2 | 0.113862 |
| 2 | 1 | 128 | 4 | 0.024903 |
| 4 | 2 | 256 | 8 | 0.007695 |
| 8 | 3 | 384 | 16 | 0.001877 |
| 16 | 4 | 512 | 32 | 0.000418 |
| 32 | 5 | 640 | 64 | 0.000053 |
The photograph, at every table size the page uses. A table of one entry costs no bits at all, because there was never anything to say.
Keep in mind
Check yourself
Questions on Parts 1 to 3
Question 1 of 4
Rounding every brightness to two decimal places does make the list of possible pieces finite, and the objection to enumerating it is that it is the wrong list rather than an endless one.
Part 4. What a Bigger Table Buys
14. The sweep, on all four pictures
One more bit per piece for every doubling of the table, and in exchange the rounding error falls. How far it falls is the trade, and it is not the same trade on every picture. The chart below draws the error against the table size on a logarithmic scale, where a constant factor per doubling is a straight line, and beside it lists the factor at each step.
…
The photograph’s error falls by 4.57, then 3.24, then 4.10, then 4.49, then 7.96. The speckled square’s falls by 1.74, then 2.52, then 2.22, then 2.30, then 2.63. The two are the same method on the same number of pieces at the same table sizes, and one of them is getting roughly twice as much for its bit as the other.
Keep in mind
15. What the textbook predicts, and what was measured
There is a standard result for how this trade should behave when the table is large. For a collection filling d coordinates, the best achievable error falls roughly as the table size raised to the power of minus two over d, so with two coordinates a doubling should buy a factor of two, and with one coordinate it should buy a factor of four.
The speckled square is the case that result describes, since every pixel there was drawn independently and the pieces genuinely fill the square, and its measured factors of 1.74 to 2.63 sit around the predicted two.
The two coordinates in these photograph patches are strongly related: neighboring pixels usually have similar brightness. The patches therefore cluster near the line where the coordinates are equal.
The measured spread along that line is 163.6 times the perpendicular spread. Although each patch is written with two coordinates, most observed variation lies close to one direction. This helps explain why its error reduction differs from a uniformly occupied two-dimensional example.
The measured reduction factors are 4.57, 3.24, 4.10, 4.49, and 7.96. Several are close to the idealized one-dimensional factor of four. The last occurs when the codebook is approaching the number of distinct patches in this small photograph, where a large-sample scaling argument is no longer a reliable description.
The comparison supports a useful distinction: the number of coordinates and the effective dimension occupied by the data need not be the same. It does not turn the idealized rate into an exact prediction for every finite codebook.
| picture | spread along over spread across | measured factor per doubling | factor predicted for that many dimensions |
|---|---|---|---|
| speckled square | 1.4 | 1.74 to 2.63 | 2, for two dimensions |
| printed chart | 2.9 | 2.07 then 7.21 | 2, for two dimensions |
| photograph | 163.6 | 3.24 to 7.96 | 4, for one dimension |
| poster | 642.7 | 69.81 at four, then 1.76 to 2.33 | 4, for one dimension |
The ratio of the two spreads is how flat the collection of pieces is. Nothing about the method changes across these rows; only the pieces do. The two outsized factors have different causes. The poster’s 69.81 arrives at the table size its four tones ask for, which is section 16, and the printed chart’s 7.21 arrives one step before its five different pieces are all held, which is section 17.
Keep in mind
16. Where the content decides the size
The poster is four flat bands of tone with a faint grain over them, and its sweep does something neither of the others does. Going from two entries to four cuts the error by 69.81, which is far outside anything the smooth curve of the photograph reaches. Going from four to eight cuts it by 1.76, which is worse than the speckled square manages at the same step.
The explanation is not subtle and is worth saying anyway. The poster has four tones, so the fourth entry is the one that finishes the job, and every entry after that is spent on the grain. When a collection genuinely has a number of parts, the curve has a corner at that number, and that corner is a fact about the picture rather than about the method. When it does not, as with the photograph and the speckled square, the curve is smooth and no table size is distinguished.
Keep in mind
17. Where the curve stops
The curve cannot go on forever, and where it stops is decided by the collection rather than by the method. The photograph has 53 different pieces, so a table of 53 entries can hold one of each and reproduce it exactly, and the rounding error at that size comes out at 4.6 × 10⁻³³, which is zero to every bit the arithmetic keeps.
Asking for 54 is asking for an entry that has nothing of its own to be, and the result is two entries at one point, which is two numbers meaning one thing.
The printed chart reaches that wall much sooner, because it has only five different pieces. Eight entries already reproduce it exactly, and three of the eight win nothing at all. Sixteen cannot be built. The chart is the useful case here precisely because it is extreme, since the same thing is happening on the photograph at 54 and is simply further away.
Keep in mind
Part 5. Two Pieces, One Number
18. Pieces that share a number
Fewer entries than different pieces means some pieces share a number, and the interesting question is how different two pieces sharing a number can be. On the photograph at two entries, the pieces (0.00, 0.00) and (0.41, 0.45) both become the number 0, and both come back as (0.2067, 0.2366). Those two pieces are 0.6088 apart in the plane, one of them being black and the other being close to mid grey.
…
The widest such pair narrows as the table grows, from 0.6088 at two entries to 0.0894 at sixteen, which is the same trade the previous Part measured seen from a different side. It never reaches zero while there are fewer entries than different pieces, and at every size there is some pair the numbers cannot tell apart.
Keep in mind
19. A picture the table was never chosen for
Everything so far has quantised a picture against a table chosen from that same picture. Take the photograph’s table of sixteen entries and put the printed chart to it instead. The rounding error goes from 0.000418 to 0.104290, which is 249.5 times worse, and 11 of the 16 entries are never asked for at all.
…
The reason is visible in the plane. The photograph’s entries all lie in the narrow band near the diagonal, since that is where its pieces were, and the chart’s pieces include (0.90, 0.05), a bright pixel next to a dark one, which is a place no entry has any reason to be. That piece is given the number 13, and 13 means the vector (0.4286, 0.4771), which is mid grey twice over. A hard edge has become a flat patch.
In a model
This is where the method is worse than the obvious alternative, and it is worth saying rather than burying. A fixed grid of levels, where each coordinate is rounded to one of a few evenly spaced values, covers the whole square whatever arrives and needs nothing fitted; it would round (0.90, 0.05) to something near (0.90, 0.05).
It pays for that by spending entries on regions no picture ever visits, which is why the fitted table wins by 249.5 times on the picture it was fitted for. A fixed grid would have kept that edge and would have spent some of its levels on brightness pairs this photograph never produces, where the fitted table put all sixteen of its entries inside the band its own pieces occupy.
Keep in mind
20. The number carries no notion of how near it was
Look at the two rows of the previous table together. The chart’s piece (0.05, 0.05) lands on entry 11 at a squared gap of 0.001, which is as good a match as anything on the photograph gets. Its piece (0.90, 0.05) lands on entry 13 at a squared gap of 0.404696, four hundred times as large. What is sent downstream in the two cases is the number 11 and the number 13, and nothing else.
A model reading those numbers has no way to tell the excellent match from the hopeless one, because the output alphabet is whole numbers and a whole number is all it gets. That is the same fact the vocabulary page ends on, that a token number says which entry and nothing more, and it is sharper here, since the entries do have positions in a space and it is tempting to believe some of that survives.
It does not. Carrying the gap alongside the number is possible and is a different scheme, one that is no longer sending whole numbers.
Keep in mind
Check yourself
Questions on Parts 4 and 5
Question 1 of 5
The speckled square’s error falls by factors of 1.74 to 2.63 per doubling and the photograph’s by 4.57 to 7.96. What accounts for the gap?
Part 6. Choosing the Table, and Entries That Never Win
21. Where the table comes from
Nothing so far has said how the entries were placed, and the answer is that they were fitted. Start from some positions, give every piece to the nearest, move each entry to the mean of the pieces that chose it, and repeat until nothing moves. That is Lloyd’s procedure and it is k-means, and the entries used everywhere on this page are the centres it settles on.
It inherits every property of that procedure, including the awkward one that it finds a local answer rather than the best one and which local answer depends on where it started. On this photograph that turns out to matter very little. Six different starting draws at eight entries reach two answers, 0.0018756 and 0.0018772, which differ in the sixth decimal place. That is a fact about this collection, whose pieces lie along a line, rather than a guarantee, and on a collection with several genuinely different good tables the spread would be real.
Keep in mind
22. Entries the collection never asks for
An entry that no piece is ever nearest to is a row of the table that is carried, transmitted and never used. It costs bits on every piece, since the number of bits is set by the size of the table and not by how much of it is live, and it returns nothing. Fitted on the collection it will quantise, the procedure leaves none of these, and every table on the photograph up to 32 entries has all of them in use.
Fit on half the photograph and measure on the other half and they appear. The table below fits on the top 64 pieces and then quantises both halves, and at sixteen entries the half it never saw asks for only ten of them while rounding three times worse than the half it was fitted on.
…
The last column is the same idea taken further, a table fitted on the whole photograph and put to the printed chart, where 27 of 32 entries are never asked for. A model reading five distinct numbers out of a possible 32 is paying five bits a piece to say something that needed three, and nothing in the numbers says so.
Keep in mind
23. The two ends of the range
The smallest table has one entry, and it is worth looking at because it is exactly the case where the method does nothing. Every piece becomes the number 0, the number costs zero bits because it could not have been anything else, and the rounding error is 0.113862, which is precisely the mean squared distance from the pieces to their own mean. The single entry is the mean, so the error is the spread of the collection and the numbers carry none of it.
The largest table is the one section 17 reached, 53 entries for the photograph, where each piece has its own number and the error is as close to zero as float arithmetic gets. Between those two ends is the entire method, and the only thing being traded along the way is bits against error.
| table size | what the numbers carry | rounding error |
|---|---|---|
| 1 entry | nothing, 0 bits per piece | 0.113862, the spread about the mean |
| 16 entries | 4 bits per piece | 0.000418 |
| 53 entries | which of the 53 pieces, about 5.73 bits | 4.6 × 10⁻³³, which is zero |
| 54 entries | nothing, the table cannot be built | not defined |
Keep in mind
Part 7. Where the Method Stops Being Defined
24. What any complete description has to settle
Several of the things this page has shown are decisions taken alongside the rule rather than consequences of it, and a description of the method that leaves them out has not described it. There are five, and each is a real choice with a cost attached rather than a detail.
| what must be settled | what turns on it |
|---|---|
| what a piece is | a pair of pixels here, a patch of sixteen or sixty-four in an image coder, a frame of features in a speech model. This fixes how many numbers a picture becomes and how much structure a single number can capture, and the two pull against each other. |
| how many entries | the bits per piece are the logarithm of this number, so it is the whole of what everything downstream pays. Bounded above by the number of different pieces, since beyond that two entries must coincide. |
| what near means | the straight-line distance is a choice, not a definition of nearness, and it is tied to the choice of squares in the error and to the mean in the fitting step. Change it and the entry a piece lands on can change, which is section 26. |
| how ties are broken | the earlier position here. Any rule is arbitrary and no rule at all means two correct implementations disagree, which section 7 shows costs nothing in error and changes which numbers come out. |
| where the table came from | which collection it was fitted on, since the answer it gives on anything else is a rounding to a table chosen for something different. The 249.5 times of section 19 is what that costs when the two differ sharply. |
Keep in mind
25. Where the arithmetic runs out
Separately from the choices there are inputs on which the rule has no answer at all, and they are worth separating from the choices because arguing about them is wasted effort. In each case something the rule needs is a quantity the input does not have. The table gathers them, with what the mathematics says.
| the case | what is undefined, or what must be decided |
|---|---|
| a table with no entries | undefined, with no choice attached. Nearest is the smallest of a set of distances, and there are no distances to take the smallest of, so there is no answer rather than a bad one. |
| two entries at the same point | undefined as a vocabulary. The number of an entry is its position, so one vector at two positions has two numbers, and every piece near it goes to whichever a tie rule prefers while the other number is never produced and means the same thing. Fitting more entries than a collection has different pieces forces it, which is why a table of 54 cannot exist for a picture holding 53 different pieces. |
| a piece with a different number of coordinates | undefined. A distance is a sum over matched coordinates, and there is no pairing between a piece of three numbers and an entry of two, so the first step of the rule cannot begin. |
| a coordinate that is not a number | undefined. Every distance involving it is not a number either, so no comparison between two of them holds and nearest names nothing. A comparison against such a value is false whichever way it is asked, which is why the case has to be excluded before the search rather than noticed during it. |
| a coordinate that is infinite | undefined in a second way. Every distance from that piece is infinite, so every entry ties with every other, and the tie rule exists to choose between two entries that are equally good rather than between entries none of which is good at all. |
| a number no entry owns | undefined on the way back. A table of 16 entries owns 0 to 15, and there is nothing for 16 to mean. This is the case a model generating numbers can reach, since nothing about a generated number keeps it in range. |
| a piece exactly between two entries | defined only once a convention is added, since nearest is not unique. The convention costs nothing in error, as section 7 measures, and decides which numbers come out, so two implementations without the same one disagree on inputs both handle correctly. |
| a piece nowhere near any entry | defined, and that is the problem. The rule always answers, since some entry is nearest however far away it is, so an input from outside anything the table was chosen for is rounded silently. A squared gap of 0.404696 and one of 0.001 both come back as one whole number. |
| the distance between two of the numbers | meaningless, exactly as it is for a word vocabulary. A number is a position in a list, so numbers 3 and 4 need not name nearby entries, and any ordering the fitting happened to produce is an accident of it. The entries have positions in a space; the numbers do not inherit them. |
| an entry that no piece is nearest to | well defined and quietly wasteful. Every piece still gets an answer, the bits per piece are still set by the size of the table, and the capacity of that row is simply not received. Nothing about the answers indicates it, so the distinct numbers actually produced have to be counted. |
Keep in mind
26. Nearest, under a distance somebody chose
The third of the five decisions in section 24 deserves its own measurement, because it is the one most often read as a definition. Nearest is a property of two vectors together with a rule for measuring rather than of the two vectors alone, and the rule used throughout this page is the straight line. Adding the two coordinate gaps instead is an equally ordinary rule, and it does not always give the same answer.
…
Of the photograph’s 128 pieces against a table of eight entries, exactly one changes hands. The piece (0.13, 0.30) is 0.1078 from entry 5 and 0.1303 from entry 1 by the straight line, so it goes to entry 5, and it is 0.1480 from entry 5 and 0.1437 from entry 1 by the sum of the gaps, so it goes to entry 1.
One piece in 128 is a small effect, and it is not zero. The choice is constrained in a second way as well, since the straight line is the measure the fitting step lowers, so changing the rule used at lookup time without changing the one used at fitting time leaves the two halves of the method aiming at different quantities.
Keep in mind
Check yourself
Questions on Parts 6 and 7
Question 1 of 5
On the photograph, every table up to 32 entries chosen from all 128 pieces has every entry in use, and entries nobody asks for appear only when the pieces being quantised are not the pieces the table was chosen from.
Try it with Botie
Build with Botie
Write and run Python