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 plotsSection 3.1 showed that a perfect sensor could save up to 0.90 cost units per vessel. No real sensor is perfect, so the questions now are: which real sensors should the robot have, how should it combine them, and how much of the 0.90 do they actually recover?
Three sensors at the sink¶
The engineers have fitted three inexpensive sensors:
| Sensor | What it measures | Why it helps |
|---|---|---|
| Camera | the vessel’s height-to-width ratio from its outline | plates are flat, tumblers are tall, bowls and kadais are in between |
| Load cell (scale) | weight in grams | a cooking vessel is far heavier than a plate or bowl |
| Grease sensor | whether the pre-rinse water turns cloudy with oil | cooking vessels are usually greasy |
Each sensor was tested on hundreds of labelled vessels, and its behaviour was summarised as a sensor model , as in Section 2.2. The camera ratio and the weight are modelled as Gaussians, with a different mean and spread for each vessel type. The grease sensor is binary, so its model is one probability per type.
vessels = ["plate", "tumbler", "bowl", "cooking vessel", "other"]
short = ["plate", "tumbler", "bowl", "cooking", "other"]
prior = np.array([0.40, 0.25, 0.20, 0.10, 0.05])
programs = ["quick rinse", "standard", "heavy degrease", "gentle"]
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)
# --- sensor models (from bench tests) ---------------------------------------
# camera: height-to-width ratio of the vessel's outline, Gaussian per type
a_mean = np.array([0.10, 1.30, 0.45, 0.40, 0.60]); a_sd = np.array([0.04, 0.20, 0.10, 0.12, 0.35])
# load cell: weight in grams, Gaussian per type
w_mean = np.array([180, 90, 150, 900, 250.]); w_sd = np.array([40, 20, 40, 250, 150.])
# grease sensor on pre-rinse water: P(reports "greasy" | type)
p_greasy = np.array([0.30, 0.05, 0.35, 0.90, 0.40])
def gauss(z, m, s):
return np.exp(-0.5 * ((z - m) / s) ** 2) / (s * np.sqrt(2 * np.pi))
fig, ax = plt.subplots(1, 3, figsize=(12, 3.2))
ra = np.linspace(0, 1.9, 400)
for k in range(5):
ax[0].plot(ra, gauss(ra, a_mean[k], a_sd[k]), label=short[k])
ax[0].set_xlabel("height / width ratio"); ax[0].set_title("camera model"); ax[0].legend(fontsize=7)
wa = np.linspace(0, 1600, 400)
for k in range(5):
ax[1].plot(wa, gauss(wa, w_mean[k], w_sd[k]))
ax[1].set_xlabel("weight [g]"); ax[1].set_title("load-cell model")
ax[2].bar(short, p_greasy, color="#9a4a16"); ax[2].set_ylim(0, 1)
ax[2].set_title('grease sensor: P("greasy" | type)'); ax[2].tick_params(axis="x", labelsize=8)
plt.tight_layout()
Look at where the curves overlap, because that is where each sensor will struggle:
The camera separates flat plates and tall tumblers well, but bowls (0.45) and cooking vessels (0.40) have almost the same shape.
The scale separates heavy cooking vessels from everything else, but plates (180 g) and bowls (150 g) weigh about the same.
The grease sensor fires for 90% of cooking vessels, but also for about a third of plates and bowls with leftover sambar or oil.
Each sensor is weak somewhere different. That is exactly the situation where combining them pays off.
Combining sensors: naive Bayes¶
Suppose the sensors’ errors are independent given the vessel type: once we know a vessel is a kadai, its weight tells us nothing extra about its camera ratio or its greasiness. Then, just as with the camera and GPS in Section 2.3, the posterior is the prior multiplied by one likelihood per sensor:
This is called naive Bayes. It is “naive” because it assumes independence even when that is only roughly true, but it is simple, fast, and needs only one small model per sensor. Once we have the posterior, the robot picks the programme with the lowest expected cost, using the posterior in place of the prior:
def posterior(ratio=None, weight=None, greasy=None):
p = prior.copy()
if ratio is not None: p = p * gauss(ratio, a_mean, a_sd)
if weight is not None: p = p * gauss(weight, w_mean, w_sd)
if greasy is not None: p = p * (p_greasy if greasy else 1 - p_greasy)
return p / p.sum()
def choose(p):
exp_cost = cost @ p
return programs[int(np.argmin(exp_cost))], exp_cost.min()Worked example: a heavy, greasy, medium-deep vessel¶
A vessel arrives. The grease sensor says greasy, the camera reports a ratio of 0.55, and the scale reads 820 g. We add the evidence one sensor at a time and watch the belief change:
steps = [("prior", posterior()),
('+ grease: "greasy"', posterior(greasy=1)),
("+ camera: ratio 0.55", posterior(ratio=0.55, greasy=1)),
("+ scale: 820 g", posterior(ratio=0.55, weight=820, greasy=1))]
fig, axes = plt.subplots(1, 4, figsize=(12, 2.9), sharey=True)
for ax, (title, p) in zip(axes, steps):
ax.bar(short, p, color="#1f3a5f"); ax.set_ylim(0, 1.05); ax.set_title(title, fontsize=9)
ax.tick_params(axis="x", labelsize=7, rotation=45)
prog, c = choose(p)
ax.text(0.5, 0.92, f"→ {prog}\n(exp. cost {c:.2f})", transform=ax.transAxes, ha="center", va="top", fontsize=8,
bbox=dict(boxstyle="round", fc="#f6f3ec", ec="#cfc6b3"))
plt.tight_layout()
for title, p in steps:
print(f"{title:>22}: " + " ".join(f"{s} {v:.3f}" for s, v in zip(short, p))) prior: plate 0.400 tumbler 0.250 bowl 0.200 cooking 0.100 other 0.050
+ grease: "greasy": plate 0.384 tumbler 0.040 bowl 0.224 cooking 0.288 other 0.064
+ camera: ratio 0.55: plate 0.000 tumbler 0.000 bowl 0.515 cooking 0.416 other 0.069
+ scale: 820 g: plate 0.000 tumbler 0.000 bowl 0.000 cooking 1.000 other 0.000

