BioHCL-SSSM / TECHNICAL_REPORT.md
unknownBrain's picture
Upload audited clean BioHCL-SSSM 256-d codebase, verified weights, 5-fold patient-grouped CV, and 11-variant ablations
bb5e4ec verified
|
Raw History Blame Contribute Delete
18.8 kB

BioHCL-SSSM Technical Report & Independent Forensic Audit

Repository: unknownBrain/BioHCL-SSSM (D:\myprojects\BioHCL-SSSM)
Dataset: Kermany Pediatric Chest X-Ray Cohort (Cell 2018; paultimothymooney/chest-xray-pneumonia, N = 5,856 JPEGs only)
Audit Pipeline: Multi-gate local execution (RTX 3080 Ti 16 GB, strict FP32 evaluation) verified via independent AWS Bedrock us.anthropic.claude-opus-4-6-v1 Gates 0–5.


1. Executive Summary

Prior development snapshots of BioHCL-SSSM contained multiple experimental artifacts across fragmented repositories (hardcoded unverified tables claiming 96.47% SOTA, an image-level 10-fold CV split claiming 99.37% with patient leakage, triple architecture mismatches between 256-d vs 512-d models, collapsed ablations masked by test-set Youden threshold tuning, thop buffer key pollution in checkpoints, unexecuted Brain MRI tracker placeholders, and exposed W&B credentials).

This repository rebuilds the project from a single canonical 256-d architecture, audits all recoverable genuine Aug-12 checkpoints under strict FP32 evaluation at fixed threshold t = 0.50, executes a leak-free 5-fold patient-grouped cross-validation (N = 5,232), and conducts a clean unified 11-variant 256-d ablation suite on Fold 0.


2. Architecture & Parameter Accounting (src/models/biohcl_sssm.py)

BioHCLSSSM (embed_dim = 256, chain_mode = "dual", num_sssm_blocks = 2, d_state = 16 + 4*i):

  • Dual-Chain Feature Extractor (DualChainExtractor):
    • Local Spatial Branch (HierarchicalConvBlock): parallel 3×3, 5×5, and 7×7 convolutions pooled adaptively to 8 × 8 = 64 spatial tokens (128-d).
    • Global Semantic Branch (BackboneExtractor): ImageNet-pretrained densenet121 (1024-d global average pooled, projected to 128-d with dropout = 0.1), broadcast across the 64 tokens, concatenated, fused (Linear(256, 256)), plus QuadraticPositionalEncoder(num_levels = 3).
  • Recurrent State-Space Mixer (LinearBioSSSMBlock × 2): expand = 2 (d_inner = 512), biological global context gate sigmoid(Linear(mean(x))), softplus discretized dt, diagonal state transition A = -exp(A_log), sequential 64-step scan executed strictly under torch.autocast(enabled=False) (FP32) to avoid FP16 overflow.
  • Exact Parameter Reconciliation:
    • model.parameters() (trainable weights): 8,340,554 (L=2 Dual SSSM)
    • model.state_dict() total scalars across 780 keys: 8,424,323 (includes 83,769 non-trainable DenseNet-121 BatchNorm running mean/variance/counter buffers).
    • Architectural Nuance Disclosure (D6): ResidualConnector modules (proj and norm, 132,608 params total across 2 blocks) are instantiated inside res_connectors and preserved in all canonical state dictionaries for strict=True weight compatibility, while BioHCLSSSM.forward() reads res_conn.skip_step directly and feeds residual tensors straight into LinearBioSSSMBlock.

3. Dataset Provenance & Kermany Split Forensics (src/data/dataset.py)

3.1 Single-Dataset Certification

Every executed script in our audit lineage runs exclusively on paultimothymooney/chest-xray-pneumonia (5,856 JPEGs: 5,216 train, 16 original tiny val, 624 official held-out test). Mentions of FigShare Brain MRI, Br35H, HAM10000, RSNA, or NIH in legacy workspace text files were unexecuted boilerplate or Pending Run spreadsheet rows.

