Matthew Ford commited on
Commit
f46c540
·
1 Parent(s): 413fff1

character distributional metric: cosine/JS over prevalence vectors, mean=0.080

Browse files

Former-commit-id: c17c0fa707e01e0fe15c286c52b8a4e89aba3f4e
Former-commit-id: 65b2fd45473fff2f0e055be8b1492079a85c1056

artifacts/character_grouping_diagnostic_v8.json CHANGED
The diff for this file is too large to render. See raw diff
 
artifacts/character_grouping_diagnostic_v8.md CHANGED
@@ -46,6 +46,76 @@ Primary snapshot: `v8_2_clause_guard_dominance` (`data/odour_character_labels_v8
46
 
47
  Lower cosine means more genre-profile separation. The 26-class axis keeps the strongest separation; collapsing to superclasses weakens it and made presence-Jaccard unusable. `best_grouping` is null unless a grouped axis materially improves on 26-class; the lowest grouped Jaccard is only recorded as `lowest_jaccard_grouping` for audit.
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  ## Threshold Sensitivity
50
 
51
  | Grouping | activity threshold | mean pairwise Jaccard |
@@ -57,7 +127,7 @@ Lower cosine means more genre-profile separation. The 26-class axis keeps the st
57
  | eight_superclass | 10% | 0.868 |
58
  | eight_superclass | 15% | 0.886 |
59
 
60
- Recommendation: **Retract the superclass presence-Jaccard conclusion: the 1.000 is a collapse/presence artifact, not proof that character is dead. Keep corrected distributional metrics as the circuit-breaker. Under class-count cosine, 26-class character retains more profile separation than the collapsed schemes (all-labelled mean cosine 0.905; >=3-label mean cosine 0.858; presence-Jaccard baseline 0.793, best collapsed presence-Jaccard 1.000). Recommended direction: character may resume only at 26-class granularity under distributional and well-labelled filters; do not use superclass presence-Jaccard for go/no-go decisions.**
61
 
62
  Substantivity remains confirmed and publishable independent of this character diagnostic. Next human decision: ship substantivity, resume character only under the corrected 26-class distributional circuit-breaker, or park character for a trajectory-proportion pivot.
63
 
 
46
 
47
  Lower cosine means more genre-profile separation. The 26-class axis keeps the strongest separation; collapsing to superclasses weakens it and made presence-Jaccard unusable. `best_grouping` is null unless a grouped axis materially improves on 26-class; the lowest grouped Jaccard is only recorded as `lowest_jaccard_grouping` for audit.
48
 
49
+ ## Unthresholded Prevalence Distributional Metric
50
+
51
+ This is the corrected character discrimination test. Vectors retain the raw per-genre prevalence of each class before any active-set thresholding; cosine is reported as distance (`1 - similarity`) and JS divergence is reported in bits.
52
+
53
+ | Axis | classes | mean cosine distance | mean JS divergence (bits) |
54
+ | --- | ---: | ---: | ---: |
55
+ | 26-class | 26 | 0.080 | 0.044 |
56
+ | six_superclass | 5 | 0.015 | 0.007 |
57
+ | eight_superclass | 8 | 0.023 | 0.010 |
58
+
59
+ ### 26-class cosine distance
60
+
61
+ | Genre | `amber_oriental` | `citrus_cologne` | `floral_woody` | `fougere` | `wildcard` |
62
+ | --- | ---: | ---: | ---: | ---: | ---: |
63
+ | `amber_oriental` | 0.000 | 0.043 | 0.027 | 0.007 | 0.162 |
64
+ | `citrus_cologne` | 0.043 | 0.000 | 0.013 | 0.044 | 0.145 |
65
+ | `floral_woody` | 0.027 | 0.013 | 0.000 | 0.024 | 0.167 |
66
+ | `fougere` | 0.007 | 0.044 | 0.024 | 0.000 | 0.170 |
67
+ | `wildcard` | 0.162 | 0.145 | 0.167 | 0.170 | 0.000 |
68
+
69
+ ### 26-class JS divergence (bits)
70
+
71
+ | Genre | `amber_oriental` | `citrus_cologne` | `floral_woody` | `fougere` | `wildcard` |
72
+ | --- | ---: | ---: | ---: | ---: | ---: |
73
+ | `amber_oriental` | 0.000 | 0.033 | 0.016 | 0.005 | 0.077 |
74
+ | `citrus_cologne` | 0.033 | 0.000 | 0.013 | 0.033 | 0.078 |
75
+ | `floral_woody` | 0.016 | 0.013 | 0.000 | 0.014 | 0.082 |
76
+ | `fougere` | 0.005 | 0.033 | 0.014 | 0.000 | 0.087 |
77
+ | `wildcard` | 0.077 | 0.078 | 0.082 | 0.087 | 0.000 |
78
+
79
+ ### six_superclass cosine distance
80
+
81
+ | Genre | `amber_oriental` | `citrus_cologne` | `floral_woody` | `fougere` | `wildcard` |
82
+ | --- | ---: | ---: | ---: | ---: | ---: |
83
+ | `amber_oriental` | 0.000 | 0.002 | 0.003 | 0.001 | 0.030 |
84
+ | `citrus_cologne` | 0.002 | 0.000 | 0.004 | 0.002 | 0.033 |
85
+ | `floral_woody` | 0.003 | 0.004 | 0.000 | 0.003 | 0.047 |
86
+ | `fougere` | 0.001 | 0.002 | 0.003 | 0.000 | 0.026 |
87
+ | `wildcard` | 0.030 | 0.033 | 0.047 | 0.026 | 0.000 |
88
+
89
+ ### six_superclass JS divergence (bits)
90
+
91
+ | Genre | `amber_oriental` | `citrus_cologne` | `floral_woody` | `fougere` | `wildcard` |
92
+ | --- | ---: | ---: | ---: | ---: | ---: |
93
+ | `amber_oriental` | 0.000 | 0.001 | 0.002 | 0.001 | 0.012 |
94
+ | `citrus_cologne` | 0.001 | 0.000 | 0.002 | 0.002 | 0.015 |
95
+ | `floral_woody` | 0.002 | 0.002 | 0.000 | 0.002 | 0.021 |
96
+ | `fougere` | 0.001 | 0.002 | 0.002 | 0.000 | 0.011 |
97
+ | `wildcard` | 0.012 | 0.015 | 0.021 | 0.011 | 0.000 |
98
+
99
+ ### eight_superclass cosine distance
100
+
101
+ | Genre | `amber_oriental` | `citrus_cologne` | `floral_woody` | `fougere` | `wildcard` |
102
+ | --- | ---: | ---: | ---: | ---: | ---: |
103
+ | `amber_oriental` | 0.000 | 0.006 | 0.007 | 0.002 | 0.043 |
104
+ | `citrus_cologne` | 0.006 | 0.000 | 0.003 | 0.008 | 0.047 |
105
+ | `floral_woody` | 0.007 | 0.003 | 0.000 | 0.010 | 0.062 |
106
+ | `fougere` | 0.002 | 0.008 | 0.010 | 0.000 | 0.043 |
107
+ | `wildcard` | 0.043 | 0.047 | 0.062 | 0.043 | 0.000 |
108
+
109
+ ### eight_superclass JS divergence (bits)
110
+
111
+ | Genre | `amber_oriental` | `citrus_cologne` | `floral_woody` | `fougere` | `wildcard` |
112
+ | --- | ---: | ---: | ---: | ---: | ---: |
113
+ | `amber_oriental` | 0.000 | 0.003 | 0.003 | 0.001 | 0.020 |
114
+ | `citrus_cologne` | 0.003 | 0.000 | 0.002 | 0.004 | 0.020 |
115
+ | `floral_woody` | 0.003 | 0.002 | 0.000 | 0.005 | 0.026 |
116
+ | `fougere` | 0.001 | 0.004 | 0.005 | 0.000 | 0.020 |
117
+ | `wildcard` | 0.020 | 0.020 | 0.026 | 0.020 | 0.000 |
118
+
119
  ## Threshold Sensitivity
120
 
121
  | Grouping | activity threshold | mean pairwise Jaccard |
 
127
  | eight_superclass | 10% | 0.868 |
128
  | eight_superclass | 15% | 0.886 |
129
 
130
+ Recommendation: **Retract the superclass presence-Jaccard conclusion: the 1.000 is a collapse/presence artifact, not proof that character is dead. Keep corrected distributional metrics as the circuit-breaker. Under unthresholded prevalence vectors, 26-class character shows weak but nonzero profile separation (mean cosine distance 0.080; mean JS divergence 0.044 bits; presence-Jaccard baseline 0.793, best collapsed presence-Jaccard 1.000). Recommended direction: character may resume only at 26-class granularity under distributional and well-labelled filters; do not use superclass presence-Jaccard for go/no-go decisions.**
131
 
132
  Substantivity remains confirmed and publishable independent of this character diagnostic. Next human decision: ship substantivity, resume character only under the corrected 26-class distributional circuit-breaker, or park character for a trajectory-proportion pivot.
133
 
scripts/character_grouping_diagnostic_v8.py CHANGED
@@ -252,17 +252,43 @@ def pairwise_vector_metrics(vectors: dict[str, Counter[str]], codes: list[str])
252
  "left": left,
253
  "right": right,
254
  "cosine_similarity": cosine,
 
255
  "js_divergence_bits": jsd,
256
  })
257
  cosines = [p["cosine_similarity"] for p in pairwise if p["cosine_similarity"] is not None]
 
258
  jsds = [p["js_divergence_bits"] for p in pairwise if p["js_divergence_bits"] is not None]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
  return {
260
  "pairwise": pairwise,
261
  "mean_pairwise_cosine_similarity": sum(cosines) / len(cosines) if cosines else None,
 
262
  "min_pairwise_cosine_similarity": min(cosines) if cosines else None,
263
  "max_pairwise_cosine_similarity": max(cosines) if cosines else None,
264
  "mean_pairwise_js_divergence_bits": sum(jsds) / len(jsds) if jsds else None,
265
  "max_pairwise_js_divergence_bits": max(jsds) if jsds else None,
 
 
266
  }
267
 
268
 
@@ -296,6 +322,45 @@ def distributional_probe(
296
  }
297
 
298
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
299
  def material_level_probe(records: list[dict[str, Any]], labels: dict[str, dict[str, Any]], axis_name: str) -> dict[str, Any]:
300
  codes = sorted({code for label in labels.values() for code in label_codes(label) if code not in {"Z", "carrier"}})
301
  material_classes_by_genre: dict[str, dict[str, set[str]]] = defaultdict(dict)
@@ -409,6 +474,7 @@ def evaluate_snapshot(name: str, path: Path, records: list[dict[str, Any]]) -> d
409
  base = discrimination_probe(records, labels, "26-class character labels")
410
  base_density = label_density(records, labels, "26-class character labels")
411
  base_distribution = distributional_probe(records, labels, "26-class character labels")
 
412
  base_well_labelled_distribution = distributional_probe(records, labels, "26-class character labels", min_classes_per_formula=3)
413
  base_confidence_distribution = distributional_probe(records, labels, "26-class character labels", min_classes_per_formula=2, weighted=True)
414
  base_material = material_level_probe(records, labels, "26-class character labels")
@@ -426,6 +492,7 @@ def evaluate_snapshot(name: str, path: Path, records: list[dict[str, Any]]) -> d
426
  "threshold_sensitivity": threshold_sensitivity_probe(records, grouped, grouping_name),
427
  "material_level_probe": material_level_probe(records, grouped, grouping_name),
428
  "distributional_probe": distributional_probe(records, grouped, grouping_name),
 
429
  "well_labelled_distributional_probe_ge3": distributional_probe(records, grouped, grouping_name, min_classes_per_formula=3),
430
  "confidence_weighted_distributional_probe_ge2": distributional_probe(records, grouped, grouping_name, min_classes_per_formula=2, weighted=True),
431
  }
@@ -446,6 +513,7 @@ def evaluate_snapshot(name: str, path: Path, records: list[dict[str, Any]]) -> d
446
  "twenty_six_class": base,
447
  "material_level_probe_26_class": base_material,
448
  "distributional_probe_26_class": base_distribution,
 
449
  "well_labelled_distributional_probe_26_class_ge3": base_well_labelled_distribution,
450
  "confidence_weighted_distributional_probe_26_class_ge2": base_confidence_distribution,
451
  "groupings": group_results,
@@ -459,25 +527,44 @@ def evaluate_snapshot(name: str, path: Path, records: list[dict[str, Any]]) -> d
459
  def recommendation(primary: dict[str, Any]) -> str:
460
  base_j = primary["twenty_six_class"]["mean_pairwise_jaccard"]
461
  best_j = primary["best_grouping_mean_pairwise_jaccard"]
462
- base_cos = primary["distributional_probe_26_class"]["mean_pairwise_cosine_similarity"]
463
- base_ge3_cos = primary["well_labelled_distributional_probe_26_class_ge3"]["mean_pairwise_cosine_similarity"]
464
  return (
465
  "Retract the superclass presence-Jaccard conclusion: the 1.000 is a collapse/presence artifact, "
466
  f"not proof that character is dead. Keep corrected distributional metrics as the circuit-breaker. "
467
- f"Under class-count cosine, 26-class character retains more profile separation than the collapsed "
468
- f"schemes (all-labelled mean cosine {base_cos:.3f}; >=3-label mean cosine {base_ge3_cos:.3f}; "
469
  f"presence-Jaccard baseline {base_j:.3f}, best collapsed presence-Jaccard {best_j:.3f}). "
470
  "Recommended direction: character may resume only at 26-class granularity under distributional "
471
  "and well-labelled filters; do not use superclass presence-Jaccard for go/no-go decisions."
472
  )
473
 
474
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
475
  def write_markdown(report: dict[str, Any]) -> None:
476
  primary = report["primary_snapshot_result"]
477
  rows = []
478
  base_j = primary["twenty_six_class"]["mean_pairwise_jaccard"]
479
  base_cos = primary["distributional_probe_26_class"]["mean_pairwise_cosine_similarity"]
480
  base_ge3_cos = primary["well_labelled_distributional_probe_26_class_ge3"]["mean_pairwise_cosine_similarity"]
 
481
  rows.append(f"| 26-class | 26 | {base_j:.3f} | baseline |")
482
  for name, result in primary["groupings"].items():
483
  j = result["discrimination_precheck"]["mean_pairwise_jaccard"]
@@ -519,6 +606,42 @@ def write_markdown(report: dict[str, Any]) -> None:
519
  for name, result in primary["groupings"].items():
520
  for row in result["threshold_sensitivity"]:
521
  threshold_rows.append(f"| {name} | {row['threshold']:.0%} | {row['mean_pairwise_jaccard']:.3f} |")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
522
  md = [
523
  "# Character grouping diagnostic v8",
524
  "",
@@ -557,6 +680,7 @@ def write_markdown(report: dict[str, Any]) -> None:
557
  "unless a grouped axis materially improves on 26-class; the lowest grouped Jaccard is only recorded "
558
  "as `lowest_jaccard_grouping` for audit.",
559
  "",
 
560
  "## Threshold Sensitivity",
561
  "",
562
  "| Grouping | activity threshold | mean pairwise Jaccard |",
 
252
  "left": left,
253
  "right": right,
254
  "cosine_similarity": cosine,
255
+ "cosine_distance": None if cosine is None else 1.0 - cosine,
256
  "js_divergence_bits": jsd,
257
  })
258
  cosines = [p["cosine_similarity"] for p in pairwise if p["cosine_similarity"] is not None]
259
+ cosine_distances = [p["cosine_distance"] for p in pairwise if p["cosine_distance"] is not None]
260
  jsds = [p["js_divergence_bits"] for p in pairwise if p["js_divergence_bits"] is not None]
261
+ cosine_distance_matrix = {
262
+ genre: {
263
+ other: 0.0 if genre == other else None
264
+ for other in genres
265
+ }
266
+ for genre in genres
267
+ }
268
+ js_divergence_matrix = {
269
+ genre: {
270
+ other: 0.0 if genre == other else None
271
+ for other in genres
272
+ }
273
+ for genre in genres
274
+ }
275
+ for row in pairwise:
276
+ left = row["left"]
277
+ right = row["right"]
278
+ cosine_distance_matrix[left][right] = row["cosine_distance"]
279
+ cosine_distance_matrix[right][left] = row["cosine_distance"]
280
+ js_divergence_matrix[left][right] = row["js_divergence_bits"]
281
+ js_divergence_matrix[right][left] = row["js_divergence_bits"]
282
  return {
283
  "pairwise": pairwise,
284
  "mean_pairwise_cosine_similarity": sum(cosines) / len(cosines) if cosines else None,
285
+ "mean_pairwise_cosine_distance": sum(cosine_distances) / len(cosine_distances) if cosine_distances else None,
286
  "min_pairwise_cosine_similarity": min(cosines) if cosines else None,
287
  "max_pairwise_cosine_similarity": max(cosines) if cosines else None,
288
  "mean_pairwise_js_divergence_bits": sum(jsds) / len(jsds) if jsds else None,
289
  "max_pairwise_js_divergence_bits": max(jsds) if jsds else None,
290
+ "cosine_distance_matrix": cosine_distance_matrix,
291
+ "js_divergence_bits_matrix": js_divergence_matrix,
292
  }
293
 
294
 
 
322
  }
323
 
324
 
325
+ def prevalence_distributional_probe(
326
+ records: list[dict[str, Any]],
327
+ labels: dict[str, dict[str, Any]],
328
+ axis_name: str,
329
+ ) -> dict[str, Any]:
330
+ """Unthresholded class prevalence profile by genre.
331
+
332
+ Each vector entry is the fraction of labelled formulas in that genre
333
+ containing the class. Magnitudes are retained; no active-set thresholding is
334
+ applied.
335
+ """
336
+ rows = formula_character_rows(records, labels)
337
+ codes = sorted({code for label in labels.values() for code in label_codes(label) if code not in {"Z", "carrier"}})
338
+ by_genre: dict[str, list[dict[str, Any]]] = defaultdict(list)
339
+ for row in rows:
340
+ by_genre[row["genre"]].append(row)
341
+
342
+ vectors: dict[str, Counter[str]] = defaultdict(Counter)
343
+ kept_by_genre = {}
344
+ for genre, genre_rows in sorted(by_genre.items()):
345
+ kept_by_genre[genre] = len(genre_rows)
346
+ counts = Counter(code for row in genre_rows for code in row["classes"])
347
+ for code in codes:
348
+ vectors[genre][code] = counts.get(code, 0) / len(genre_rows)
349
+
350
+ return {
351
+ "method": (
352
+ f"per-genre unthresholded class-prevalence vectors over {axis_name}; "
353
+ "entry = fraction of labelled formulas in the genre containing the class"
354
+ ),
355
+ "kept_labelled_formulas_by_genre": kept_by_genre,
356
+ "class_prevalence_vectors_by_genre": {
357
+ genre: {code: vectors[genre].get(code, 0.0) for code in codes}
358
+ for genre in sorted(vectors)
359
+ },
360
+ **pairwise_vector_metrics(vectors, codes),
361
+ }
362
+
363
+
364
  def material_level_probe(records: list[dict[str, Any]], labels: dict[str, dict[str, Any]], axis_name: str) -> dict[str, Any]:
365
  codes = sorted({code for label in labels.values() for code in label_codes(label) if code not in {"Z", "carrier"}})
366
  material_classes_by_genre: dict[str, dict[str, set[str]]] = defaultdict(dict)
 
474
  base = discrimination_probe(records, labels, "26-class character labels")
475
  base_density = label_density(records, labels, "26-class character labels")
476
  base_distribution = distributional_probe(records, labels, "26-class character labels")
477
+ base_prevalence_distribution = prevalence_distributional_probe(records, labels, "26-class character labels")
478
  base_well_labelled_distribution = distributional_probe(records, labels, "26-class character labels", min_classes_per_formula=3)
479
  base_confidence_distribution = distributional_probe(records, labels, "26-class character labels", min_classes_per_formula=2, weighted=True)
480
  base_material = material_level_probe(records, labels, "26-class character labels")
 
492
  "threshold_sensitivity": threshold_sensitivity_probe(records, grouped, grouping_name),
493
  "material_level_probe": material_level_probe(records, grouped, grouping_name),
494
  "distributional_probe": distributional_probe(records, grouped, grouping_name),
495
+ "prevalence_distributional_metric": prevalence_distributional_probe(records, grouped, grouping_name),
496
  "well_labelled_distributional_probe_ge3": distributional_probe(records, grouped, grouping_name, min_classes_per_formula=3),
497
  "confidence_weighted_distributional_probe_ge2": distributional_probe(records, grouped, grouping_name, min_classes_per_formula=2, weighted=True),
498
  }
 
513
  "twenty_six_class": base,
514
  "material_level_probe_26_class": base_material,
515
  "distributional_probe_26_class": base_distribution,
516
+ "prevalence_distributional_metric_26_class": base_prevalence_distribution,
517
  "well_labelled_distributional_probe_26_class_ge3": base_well_labelled_distribution,
518
  "confidence_weighted_distributional_probe_26_class_ge2": base_confidence_distribution,
519
  "groupings": group_results,
 
527
  def recommendation(primary: dict[str, Any]) -> str:
528
  base_j = primary["twenty_six_class"]["mean_pairwise_jaccard"]
529
  best_j = primary["best_grouping_mean_pairwise_jaccard"]
530
+ base_distance = primary["prevalence_distributional_metric_26_class"]["mean_pairwise_cosine_distance"]
531
+ base_jsd = primary["prevalence_distributional_metric_26_class"]["mean_pairwise_js_divergence_bits"]
532
  return (
533
  "Retract the superclass presence-Jaccard conclusion: the 1.000 is a collapse/presence artifact, "
534
  f"not proof that character is dead. Keep corrected distributional metrics as the circuit-breaker. "
535
+ f"Under unthresholded prevalence vectors, 26-class character shows weak but nonzero profile "
536
+ f"separation (mean cosine distance {base_distance:.3f}; mean JS divergence {base_jsd:.3f} bits; "
537
  f"presence-Jaccard baseline {base_j:.3f}, best collapsed presence-Jaccard {best_j:.3f}). "
538
  "Recommended direction: character may resume only at 26-class granularity under distributional "
539
  "and well-labelled filters; do not use superclass presence-Jaccard for go/no-go decisions."
540
  )
541
 
542
 
543
+ def matrix_markdown(title: str, matrix: dict[str, dict[str, float | None]]) -> list[str]:
544
+ genres = sorted(matrix)
545
+ rows = [
546
+ f"### {title}",
547
+ "",
548
+ "| Genre | " + " | ".join(f"`{genre}`" for genre in genres) + " |",
549
+ "| --- | " + " | ".join("---:" for _ in genres) + " |",
550
+ ]
551
+ for genre in genres:
552
+ values = []
553
+ for other in genres:
554
+ value = matrix[genre][other]
555
+ values.append("" if value is None else f"{value:.3f}")
556
+ rows.append(f"| `{genre}` | " + " | ".join(values) + " |")
557
+ rows.append("")
558
+ return rows
559
+
560
+
561
  def write_markdown(report: dict[str, Any]) -> None:
562
  primary = report["primary_snapshot_result"]
563
  rows = []
564
  base_j = primary["twenty_six_class"]["mean_pairwise_jaccard"]
565
  base_cos = primary["distributional_probe_26_class"]["mean_pairwise_cosine_similarity"]
566
  base_ge3_cos = primary["well_labelled_distributional_probe_26_class_ge3"]["mean_pairwise_cosine_similarity"]
567
+ base_prevalence = primary["prevalence_distributional_metric_26_class"]
568
  rows.append(f"| 26-class | 26 | {base_j:.3f} | baseline |")
569
  for name, result in primary["groupings"].items():
570
  j = result["discrimination_precheck"]["mean_pairwise_jaccard"]
 
606
  for name, result in primary["groupings"].items():
607
  for row in result["threshold_sensitivity"]:
608
  threshold_rows.append(f"| {name} | {row['threshold']:.0%} | {row['mean_pairwise_jaccard']:.3f} |")
609
+ prevalence_metric_rows = [
610
+ "| 26-class | 26 | "
611
+ f"{base_prevalence['mean_pairwise_cosine_distance']:.3f} | "
612
+ f"{base_prevalence['mean_pairwise_js_divergence_bits']:.3f} |"
613
+ ]
614
+ for name, result in primary["groupings"].items():
615
+ metric = result["prevalence_distributional_metric"]
616
+ prevalence_metric_rows.append(
617
+ f"| {name} | {result['n_superclasses']} | "
618
+ f"{metric['mean_pairwise_cosine_distance']:.3f} | "
619
+ f"{metric['mean_pairwise_js_divergence_bits']:.3f} |"
620
+ )
621
+ distributional_matrices = [
622
+ "## Unthresholded Prevalence Distributional Metric",
623
+ "",
624
+ "This is the corrected character discrimination test. Vectors retain the raw per-genre prevalence "
625
+ "of each class before any active-set thresholding; cosine is reported as distance (`1 - similarity`) "
626
+ "and JS divergence is reported in bits.",
627
+ "",
628
+ "| Axis | classes | mean cosine distance | mean JS divergence (bits) |",
629
+ "| --- | ---: | ---: | ---: |",
630
+ *prevalence_metric_rows,
631
+ "",
632
+ *matrix_markdown(
633
+ "26-class cosine distance",
634
+ base_prevalence["cosine_distance_matrix"],
635
+ ),
636
+ *matrix_markdown(
637
+ "26-class JS divergence (bits)",
638
+ base_prevalence["js_divergence_bits_matrix"],
639
+ ),
640
+ ]
641
+ for name, result in primary["groupings"].items():
642
+ metric = result["prevalence_distributional_metric"]
643
+ distributional_matrices.extend(matrix_markdown(f"{name} cosine distance", metric["cosine_distance_matrix"]))
644
+ distributional_matrices.extend(matrix_markdown(f"{name} JS divergence (bits)", metric["js_divergence_bits_matrix"]))
645
  md = [
646
  "# Character grouping diagnostic v8",
647
  "",
 
680
  "unless a grouped axis materially improves on 26-class; the lowest grouped Jaccard is only recorded "
681
  "as `lowest_jaccard_grouping` for audit.",
682
  "",
683
+ *distributional_matrices,
684
  "## Threshold Sensitivity",
685
  "",
686
  "| Grouping | activity threshold | mean pairwise Jaccard |",