Github Gists are a readable way to pass around code fragments. Over the years I’ve put a lot of weird little things on mine, and they form a little history of my hard thinking. Thoughts I couldn’t have had (or couldn’t have finished) without Python.

#### Via Julia Galef: comparing Spock’s predictive skill to a coin flip

The online forecasting community have a way of scoring how calibrated someone is, the Brier score. Julia Galef gathered every time Spock from Star Trek made one of his characteristic probability statements. I in turn just summarised her data into his Brier score: 0.57, a truly terrible score. (On average, his predictions are off by a full 75% out of 100%.)

So the Enterprise would do better to consult a random process like a coin flip (and in fact they do ignore him most of the time).

As Galef notes, this matters because Spock is one of the main exemplars for rational thought, and he is a dingbat, which might explain some people’s attitude towards explicit rationality.

A natural objection: the episodes we see are not a representative sample of events; they are “selected” to be as dramatic and telegenic as they can be, which means that of course Spock predicts wrong! But by the exact same token, these are the events it is most important for Spock to predict well, and he does terribly, so the expected value of listening to him is still bad even if he gets everything else right.

(My preferred explanation is that Vulcans are in fact stupid, they just talk like smart people.)

#### An optimal solution to a friend’s data adventure game.

Fun! Only interesting because it includes expected value and risk-sensitive optimisation solutions. EV alone would not have done well at this task; I gave it only 20% of the budget.

The death sensitive bit is here: just variance (z-score) as a danger score.

#### Kelly for maximum house insurance cost

The Kelly criterion is an interesting piece of abstract nonsense that tells you how much you should bet / pay for insurance, given how much money you have, if losing all your money means death / infinite loss. It takes a bit of work to compute it, but it gives surprisingly intuitive answers, and it beats the hell out of EV when there are big downside risks.

#### Reported vs real (excess) COVID deaths, 2020

One of the 700 bitter stupid information-free arguments people had about COVID early on was the “infection-fatality ratio” - was it 0.1% like flu? 3% like SARS? I did this script to show that the ascertainment rate (the % of cases you catch in your system) isn’t constant, in order to justify a modelling choice, as part of me losing a year pretending (quite well) to be an epidemiologist.

#### Converting between the effect sizes used in social sciences

A quiet improvement in psychology over the last 15 years: people started to foreground the actual size of the effects they studied, and to use nice standard metrics for em. (Part of my inexplicable procrastination on my PhD quals was dissing 300 psychology papers.)

#### A really nice way to juggle probabilities: dict keys

Solutions to Chapter 2 from the mighty mighty ITILA.

Also the classic minimal case of Bayesian updates, coins and binomials.

#### Google character recognition

I recently scanned in my teenage handwritten notebooks, and tried out the GCP OCR. It’s free up to a few thousand requests. Accuracy is surprisingly not great; corrections take about 15 minutes per small book. If my time was more valuable / if it wasn’t a joy to look at these dumb notes again I might try fine-tuning a Transformer on my handwriting.

#### Helping a friend maximise his alcohol purchases

This was part of my trying to sell him on the value of programming, god save him.

#### Tax check

Boring script to see how much teaching I can do without incurring tax.

#### Queue as Poisson process.

Incredibly involved exercise from BDA Chapter 1. Not conceptually difficult, just very fiddly.

#### Check power of 3 in near-constant time

$$3^x \leq 2^{63} - 1$$ take log_3

i.e. $$x = \log_3(2^{63} - 1)$$

We know $$3^x \,\,\%\,\, 3^y = 0$$ for y < x

So for a near-constant time check, just ensure that you make $$3^x$$ definitionally larger than $$3^y$$. e.g. set it to the MAX int of your system, and then take the mod.