3.2 Union-Find Patient + MD5 Duplicate Grouping

  • Split Restart Disambiguation: Kermany test/PNEUMONIA/ restarts person1..1685 numbering independently of train/PNEUMONIA/ (person1..1945) and val/PNEUMONIA/ (person1946..1954). Similarly, IM-* and NORMAL2-IM-* are disjoint series with non-overlapping integer ranges across train, val, and test (0 overlap). Patient grouping therefore prefixes PNEUMONIA IDs by {split}_person_{id}.
  • MD5 & Perceptual Hash Forensics:
    • Cross-split (train+val vs. test) exact MD5 duplicates: 0 (verified via runtime assertion).
    • Closest 64×64 pixel MAE across coarse 64-bit dHash collisions between train+val and test: 0.0669 (no near-duplicate images leaked).
    • Intra-train+val exact MD5 duplicates: 30 duplicate groups, all occurring within the same patient ID. Before splitting, Union-Find merges both shared raw_patient AND identical md5 hashes, collapsing 5,232 images into 2,861 patient groups.
    • Official Test Duplicate Disclosure: One exact-byte duplicate pair exists inside official test/NORMAL (NORMAL2-IM-0095-0001.jpeg == NORMAL2-IM-0096-0001.jpeg). Official N = 624 is retained unmodified for benchmark comparability (233 unique NORMAL scans, 234 files).
    • Demographics & Shift: All cohorts are pediatric patients (ages 1–5); class balance shifts from 74.2% Pneumonia in train+val (3,883 / 5,232) to 62.5% Pneumonia in official test/ (390 / 624).

4. Priority 1: Held-Out Official Test Evaluation (N = 624, Fixed t = 0.50)

Re-evaluated directly from verified Aug-12 checkpoints (checkpoints/aug12_verified/) in strict FP32 at fixed threshold t = 0.50 (results/priority1_test_evaluation.csv), with 10,000-iteration non-parametric bootstrap 95% CIs and exact two-sided McNemar tests (results/priority1_mcnemar.json).

Model Params (Trainable) GMACs Acc % [95% CI] Prec % Rec % Spec % F1 [95% CI] ROC-AUC [95% CI] PR-AUC Brier ECE CM (TN/FP/FN/TP)
Student BioHCL-SSSM (KD) 8,340,554 3.429 87.50 [84.78, 90.06] 83.62 99.49 67.52 0.9087 [0.8873, 0.9280] 0.9391 [0.9140, 0.9614] 0.9418 0.1218 0.1229 158 / 76 / 2 / 388
Baseline ResNet-50 23,512,130 4.132 84.29* [81.41, 87.18] 80.17 99.49 58.97 0.8879 [0.8649, 0.9093] 0.9605 [0.9431, 0.9755] 0.9694 0.1481 0.1465 138 / 96 / 2 / 388
Ablation: Single-CNN 1,249,822 1.132 83.81 [80.93, 86.70] 84.99 90.00 73.50 0.8742 [0.8489, 0.8975] 0.9116 [0.8881, 0.9332] 0.9455 0.1179 0.0467 172 / 62 / 39 / 351
Ablation: No Bio-Prior 8,340,554 3.429 82.37 [79.33, 85.42] 78.11 99.74 53.42 0.8761 [0.8522, 0.8985] 0.9506 [0.9344, 0.9651] 0.9691 0.1701 0.1681 125 / 109 / 1 / 389
Ablation: No Positional 8,340,554 3.417 81.09 [77.88, 84.13] 76.88 99.74 50.00 0.8683 [0.8437, 0.8910] 0.9701 [0.9568, 0.9813] 0.9794 0.1875 0.1879 117 / 117 / 1 / 389

*FP32 vs. AMP Equivalence Note: Aug-12 Colab notebooks evaluated under torch.amp.autocast('cuda'), which flips 1 borderline Normal sample (p = 0.5036 FP32 → < 0.50 AMP) in ResNet-50 (84.46% AMP vs. 84.29% strict FP32).

Paired Exact McNemar Significance (Student_BioHCL_SSSM vs. Comparisons)

  • vs. Baseline_ResNet50: ΔAcc = +3.21% [+1.44%, +4.97%] (27 Student-only correct vs. 7 ResNet50-only correct), exact p = 0.000821 (2.82× fewer trainable parameters: 8.34M vs 23.51M).
  • vs. Ablation_SingleCNN: ΔAcc = +3.69% [+0.64%, +6.57%] (56 vs. 33), p = 0.019187.
  • vs. Ablation_NoBioPrior: ΔAcc = +5.13% [+3.21%, +7.05%] (35 vs. 3), p = 6.68e-8.
  • vs. Ablation_NoPositional: ΔAcc = +6.41% [+4.49%, +8.49%] (42 vs. 2), p = 1.13e-10.

Crucial Calibration vs. Ranking Finding (Brier / ECE vs. ROC-AUC)

