Repository navigation
Commit adf00ae
authored
Match each test annotation at most once in compare_annotations (#606)
`compare_annotations` can match one test annotation to two reference
annotations:
```python
c = processing.compare_annotations(np.array([0, 2, 4, 5]), np.array([1, 5]), window_width=6)
c.matching_sample_nums # [0, -1, 0, 1]: test annotation 0 is used twice
c.fp, c.positive_predictivity # -1, 1.5
```
When a reference annotation loses a contested test annotation to the
next reference, `compare` falls back to the previous test annotation. It
only checks that the *previous reference* didn't take it, so if that
reference was unmatched, a test annotation matched earlier on can be
matched again.
**Fix:** keep track of the last matched test annotation. Matches are
made in increasing order, so the fallback is used only if it comes after
that one. This replaces the old check (which it covers).
**Checking that nothing else changes:**
- On 200,000 random small cases, the new code gives exactly the same
matches as `main` whenever `main` doesn't match a test annotation twice
(about 6% of the cases did). With the fix, none do.
- On record 100 (gqrs and xqrs against the reference beats, two window
sizes), the matches are identical.
**Tests:** the example above, plus a randomized check that matches are
unique, in order and within the window, and that `fp` is never negative.
Both fail on `main`. `pytest -m "not network"` and the docs build pass.
This is separate from #566, which handles empty inputs in `_calc_stats`.3 files changed
Lines changed: 38 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
26 | 29 | | |
27 | 30 | | |
28 | 31 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
158 | 161 | | |
159 | 162 | | |
160 | 163 | | |
| |||
186 | 189 | | |
187 | 190 | | |
188 | 191 | | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
| 192 | + | |
194 | 193 | | |
195 | 194 | | |
196 | 195 | | |
| |||
200 | 199 | | |
201 | 200 | | |
202 | 201 | | |
| 202 | + | |
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| 216 | + | |
216 | 217 | | |
217 | 218 | | |
218 | 219 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
247 | 276 | | |
248 | 277 | | |
249 | 278 | | |
| |||
0 commit comments