Speed

Grid B F1 Fraction

Break the 0.625 arithmetic tie as Grid B drops to F1 = 12/30 = 0.40, opening a 0.225 harmonic penalty gap.

The problem

Grid A (0.75 and 0.50) and Grid B (0.25 and 1.00) tied at 0.625 under (P + R) / 2, yet Grid A earned F1 = 0.60. What happens when we apply F1 = 2 * TP / (2 * TP + FP + FN) to aggressive Grid B ([6, 18, 0, 6]), and how large is the penalty arith - f1 caused by its lopsided rates?

We compute [f1, arith, gap] on Grid B across fp_cut = 0, 6, 12, 18 and watch the arith - f1 gap shrink toward zero as precision catches up to recall.

Work through the numbers

Evaluate Grid B (TP = 6, FP = 18, FN = 0, TN = 6) at fp_cut = 0 (FP_adj = 18, P = 0.25, R = 1.00):

  • Harmonic mean `F1`: (2 * 6) / (2 * 6 + 18 + 0) = 12 / 30 = 2 / 5 = 0.40 (equivalently 2 * 0.25 * 1.00 / 1.25 = 0.50 / 1.25 = 0.40).
  • Arithmetic mean: (0.25 + 1.00) / 2 = 0.625.
  • Harmonic penalty `gap`: 0.625 - 0.400 = 0.225 (9 / 40).

F1 breaks the 0.625 tie cleanly: cautious Grid A (0.60) beats aggressive Grid B (0.40) by 0.20. Cutting false alarms via fp_cut = 6, 12, 18 lifts F1 to 12/24 = 0.50, 12/18 ≈ 0.667, and 12/12 = 1.00, shrinking gap from 0.225 to 1/6 ≈ 0.167, 1/12 ≈ 0.083, and 0.00.

The live model

Three horizontal bars compare purple f1, blue arith, and red gap (arith - f1) on [0, 1], above a summary card contrasting Grid B's F1 against Grid A's 0.60. Slide fp_cut from 0 to 18: at fp_cut = 0, purple f1 (0.40) lags far behind blue arith (0.625), creating a 0.225 red penalty bar; at fp_cut = 18, P = R = 1.00 and the red gap disappears.

Grid B bars showing F1 0.4, arithmetic mean 0.625, and harmonic penalty gap 0.225 at fp_cut 0.
let fp_cut = scene.parameter("fp_cut", 0.0, 0.0, 18.0, 6.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_cut;
let precision = tp.div(tp + fp_adj);
let recall = tp.div(tp + miss_pos);
let arith = (precision + recall).div(2.0);
let f1 = (tp * 2.0).div(tp * 2.0 + fp_adj + miss_pos);
let gap = arith - f1;
let parts = torch.list().add(f1).add(arith).add(gap);
let answer = torch.cat(parts, 0);
out.set("grid_f1_gap", answer);
{
  "grid_f1_gap": [
    0.4,
    0.625,
    0.22499999999999998
  ]
}

Your turn

Compute [f1, arith, gap] in answer where gap = arith - f1 and fp_adj = fp - fp_cut. The starter subtracts in the reverse order (f1 - arith = -0.225). Check tests unseen confusion vectors and fp_cut values.

Starter model computes negative gap f1 - arith = -0.225 instead of arith - f1 = 0.225.
let fp_cut = scene.parameter("fp_cut", 0.0, 0.0, 18.0, 6.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_cut;
let precision = tp.div(tp + fp_adj);
let recall = tp.div(tp + miss_pos);
let arith = (precision + recall).div(2.0);
let f1 = (tp * 2.0).div(tp * 2.0 + fp_adj + miss_pos);
let gap = f1 - arith;
let parts = torch.list().add(f1).add(arith).add(gap);
let answer = torch.cat(parts, 0);
out.set("grid_f1_gap", answer);
{
  "grid_f1_gap": [
    0.4,
    0.625,
    -0.22499999999999998
  ]
}

Compute the [3] vector answer = [f1, arith, gap] with fp_adj = fp - fp_cut and gap = arith - f1.

Read the result carefully

Algebra explains why Grid B's penalty (0.225) is nine times Grid A's penalty (0.025): for any positive P and R, (P + R) / 2 - 2 * P * R / (P + R) = (P - R)^2 / (2 * (P + R)).

Both grids share P + R = 1.25, so 2 * (P + R) = 2.50 is identical, while Grid B's spread |0.25 - 1.00| = 0.75 is three times Grid A's spread |0.75 - 0.50| = 0.25. Squaring a 3x wider imbalance produces a 9x larger penalty (0.5625 / 2.50 = 0.225 vs 0.0625 / 2.50 = 0.025).

Recap

  • On Grid B ([6, 18, 0, 6]), F1 = 12 / 30 = 0.40, losing to Grid A's F1 = 0.60 by 20 percentage points.
  • Grid B's harmonic-mean penalty arith - f1 = 0.625 - 0.400 = 0.225 is 9 times Grid A's 0.025 gap.
  • Because arith - f1 = (P - R)^2 / (2 * (P + R)), F1 penalizes squared disagreement between precision and recall and vanishes only when P == R.