Although Baseline_ResNet50 (0.9605) and Ablation_NoPositional (0.9701) achieve higher ranking ROC-AUC than Student_BioHCL_SSSM (0.9391), their probability calibration at the fixed t = 0.50 decision boundary is severely shifted toward positive predictions (ECE = 0.1465 and 0.1879, Specificity = 58.97% and 50.00%). Student_BioHCL_SSSM achieves substantially lower calibration error (Brier = 0.1218, ECE = 0.1229) and 20–41 fewer false positives (TN = 158 vs. 138 / 125 / 117), yielding significantly higher accuracy and F1 at t = 0.50. See figures/fig1_priority1_confusion_matrices.png and figures/fig2_roc_and_calibration.png.

(Caveat: The Aug-12 train/val internal split inside df_trainval used image-level stratification rather than patient grouping; test/ N=624 remained strictly separate.)


5. Priority 3: Patient-Grouped 5-Fold Cross-Validation (N = 5,232, Zero Leakage)

Trained direct BioHCLSSSM(embed_dim=256, L=2) per fold (AdamW lr=1e-4, warmup=5, epochs=50, patience=10 on Val Macro-F1, WeightedRandomSampler + unweighted CE, official test/ strictly excluded; fixed t = 0.50 OOF).

Fold Best Ep / Ran Train / Val Imgs Train / Val Groups Group / MD5 Overlap Acc % Prec % Rec % Spec % F1 Macro-F1 ROC-AUC Brier ECE CM (TN/FP/FN/TP)
0 18 / 28 4,218 / 1,014 2,288 / 573 0 / 0 99.01 99.59 99.06 98.89 0.9933 0.9874 0.9995 0.0092 0.0089 267 / 3 / 7 / 737
1 27 / 37 4,188 / 1,044 2,288 / 573 0 / 0 99.62 99.87 99.61 99.63 0.9974 0.9951 0.9999 0.0040 0.0041 272 / 1 / 3 / 768
2 32 / 42 4,194 / 1,038 2,289 / 572 0 / 0 99.42 99.74 99.48 99.24 0.9961 0.9924 0.9989 0.0056 0.0063 261 / 2 / 4 / 771
3 7 / 17 4,163 / 1,069 2,289 / 572 0 / 0 99.53 99.87 99.50 99.63 0.9969 0.9938 0.9993 0.0042 0.0036 267 / 1 / 4 / 797
4 7 / 17 4,165 / 1,067 2,290 / 571 0 / 0 99.16 99.37 99.49 98.18 0.9943 0.9890 0.9993 0.0090 0.0096 270 / 5 / 4 / 788
Mean ± SD — 5,232 2,861 0 / 0 99.35 ± 0.26 99.69 ± 0.21 99.43 ± 0.21 99.11 ± 0.61 0.9956 ± 0.0017 0.9915 ± 0.0032 0.9994 ± 0.0004 0.0064 ± 0.0025 0.0065 ± 0.0027 —
Pooled OOF — 5,232 2,861 0 / 0 99.35 99.69 99.43 99.11 0.9956 0.9915 0.9991 0.0064 0.0061 1,337 / 12 / 22 / 3,861

Pooled OOF 95% Bootstrap CIs: Acc [99.12%, 99.56%], F1 [0.9941, 0.9970], Rec [99.18%, 99.66%], Spec [98.58%, 0.9956%], AUC [0.9985, 0.9996].

Interpreting the Internal CV (99.35%) vs. External Test (87.50%) Gap

BioHCL-SSSM achieves 99.35% ± 0.26% accuracy under strict patient-grouped 5-fold CV (N=5,232, 2,861 patients), demonstrating strong within-distribution generalization. External transfer to the official Kermany held-out test set (N=624) yields 87.50% (KD Student) and 82.69% (single-fold direct SSSM_L2_Ref), exposing a real ~12-point distribution-shift gap between Kermany train+val (74.2% Pneumonia) and test/ (62.5% Pneumonia / distinct acquisition cohort). The old Sep-4 99.37% 10-fold CV number was inflated by image-level patient leakage (512-d, 3 blocks) and is formally retired; our 99.35% matches its magnitude only coincidentally within-distribution.


6. Priority 4: Unified 256-d Controlled Ablation Suite (Fold 0, N = 624 Test)

