Coffee Machines and Optimisation
Our world is full of choices and existential dilemmas. What to have for lunch, what to study, or what to do this Saturday evening?
Being confronted with the options offered by my office coffee machine this morning motivated this article:

More generally, life constantly asks us: How will you spend today? What about tomorrow?
All of these questions can be approached as optimisation problems. Optimisation is the task of maximising or minimising an objective with a set of decisions.
Important caveat: This article is not about making use of every minute of one’s time. There is joy in inefficiency, uncertainty and boredom. Its goal is simply to study the mathematical problem of optimisation.
Some example optimisation problems are shown below:
| Problem | Objective | Decision Variables |
|---|---|---|
| Find the shortest route to work | Minimise commute time | Path taken (streets, transport type, etc.) |
| Find the cheapest internet plan that meets needs | Minimise monthly cost | Internet provider/plan |
| Make incredible coffee in the morning | Maximise coffee quality | Settings of the coffee machine |
Now, how to handle the coffee machine problem? How would you set up these dials? Which buttons would you press?
This article will show how many different optimisation methods can be applied to the problem of maximising coffee goodness.
Outsourcing the Decision
Being reasonable adults, we all know that the easiest way to deal with a decision is not to make it, and accept the default settings. This approach has many advantages.
First, it saves precious cognitive power, saving your decision energy for another, more important task. Second, the current settings were used by the previous coffee drinker. Depending on your company, you may be able to trust them. This is the equivalent of asking for “the same” at a restaurant in a foreign country (I strongly recommend the latter).
A more sophisticated approach is to ask colleagues you trust for advice. As you expect colleagues who are similar to you to have similar coffee tastes, this is not a bad idea either. This is how I choose most of my books, leveraging the filtering work done by a few trusted others.
Exhaustive Search
Now, let’s get a bit more involved. Let’s say you will not settle for the defaults or what other people say. You want to make the optimal coffee, the best cup the office has ever tasted. You will not settle for mediocrity.
In that case, you may want to try all possible combinations. Even for this basic coffee machine, this could get tricky.

The water quantity dial has 11 possible values, the coffee intensity dial has 8 possible values. The user also has a choice between a single or a double cup. These options create \(11 \cdot 8 \cdot 2 = 176\) unique possibilities.
At the pace of one coffee per working day, you would need around 35 weeks (and many disappointing cups) to explore them all. If that is your goal, I wish you all the best on your journey.
Embracing Chaos
Could we avoid exhaustive search? For the more adventurous members of the office, you could simply try a new random combination every day for 20 days. By the end of these 20 days, you would probably have found a very decent coffee machine setting.
With this method, we cap the number of trials to 20 (or any other number) but accept to give up on optimality; i.e., we have to accept that we may never uncover the optimal setting.
Little by Little
But is there a way to avoid exhaustive search while still finding the optimal settings? The previous two methods have one obvious drawback: they have a fixed sampling strategy.
In other words, imagine you discover a great coffee machine setting. With both exhaustive and random search, you will stick to the strategy of either:
- Trying all other settings
- Trying purely random settings
It would make sense, if you found a great setting, to explore the locality of this setting; i.e., other similar settings.
For instance, you have just tasted a great cup of coffee, and yet, it was a tiny bit too strong. You could simply move the coffee dial one tick to the left. On another hand, if the cup was a bit too watery, you can move the water dial one tick to the left, or the coffee dial one tick to the right (or both if you are feeling adventurous).
This may sound trivial, but is the simple idea behind the Gradient Descent algorithm, the backbone of Deep Learning. Adapt the parameters (dials) in small increments based on their impact on the objective function (coffee goodness).
If the cup of coffee is way too strong, it is a good idea to move the dial at least two ticks to the left. If it is just a bit too weak, one tick to the right should be enough. These two ticks vs one tick are similar to the gradient of the objective function (goodness of coffee) at the current point.

Prior Beliefs
Coffee machines and coffee preferences do not exist in a vacuum. Going to the coffee machine, you may already know your preferences.
From a personal perspective, I only drink one cup of basic black coffee a day. When discovering a new machine, I know that I will have a tendency to prefer the medium settings. These prior beliefs can be used to begin the search for the optimal cup, limiting the range of options.
This, again, may seem trivial. Yet, this is the basic application of Bayes’ Rule. You start with a prior belief and update this belief with experimentation. This reduces the space of the search in light of the coffee drinker’s past experience.
Final Thoughts
Many problems of our daily life can be viewed as optimisation tasks. In these problems, the goal is to maximise or minimise something, such as satisfaction, short term pleasure or taste of a coffee cup.
These problems can be approached with a wide range of optimisation methods. If this topic sounds interesting, I would recommend heading to the series I wrote on optimisation a few months ago. I hope you like it!
