92 points · by headalgorithm · 7y ago · 24 comments
Thompson sampling is easy to implement, predictable, stable, and you can leave your experiments running forever without supervision. It has very few drawbacks.
With a combination of two HyperLogLogs and a Bloom filter, you can also have a really nice scalable distributed implementation (HLLs and BFs combine in an idempotent manner, so updates are lock-free), albeit at the cost of low precision early on as the number of samples is low.
Don't use a library. Thompson sampling itself is not difficult (specifically, 6 lines, as I'm looking at my Clojure code), you will need to understand it very well anyway, and most libraries will include lots of superfluous garbage. Most of the work is not with Thompson sampling, but with processing your events, and that is something which is application-specific anyway and can't be abstracted well.
Thompson sampling, on the other hand... I'm in love. Clean, simple, straight-forward, and so close to the optimal solution that you will never notice the difference. If you don't understand how to implement it, the stuff that you need to learn (mostly about the beta distribution) is generally useful and well worth studying. Though, after several years now, I'm still looking for an excuse to apply it somewhere. I can't get this method out of my head.
Going through "A tutorial on Thompson Sampling" and being eager to hone my skills in Clojure, I would be very interested in reading this code if there would be a repository online or a gist you could share with us.
Best Regards.
(There are some very degenerate cases that are allowed; medical trials can fail and succeed so spectacularly that they can skip to the end of the given phase, for instance, which is sort of a degenerate case of a multi-armed bandit approach. But it's a rare exception.)
We've suffered a lot from the phrase "the scientific method" because of the article "the". The name of the game is to increase and decrease confidence in hypotheses by any legitimate statistical method, not to follow "the" method. Science suffers immensely as a result of the extreme requirement to "call your shots" in advance, which contributes to all sorts of problems. The current system almost entirely forbids any sort of exploration; it is sort of snuck in the side door, rather than officially supported.
(It's very analogous to the problems with waterfall design in our industry; the absolute worst times to estimate how expensive a problem is, how likely the solution is to solve it, how the solution will integrate with the rest of the world, and all of the other interesting engineering issues is at the very beginning of the project, when you know the least. One of the virtues of an iterative process is your ability to react to what you learn; waterfall is such a problem because you still inevitably learn these things but the process forbids you from exploiting that knowledge.)
Science is currently suffering a 50+% replication failure crisis as a result of not following "the" method. Studies forced to preregister have shown a dramatic reduction in false positives.
Sure, the pretend system says this scientist has done noble and laudable work by showing some hypothesis was wrong, but who cares what the pretend system says? Certainly not anyone who wants promotions (or even just job security) and grant money.
"...It involves formulating hypotheses, via induction, based on such observations; experimental and measurement-based testing of deductions drawn from the hypotheses; and refinement (or elimination) of the hypotheses based on the experimental findings. These are principles of the scientific method, as distinguished from a definitive series of steps applicable to all scientific enterprises."
https://en.wikipedia.org/wiki/Scientific_method
There are many ways to implement this method, but if you leave out a single element, you're doing something other than science.
The definition I cited says nothing about the particulars - it just enumerates three essential elements.
What would you propose instead as general principles for a scientific method?
Multi armed bandit is more like math anyway.
There's nothing wrong with that as a hypothesis.
Well it's not Popperian, so it is controversial in that regard.
I'm actually completely fine with the first part of your hypothesis ("With the following 'arms' for the bandit"). Since an n-armed bandit experiment is just a shorthand for n-1 vs everything else experiments.
However I'm a bit confused/concerned by the procedure for developing more arms. What kind of situation are you imagining where that's useful? (Like I'd really want to hear a concrete example of this style of hypothesis).
Imagine four slot machines. Each time you play, you choose one with a weighted probability, and the weight is how many times it won in the past.
So on your first play, you randomly select a machine. Now imagine that machine wins. It now has a probability of 1 vs the other three with 0. So you play it again. Now it loses. It now has a .5 probability, and the other ones have 0. Your next play will be a 50% chance of the same machine, and 50% chance of one of the others. You keep going this way and eventually you will pick the one that wins the most often most of the time, but sometimes you'll pick one of the others, just to make sure your probabilities are still correct.
How is this useful to a programmer? It's great for A/B tests. For example you come up with four different home pages, and then define success as clicking on the signup link. At first you randomly show a homepage to each visitor, but as you progress, you'll get one homepage that converts better than the others. You'll show that one most often, but sometimes show the other ones to give them a chance to "catch up", just in case your initial traffic happened to be biased.
FWIW, the article already contains a very accessible description of what the problem is about: "Imagine you are in a casino facing multiple slot machines and each is configured with an unknown probability of how likely you can get a reward at one play. The question is: What is the best strategy to achieve highest long-term rewards?"
extension of that paper: https://www.aaai.org/ocs/index.php/AAAI/AAAI12/paper/viewFil...
This author uses K as the infinite bound count variable in the tuple - yet n is used in literature more frequently for uncounted variables of any unbounded set including Tuples.
Basically, historical consistency trumps cross-disciplinary consistency.