All 11 variants shared Fold 0 (4,218 train / 1,014 val), --epochs 30 --patience 8, --seed 42, zero double-weighting (WeightedRandomSampler paired ONLY with unweighted CE; weighted_ce and focal trained under uniform shuffle), and clean weight saving prior to throwaway thop.profile().

Variant Config (Block / L / Skip / Sampler / Loss / λ) Status (Best Ep) Params GMACs Val Acc % Test Acc % [95% CI] Test Spec % Test F1 Test AUC Test Brier CM (TN/FP/FN/TP)
SSSM_L2_Ref sssm / 2 / T / WRS / ce / 0.0 CONVERGED (15) 8,340,554 3.429 99.01 82.69 [79.65, 85.58] 54.27 0.8781 0.9588 0.1663 127 / 107 / 1 / 389
MHSA_L2_8Heads mhsa / 2 / T / WRS / ce / 0.0 CONVERGED (21) 8,563,162 3.410 99.31 83.01 [79.97, 85.90] 55.56 0.8798 0.9482 0.1659 130 / 104 / 2 / 388
Depth_SSSM_L1 sssm / 1 / T / WRS / ce / 0.0 CONVERGED (21) 7,856,396 3.403 99.21 80.61 [77.40, 83.65] 49.15 0.8651 0.9566 0.1853 115 / 119 / 2 / 388
Depth_SSSM_L3 sssm / 3 / T / WRS / ce / 0.0 CONVERGED (26) 8,828,820 3.456 98.92 82.37 [79.33, 85.26] 53.85 0.8758 0.9405 0.1721 126 / 108 / 2 / 388
Depth_SSSM_L4 sssm / 4 / T / WRS / ce / 0.0 CONVERGED (10) 9,321,194 3.483 98.72 85.26 [82.37, 87.98] 61.54 0.8940 0.9708 0.1449 144 / 90 / 2 / 388
Ablation_NoSkip_L2 sssm / 2 / F / WRS / ce / 0.0 CONVERGED (17) 8,340,554 3.429 99.11 84.62 [81.73, 87.34] 59.83 0.8899 0.9759 0.1495 140 / 94 / 2 / 388
Loss_WeightedCE_Uniform sssm / 2 / T / Unif / wCE / 0.0 CONVERGED (12) 8,340,554 3.429 98.52 85.90 [83.17, 88.62] 63.25 0.8981 0.9384 0.1347 148 / 86 / 2 / 388
Loss_FocalGamma2_Uniform sssm / 2 / T / Unif / focal / 0.0 CONVERGED (17) 8,340,554 3.429 98.92 82.69 [79.65, 85.58] 53.85 0.8784 0.9636 0.1482 126 / 108 / 0 / 390
Consistency_Lambda_0.01 sssm / 2 / T / WRS / ce / 0.01 CONVERGED (26) 8,340,554 3.429 98.92 81.41 [78.21, 84.46] 51.28 0.8700 0.8514 0.1797 120 / 114 / 2 / 388
Consistency_Lambda_0.05 sssm / 2 / T / WRS / ce / 0.05 CONVERGED (21) 8,340,554 3.429 99.11 78.69 [75.32, 81.89] 44.02 0.8537 0.7233 0.1991 103 / 131 / 2 / 388
Consistency_Lambda_0.20 sssm / 2 / T / WRS / ce / 0.20 CONVERGED (14) 8,340,554 3.429 98.82 82.69 [79.65, 85.58] 54.27 0.8781 0.8867 0.1499 127 / 107 / 1 / 389

7. Forensic Audit Comparison: Legacy / Invalidated Claims vs. Verified Clean Results

