Skip to content

Model — Mamba SSM classifier

Why a state-space model

ECG windows are long sequences with local morphology (QRS width) and longer rhythm context. Mamba-style selective SSMs give linear-time sequence modeling with input-dependent gating: keep the sharp QRS complex, decay flat baseline. Cheaper than attention at 360 Hz, stronger than plain CNN/LSTM baselines.

Design (planned)

  • Input: per-branch per-step features (dim D, length T) — signal branch or scalogram branch, see architecture.md.
  • Core: stacked Mamba blocks (norm → selective SSM → residual, x L layers).
  • Head: temporal pooling (mean + max concat) → linear → 5 logits.
  • Fusion (Approach A primary): one such model per branch; fuse by averaging the two logit vectors, then per-class thresholds. Learned per-class gate only if averaging underperforms.
  • Pure PyTorch implementation first; mamba-ssm package only if needed later. Keeps CPU and Intel Arc runs simple.

Loss

  • Default: BCEWithLogitsLoss (multi-label head), pos-weighted for imbalance.
  • If single-label-per-beat is confirmed: cross-entropy with class weights. The head shape stays 5 logits either way; only loss + decision rule change.

Metrics (per class + macro)

  • F1 per class, macro F1 (primary), sensitivity/recall on V (safety metric).
  • Confusion matrix on beats; precision-recall curves for threshold tuning.
  • Report DS2 test split only; validation split carved from DS1.

Baselines (to beat)

  1. 1D-CNN on raw signal.
  2. CNN + LSTM.
  3. Mamba SSM (this model) — must beat both on macro F1 and V recall.

Risks

  • Q and F are rare; expect near-zero F1 without weighting. Acceptable if N/V/S hold.
  • Inter-patient generalization is the hard part; patient-wise splits are non-negotiable.