Smoothing a jumpy week
Tonight's idea
Daily temperatures jump about: warm, cold, warm again. To see the trend, replace each day's number by the average of three: the day before, the day itself and the day after. This is a 3-day running average. The first and last days have a neighbour missing, so on this sheet we leave them out.
A running average takes in a whole list and gives back a whole new list. Each new number is a weighted average of old ones. Here the three weights are \(\tfrac13\), \(\tfrac13\) and \(\tfrac13\).
A rule that turns one list into another is called an operator. Run a list through this one twice and each final number draws on five days, not three. A simple photo blur works the same way: each pixel's brightness is replaced by an average of it and its neighbours. Blurring is easy. Un-blurring is the hard direction, because different sharp rows can give exactly the same blurred row. Tonight you will see why.
Watch one: ten days of temperatures
Ten days of made-up noon temperatures in °C, with the running average underneath.
| Day | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|
| Temperature | 12 | 18 | 15 | 21 | 12 | 18 | 21 | 15 | 18 | 24 |
| Running average | 15 | 18 | 16 | 17 | 17 | 18 | 18 | 19 |
Day 2: \((12 + 18 + 15) \div 3 = 45 \div 3 = 15\). Day 3: \((18 + 15 + 21) \div 3 = 54 \div 3 = 18\). Day 4: \((15 + 21 + 12) \div 3 = 48 \div 3 = 16\). And so on. Days 1 and 10 get no average, so ten numbers become eight.
The temperatures (thin line) run from 12 to 24, and their biggest change from one day to the next is 9. The averages (thick line) run only from 15 to 19, and their biggest change is 3.
Your turn
- One week of made-up temperatures in °C: 6, 12, 3, 9, 15, 6, 3. (a) Work out the 3-day running average. How many numbers do you get? (b) Find the biggest change from one day to the next in the week, and then in your averages.
- A row of nine pixels is dark except for one bright pixel in the middle. Their brightnesses are 0, 0, 0, 0, 9, 0, 0, 0, 0. (a) Blur the row once with the running average. (b) Blur your answer again. (c) Add up the brightness in each of the three rows. What has the blur done to the bright pixel?
- Five days: 3, 12, 6, 9, 9. (a) Take the running average, then the running average of your answer. You should end with one number. (b) Now work out \((1 \times 3 + 2 \times 12 + 3 \times 6 + 2 \times 9 + 1 \times 9) \div 9\). (c) Explain why the two agree. Hint: call the days \(a, b, c, d, e\) and count how many times each one is used.
- Un-blurring. Every row here has five pixels, so its blur has three. (a) Check that 4, 4, 4, 4, 4 and 5, 3, 4, 5, 3 both blur to 4, 4, 4. (b) Find a third row that blurs to 4, 4, 4. (c) Another row blurs to 5, 7, 6. From that alone you cannot tell what it was. Now you are told its first two pixels are 3 and 6. Find the other three.
Stretch: the invisible pattern
Look at the pattern \(1, -1, 0, 1, -1, 0, \dots\), which repeats for ever. (a) Add up any three neighbours in a row. What do you always get, and why? (b) Take the row 6, 9, 3, 6, 12, 6 and add the pattern to it, place by place. Work out the running average of the old row and of the new row. (c) Explain why adding this pattern to any row never changes its running average. Then find a different pattern that is invisible in the same way.
Answers
- (a) The sums of three are 21, 24, 27, 30 and 24, so the averages are 7, 8, 9, 10, 8. Seven numbers give five. (b) In the week the biggest change is 9, from 12 down to 3 (and again from 15 down to 6). In the averages it is 2, from 10 down to 8. The biggest jump in a running average is never bigger than the biggest jump in the list it came from.
- (a) 0, 0, 3, 3, 3, 0, 0. Each of the three averages that includes the 9 is \(9 \div 3 = 3\). (b) 1, 2, 3, 2, 1. For example \((0 + 0 + 3) \div 3 = 1\) and \((0 + 3 + 3) \div 3 = 2\). (c) Each row adds up to 9. The blur has not removed any light. It has spread one bright pixel over three pixels, then over five, and the peak has dropped from 9 to 3. The total stays the same here because the row is dark near both ends. A row that is bright at its ends loses some of its total when the ends are left out.
- (a) First pass: \((3 + 12 + 6) \div 3 = 7\), \((12 + 6 + 9) \div 3 = 9\), \((6 + 9 + 9) \div 3 = 8\). Second pass: \((7 + 9 + 8) \div 3 = 8\). (b) \((3 + 24 + 18 + 18 + 9) \div 9 = 72 \div 9 = 8\). (c) The second pass adds the three sums \(a + b + c\), \(b + c + d\) and \(c + d + e\), and the two passes divide by 3 twice, which is dividing by 9. In those sums \(a\) appears once, \(b\) twice, \(c\) three times, \(d\) twice and \(e\) once. So two passes are one weighted average with weights 1, 2, 3, 2, 1 out of 9. The middle day counts most.
- (a) Every three neighbours in the first row add to 12. In the second, \(5 + 3 + 4 = 12\), \(3 + 4 + 5 = 12\) and \(4 + 5 + 3 = 12\). Each average is \(12 \div 3 = 4\). (b) Many answers, such as 3, 6, 3, 3, 6 or 6, 2, 4, 6, 2. Pick any first three pixels that add to 12, then repeat the first two. (c) The first three add to \(3 \times 5 = 15\), so the third is \(15 - 3 - 6 = 6\). The middle three add to \(3 \times 7 = 21\), so the fourth is \(21 - 6 - 6 = 9\). The last three add to \(3 \times 6 = 18\), so the fifth is \(18 - 6 - 9 = 3\). The row was 3, 6, 6, 9, 3. The blur kept three numbers out of five. You needed two more to get the row back.
Stretch. (a) Always 0. Any three neighbours are a 1, a \(-1\) and a 0 in some order, because the pattern repeats every three places. (b) The new row is 7, 8, 3, 7, 11, 6. Both rows have running average 6, 6, 7, 8. (c) Adding the pattern changes each sum of three neighbours by \(1 + (-1) + 0 = 0\), so every average stays the same. Another invisible pattern is \(2, -2, 0, 2, -2, 0, \dots\) or \(1, 0, -1, 1, 0, -1, \dots\). Any three numbers that add to 0, repeated for ever, will do. So the blurred row cannot tell you whether such a pattern was in the original. That information is lost for good, and no clever method can bring it back from the blurred row alone.