Artifact / Claim Prior Unaudited / Invalid Value Root Defect Identified During Audit Verified Clean Status / Replacement
1_sota_benchmarks_master.csv (v2/) 96.47% Acc / 97.22% F1 / 99.37% AUC (No Bio-Prior = 93.43%) Hardcoded directly inside build_revised_deliverables.py; 0 backing scripts or checkpoints Retired. Canonical Aug-12 KD Student on official N=624 test is 87.50% (0.9087 F1, 0.9391 AUC; No Bio-Prior 82.37%)
Sep-4 10-Fold CV (4_10_fold_cross_validation_metrics.csv) 99.37% ± 0.33% (512-d, 3 blocks) StratifiedKFold on image paths leaked same patient across train & val folds; checkpoint shape incompatible with 256-d Student Retired. Replaced by clean patient/MD5-grouped 5-fold CV (256-d, L=2): 99.35% ± 0.26% (0 overlap, N=5,232 OOF)
remaining_ablations_results.csv MHSA 79.65%, L1 75.32%, NoSkip 63.46%, λ=0.2/0.5/1.0 76.1%/66.5%/58.0% All 6 collapsed to 100%-Pneumonia at t=0.50 (62.5%), rescued via test-set Youden threshold tuning + CLASS_WEIGHTS+WRS collision + thop buffer pollution Re-run cleanly (Priority 4 Fold 0 @ fixed t=0.50): all 11 converged (MHSA 83.01%, L1 80.61%, NoSkip 84.62%, λ=0.01/0.05/0.20 = 81.41%/78.69%/82.69%)
2_table1 / 3_table2 / 4_table3 (v2/) Depthwise Conv 91.2%, Element-Wise Sum 94.15%, d_state=16/32, E=1/4, Focal 94.07% Unimplemented modules & hardcoded rows in build_revised_deliverables.py Removed. Replaced strictly by real Priority 1 & Priority 4 experimental tables (Focal γ=2 = 82.69%, WeightedCE = 85.90%)
multi_dataset_benchmark_tracker.xlsx FigShare Brain MRI 99.35%, Br35H 99.7% Unexecuted spreadsheet rows marked Pending Run / TBD_*.pt Removed. Strictly scoped to Kermany Chest X-Ray (5,856 images) only
unknownBrain/bestweightsforallmodels Assumed Chest X-Ray weights Probed shape (15, 1280) — 15-class unrelated model Excluded. Never mixed with BioHCL-SSSM
Code security & canonical class Exposed W&B key in extracted_code.py; 3 divergent BioHCLSSSM definitions Hardcoded token leak & 49 vs 64 token / return-tuple mismatch Resolved. 0 secrets across repo; ONE canonical BioHCLSSSM (src/models/biohcl_sssm.py)

8. Mandatory Scientific Disclosures (D1–D7 & Audit Conditions)

  1. D1 — Single-Fold Limitation (Priority 4): All Priority 4 ablation results originate from a single patient-grouped Fold 0 split (4,218 train, 1,014 val, 624 test; --seed 42 shared across variants for controlled initialization). No multi-fold paired significance testing was performed on ablation rankings, which may vary across folds.
  2. D2 — SSSM vs. Tuned 8-Head MHSA: On Fold 0 without KD, SSSM_L2_Ref (82.69%, AUC=0.9588) and MHSA_L2_8Heads (83.01%, AUC=0.9482) overlap substantially in 95% CIs ([79.65, 85.58] vs. [79.97, 85.90]). No superiority of SSSM over MHSA is claimed on Fold 0 alone.
  3. D3 — Counterintuitive Depth & Skip Outcomes: On Fold 0 without KD, Depth_SSSM_L4 (85.26%, AUC=0.9708) and Ablation_NoSkip_L2 (84.62%, AUC=0.9759) outperformed SSSM_L2_Ref (82.69%, AUC=0.9588). Reported candidly as single-fold findings warranting future multi-fold KD sweeps.
  4. D4 — Class-Imbalance Strategy Impact: Loss_WeightedCE_Uniform achieved the highest Fold-0 test accuracy (85.90%, F1=0.8981, Spec=63.25%) compared with WeightedRandomSampler + CE (82.69%) and Focal γ=2 (82.69%, Rec=100.0%).
  5. D5 — Batch Feature-Consistency Regularizer (λ_phys): Introducing λ_phys > 0 preserved high internal validation accuracy (98.8%–99.1%) while monotonically collapsing batch feature dispersion (train_phys 17.5 -> 0.6) and degrading external test ROC-AUC by up to 23.6 points (0.9588 -> 0.7233 at λ=0.05, partially basin-shifting to 0.8867 at λ=0.20). This proves batch-structure overfitting and justifies λ_phys = 0.0 in all clean models.
  6. D6 — ResidualConnector Ghost Parameters: Both SSSM_L2_Ref and Ablation_NoSkip_L2 contain 8,340,554 trainable parameters (132,608 from ResidualConnector projection/norm modules unused inside forward()), keeping NoSkip parameter-neutral.
  7. D7 — Clinical Operating Point & Population Scope: High Pneumonia sensitivity (≥ 90%) comes with moderate specificity (44%–73.5%) at uncalibrated t = 0.50 due to train/test prevalence shift (74.2% -> 62.5%) in this pediatric cohort (ages 1–5). Threshold calibration must be performed on a dedicated validation subset, never test/.