Source
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams.update({
"figure.figsize": (7, 3.6), "figure.dpi": 110,
"axes.spines.top": False, "axes.spines.right": False,
"axes.grid": True, "grid.alpha": 0.25, "font.size": 10,
})
rng = np.random.default_rng(7) # fixed seed so the text matches the plotsChapter 2 gave the robot a toolkit: probability, sensor models, Bayes’ rule, and expected cost. This chapter puts the whole toolkit to work on one robot, the vessel-washing robot we first met in Section 2.1.
The robot stands beside the kitchen sink of a family of five. On a typical day about 60 vessels pass through it after breakfast, lunch, and dinner: steel plates, tumblers, bowls, the cooking vessels (kadai, pressure cooker, pots), and a few odd items such as a non-stick tawa, a sieve, or a glass jar. For each vessel, the robot has one job: choose the right wash programme.
States: what kind of vessel is this?¶
The robot’s state is the type of the vessel in front of it. We use the same five types and the same probabilities as in Section 2.1:
| Vessel type | Plate | Tumbler | Bowl | Cooking vessel | Other |
|---|---|---|---|---|---|
| 0.40 | 0.25 | 0.20 | 0.10 | 0.05 |
In this chapter this PMF plays the role of the prior from Section 2.3: what the robot believes about a vessel before any sensor has looked at it.
Actions: four wash programmes¶
The robot can run one of four programmes:
| Programme | What it does | Good for |
|---|---|---|
| Quick rinse | short, cool spray | lightly used tumblers |
| Standard | detergent, warm water, medium scrub | everyday plates and bowls |
| Heavy degrease | hot water, strong detergent, long hard scrub | oily kadais and pots with stuck-on food |
| Gentle | soft brush, mild detergent, low pressure | non-stick tawas, glass jars, sieves |
Costs: three kinds of mistakes¶
Choosing the wrong programme can go wrong in three different ways, and they are not equally bad:
Under-cleaning. A greasy kadai given a quick rinse comes out oily. Someone must wash it again by hand, which costs time, water, and patience.
Over-cleaning. A lightly used tumbler given a heavy degrease comes out clean, but the robot wasted hot water, detergent, electricity, and time.
Damage. A non-stick tawa given a heavy degrease loses its coating. That is the most expensive mistake, because the vessel must be replaced.
We capture all of this in a cost matrix , the cost of running programme on a vessel of type , exactly as in Section 2.4. The robot reads it one column at a time: if the vessel is a cooking vessel, how bad is each programme?
vessels = ["plate", "tumbler", "bowl", "cooking vessel", "other"]
prior = np.array([0.40, 0.25, 0.20, 0.10, 0.05]) # the PMF from Section 2.1
programs = ["quick rinse", "standard", "heavy degrease", "gentle"]
# cost[program, vessel] (illustrative cost units)
cost = np.array([[3, 1, 3, 12, 4],
[2, 2, 2, 8, 5],
[4, 4, 4, 3, 9],
[5, 4, 5, 10, 2]], dtype=float)
fig, ax = plt.subplots(figsize=(7.5, 3))
im = ax.imshow(cost, cmap="OrRd")
ax.set_xticks(range(5), vessels); ax.set_yticks(range(4), programs); ax.grid(False)
for i in range(4):
for j in range(5):
best = cost[i, j] == cost[:, j].min()
ax.text(j, i, f"{cost[i, j]:.0f}", ha="center", va="center",
fontweight="bold" if best else "normal", color="black")
ax.set_title("Cost C(programme, vessel) — bold = best programme for that vessel")
plt.colorbar(im, ax=ax, shrink=0.8);
Reading down each column, the best programme for each vessel type is:
| Vessel | Plate | Tumbler | Bowl | Cooking vessel | Other |
|---|---|---|---|---|---|
| Best programme | standard | quick rinse | standard | heavy degrease | gentle |
| Cost | 2 | 1 | 2 | 3 | 2 |
Even the right programme costs something, since washing always uses water and energy. A robot that always knew the vessel type would pay these costs and no more.
Deciding without any sensors¶
Now suppose the robot has no sensors at all. It cannot tell a plate from a kadai, so it must pick one programme and run it on every vessel. Which one?
This is exactly the expected-cost decision from Section 2.4:
For standard, for example: .
expected = cost @ prior
for p, e in zip(programs, expected):
print(f"{p:>15}: expected cost {e:.2f} per vessel")
blind = int(np.argmin(expected))
print(f"\nBest programme without sensing: {programs[blind]}") quick rinse: expected cost 3.45 per vessel
standard: expected cost 2.75 per vessel
heavy degrease: expected cost 4.15 per vessel
gentle: expected cost 5.10 per vessel
Best programme without sensing: standard
Without sensors, the robot should run standard on everything, at an average of 2.75 cost units per vessel. Standard is a compromise: it is the best choice for plates and bowls (60% of vessels) and not disastrous for anything else.
The best possible: perfect sensing¶
At the other extreme, imagine a perfect sensor that always reports the true type. Then the robot would pick the best programme for every vessel, and its average cost would be
A robot with perfect knowledge is called an oracle, and its cost is a floor that no real robot can beat.
The difference, cost units per vessel, is the value of perfect information for this task. It is the most that any sensor, however expensive, could ever save. At 60 vessels a day that is up to 54 cost units a day, which gives the engineer a budget: a sensor that costs more than it could possibly save is not worth installing.
days, per_day = 7, 60
stream = rng.choice(5, size=days * per_day, p=prior)
blind_cost = np.cumsum(cost[blind, stream])
oracle_cost = np.cumsum(cost[:, stream].min(axis=0))
n = np.arange(1, len(stream) + 1)
plt.plot(n, blind_cost, c="#9a4a16", lw=2, label="no sensors (always standard)")
plt.plot(n, oracle_cost, c="#1f3a5f", lw=2, label="oracle (perfect sensing)")
plt.fill_between(n, oracle_cost, blind_cost, color="#e07a3a", alpha=0.12, label="room for a sensor to help")
for d in range(1, days):
plt.axvline(d * per_day, c="gray", lw=0.5, ls=":")
plt.xlabel("vessels washed (dotted lines = end of each day)"); plt.ylabel("cumulative cost"); plt.legend(fontsize=8)
print(f"week total — no sensors: {blind_cost[-1]:.0f}, oracle: {oracle_cost[-1]:.0f}, gap: {blind_cost[-1] - oracle_cost[-1]:.0f}")week total — no sensors: 1167, oracle: 786, gap: 381

Figure 1:Cumulative cost over one week (420 vessels) for a robot with no sensors (always standard) and for an oracle that knows every vessel’s type. The gap between the two lines is the most any sensor could save.
Most of the gap comes from the cooking vessels. They are only 10% of the stream, but every one that gets standard instead of heavy degrease costs 5 extra units. Tumblers add a little too: each gets standard (2) instead of a quick rinse (1). The next section asks which sensors can close this gap, and by how much.