Figure 1:Belief about one vessel as each sensor’s evidence is added. Grease alone shifts belief toward cooking vessels, the camera rules out plates and tumblers, and the weight settles it.
Follow the reasoning step by step:
Prior. Plates are most likely (0.40), so the robot would run standard.
Grease says “greasy”. Belief in cooking vessel jumps from 0.10 to about 0.29, but plates and bowls with oily leftovers are still likely. The decision stays standard.
Camera ratio 0.55. Plates (0.10) and tumblers (1.30) can’t produce this shape, so they drop to almost zero. Now it is bowl (about 0.52) versus cooking vessel (about 0.42).
Scale 820 g. No bowl weighs anywhere near that much. The belief in cooking vessel goes to almost 1, and the robot runs heavy degrease.
No single sensor could have done this alone. The camera could not tell bowl from kadai, and grease alone did not change the decision. Together they are decisive.
A second example: light, shallow, and clean¶
The next vessel is not greasy, has a ratio of 0.30, and weighs 170 g. What does each sensor say on its own, and what do they say together?
cases = {"scale only (170 g)": posterior(weight=170),
"camera only (0.30)": posterior(ratio=0.30),
"grease only (clean)": posterior(greasy=0),
"all three": posterior(ratio=0.30, weight=170, greasy=0)}
for name, p in cases.items():
prog, c = choose(p)
top = np.argsort(p)[::-1][:2]
print(f"{name:>20}: {short[top[0]]} {p[top[0]]:.2f}, {short[top[1]]} {p[top[1]]:.2f} → {prog} (exp. cost {c:.2f})") scale only (170 g): plate 0.67, bowl 0.31 → standard (exp. cost 2.06)
camera only (0.30): bowl 0.49, cooking 0.44 → heavy degrease (exp. cost 3.93)
grease only (clean): plate 0.41, tumbler 0.35 → standard (exp. cost 2.22)
all three: bowl 0.96, other 0.04 → standard (exp. cost 2.11)
On its own, the camera is torn between bowl and cooking vessel (both are medium-deep), and because a mistake on a kadai is costly, it plays safe with heavy degrease. That is the right call given what it knows, but an expensive one. The scale alone thinks plate is likelier than bowl. Together, the evidence points clearly to a bowl, and the robot runs standard.
Which sensors are worth installing?¶
To compare sensor combinations fairly, we simulate thousands of vessels and let the robot use only some of its sensors. We record two numbers: accuracy (how often the most probable type is correct) and average cost (what the robot actually pays).
N = 20000
x = rng.choice(5, size=N, p=prior)
ratio = np.maximum(0.02, rng.normal(a_mean[x], a_sd[x]))
weight = np.maximum(20.0, rng.normal(w_mean[x], w_sd[x]))
greasy = (rng.random(N) < p_greasy[x]).astype(int)
def evaluate(use):
P = np.tile(prior, (N, 1))
if "camera" in use: P = P * gauss(ratio[:, None], a_mean, a_sd)
if "scale" in use: P = P * gauss(weight[:, None], w_mean, w_sd)
if "grease" in use: P = P * np.where(greasy[:, None] == 1, p_greasy, 1 - p_greasy)
P /= P.sum(axis=1, keepdims=True)
action = np.argmin(P @ cost.T, axis=1)
return cost[action, x].mean(), np.mean(P.argmax(axis=1) == x)
combos = [(), ("grease",), ("scale",), ("camera",), ("camera", "grease"), ("camera", "scale"), ("camera", "scale", "grease")]
results = {(" + ".join(c) or "none"): evaluate(c) for c in combos}
oracle = cost[:, x].min(axis=0).mean()
print(f"{'sensors':>24} | avg cost | accuracy")
for name, (c, acc) in results.items():
print(f"{name:>24} | {c:8.2f} | {acc:7.1%}")
print(f"{'oracle':>24} | {oracle:8.2f} |") sensors | avg cost | accuracy
none | 2.77 | 40.1%
grease | 2.77 | 40.1%
scale | 2.08 | 71.5%
camera | 2.43 | 85.3%
camera + grease | 2.23 | 87.4%
camera + scale | 1.96 | 97.1%
camera + scale + grease | 1.95 | 97.3%
oracle | 1.86 |
names = list(results)
costs = [results[n][0] for n in names]
accs = [results[n][1] for n in names]
fig, ax = plt.subplots(figsize=(8, 3.6))
bars = ax.barh(names, costs, color="#1f3a5f")
ax.axvline(results["none"][0], c="#9a4a16", ls="--", lw=1, label="no sensors")
ax.axvline(oracle, c="#2e8b57", ls="--", lw=1, label="oracle")
for b, a in zip(bars, accs):
ax.text(b.get_width() + 0.02, b.get_y() + b.get_height() / 2, f"accuracy {a:.0%}", va="center", fontsize=8)
ax.set_xlim(1.5, 3.2); ax.invert_yaxis(); ax.set_xlabel("average cost per vessel"); ax.legend(fontsize=8, loc="lower right")
plt.tight_layout()
Figure 2:Average cost per vessel for each sensor combination (bars), between the no-sensor cost and the oracle floor (dashed lines). Accuracy is printed on each bar. The camera alone is more accurate than the scale alone, yet costs more.
Three lessons stand out in Figure 2.
1. Accuracy is not the same as cost. The camera alone identifies the vessel correctly more often than the scale alone (about 85% against 72%), yet the scale alone gives a lower cost. The scale’s mistakes are cheap: it confuses plates with bowls, which get the same programme anyway. The camera’s mistakes are expensive: it confuses bowls with kadais, forcing costly heavy degrease “just in case”. Judge a sensor by the decisions it improves, not by how often it is right.
2. A sensor can be informative yet useless alone. The grease sensor on its own leaves the cost exactly where it was with no sensors. It does change the robot’s belief, but never enough to change the decision: whatever it reports, standard stays the best choice. This is the value-of-information idea from Section 2.4: information only has value if it can change what the robot does. Combined with the camera, however, the grease sensor does help, because it tips the camera’s bowl-versus-kadai dilemmas.
3. The right pair gets close to the floor. Camera plus scale recovers most of the 0.90 gap, and adding the grease sensor adds only a sliver more. Whether the third sensor is worth its price, maintenance, and cleaning depends on how much that sliver is worth over thousands of vessels.