Skip to content

information and entropy

learning from examples

what it is

How mixed a group is can be counted, and so can how much a question tells you about it. This page counts both, first on 8 points and then on a school's students.

Take the 8 points drawn below, 5 triangles and 3 squares. Pick one without looking, and 5 times in 8 it is a triangle. The group is mixed, but not evenly.

02468100246810
Eight points, 5 triangles and 3 squares. Four triangles lie between 0 and 3 along the bottom, and two triangles and two squares lie between 7 and 10 up the side.

Say you must find one of 8 things by yes-or-no questions, each halving what is left: 8, then 4, then 2, then 1. That takes 3 questions. The log to base 2 of 8 is 3, the power 2 is raised to, to make 8. So a thing that is 1 in 8 of the group takes the log of 8, the log of one over its share, to single out.

rounding down84213 halvingsrounding up84213 halvings
Finding one of 8 by halving, 8 to 4 to 2 to 1. Three questions, and the log to base 2 of 8 is 3. 1 in 2 takes 1 question and 1 in 4 takes 2. The commoner a shape, the fewer questions, so 5 in 8 takes less than 1.

Entropy averages that count over the group: each shape's share times the log of one over its share, added. The table works it for the 5 triangles and 3 squares: 5/8 × 0.678 + 3/8 × 1.415, about 0.954. A shape with no points adds nothing, as it never turns up.

shapeshareone over the sharelog to base 2share × log
triangles5/88/50.6780.4238
squares3/88/31.4150.5306
added0.9544
The entropy of 5 triangles and 3 squares, worked a shape at a row. The last column adds to about 0.954. 8/5 is 1.6, which is not a whole power of 2, so its log comes from a calculator. Press the log key on 1.6, divide by the log key on 2, and get about 0.678.
5triangles3squares00.5100.510.954
The same 8 points, a bar for each shape. The curve is the entropy at every share of triangles, and the point marks this group's, about 0.954.

A group of one shape has entropy 0: its share is 1, and the log of 1 is 0, so no question is needed. Half and half is 1/2 × 1 + 1/2 × 1 = 1, as the log to base 2 of 2 is 1. The curve, drawn at every share, is highest there. The slider below moves between them.

4triangles4squares00.5100.511

4 triangles and 4 squares: an entropy of 1.

With scripts on, a slider sets how many of the 8 are triangles. The bars, the point and this line change with it.

A group of 8 with the share free to change. All of one shape is 0, and half and half, at the top of the curve, is 1.

A question splits the group in two. Across 0 to 3? asks whether a point stands between 0 and 3 along the bottom. It puts 4 triangles on one side, one shape, entropy 0. The other side has 1 triangle and 3 squares: 1/4 × 2 + 3/4 × 0.415 = 0.811. One over 1/4 is 4, whose log is 2, and one over 3/4 is 4/3, whose log is about 0.415. A question's gain is the group's entropy minus each side's entropy times its share of the group: 0.954 − (4/8 × 0 + 4/8 × 0.811) = 0.549. The information a question gives is its gain.

trianglessquares5 + 3all 80.9544 + 0yes01 + 3no0.811
questiongain
across 0 to 3?0.549
up 7 to 10?0.049
across 0 to 1?0.092

The question gains 0.549.

With scripts on, a picker shows each question's two sides. The drawing and this line change with it.

Three questions on the 8 points. Across 0 to 3 gains most.

Up 7 to 10? leaves 2 triangles and 2 squares on one side, entropy 1, and 3 triangles and 1 square on the other, 0.811. It gains 0.954 − (4/8 × 1 + 4/8 × 0.811) = 0.049, far less.

A decision tree that measures how mixed a group is this way, as this site's does, weighs every question and asks the one that gains most. It then does the same inside each side. It stops when a group is one shape, when it has asked as many questions in a row as it is allowed, or when no question gains. Some trees measure how mixed a group is in another way.

02468100246810A5+3B4+0C1+3D1+1E0+2

where the formulas come from

Each question is worked out one numbered line at a time. A line shows the move it makes, the line itself, and why the move is allowed. A line either follows from the lines above it, or brings in something the question needs, such as how the method works, a small fact about nn, or a result from another page, with its own reason. Press 'hide the lines, then guess each one' to cover the lines and uncover them one by one, guessing each before you see it.

question 1Why is a group of nn triangles and nn squares exactly 1 mixed?
  1. the move: each share times the log of one over it

    the line:
    H=n2n log⁡2 2nn+n2n log⁡2 2nnH = \frac{n}{2n} \,\log_2\, \frac{2n}{n} + \frac{n}{2n} \,\log_2\, \frac{2n}{n}

    why it is allowed: HH is the entropy of nn triangles and nn squares. Each shape's share is nn of the 2n2n points, and one over it is 2n2n over nn.

  2. the move: cancel the n

    the line:
    H=12 log⁡2 2+12 log⁡2 2H = \frac{1}{2} \,\log_2\, 2 + \frac{1}{2} \,\log_2\, 2

    why it is allowed: By line 1, nn over 2n2n is a half, and 2n2n over nn is 2.

  3. the move: two halves make one

    the line:
    H=log⁡2 2H = \log_2\, 2

    why it is allowed: By line 2, half of a number added to half of it is the number.

  4. the move: read the log

    the line:
    H=1H = 1

    why it is allowed: By line 3, 2 is 2 to the power 1, so its log to base 2 is 1. For 4 triangles and 4 squares, 1.

try it with a small nn: at n=4n = 4, line 1 gives H=1H = 1, which you can work out by hand

a worked example

A school asks 12 students how they come in. 9 walk and 3 ride. Which question tells more about who rides, does a student live within 2 km, or does a student have a brother or sister at the school?

  1. The group: the walkers' share is 9/12 and the riders' 3/12, so its entropy is 9/12 × 0.415 + 3/12 × 2, about 0.811.
  2. Within 2 km? 9 say yes, 8 walkers and 1 rider, entropy 8/9 × 0.170 + 1/9 × 3.170, about 0.503. 3 say no, 1 walker and 2 riders, entropy 0.918. The gain is 0.811 − (9/12 × 0.503 + 3/12 × 0.918) = 0.204.
  3. A brother or sister at the school? 7 say yes, 5 walkers and 2 riders, entropy 0.863. 5 say no, 4 walkers and 1 rider, entropy 0.722. The gain is 0.811 − (7/12 × 0.863 + 5/12 × 0.722) = 0.007.
  4. Living within 2 km tells far more, so a decision tree would ask it first.
walkersriders9 + 3all 120.8118 + 1yes0.5031 + 2no0.918
questiongain
within 2 km?0.204
a brother or sister here?0.007

The question gains 0.204.

With scripts on, a picker shows each question's two sides. The drawing and this line change with it.

The 12 students, 9 walkers and 3 riders, and two questions. Within 2 km gains far more.

the trap

check yourself

  1. A group holds 6 triangles and no squares. What is its entropy?

    the answer

    0. Every point is one shape, so nothing is mixed.

  2. A group holds 4 triangles and 4 squares. What is its entropy?

    the answer

    1. Half and half is the top of the curve.

  3. A question splits 5 triangles and 5 squares into two sides, 3 triangles and 3 squares, and 2 triangles and 2 squares. What does it gain?

    the answer

    0. Each side is half and half, entropy 1, as mixed as the group, so nothing is gained.