Catch-up to Lookout 1.0.0: building and evaluating a simple predictor
See the announcement for context, but TLDR: this is a catch-up devblog-style post on where I am with Lookout, which is currently at 1.0.0-alpha.1. Today we'll focus on building and evaluating a simple Predictor.
There is a great way to think about this sort of problem that I think can be attributed to Dr John Hallam, who was a professor on my AI course in the '90s, which went something like:
To stop a robot getting stuck in a corner, you can try to make a clever robot that can get itself out of any jam, or you can make a dumb cylindrical robot that can never get stuck (as it can just turn on the spot).
This then leads to the idea that the 'intelligence' of a system should be thought of as always including the 'designer' who anticipated problems ahead of time and produced a simpler run-time solution.
Applied to our context, we'd like our Predictor to have as few dependencies as possible, whilst still being proven to be robust and usable. This latter part is where Evaluation becomes super-important, and is actually where the bulk of my time has been spent.
The plan of attack for Evaluation roughly broke down as:
- Gather ground-truth real train positions in bulk
- Establish a measurement framework that fits our problem
- Define a perfect Oracle to measure any Predictor against
- Put together the simplest Predictor that can run for real, and compare against the Oracle
- Repeat 4 for incrementally more complex Predictors, until we reach acceptable performance
Ground truth
I'd already been gathering GPS data on my personal devices, which is great for sampling the real environment, but not so great for getting the scale of data we need for measuring things like Precision/Recall.
Thankfully I'd previously discovered MOTIS as a great way to get access to transport data at scale. This is something I may consider using live in the future as part of the App, but here I used it to record real train positions over multiple days in Germany.
I could easily watch this for hours (they look like little fireflies to me). Anyway, this shows rail traffic over a couple of days in Germany, from trains that really ran.
These aren't real measured positions, in the sense that they are live-interpolated based on timetable data and delay updates, but don't come from a GPS sensor on the train. So, these won't include things like GPS error, but that's ok as that can be modelled separately (one for a later post).
I didn't like needing to leave a process sampling from MOTIS for days at a time, and there may be other per-country ways I could have attempted to get bulk immediate access to train positions. I'd still like to consider something like that in the future, but I liked this way as I could treat MOTIS as an abstraction layer over the bespoke ways in which each country manifests this data. I could also build upon existing config from things like https://transitous.org/sources/ to set up my local instance.
What does good look like?
This problem relates to trains, so it was initially tempting to use a scoring method inspired by train arrival, but this has the problem that a late notification can still get a positive score, in the same way that a train a few minutes late still counts as on time.
Instead it was more appropriate to use a score closer to how weather forecasts are scored. We end up with a scoring profile like:
This needs to be combined with a definition of Precision and Recall that is based on the total score for an evaluated train session:
- Precision: total score, divided by the number of notifications raised
- Recall: total score, divided by the number of real passes
This way, for example, a Predictor can't get away with always predicting an upcoming pass, as that would hurt Precision, even if it got perfect Recall.
CrowFlies vs the Oracle
One of the things I was concerned about was defining a scoring method that somehow made a maximum score impossible, perhaps because there are some tracks that double back on themselves in weird ways.
To form a true baseline for any session, I introduce an "Oracle" Predictor which is allowed to cheat and look at the answers, i.e. it knows everything about a pass.
In general I've found that the Oracle always gets a perfect score, but it's there as a safety check if and when something weird comes up.
At the other end of the scale we have the dumbest Predictor, CrowFlies, which looks to see if a known crossing is within some distance of the current position:
On the test set, this produces a Precision of 0.37 and a Recall of 0.91, for a weighted F0.5 score of 0.42 (I weight more towards Precision than Recall).
So, have we got a "robot that can never get stuck"? Definitely not: it notifies about every pass, but for roughly one pass in ten it only does so at the last moment, and most of its notifications are for crossings the train never reaches.
However, that's enough for today. In our next post, we'll cover what might be a 'good-enough' Predictor, at least for an alpha release: LightCone.
Related development detail:
- getting a second source of position data from MOTIS
- MOTIS as ground truth
- Crow-flies predictor on the M5 device and in rerun
- Evaluation framework with associated Crow Flies predictor improvement
- Evaluation
- MOTIS