This post fits the heater model from 104 to a real room instead of a simulated one. The data is six and a half months of hourly temperature readings from my office, with the weather outside and a sensor on the door. The building controls the heating, so the log has no record of it. You will see the model's one private field pick up a warm-up of about three-quarters of a degree an hour every morning, how that compares with a model that is simply given the time of day, why the door made no difference, and the October mornings the field gets wrong. The model has eleven weights and trains in 0.3 seconds.
My office has a sensor on the door. I put it there because a door seemed like the obvious thing that would change how the room behaves, and because 104 spent a whole post teaching a model to find a door it couldn't see. Six months later I fitted 104's model to the office's real log, held the door back as an answer key, and the door turned out not to matter at all. The thing that did matter was a warm-up of about three-quarters of a degree an hour every morning, which no sensor records and I hadn't noticed. The model's private field found it by itself.
The hidden state a model learns is whatever the inputs leave unexplained, which here was the heating and not the door.
The code is in tools/office_fit.ts and the hourly data is in office-hourly.csv, so everything below can be rerun.
The room and its log
The office is a small room in a serviced building in Ashford, Kent. Since April the room has been logged by Unimo, which is our own product at CrossMoore. A Unimo hub in the office reads four cheap Zigbee sensors and fetches the weather.
Unimo builds a live 3D model of a site from the documents, photographs and drawings you already have. It brings the site's readings (weather, noise, power, and here a room's temperature and its door) into one view, and turns them into dashboards and reports without a specialist team. I was part of making it, so I would say this, but if you run a building or a site you should buy it immediately. Everything in this post came out of data it had been collecting for months before I thought to look.
| sensor | what it reports | in the log from |
|---|---|---|
| temperature and humidity (Sonoff SNZB-02P) | on change, about every five to ten minutes | 17 April |
| door contact (SNZB-04P) | open or shut, on change and hourly | 30 July |
| motion (SNZB-03P) | occupied or not | 30 July |
| smart plug, with a lamp on it | signal strength only | 30 July |
| OpenWeatherMap | outside temperature and humidity, every twelve minutes | 17 April |
Averaged into hours, that is 4,426 hours with both a room reading and an outside reading, from 17 April to 3 November. The weather comes from a point in east London about 45 miles away, because that is where the hub's location was set, so "outside" below means roughly the right part of England. The weather feed went quiet from 19 to 29 June and the hub was offline from 20 to 24 September. The office also flooded on 4 September, which comes back at the end.
Every day in the log. The bars are the room's daily range, the blue line its daily mean, and the grey line the mean outside. From May to August the outside mean swings between about 8 and 28 degrees and the room barely notices. The flood arrives on 4 September and the door is propped open on the 7th, where it stays until 2 November.
In the simulated room the log had three fields: the room, the outside, and whether the heater was on. This log has the first two and nothing in the third. The building runs the heating and doesn't tell Unimo, and the only thing in the room I can switch is a lamp.
What three weights make of it
With no heater column, the 103 model drops to three weights: the room, the outside and a bias. Fitted to the 2,895 hourly transitions before the flood, with the inputs centred and scaled as in 104, it learns that the room loses 0.025 degrees an hour for every degree it sits above 21, and gains 0.0012 an hour for every degree the outside is above 14. In the simulation those two numbers were equal and opposite. Here the outside barely registers, and the model says this room settles at about 22 degrees whatever the weather does.
That is a building with a thermostat, read straight from the logs, and three weights can't say anything more about it. Scored one hour ahead, the model's error is 0.407 degrees. Guessing "the same as now" every hour gets 0.410.
One private field
The model from 104, with the heater input taken out, keeps one number to itself. act predicts the next hour from the room, the outside and that number. observe updates the number from what the room just did.
act(state: Hour): number {
const f = inputs(state), w = this.w;
const base = w.room * f.room + w.outside * f.outside + w.bias;
const extra = w.fieldRoom * f.room + w.fieldOutside * f.outside + w.fieldBias;
return state.roomTemp + base + this.#field * extra;
}
observe(state: Hour, nextState: Hour) {
const f = inputs(state), w = this.w;
const change = nextState.roomTemp - state.roomTemp;
this.#field = Math.tanh(w.uField * this.#field + w.uRoom * f.room + w.uOutside * f.outside + w.uChange * change + w.uBias);
}
Each local day is an episode, so the field starts at zero at midnight, and training walks each day forwards and back as in 104. Eleven weights, 126 days, three thousand epochs, 0.3 seconds. On those days its one-hour error is 0.276, a third lower than the three-weight model's.
The field isn't labelled, so to see what it learned I averaged it by hour of day.
Top: the average change in the room over the next hour, by local time. From April to August it cools by about a tenth of a degree an hour overnight, then warms by 0.74 degrees in the hour from 07:00 and 0.67 in the hour from 08:00. In October the warm-up comes an hour later and ends sooner. Bottom: the private field, averaged the same way. It sits near zero all day except the morning.
The field sits near zero overnight and through the afternoon, and drops to -0.52 at 08:00. The top half of the chart shows why. Something warms this room by about three-quarters of a degree an hour every morning, Saturdays and Sundays included. It is the largest single thing that happens to the room, and nothing in the log records it. I didn't know it was there until the field pointed at it.
The weights say how. An hour that warmed pushes the field negative, and a negative field adds warmth to the next hour's prediction: at -0.5, about two-thirds of a degree, which is the size of the warm-up. The field has almost no memory, so it reads each hour fresh. That suits a warm-up that lasts two or three hours and stops.
Is it just learning the clock?
A warm-up at the same time every day is a timetable, and the obvious way to model a timetable is to hand the model the clock. So I fitted one more model: room, outside, and a separate bias for every hour of the day, 25 weights by least squares. If the field is only rediscovering the time of day, this timetable model should do as well.
| one hour ahead, rms error in degrees | hours | same as now | three-weight | timetable | latent |
|---|---|---|---|---|---|
| April to August (fitted) | 2,895 | 0.410 | 0.407 | 0.324 | 0.276 |
| the flood, 4 to 20 September | 322 | 0.599 | 0.596 | 0.517 | 0.508 |
| drying out, 24 September to 6 October | 274 | 0.656 | 0.650 | 0.547 | 0.518 |
| October | 599 | 0.417 | 0.423 | 0.380 | 0.402 |
Mostly, yes. The timetable model gets most of the way, from 0.410 to 0.324. The field takes it on to 0.276, because it reacts to the hour the warm-up actually starts, which varies from day to day.
Two days, one hour at a time. Each dot is a model's prediction for that hour, made from the reading an hour earlier. Left, Thursday 18 June: the warm-up starts at 07:00, the three-weight model trails it by an hour all morning, and the latent model catches it from the second hour, once its field has dropped to -0.72. Right, Thursday 22 October: the room is four degrees colder, the warm-up is sharper and shorter, and the field keeps adding warmth after the warm-up has eased off.
These two days are from the middle of their months, not the best of them. On 18 June the first hour of the warm-up catches both models out, as step 11 did in 104, because nothing has happened yet for the field to read. From the second hour the field has seen the room move. Across April to August, the error for the hour from 08:00 drops from 1.02 degrees to 0.52.
The timetable model works because I already knew to give it the hour of day. The field was never given the time.
The door it ignored
The door is the one thing in the log the model is never shown, which makes it an answer key. If the field had picked up the door, it would differ between hours with the door open and hours with it shut. It doesn't: -0.052 over the 1,121 open hours, -0.046 over the 901 shut ones.
In fairness to the field, the door gave it nothing to find. It opens onto an inside corridor that is probably the same temperature as the room, and in the hourly log it changes state twice in fourteen weeks: open on 7 September, shut on 2 November. 104's door moved 310 times in 4,800 steps. Given the door as an input, the timetable model concludes that the room follows the outside temperature slightly less while the door is open. An open door doesn't do that. The autumn arrived the same week, and with only two changes in the log there is no telling the door's effect from the season's.
Where it stops
October is the one stretch where the timetable model does better, 0.380 against 0.402. The right-hand day shows why. The room sits near 17 degrees, colder than the summer that taught the model this room drifts back towards 22, and the warm-up comes as one sharp hour rather than two or three steady ones. The field switches on at 09:00, exactly as summer taught it, and adds a summer warm-up to hours that no longer have one: 20.4 predicted for a room that reached 19.5. Refitting on all six months only brings October to 0.378. A single field can't represent both the summer warm-up and the October one.
What to log
I added a door sensor because I could picture a door changing a room. I didn't add anything for the heating because I don't control it and couldn't picture it.
So log the plain readings densely and for a long time, and let a model with a little private state show where the unexplained behaviour is. Then go and find out what it is. I still don't know what warms this office at eight every morning. A timer on the building's heating would do it, and so would the sun through an east-facing window. The field can't tell me which. What it gave me is a precise question, about three-quarters of a degree an hour starting at 07:00 in summer and 08:00 in October, which is far more than the door sensor ever told me.
The flood
The temperature model barely noticed the flood. The flood is in the humidity, which none of these models reads. From about two in the morning on 4 September, with nobody in the office until 06:27, the room's humidity climbed from 66.8 percent to 76.5, and by the next day its air held 5.7 grams of water per cubic metre more than the outside air, against a summer range of -2.5 to +3.4. Whether a model watching that column would have raised the alarm before anyone walked in is a question for the monitor in the next post, and the office is where it gets tested.
Running it yourself
node --no-warnings tools/office_fit.ts reads office-hourly.csv, fits all four models, prints every number in this post and writes the CSVs behind the charts. tools/office_export.sh shows how the CSV was made from the hub's databases. I left the motion sensor out of the published data, since it is a record of when I'm at my desk, and the weather rows went in without their coordinates. A different seed finds different weights and the same two results.
First published on stepinto.dev.
Top comments (0)