Skip to content

NK/LK per-protein rows are named by the matrix rows they came from - #27

Merged
frapercan merged 1 commit into
mainfrom
fix/nk-lk-per-protein-row-index
Nov 7, 2026
Merged

frapercan merged 1 commit into
mainfrom
fix/nk-lk-per-protein-row-index

Conversation

@frapercan

Copy link
Copy Markdown
Owner

What

In compute_metrics, the NK/LK sparse branch now passes np.flatnonzero(proteins_has_gt) as the sink's row index, as the PK branch already does. Before, it passed np.arange(p.shape[0]).

Why

The NK/LK path drops the proteins that have no truth in the terms of interest before it calls the kernel. Its per-protein rows are therefore a subset of the matrix rows. Naming them 0..n-1 gave every row after the first dropped protein the id of its neighbour.

PROTEA's producer detected this and refused to write those tables (unmappable_row_numbering). That cost NK:MFO and LK:MFO their per-protein breakdown on window 211->227, where the filter drops 4 and 11 proteins respectively. When no protein is dropped, flatnonzero equals arange, so every other table is unchanged.

The docstring of TestTheRowsCanBeNamed claimed that "the NK/LK kernel sees every row". That was false, and it is corrected.

Test

  • TestTheNkLkPathNamesTheRowsItKeeps drops two of five proteins and checks two things: the row index names the kept rows (0, 2, 4), and each named row carries its own protein's truth count.
  • On the old code both tests fail; with the fix the 16 tests of tests/test_per_protein_sink.py pass, and so does the full suite.
  • ruff check is clean on both files.

Deploy

Do not merge or deploy this until PROTEA exploration 3 has closed its evaluations and comparisons. All four of its arms must be evaluated with e937e0e.

compute_metrics drops the proteins with no truth in the terms of interest
before the NK/LK kernel, as the PK path does, but handed the sink
arange(n) as the row index. Every row after the first dropped protein
carried its neighbour's id. PROTEA's producer refused those tables as
unmappable_row_numbering: NK and LK molecular_function on window
211->227, where that filter drops 4 and 11 proteins respectively.

The row index is now flatnonzero(proteins_has_gt), as in the PK branch.
With nothing dropped it equals arange, so every other table is
unchanged. The class docstring that stated the false premise is
corrected. The two new tests fail on the old code and pass now.
@frapercan
frapercan marked this pull request as ready for review November 7, 2026 11:46
@frapercan
frapercan merged commit 203af0a into main Nov 7, 2026
6 checks passed
@frapercan
frapercan deleted the fix/nk-lk-per-protein-row-index branch November 7, 2026 11:47
github-actions Bot pushed a commit to frapercan/PROTEA that referenced this pull request Nov 7, 2026
Picks up
[cafaeval-protea#27](frapercan/cafaeval-protea#27),
merged at `203af0a28f0bb6f8cd0588c0d6d02ebf251eccce`.

## What it fixes

The NK/LK branch of `compute_metrics` passed `np.arange(p.shape[0])` as
`row_index` for a prediction matrix it had already filtered to the
proteins
carrying truth, while `ids` numbered the unfiltered ground truth. So
from the
first dropped protein onward every row would have worn a neighbour's
accession.
It now passes `np.flatnonzero(proteins_has_gt)`, which the PK branch
already
did.

That is why two panels have had no per-protein breakdown since the grid
artefact existed, with the reason on the record every time:

```
unmappable_row_numbering   LK molecular_function   10
unmappable_row_numbering   NK molecular_function   10
```

NK covered 3,390 of 3,394 ground-truth proteins and LK 2,433 of 2,444,
so the
filter did remove rows and the numbering did not survive it. With this
pin the
producer stops refusing and a paired comparison reaches **eight** panels
instead of six. `PK:BPO` stays refused: its weighted and unweighted
branches
score different populations, which one row set cannot hold, and that is
structural.

## Nothing already written moves

When no protein is dropped, `flatnonzero` of an all-true mask is
`arange`, so
every per-protein table that was written stays identical and only the
two that
were refused start being written.

Exploration 3 is decided and all four of its arms were evaluated on
`e937e0e1`, so this changes none of its numbers. That was the reason it
stayed
in draft until the exploration closed.

## Lock

`poetry lock` changes the reference, the resolved reference and the
content
hash. `poetry check --lock` exits 0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant