# Stage-1 confused entropy (official test)

Checkpoint: `save/icbhi_beats_frame_asd_frame_asd_F12_sastruct_s1_rerun2/best.pth`.
Split: official 60/40 test fold, one row per respiratory cycle (n=2756).
SpecAug off. MIL top-3. Dual threshold tau_c=0.91, tau_w=0.75.
Entropy gate for "high" is ln(2) = 0.693 nats (max ln 4 = 1.386).
SNR column is a within-cycle frame-RMS contrast (p90/p10), not a dataset SNR label.

Reproduced score of the on-disk `best.pth` at the saved thresholds: Sp 81.25, Se 48.60, Score 64.93.
`class_metrics.json` in the same folder records Sp 84.55, Se 48.09, Score 66.32 from epoch 4.
That number is the pre-EMA weights. `train.py` used to apply the moving average and then save, so the file is one EMA step past the scored weights. The 66.32 weights are not in the checkpoint. Later runs save the scored weights first.
Fixing one normal error is worth 0.032 score points. Fixing one abnormal error is worth 0.042.

Counterfactual, no retrain: crackle pooled by max, wheeze still top-3, thresholds re-searched under Se>=48 and Sp>=72: Score 65.31 (Sp 82.27, Se 48.34, tau 0.91/0.83).
Both heads max-pooled: Score 65.27 (Sp 81.00, Se 49.53).


### Buckets

| bucket | n | share | mean_entropy | mean_margin |
| --- | --- | --- | --- | --- |
| high_entropy_correct | 991 | 0.3596 | 0.9175 | 0.2983 |
| high_entropy_wrong | 549 | 0.1992 | 0.9302 | 0.3132 |
| low_entropy_correct | 864 | 0.3135 | 0.535 | 0.6974 |
| low_entropy_wrong | 352 | 0.1277 | 0.5494 | 0.6972 |

### Confusion cells (n>=7), sorted by score points if every cycle in the cell were fixed

| truth | pred | n | hurts | score_points_if_fixed | mean_entropy | mean_margin | mean_p_c | mean_p_c_max | frac_high_entropy | crackle_near_tau | crackle_p_below_0.30 |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| crackle | normal | 300 | Se | 12.744 | 0.7592 | 0.48 | 0.627 | 0.6466 | 0.5667 | 142 | 51 |
| normal | wheeze | 201 | Sp | 6.365 | 0.7883 | 0.4784 | 0.2943 | 0.3104 | 0.6816 | 0 | 0 |
| wheeze | normal | 99 | Se | 4.206 | 1.009 | 0.2693 | 0.4444 | 0.4636 | 0.9293 | 0 | 0 |
| both | wheeze | 92 | Se | 3.908 | 0.7404 | 0.3995 | 0.6322 | 0.6563 | 0.5978 | 33 | 8 |
| normal | crackle | 91 | Sp | 2.882 | 0.5878 | 0.6681 | 0.9408 | 0.9466 | 0.2088 | 0 | 0 |
| both | normal | 36 | Se | 1.529 | 1.0874 | 0.2639 | 0.6058 | 0.6282 | 0.8889 | 11 | 4 |
| crackle | wheeze | 30 | Se | 1.274 | 0.8159 | 0.4223 | 0.7125 | 0.7248 | 0.7667 | 17 | 1 |
| wheeze | crackle | 18 | Se | 0.765 | 0.7175 | 0.4579 | 0.944 | 0.9483 | 0.5 | 0 | 0 |
| wheeze | both | 13 | Se | 0.552 | 0.4441 | 0.7594 | 0.9437 | 0.9495 | 0.2308 | 0 | 0 |
| both | crackle | 11 | Se | 0.467 | 0.6571 | 0.5868 | 0.932 | 0.9393 | 0.3636 | 0 | 0 |
| normal | normal | 1283 | none | 0.0 | 0.7865 | 0.4444 | 0.4559 | 0.4724 | 0.6134 | 0 | 0 |
| crackle | crackle | 313 | none | 0.0 | 0.5634 | 0.6774 | 0.951 | 0.9552 | 0.1917 | 0 | 0 |
| wheeze | wheeze | 255 | none | 0.0 | 0.7225 | 0.4425 | 0.4251 | 0.4423 | 0.5647 | 0 | 0 |

### By true class

| class | n | recall | mean_entropy_correct | mean_entropy_wrong | high_entropy_wrong | low_entropy_wrong | mean_p_c_wrong | mean_p_c_max_wrong |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| normal | 1579 | 81.25395820139329 | 0.786485636782479 | 0.7260428126397971 | 158 | 138 | 0.5015682531269016 | 0.5143726683800688 |
| crackle | 649 | 48.22804314329738 | 0.5634079728834926 | 0.7621637608501173 | 196 | 140 | 0.6399494072732826 | 0.6585979056988089 |
| wheeze | 385 | 66.23376623376623 | 0.7224768269295786 | 0.9121842651413037 | 104 | 26 | 0.5634610793624933 | 0.5793018967199784 |
| both | 143 | 2.797202797202797 | 0.4568459168076515 | 0.8236929754987895 | 91 | 48 | 0.6490762460467626 | 0.6713897845299124 |

