Grid A F1 Fraction
Derive Grid A's harmonic mean F1 = 2*TP / (2*TP + FP + FN) = 6/10 = 0.60 from precision 0.75 and recall 0.50.
The problem
The harmonic mean F1 replaces the equal-weight sum (P + R) / 2 with the reciprocal average 2 / (1/P + 1/R) = 2 * P * R / (P + R), which algebraically collapses into a single integer ratio of confusion counts: 2 * TP / (2 * TP + FP + FN). What exact fraction does Grid A ([3, 1, 3, 23]) earn under F1, and why does F1 land below 0.625?
We compute [precision, recall, f1] for Grid A across fp_shift from -1 to +3—with fp_shift rows coming out of the 23 true negatives—and watch F1 hug the smaller of the two rates whenever precision and recall diverge.
Work through the numbers
Evaluate both equivalent F1 formulas on Grid A (TP = 3, FP = 1, FN = 3, TN = 23) at fp_shift = 0 (FP_adj = 1):
- Rate formula: with
P = 3 / 4 = 0.75andR = 3 / 6 = 0.50,2 * P * R / (P + R) = 2 * 0.75 * 0.50 / (0.75 + 0.50) = 0.75 / 1.25 = 3 / 5 = 0.60. - Count fraction:
2 * TP / (2 * TP + FP_adj + FN) = (2 * 3) / (2 * 3 + 1 + 3) = 6 / 10 = 0.60.
Every matched positive counts twice in the numerator (2 * TP = 6, once in the predicted pool TP + FP = 4 and once in the actual pool TP + FN = 6), divided by the sum of both denominators (4 + 6 = 10).
At fp_shift = -1 (FP_adj = 0, P = 1.00), F1 = 6 / 9 ≈ 0.667 vs arithmetic mean 0.75. At fp_shift = +2 (FP_adj = 3, P = R = 0.50), F1 = 6 / 12 = 0.50, matching the arithmetic mean because both rates agree.
The live model
Three horizontal bars plot Grid A's amber precision, green recall, and purple f1, above a card displaying the integer fraction 2*TP / (2*TP + FP_adj + FN). Slide fp_shift from -1 to 3: whenever precision and recall differ, purple f1 sits closer to the shorter bar than the midpoint does, touching the midpoint only at fp_shift = 2 where P = R = 0.50.

let fp_shift = scene.parameter("fp_shift", 0.0, -1.0, 3.0, 1.0);
let tp = input.slice(0, 0, 1);
let fp = input.slice(0, 1, 2);
let miss_pos = input.slice(0, 2, 3);
let fp_adj = fp + fp_shift;
let precision = tp.div(tp + fp_adj);
let recall = tp.div(tp + miss_pos);
let f1 = (tp * 2.0).div(tp * 2.0 + fp_adj + miss_pos);
let parts = torch.list().add(precision).add(recall).add(f1);
let answer = torch.cat(parts, 0);
out.set("grid_f1", answer);
{
"grid_f1": [
0.75,
0.5,
0.6
]
}Your turn
Compute [precision, recall, f1] in answer using fp_adj = fp + fp_shift. The starter still computes the arithmetic average (precision + recall) / 2.0 (0.625) instead of the harmonic mean F1 (0.60). Check verifies unseen confusion vectors and fp_shift settings.

let fp_shift = scene.parameter("fp_shift", 0.0, -1.0, 3.0, 1.0);
let tp = input.slice(0, 0, 1);
let fp = input.slice(0, 1, 2);
let miss_pos = input.slice(0, 2, 3);
let fp_adj = fp + fp_shift;
let precision = tp.div(tp + fp_adj);
let recall = tp.div(tp + miss_pos);
let f1 = (precision + recall).div(2.0);
let parts = torch.list().add(precision).add(recall).add(f1);
let answer = torch.cat(parts, 0);
out.set("grid_f1", answer);
{
"grid_f1": [
0.75,
0.5,
0.625
]
}Compute the [3] vector answer = [precision, recall, f1] using fp_adj = fp + fp_shift.
Read the result carefully
Notice why 2 * TP / (2 * TP + FP + FN) is called the pooled-denominator fraction (or Sørensen-Dice coefficient): adding the precision fraction 3 / 4 and recall fraction 3 / 6 numerator-to-numerator and denominator-to-denominator produces (3 + 3) / (4 + 6) = 6 / 10 = 0.60. Because the larger denominator (6 vs 4) carries heavier weight in 4 + 6, whichever metric has the larger denominator — and therefore the smaller rate — pulls F1 downward.
Recap
F1 = 2 * P * R / (P + R)simplifies identically to2 * TP / (2 * TP + FP + FN).- On Grid A (
[3, 1, 3, 23]),F1 = 6 / 10 = 0.60, sitting0.025below the0.625arithmetic mean. F1equals(P + R) / 2only whenprecision == recall(fp_shift = 2, where both equal0.50).