kg-path-review cardinality: per-transform max under-reports merged degree by ~2x; the union is exact
Found reviewing #771, in that PR's own fix.
#768 correctly identified that summing row counts across transforms over-reports. The fix took the **maximum per transform**. That swaps one error for the opposite one: where `sum` double-counted overlap, `max` discards everything the other transforms contribute.
Measured against the merged KG, `biolink:has_phenotype`, top subjects by union:
| subject | max (the fix) | **union** | sum (the old bug) | merged KG |
|---|---:|---:|---:|---:|
| `NCBITaxon:562` | 36 | **76** | 112 | **76** |
| `NCBITaxon:698769` | 36 | **67** | 109 | **67** |
| `NCBITaxon:258723` | 29 | **66** | 89 | **66** |
| `NCBITaxon:361277` | 37 | **66** | 104 | **66** |
| `NCBITaxon:115561` | 36 | **65** | 70 | **65** |
**The union equals the merged-graph degree exactly in every case**, because that is what the merge computes: distinct `(subject, predicate, object)` triples across sources. `max` under-reports by roughly 2x here.
Why it matters for a threshold check: a subject with ~1,200 phenotypes in `metatraits` and ~1,200 in `metatraits_gtdb` with little overlap has a merged degree near 2,400 — CRITICAL against the documented 2,000 envelope — but `max` reports 1,200 and files at most a WARNING. The archetype exists to find exactly that kind of leak, so under-reporting is the more dangerous direction of the two.
**Fix:** union the distinct objects across transforms, and name the contributing transforms rather than a single "worst" one. That is both the honest number and the one the envelopes were written against, since they describe a per-graph degree.
Note the earlier verification was too weak to catch this: I confirmed `union == max` for `NCBITaxon:1965294` (33 both ways, metatraits' 27 being a subset) and generalised from one subject where the sets happened to nest.
关闭于 16 天前 1 条评论