### By device

| group | n | accuracy | mean_entropy | high_entropy_wrong | low_entropy_wrong |
| --- | --- | --- | --- | --- | --- |
| AKGC417L | 1836 | 68.1917211328976 | 0.7528239189685689 | 354 | 230 |
| Litt3200 | 461 | 58.13449023861171 | 0.8747057619943018 | 138 | 55 |
| Meditron | 459 | 72.98474945533769 | 0.6320602282849273 | 57 | 67 |

### By cycle length

| group | n | accuracy | mean_entropy | high_entropy_wrong | low_entropy_wrong |
| --- | --- | --- | --- | --- | --- |
| 1-2s | 772 | 71.6321243523316 | 0.7697919494824706 | 155 | 64 |
| 2-3s | 760 | 70.39473684210526 | 0.7393948803606786 | 130 | 95 |
| <1s | 103 | 75.72815533980582 | 0.6327511998056208 | 11 | 14 |
| >=3s | 1121 | 61.462979482604815 | 0.761950801635937 | 253 | 179 |

### By within-cycle contrast

| group | n | accuracy | mean_entropy | high_entropy_wrong | low_entropy_wrong |
| --- | --- | --- | --- | --- | --- |
| 12-18dB | 1722 | 70.09291521486644 | 0.7275474122471234 | 299 | 216 |
| 6-12dB | 758 | 63.98416886543536 | 0.7839698481292398 | 173 | 100 |
| <6dB | 11 | 9.090909090909092 | 0.8768242705952037 | 9 | 1 |
| >=18dB | 265 | 61.132075471698116 | 0.8256938133599623 | 68 | 35 |

### Patients with the most sensitivity errors (top 15)

| patient | device | errors | se_errors | sp_errors | mean_entropy |
| --- | --- | --- | --- | --- | --- |
| 178 | AKGC417L | 76 | 61 | 15 | 0.9117 |
| 151 | AKGC417L | 72 | 47 | 25 | 0.9694 |
| 156 | AKGC417L | 44 | 43 | 1 | 0.7625 |
| 160 | AKGC417L | 44 | 39 | 5 | 0.7939 |
| 218 | Meditron | 42 | 39 | 3 | 0.7766 |
| 174 | AKGC417L | 36 | 36 | 0 | 0.7222 |
| 205 | AKGC417L | 53 | 27 | 26 | 0.6148 |
| 223 | Meditron | 27 | 26 | 1 | 0.6755 |
| 198 | AKGC417L | 26 | 25 | 1 | 0.8576 |
| 176 | AKGC417L | 23 | 23 | 0 | 0.8008 |
| 177 | AKGC417L | 24 | 22 | 2 | 0.8917 |
| 207 | AKGC417L | 22 | 21 | 1 | 0.7787 |
| 149 | Meditron | 22 | 19 | 3 | 0.9081 |
| 170 | AKGC417L | 39 | 18 | 21 | 0.5909 |
| 147 | AKGC417L | 36 | 18 | 18 | 0.7123 |

Low-entropy wrong means the four-class product is peaked (H < ln 2) and the dual-threshold label is still wrong.
That is an overconfident error. High-entropy wrong is a confused miss.
crackle_near_tau counts crackle-positive cycles whose top-3 p_c is in [0.75, 1) but the threshold still says no crackle.
crackle_p_below_0.30 counts crackle-positive cycles the crackle head has essentially given up on.

Shapes on this run: wave B x 80000, tokens B x 248 x 768, each head logit B x 248.
A few cycles are in `s1_trace_cycles.json`.

## Measured hinge finetunes (not a path to 67)

`--lambda_boundary 0.1`, 2 epochs, LR 1e-5, resumed from this checkpoint, Adam moments reset. Official test, thresholds re-searched.

| run | Score | Sp | Se | crackle | wheeze | both |
| --- | --- | --- | --- | --- | --- | --- |
| on-disk stage-1, no extra loss | 64.93 | 81.25 | 48.60 | 48.2 | 66.2 | 2.8 |
| boundary (includes false-wheeze pull-down) | 64.77 | 80.18 | 49.36 | 60.1 | 43.1 | 17.5 |
| boundary2 (pull-down removed) | 64.83 | 81.32 | 48.34 | 60.4 | 39.7 | 16.8 |

Crackle and both recall move the way the audit predicts. Wheeze recall falls because tau_w is pushed to 0.91-0.95. Score does not rise. Default `--lambda_boundary 0` leaves the old loss unchanged.

