diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S002/data.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S002/data.py new file mode 100644 index 0000000000000000000000000000000000000000..e3cf61f3b1ac4d22858c6e6f387024abd27d953d --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S002/data.py @@ -0,0 +1,33 @@ +import json +from functools import lru_cache +from pathlib import Path +import numpy as np +import torch +@lru_cache(maxsize=8) +def array(path):return np.load(path,mmap_mode='r',allow_pickle=False) +class Dataset(torch.utils.data.Dataset): + def __init__(self,root,limit=None,cache=False): + self.root=Path(root) + self.rows=json.loads((self.root/'manifest.json').read_text())['samples'] + if limit:self.rows=self.rows[:limit] + self.cached=None + if cache and self.rows: + from collections import defaultdict + groups=defaultdict(list) + for i,r in enumerate(self.rows):groups[r['path']].append((i,r['index'])) + for name,indices in groups.items(): + path=(self.root/name).resolve() + if not path.is_relative_to(self.root.resolve()):raise ValueError('input outside root') + source=np.load(path,mmap_mode='r',allow_pickle=False) + if self.cached is None:self.cached=torch.empty((len(self.rows),*source.shape[1:]),dtype=torch.float32) + dst,src=zip(*indices) + self.cached[list(dst)]=torch.as_tensor(source[list(src)]/100,dtype=torch.float32) + def __len__(self):return len(self.rows) + def __getitem__(self,i): + r=self.rows[i] + if self.cached is not None:return self.cached[i],r.get('label',-1),r['id'] + p=(self.root/r['path']).resolve() + if not p.is_relative_to(self.root.resolve()):raise ValueError('input outside root') + # Division precedes float32 conversion, matching official FACED/TUEV collate. + x=np.asarray(array(str(p))[r['index']])/100 + return torch.as_tensor(x,dtype=torch.float32),r.get('label',-1),r['id'] diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S002/infer.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S002/infer.py new file mode 100644 index 0000000000000000000000000000000000000000..acc9f5ca2f481bee8e9ee0f575bb853985a0be71 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S002/infer.py @@ -0,0 +1,24 @@ +import argparse,json +from pathlib import Path +import numpy as np +import torch +from model import SharedSpectral,SPECS +from data import Dataset + +def main(): + ap=argparse.ArgumentParser();ap.add_argument('input',type=Path);ap.add_argument('output',type=Path);a=ap.parse_args() + root=Path(__file__).resolve().parent + cfg=json.loads((root/'config.json').read_text()) + track=json.loads((a.input/'manifest.json').read_text())['track'] + if track not in SPECS: raise ValueError('Unknown track') + torch.set_num_threads(4) + device='cuda' if torch.cuda.is_available() else 'cpu' + model=SharedSpectral(**cfg['architecture']).to(device) + model.load_state_dict(torch.load(root/'weights.pt',map_location=device,weights_only=True),strict=True) + model.eval();a.output.mkdir(parents=True,exist_ok=True) + loader=torch.utils.data.DataLoader(Dataset(a.input),batch_size=128,num_workers=0,shuffle=False) + with torch.inference_mode(),(a.output/'predictions.jsonl').open('w') as f: + for x,_,ids in loader: + p=model(track,x.to(device)).softmax(-1).cpu().numpy() + for sid,pp in zip(ids,p):f.write(json.dumps({'id':sid,'probabilities':pp.tolist()})+'\n') +if __name__=='__main__':main() diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S002/training.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S002/training.json new file mode 100644 index 0000000000000000000000000000000000000000..f8ebff37345032624fd35450370a179502ad5c53 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S002/training.json @@ -0,0 +1,844 @@ +{ + "settings": { + "output": "/workspace/research/runs/spectral1", + "seed": 42, + "epochs": 30, + "steps": 500, + "batch_size": 128, + "lr": 0.0005, + "width": 256, + "depth": 3, + "dropout": 0.35, + "weight_decay": 0.05, + "mixup": 0.0, + "init": null + }, + "shared_backbone": "backbone", + "all_tracks_update_shared_backbone": true, + "normalization_fit_split": "train", + "parameters": 14112534, + "history": [ + { + "epoch": 1, + "updates_by_track": 100, + "losses": { + "faced": 1.837755205631256, + "tuev": 0.4842070505023003, + "ad65": 0.21590098470449448, + "openbmi": 0.5858061927556991, + "longitudinal": 0.42181126683950426 + }, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 257, + 245, + 165, + 195, + 119, + 133, + 193, + 53, + 320 + ], + "confusion_matrix": [ + [ + 48, + 17, + 14, + 22, + 14, + 11, + 25, + 5, + 24 + ], + [ + 18, + 62, + 10, + 24, + 12, + 9, + 18, + 4, + 23 + ], + [ + 28, + 19, + 32, + 12, + 11, + 19, + 27, + 4, + 28 + ], + [ + 22, + 24, + 23, + 36, + 15, + 4, + 16, + 8, + 32 + ], + [ + 38, + 38, + 25, + 45, + 20, + 15, + 17, + 2, + 40 + ], + [ + 18, + 15, + 17, + 15, + 12, + 34, + 20, + 13, + 36 + ], + [ + 26, + 25, + 18, + 16, + 14, + 14, + 34, + 3, + 30 + ], + [ + 22, + 27, + 11, + 23, + 11, + 19, + 22, + 11, + 34 + ], + [ + 37, + 18, + 15, + 2, + 10, + 8, + 14, + 3, + 73 + ] + ], + "per_class_recall": [ + 0.26666666666666666, + 0.34444444444444444, + 0.17777777777777778, + 0.2, + 0.08333333333333333, + 0.18888888888888888, + 0.18888888888888888, + 0.06111111111111111, + 0.40555555555555556 + ], + "balanced_accuracy": 0.21296296296296294, + "accuracy": 0.20833333333333334, + "weighted_f1": 0.19537403895666947, + "macro_f1": 0.19848342511012498, + "kappa": 0.11081397292328254, + "samples": 1680, + "reward": 0.21296296296296294, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 224, + 539, + 102, + 356, + 2505, + 11761 + ], + "confusion_matrix": [ + [ + 19, + 29, + 26, + 0, + 9, + 36 + ], + [ + 0, + 12, + 0, + 0, + 279, + 0 + ], + [ + 7, + 65, + 10, + 0, + 581, + 6 + ], + [ + 0, + 36, + 0, + 35, + 0, + 15 + ], + [ + 0, + 1, + 0, + 1, + 468, + 30 + ], + [ + 198, + 396, + 66, + 320, + 1168, + 11674 + ] + ], + "per_class_recall": [ + 0.15966386554621848, + 0.041237113402061855, + 0.014947683109118086, + 0.4069767441860465, + 0.936, + 0.8445955722760816 + ], + "balanced_accuracy": 0.4005701630865877, + "accuracy": 0.7889197391360496, + "weighted_f1": 0.8279708978381558, + "macro_f1": 0.2580220626735159, + "kappa": 0.3316723247964325, + "samples": 15487, + "reward": 0.4005701630865877, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 544, + 346, + 453 + ], + "confusion_matrix": [ + [ + 274, + 145, + 45 + ], + [ + 145, + 172, + 76 + ], + [ + 125, + 29, + 332 + ] + ], + "per_class_recall": [ + 0.5905172413793104, + 0.43765903307888043, + 0.6831275720164609 + ], + "balanced_accuracy": 0.5704346154915506, + "accuracy": 0.5793000744601638, + "weighted_f1": 0.5799410326020693, + "macro_f1": 0.5720933182023854, + "kappa": 0.3650766423143895, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 8, + 5, + 5 + ], + "confusion_matrix": [ + [ + 4, + 3, + 0 + ], + [ + 2, + 2, + 1 + ], + [ + 2, + 0, + 4 + ] + ], + "per_class_recall": [ + 0.5714285714285714, + 0.4, + 0.6666666666666666 + ], + "balanced_accuracy": 0.546031746031746, + "accuracy": 0.5555555555555556, + "weighted_f1": 0.560942760942761, + "macro_f1": 0.5535353535353535, + "kappa": 0.3239436619718309 + }, + "reward": 0.546031746031746, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 1443, + 2957 + ], + "confusion_matrix": [ + [ + 964, + 1236 + ], + [ + 479, + 1721 + ] + ], + "per_class_recall": [ + 0.4381818181818182, + 0.7822727272727272 + ], + "balanced_accuracy": 0.6102272727272727, + "accuracy": 0.6102272727272727, + "weighted_f1": 0.5983382295509261, + "macro_f1": 0.5983382295509261, + "kappa": 0.22045454545454546, + "samples": 4400, + "subject_scores": { + "19": 0.6950000000000001, + "35": 0.545, + "34": 0.5349999999999999, + "51": 0.6675, + "20": 0.6525, + "44": 0.7375, + "24": 0.5549999999999999, + "15": 0.5325, + "31": 0.68, + "26": 0.5525, + "23": 0.56 + }, + "reward": 0.6102272727272727, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4602, + 3816 + ], + "confusion_matrix": [ + [ + 3652, + 608 + ], + [ + 950, + 3208 + ] + ], + "per_class_recall": [ + 0.8572769953051643, + 0.7715247715247715 + ], + "balanced_accuracy": 0.8144008834149679, + "accuracy": 0.814920408648135, + "weighted_f1": 0.8145227049484558, + "macro_f1": 0.814404091564341, + "kappa": 0.6294215557528924, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8322374249306739, + "sub-G2007": 0.7939135582111965, + "sub-G2019": 0.8546280166979509, + "sub-G2031": 0.7822427227936398, + "sub-G2015": 0.8509791437797529, + "sub-CTR002": 0.8928359222476869, + "sub-G2011": 0.7801365675763949, + "sub-G2035": 0.9022323249571733, + "sub-CTR003": 0.46374458874458874 + }, + "reward": 0.7947722522154508, + "subjects": 9 + } + }, + "seconds": 8.115101099014282 + }, + { + "epoch": 2, + "updates_by_track": 200, + "losses": { + "faced": 1.3197942888736724, + "tuev": 0.35953703671693804, + "ad65": 0.17408071279525758, + "openbmi": 0.4457417243719101, + "longitudinal": 0.32790970653295515 + }, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 175, + 179, + 184, + 261, + 229, + 121, + 161, + 124, + 246 + ], + "confusion_matrix": [ + [ + 30, + 12, + 14, + 28, + 25, + 8, + 27, + 8, + 28 + ], + [ + 9, + 57, + 9, + 28, + 28, + 5, + 18, + 13, + 13 + ], + [ + 24, + 15, + 34, + 26, + 13, + 16, + 15, + 12, + 25 + ], + [ + 12, + 15, + 29, + 44, + 29, + 2, + 14, + 12, + 23 + ], + [ + 15, + 25, + 28, + 49, + 50, + 15, + 16, + 12, + 30 + ], + [ + 15, + 7, + 20, + 17, + 22, + 43, + 12, + 20, + 24 + ], + [ + 26, + 15, + 15, + 28, + 20, + 11, + 32, + 15, + 18 + ], + [ + 19, + 22, + 18, + 25, + 25, + 15, + 15, + 19, + 22 + ], + [ + 25, + 11, + 17, + 16, + 17, + 6, + 12, + 13, + 63 + ] + ], + "per_class_recall": [ + 0.16666666666666666, + 0.31666666666666665, + 0.18888888888888888, + 0.24444444444444444, + 0.20833333333333334, + 0.2388888888888889, + 0.17777777777777778, + 0.10555555555555556, + 0.35 + ], + "balanced_accuracy": 0.22191358024691357, + "accuracy": 0.22142857142857142, + "weighted_f1": 0.21979152243904798, + "macro_f1": 0.22003492637365382, + "kappa": 0.12321945847597604, + "samples": 1680, + "reward": 0.22191358024691357, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 113, + 573, + 83, + 202, + 2202, + 12314 + ], + "confusion_matrix": [ + [ + 0, + 37, + 27, + 0, + 22, + 33 + ], + [ + 0, + 12, + 0, + 0, + 279, + 0 + ], + [ + 3, + 104, + 12, + 0, + 527, + 23 + ], + [ + 0, + 24, + 0, + 51, + 0, + 11 + ], + [ + 0, + 0, + 0, + 1, + 468, + 31 + ], + [ + 110, + 396, + 44, + 150, + 906, + 12216 + ] + ], + "per_class_recall": [ + 0.0, + 0.041237113402061855, + 0.017937219730941704, + 0.5930232558139535, + 0.936, + 0.8838084213572566 + ], + "balanced_accuracy": 0.412001001717369, + "accuracy": 0.8238522631884807, + "weighted_f1": 0.849353580581419, + "macro_f1": 0.2825119959741656, + "kappa": 0.38132710505585, + "samples": 15487, + "reward": 0.412001001717369, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 536, + 352, + 455 + ], + "confusion_matrix": [ + [ + 279, + 150, + 35 + ], + [ + 152, + 170, + 71 + ], + [ + 105, + 32, + 349 + ] + ], + "per_class_recall": [ + 0.6012931034482759, + 0.43256997455470736, + 0.7181069958847737 + ], + "balanced_accuracy": 0.5839900246292523, + "accuracy": 0.5941921072226359, + "weighted_f1": 0.5947617631793346, + "macro_f1": 0.5853799732304393, + "kappa": 0.38774750539323577, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 6, + 6, + 6 + ], + "confusion_matrix": [ + [ + 3, + 4, + 0 + ], + [ + 2, + 2, + 1 + ], + [ + 1, + 0, + 5 + ] + ], + "per_class_recall": [ + 0.42857142857142855, + 0.4, + 0.8333333333333334 + ], + "balanced_accuracy": 0.5539682539682539, + "accuracy": 0.5555555555555556, + "weighted_f1": 0.5582750582750583, + "macro_f1": 0.5528360528360529, + "kappa": 0.33333333333333337 + }, + "reward": 0.5539682539682539, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2332, + 2068 + ], + "confusion_matrix": [ + [ + 1461, + 739 + ], + [ + 871, + 1329 + ] + ], + "per_class_recall": [ + 0.6640909090909091, + 0.6040909090909091 + ], + "balanced_accuracy": 0.634090909090909, + "accuracy": 0.634090909090909, + "weighted_f1": 0.6337612942557392, + "macro_f1": 0.6337612942557392, + "kappa": 0.2681818181818182, + "samples": 4400, + "subject_scores": { + "19": 0.7124999999999999, + "35": 0.55, + "34": 0.5425, + "51": 0.6525, + "20": 0.6875, + "44": 0.865, + "24": 0.57, + "15": 0.52, + "31": 0.685, + "26": 0.54, + "23": 0.65 + }, + "reward": 0.6340909090909091, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4743, + 3675 + ], + "confusion_matrix": [ + [ + 3660, + 600 + ], + [ + 1083, + 3075 + ] + ], + "per_class_recall": [ + 0.8591549295774648, + 0.7395382395382395 + ], + "balanced_accuracy": 0.7993465845578521, + "accuracy": 0.800071275837491, + "weighted_f1": 0.7992702199536446, + "macro_f1": 0.7991010528725839, + "kappa": 0.5995269115485379, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8247760032614722, + "sub-G2007": 0.6755647147391388, + "sub-G2019": 0.817720267605105, + "sub-G2031": 0.7768687400624462, + "sub-G2015": 0.887980417124405, + "sub-CTR002": 0.9382480264833206, + "sub-G2011": 0.7719037383413225, + "sub-G2035": 0.926835468058191, + "sub-CTR003": 0.5305735930735931 + }, + "reward": 0.7944967743054439, + "subjects": 9 + } + }, + "seconds": 9.67720913887024 + } + ] +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S010/covariances.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S010/covariances.py new file mode 100644 index 0000000000000000000000000000000000000000..a65153f3b18f31995ff206a8e2fb8a7fd7a254dd --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S010/covariances.py @@ -0,0 +1,25 @@ +"""Shared neural filter-bank covariance decoder with spatial input adapters.""" +import torch +from torch import nn +SPECS={'faced':(32,10,9),'tuev':(16,5,6),'ad65':(19,10,3),'openbmi':(62,4,2),'longitudinal':(58,2,2)} +TRACKS=tuple(SPECS) +BANDS=[(1,4),(4,8),(8,12),(12,16),(16,20),(20,24),(24,28),(28,32),(32,40),(40,48)] + +@torch.no_grad() +def extract_covariances(t,x): + x=torch.nan_to_num(x.float().flatten(2)).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if t in ('faced','tuev'): + x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + else:x=x-x.mean(1,keepdim=True) + # Per-window normalization, preserving spatial and frequency power ratios. + x=x/x.square().mean((1,2),keepdim=True).clamp_min(1e-12).sqrt() + frames=x.unfold(-1,400,200);frames=frames-frames.mean(-1,keepdim=True) + z=torch.fft.rfft(frames*torch.hann_window(400,device=x.device),dim=-1)/200 + covs=[] + for lo,hi in BANDS: + v=z[...,2*lo:2*hi].flatten(2) + cov=(v.real@v.real.transpose(-1,-2)+v.imag@v.imag.transpose(-1,-2))/v.shape[-1] + covs.append(cov) + return torch.stack(covs,1) + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S010/data.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S010/data.py new file mode 100644 index 0000000000000000000000000000000000000000..e3cf61f3b1ac4d22858c6e6f387024abd27d953d --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S010/data.py @@ -0,0 +1,33 @@ +import json +from functools import lru_cache +from pathlib import Path +import numpy as np +import torch +@lru_cache(maxsize=8) +def array(path):return np.load(path,mmap_mode='r',allow_pickle=False) +class Dataset(torch.utils.data.Dataset): + def __init__(self,root,limit=None,cache=False): + self.root=Path(root) + self.rows=json.loads((self.root/'manifest.json').read_text())['samples'] + if limit:self.rows=self.rows[:limit] + self.cached=None + if cache and self.rows: + from collections import defaultdict + groups=defaultdict(list) + for i,r in enumerate(self.rows):groups[r['path']].append((i,r['index'])) + for name,indices in groups.items(): + path=(self.root/name).resolve() + if not path.is_relative_to(self.root.resolve()):raise ValueError('input outside root') + source=np.load(path,mmap_mode='r',allow_pickle=False) + if self.cached is None:self.cached=torch.empty((len(self.rows),*source.shape[1:]),dtype=torch.float32) + dst,src=zip(*indices) + self.cached[list(dst)]=torch.as_tensor(source[list(src)]/100,dtype=torch.float32) + def __len__(self):return len(self.rows) + def __getitem__(self,i): + r=self.rows[i] + if self.cached is not None:return self.cached[i],r.get('label',-1),r['id'] + p=(self.root/r['path']).resolve() + if not p.is_relative_to(self.root.resolve()):raise ValueError('input outside root') + # Division precedes float32 conversion, matching official FACED/TUEV collate. + x=np.asarray(array(str(p))[r['index']])/100 + return torch.as_tensor(x,dtype=torch.float32),r.get('label',-1),r['id'] diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S010/features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S010/features.py new file mode 100644 index 0000000000000000000000000000000000000000..88f7e8b14c9fab44733d5224ede6d6b5c7f76a45 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S010/features.py @@ -0,0 +1,63 @@ +"""One shared residual backbone, five linear input adapters and output heads.""" +import torch +from torch import nn + +SPECS = {'faced': (32, 10, 9), 'tuev': (16, 5, 6), 'ad65': (19, 10, 3), + 'openbmi': (62, 4, 2), 'longitudinal': (58, 2, 2)} +TRACKS = tuple(SPECS) +EDGES = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,18,20,22,25,28,32,36,40,45,50,60,70,80,95] +COV_BANDS = [(1,4),(4,8),(8,12),(12,16),(16,20),(20,28),(28,40)] + +def feature_dim(channels): + return channels * (4*(len(EDGES)-1)+4) + len(COV_BANDS)*channels*(channels-1)//2 + +@torch.no_grad() +def extract_features(track, x): + """Fixed features; no batch statistics or fitted inference transformations.""" + x = x.float().flatten(2) + x = torch.nan_to_num(x, nan=0., posinf=1e5, neginf=-1e5).clamp(-1e5,1e5) + x = x - x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'): + x = x - x.mean(1,keepdim=True) + rms = x.square().mean(-1).clamp_min(1e-12).sqrt() + norm = x / rms.unsqueeze(-1) + moments = torch.stack([rms.log(), norm.abs().amax(-1).clamp_min(1).log(), + norm.pow(4).mean(-1).clamp_min(1).log(), + (norm[...,1:]-norm[...,:-1]).square().mean(-1).clamp_min(1e-10).log()],-1) + frames = x.unfold(-1,400,200) + frames = frames - frames.mean(-1,keepdim=True) + window = torch.hann_window(400,device=x.device) + z = torch.fft.rfft(frames*window,dim=-1)/200 + power = z.abs().square() + bands = torch.stack([power[...,2*lo:2*hi].mean(-1) for lo,hi in zip(EDGES[:-1],EDGES[1:])],-1) + lp = bands.mean(-2).clamp_min(1e-12).log() + variation = bands.clamp_min(1e-12).log().std(-2,correction=0) + relative_frequency = lp - lp.mean(-1,keepdim=True) + relative_channel = lp - lp.mean(1,keepdim=True) + parts = [torch.cat([lp, relative_frequency, relative_channel, variation, moments],-1).flatten(1)] + ii,jj = torch.triu_indices(x.shape[1],x.shape[1],offset=1,device=x.device) + for lo,hi in COV_BANDS: + v = z[...,2*lo:2*hi].flatten(2) + cov = v.real @ v.real.transpose(-1,-2) + v.imag @ v.imag.transpose(-1,-2) + d = cov.diagonal(dim1=-2,dim2=-1).clamp_min(1e-12).sqrt() + cor = cov / (d.unsqueeze(1)*d.unsqueeze(2)).clamp_min(1e-12) + parts.append(cor[:,ii,jj].clamp(-1,1)) + result = torch.cat(parts,-1) + return torch.nan_to_num(result).clamp(-40,40) + +class Standardize(nn.Module): + def __init__(self, dim): + super().__init__() + self.register_buffer('mean',torch.zeros(dim)) + self.register_buffer('scale',torch.ones(dim)) + def forward(self,x): + return ((x-self.mean)/self.scale).clamp(-8,8) + +class Residual(nn.Module): + def __init__(self,width,dropout): + super().__init__() + self.net=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(), + nn.Dropout(dropout),nn.Linear(width*2,width),nn.Dropout(dropout)) + def forward(self,x): + return x+self.net(x) + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S010/infer.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S010/infer.py new file mode 100644 index 0000000000000000000000000000000000000000..aecb1722284d7707ed4097a3308cb15f870b6826 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S010/infer.py @@ -0,0 +1,24 @@ +import argparse,json +from pathlib import Path +import torch +from model import HybridModel,SPECS +from data import Dataset +from covariances import extract_covariances +p=argparse.ArgumentParser();p.add_argument('input',type=Path);p.add_argument('output',type=Path);a=p.parse_args() +root=Path(__file__).resolve().parent;c=json.loads((root/'config.json').read_text());t=json.loads((a.input/'manifest.json').read_text())['track'] +if t not in SPECS:raise ValueError('unknown track') +torch.set_num_threads(4);device='cuda' if torch.cuda.is_available() else 'cpu' +m=HybridModel(**c['architecture']).to(device);m.load_state_dict(torch.load(root/'weights.pt',map_location=device,weights_only=True));m.eval() +a.output.mkdir(parents=True,exist_ok=True) +with torch.inference_mode(),(a.output/'predictions.jsonl').open('w') as f: + for x,_,ids in torch.utils.data.DataLoader(Dataset(a.input),batch_size=64,num_workers=0): + # FFT features stay float32; convolutions can use bfloat16 on CUDA. + x=x.to(device) + from features import extract_features + torch.backends.cuda.matmul.allow_tf32=False + features=extract_features(t,x) + covariances=extract_covariances(t,x) + torch.backends.cuda.matmul.allow_tf32=True + with torch.autocast(device,dtype=torch.bfloat16,enabled=device=='cuda'):pred=m(t,x,features,covariances=covariances) + pp=pred.float().softmax(-1).cpu().numpy() + for sid,pr in zip(ids,pp):f.write(json.dumps({'id':sid,'probabilities':pr.tolist()})+'\n') diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S010/infer.sh b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S010/infer.sh new file mode 100644 index 0000000000000000000000000000000000000000..3aae9b42834f2f278e52148d5a07835d9960a4ea --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S010/infer.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -euo pipefail +exec python "$(dirname -- "$0")/infer.py" "$1" "$2" diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S010/model.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S010/model.py new file mode 100644 index 0000000000000000000000000000000000000000..6ae9ac268c5473a467a16cf87aaf26a94519d302 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S010/model.py @@ -0,0 +1,103 @@ +"""One fused waveform/spectral backbone used identically by all five tasks.""" +import torch +from torch import nn +from braindecode.models import BIOT +from features import SPECS,TRACKS,feature_dim,extract_features,Standardize,Residual +from covariances import BANDS,extract_covariances + +class InputAdapter(nn.Module): + def __init__(self,c,width,channels,spectral_enabled=True): + super().__init__() + self.signal=nn.Conv1d(c,channels,1,bias=False) + self.neural=nn.Conv1d(c,18,1,bias=False) + self.normalizer=Standardize(feature_dim(c)) + self.spectral=nn.Linear(feature_dim(c),width) + self.dropout=nn.Dropout(.1) + self.register_buffer("spectral_enabled",torch.tensor(float(spectral_enabled))) + self.spatial_weight=nn.Parameter(torch.randn(len(BANDS),24,c)/c**.5) + def spatial_features(self,covariances): + with torch.autocast(covariances.device.type,enabled=False): + w=self.spatial_weight.float()/self.spatial_weight.float().norm(dim=-1,keepdim=True).clamp_min(1e-6) + power=torch.einsum('bfc,nbcd,bfd->nbf',w,covariances.float(),w).clamp_min(1e-8).log() + return torch.cat([power,power-power.mean(1,keepdim=True)],1).flatten(1) + def forward(self,x,features,covariance_features): + return self.signal(x).unsqueeze(1),self.spectral_enabled*self.spectral(self.dropout(self.normalizer(features))),self.neural(x),covariance_features + +class SharedBackbone(nn.Module): + def __init__(self,channels,width,depth,dropout,wave_filters): + super().__init__() + self.waveform=nn.Sequential( + nn.Conv2d(1,wave_filters,(1,64),padding=(0,32),bias=False),nn.GroupNorm(1,wave_filters), + nn.Conv2d(wave_filters,2*wave_filters,(channels,1),groups=wave_filters,bias=False),nn.GroupNorm(1,2*wave_filters),nn.ELU(), + nn.AvgPool2d((1,4)),nn.Dropout(.35), + nn.Conv2d(2*wave_filters,2*wave_filters,(1,16),padding=(0,8),groups=2*wave_filters,bias=False),nn.Conv2d(2*wave_filters,2*wave_filters,1,bias=False), + nn.GroupNorm(1,2*wave_filters),nn.ELU(),nn.AvgPool2d((1,8)),nn.Dropout(.35)) + self.wave_summary=nn.Sequential(nn.AdaptiveAvgPool2d((1,8)),nn.Flatten(),nn.Linear(2*wave_filters*8,width)) + self.fusion=nn.Sequential(nn.LayerNorm(width),nn.GELU(),nn.Dropout(dropout), + *[Residual(width,dropout) for _ in range(depth)],nn.LayerNorm(width)) + # Both representations interact before the shared residual stack. + self.wave_gain=nn.Parameter(torch.tensor(.1)) + self.biot=BIOT(n_chans=18,n_outputs=2,n_times=400,sfreq=200) + self.biot.final_layer=nn.Identity() + self.biot_projection=nn.Sequential(nn.LayerNorm(256),nn.Linear(256,width),nn.Dropout(.2)) + nn.init.normal_(self.biot_projection[1].weight,std=.001);nn.init.zeros_(self.biot_projection[1].bias) + self.covariance_encoder=nn.Sequential(nn.LayerNorm(len(BANDS)*24*2),nn.Linear(len(BANDS)*24*2,width),nn.GELU(),nn.Dropout(.4), + *[Residual(width,.4) for _ in range(2)],nn.LayerNorm(width)) + self.covariance_projection=nn.Linear(width,width) + nn.init.zeros_(self.covariance_projection.weight);nn.init.zeros_(self.covariance_projection.bias) + def forward(self,signal,spectral,neural_signal,covariance_features): + wave=self.waveform(signal) + neural=self.biot(neural_signal.float()) + neural=self.biot_projection[0](neural) + projected=self.biot_projection[2](self.biot_projection[1](neural)) + with torch.autocast(signal.device.type,enabled=False): + covariance_embedding=self.covariance_encoder(covariance_features.float()) + original=spectral+self.wave_gain*self.wave_summary(wave)+.01*projected + coupled=.001*self.covariance_projection(covariance_embedding).to(original.dtype) + fused=self.fusion(original+coupled) + return torch.cat([wave.flatten(1),fused,neural,covariance_embedding],-1) + +class HybridModel(nn.Module): + def __init__(self,channels=32,width=128,depth=2,dropout=.5,wave_filters=32): + super().__init__() + self.adapters=nn.ModuleDict({t:InputAdapter(c,width,channels,spectral_enabled=t not in ("faced","tuev","openbmi")) for t,(c,s,k) in SPECS.items()}) + self.backbone=SharedBackbone(channels,width,depth,dropout,wave_filters) + self.heads=nn.ModuleDict({t:nn.Linear(2*wave_filters*(((s*200+1)//4+1)//8)+width+256+width,k) for t,(c,s,k) in SPECS.items()}) + def forward(self,t,x,features=None,covariances=None,covariance_features=None): + if features is None:features=extract_features(t,x) + if covariance_features is None: + if covariances is None:covariances=extract_covariances(t,x) + covariance_features=self.adapters[t].spatial_features(covariances) + signal=x.flatten(2);signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + adapted=self.adapters[t](signal,features,covariance_features) + representation=self.backbone(*adapted) + if t in ('faced','openbmi'): + representation=torch.cat([representation[:,:-384],torch.zeros_like(representation[:,-384:-128]),representation[:,-128:]],-1) + if t=='ad65': + with torch.autocast(x.device.type,enabled=False):return self.heads[t](representation.float()) + # This is one linear head, evaluated in feature blocks so appending + # zero-weight columns preserves the prior bfloat16 GEMM dimensions. + head=self.heads[t] + prior=nn.functional.linear(representation[:,:-128].contiguous(),head.weight[:,:-128].contiguous(),head.bias) + added=nn.functional.linear(representation[:,-128:].contiguous(),head.weight[:,-128:].contiguous()) + return prior+added + +def widen_state_dict(state,multiplier=2): + """Duplicate temporal features and divide downstream sums to preserve outputs.""" + result={} + for key,value in state.items(): + if key.startswith('backbone.waveform.'): + layer=int(key.split('.')[2]) + if layer in (0,2,7):value=value.repeat(multiplier,1,1,1) + elif layer in (1,3,9):value=value.repeat(multiplier) + elif layer==8:value=value.repeat(multiplier,multiplier,1,1)/multiplier + elif key=='backbone.wave_summary.2.weight':value=value.repeat(1,multiplier)/multiplier + elif key.startswith('heads.') and key.endswith('.weight'): + raw=value[:,:-128]/multiplier + value=torch.cat([raw]*multiplier+[value[:,-128:]],1) + result[key]=value + return result + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S010/training.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S010/training.json new file mode 100644 index 0000000000000000000000000000000000000000..fa249074355c8f4afd32f06b27c2f54d4fe8abaf --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S010/training.json @@ -0,0 +1,2097 @@ +{ + "settings": { + "source": "/workspace/research/runs/hybrid_biot_csp_bf16head/epoch-001", + "features": "/workspace/research/head_features_v1", + "incumbent": "/workspace/research/runs/head_refinement1/epoch-012", + "output": "/workspace/research/runs/head_dropout1", + "epochs": 30, + "steps": 200, + "batch_size": 256, + "lr": 1e-05, + "clinical_lr": 0.0001, + "retention": 2.0, + "dropout": 0.2, + "seed": 7 + }, + "history": [ + { + "epoch": 14, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 157, + 194, + 179, + 214, + 244, + 162, + 180, + 173, + 177 + ], + "confusion_matrix": [ + [ + 78, + 14, + 5, + 23, + 19, + 9, + 13, + 9, + 10 + ], + [ + 11, + 88, + 9, + 13, + 19, + 11, + 13, + 6, + 10 + ], + [ + 6, + 7, + 94, + 20, + 17, + 5, + 7, + 10, + 14 + ], + [ + 14, + 18, + 9, + 71, + 21, + 8, + 16, + 15, + 8 + ], + [ + 13, + 13, + 16, + 26, + 113, + 17, + 13, + 18, + 11 + ], + [ + 6, + 12, + 12, + 15, + 12, + 83, + 10, + 14, + 16 + ], + [ + 8, + 12, + 8, + 14, + 16, + 14, + 90, + 9, + 9 + ], + [ + 8, + 16, + 15, + 17, + 15, + 10, + 10, + 83, + 6 + ], + [ + 13, + 14, + 11, + 15, + 12, + 5, + 8, + 9, + 93 + ] + ], + "per_class_recall": [ + 0.43333333333333335, + 0.4888888888888889, + 0.5222222222222223, + 0.39444444444444443, + 0.4708333333333333, + 0.46111111111111114, + 0.5, + 0.46111111111111114, + 0.5166666666666667 + ], + "balanced_accuracy": 0.472067901234568, + "accuracy": 0.4720238095238095, + "weighted_f1": 0.4732298815998091, + "macro_f1": 0.47346276059386383, + "kappa": 0.40521122712903535, + "samples": 1680, + "reward": 0.472067901234568, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 995, + 658, + 146, + 706, + 1616, + 11366 + ], + "confusion_matrix": [ + [ + 42, + 38, + 18, + 4, + 0, + 17 + ], + [ + 0, + 185, + 0, + 78, + 28, + 0 + ], + [ + 110, + 127, + 128, + 61, + 243, + 0 + ], + [ + 6, + 0, + 0, + 79, + 0, + 1 + ], + [ + 2, + 0, + 0, + 25, + 420, + 53 + ], + [ + 835, + 308, + 0, + 459, + 925, + 11295 + ] + ], + "per_class_recall": [ + 0.35294117647058826, + 0.6357388316151202, + 0.19133034379671152, + 0.9186046511627907, + 0.84, + 0.8171755172912748 + ], + "balanced_accuracy": 0.6259650867227476, + "accuracy": 0.7844643894879576, + "weighted_f1": 0.8358334233956254, + "macro_f1": 0.3787874146773398, + "kappa": 0.36546485724249755, + "samples": 15487, + "reward": 0.6259650867227476, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2040, + 2360 + ], + "confusion_matrix": [ + [ + 1690, + 510 + ], + [ + 350, + 1850 + ] + ], + "per_class_recall": [ + 0.7681818181818182, + 0.8409090909090909 + ], + "balanced_accuracy": 0.8045454545454546, + "accuracy": 0.8045454545454546, + "weighted_f1": 0.8042866600463423, + "macro_f1": 0.8042866600463423, + "kappa": 0.6090909090909091, + "samples": 4400, + "subject_scores": { + "19": 0.8574999999999999, + "35": 0.9525, + "34": 0.6475, + "51": 0.75, + "20": 0.815, + "44": 0.935, + "24": 0.595, + "15": 0.8975, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.725 + }, + "reward": 0.8045454545454546, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4576, + 3842 + ], + "confusion_matrix": [ + [ + 3659, + 601 + ], + [ + 917, + 3241 + ] + ], + "per_class_recall": [ + 0.8589201877934273, + 0.7794612794612794 + ], + "balanced_accuracy": 0.8191907336273534, + "accuracy": 0.819672131147541, + "weighted_f1": 0.8193351694632243, + "macro_f1": 0.8192264033499321, + "kappa": 0.6389628187072087, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.837643455629449, + "sub-G2007": 0.7651266214233094, + "sub-G2019": 0.8242345047591977, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8446221994740171, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9564871486872261, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8163402301328146, + "subjects": 9 + } + }, + "selected_head_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 0, + "longitudinal": 14 + } + }, + { + "epoch": 16, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 157, + 194, + 179, + 214, + 244, + 162, + 180, + 173, + 177 + ], + "confusion_matrix": [ + [ + 78, + 14, + 5, + 23, + 19, + 9, + 13, + 9, + 10 + ], + [ + 11, + 88, + 9, + 13, + 19, + 11, + 13, + 6, + 10 + ], + [ + 6, + 7, + 94, + 20, + 17, + 5, + 7, + 10, + 14 + ], + [ + 14, + 18, + 9, + 71, + 21, + 8, + 16, + 15, + 8 + ], + [ + 13, + 13, + 16, + 26, + 113, + 17, + 13, + 18, + 11 + ], + [ + 6, + 12, + 12, + 15, + 12, + 83, + 10, + 14, + 16 + ], + [ + 8, + 12, + 8, + 14, + 16, + 14, + 90, + 9, + 9 + ], + [ + 8, + 16, + 15, + 17, + 15, + 10, + 10, + 83, + 6 + ], + [ + 13, + 14, + 11, + 15, + 12, + 5, + 8, + 9, + 93 + ] + ], + "per_class_recall": [ + 0.43333333333333335, + 0.4888888888888889, + 0.5222222222222223, + 0.39444444444444443, + 0.4708333333333333, + 0.46111111111111114, + 0.5, + 0.46111111111111114, + 0.5166666666666667 + ], + "balanced_accuracy": 0.472067901234568, + "accuracy": 0.4720238095238095, + "weighted_f1": 0.4732298815998091, + "macro_f1": 0.47346276059386383, + "kappa": 0.40521122712903535, + "samples": 1680, + "reward": 0.472067901234568, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 995, + 658, + 146, + 706, + 1616, + 11366 + ], + "confusion_matrix": [ + [ + 42, + 38, + 18, + 4, + 0, + 17 + ], + [ + 0, + 185, + 0, + 78, + 28, + 0 + ], + [ + 110, + 127, + 128, + 61, + 243, + 0 + ], + [ + 6, + 0, + 0, + 79, + 0, + 1 + ], + [ + 2, + 0, + 0, + 25, + 420, + 53 + ], + [ + 835, + 308, + 0, + 459, + 925, + 11295 + ] + ], + "per_class_recall": [ + 0.35294117647058826, + 0.6357388316151202, + 0.19133034379671152, + 0.9186046511627907, + 0.84, + 0.8171755172912748 + ], + "balanced_accuracy": 0.6259650867227476, + "accuracy": 0.7844643894879576, + "weighted_f1": 0.8358334233956254, + "macro_f1": 0.3787874146773398, + "kappa": 0.36546485724249755, + "samples": 15487, + "reward": 0.6259650867227476, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2040, + 2360 + ], + "confusion_matrix": [ + [ + 1690, + 510 + ], + [ + 350, + 1850 + ] + ], + "per_class_recall": [ + 0.7681818181818182, + 0.8409090909090909 + ], + "balanced_accuracy": 0.8045454545454546, + "accuracy": 0.8045454545454546, + "weighted_f1": 0.8042866600463423, + "macro_f1": 0.8042866600463423, + "kappa": 0.6090909090909091, + "samples": 4400, + "subject_scores": { + "19": 0.8574999999999999, + "35": 0.9525, + "34": 0.6475, + "51": 0.75, + "20": 0.815, + "44": 0.935, + "24": 0.595, + "15": 0.8975, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.725 + }, + "reward": 0.8045454545454546, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4574, + 3844 + ], + "confusion_matrix": [ + [ + 3658, + 602 + ], + [ + 916, + 3242 + ] + ], + "per_class_recall": [ + 0.8586854460093897, + 0.7797017797017797 + ], + "balanced_accuracy": 0.8191936128555847, + "accuracy": 0.819672131147541, + "weighted_f1": 0.8193389120476722, + "macro_f1": 0.819230668900581, + "kappa": 0.6389648996053923, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8368421735781668, + "sub-G2007": 0.7651266214233094, + "sub-G2019": 0.8242345047591977, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8446221994740171, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9573204820205594, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8163437913863759, + "subjects": 9 + } + }, + "selected_head_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 0, + "longitudinal": 16 + } + } + ], + "shared_backbone_training": "inherited joint training on all five training splits; frozen during final linear-head refinement", + "parent_training_receipt": { + "all_tracks_update_shared_backbone": true, + "parameters": 10427373, + "source_training_settings": { + "output": "/workspace/research/runs/hybrid_biot_csp_stable1", + "epochs": 30, + "steps": 100, + "batch_size": 64, + "seed": 7, + "hidden": 32, + "dropout": 0.5, + "lr": 1e-06, + "head_lr": 1e-07, + "weight_decay": 0.05, + "init": "/workspace/research/runs/hybrid_biot_fusionshrink0100/epoch-001/weights.pt", + "mixup": 0.0, + "clinical_lr": 0.0001, + "neural_lr": 1e-05, + "covariance_parent": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "ad_pool": 8 + }, + "parent_training_history": [ + { + "epoch": 1, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 157, + 190, + 178, + 212, + 242, + 166, + 182, + 175, + 178 + ], + "confusion_matrix": [ + [ + 77, + 14, + 5, + 22, + 19, + 9, + 14, + 10, + 10 + ], + [ + 12, + 86, + 9, + 13, + 19, + 11, + 14, + 6, + 10 + ], + [ + 6, + 7, + 93, + 20, + 17, + 5, + 7, + 10, + 15 + ], + [ + 14, + 18, + 9, + 71, + 21, + 8, + 16, + 15, + 8 + ], + [ + 13, + 13, + 17, + 26, + 111, + 17, + 14, + 18, + 11 + ], + [ + 6, + 11, + 11, + 15, + 11, + 86, + 10, + 14, + 16 + ], + [ + 8, + 11, + 9, + 13, + 17, + 14, + 89, + 10, + 9 + ], + [ + 8, + 16, + 14, + 17, + 15, + 11, + 10, + 83, + 6 + ], + [ + 13, + 14, + 11, + 15, + 12, + 5, + 8, + 9, + 93 + ] + ], + "per_class_recall": [ + 0.42777777777777776, + 0.4777777777777778, + 0.5166666666666667, + 0.39444444444444443, + 0.4625, + 0.4777777777777778, + 0.49444444444444446, + 0.46111111111111114, + 0.5166666666666667 + ], + "balanced_accuracy": 0.46990740740740744, + "accuracy": 0.46964285714285714, + "weighted_f1": 0.4707562771324448, + "macro_f1": 0.471133142475755, + "kappa": 0.4025575937544903, + "samples": 1680, + "reward": 0.46990740740740744, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 1415, + 660, + 126, + 754, + 1618, + 10914 + ], + "confusion_matrix": [ + [ + 45, + 38, + 15, + 0, + 4, + 17 + ], + [ + 17, + 164, + 0, + 61, + 49, + 0 + ], + [ + 130, + 126, + 111, + 89, + 213, + 0 + ], + [ + 7, + 2, + 0, + 76, + 0, + 1 + ], + [ + 4, + 0, + 0, + 24, + 435, + 37 + ], + [ + 1212, + 330, + 0, + 504, + 917, + 10859 + ] + ], + "per_class_recall": [ + 0.37815126050420167, + 0.563573883161512, + 0.16591928251121077, + 0.8837209302325582, + 0.87, + 0.7856316017942411 + ], + "balanced_accuracy": 0.6078328263672873, + "accuracy": 0.7548266287854329, + "weighted_f1": 0.8168597460216521, + "macro_f1": 0.3587540627106629, + "kappa": 0.32929623559334475, + "samples": 15487, + "reward": 0.6078328263672873, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2059, + 2341 + ], + "confusion_matrix": [ + [ + 1696, + 504 + ], + [ + 363, + 1837 + ] + ], + "per_class_recall": [ + 0.7709090909090909, + 0.835 + ], + "balanced_accuracy": 0.8029545454545455, + "accuracy": 0.8029545454545455, + "weighted_f1": 0.8027519892716276, + "macro_f1": 0.8027519892716275, + "kappa": 0.605909090909091, + "samples": 4400, + "subject_scores": { + "19": 0.8425, + "35": 0.9525, + "34": 0.64, + "51": 0.7475, + "20": 0.82, + "44": 0.94, + "24": 0.5974999999999999, + "15": 0.9, + "31": 0.8825000000000001, + "26": 0.79, + "23": 0.72 + }, + "reward": 0.8029545454545456, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4572, + 3846 + ], + "confusion_matrix": [ + [ + 3656, + 604 + ], + [ + 916, + 3242 + ] + ], + "per_class_recall": [ + 0.8582159624413146, + 0.7797017797017797 + ], + "balanced_accuracy": 0.8189588710715472, + "accuracy": 0.8194345450225707, + "weighted_f1": 0.8191046137658184, + "macro_f1": 0.8189967516241878, + "kappa": 0.6384913111521573, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.837643455629449, + "sub-G2007": 0.7644167136410334, + "sub-G2019": 0.8242345047591977, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8429774626319118, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9564871486872261, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8160786029523278, + "subjects": 9 + } + }, + "losses": { + "faced": 1.1245228350162506, + "tuev": 0.8237144947052002, + "ad65": 0.5528117254376411, + "openbmi": 0.41377417743206024, + "longitudinal": 0.23846278339624405 + }, + "seconds": 33.64874625205994 + } + ], + "history": [ + { + "epoch": 1, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 158, + 189, + 178, + 213, + 242, + 166, + 182, + 176, + 176 + ], + "confusion_matrix": [ + [ + 77, + 14, + 5, + 22, + 19, + 9, + 14, + 10, + 10 + ], + [ + 12, + 86, + 9, + 13, + 19, + 11, + 14, + 6, + 10 + ], + [ + 6, + 7, + 93, + 21, + 17, + 5, + 7, + 10, + 14 + ], + [ + 14, + 18, + 9, + 71, + 21, + 8, + 16, + 15, + 8 + ], + [ + 13, + 13, + 17, + 26, + 111, + 17, + 14, + 18, + 11 + ], + [ + 6, + 11, + 11, + 15, + 11, + 86, + 10, + 14, + 16 + ], + [ + 8, + 11, + 9, + 13, + 17, + 14, + 89, + 10, + 9 + ], + [ + 8, + 16, + 14, + 17, + 15, + 11, + 10, + 84, + 5 + ], + [ + 14, + 13, + 11, + 15, + 12, + 5, + 8, + 9, + 93 + ] + ], + "per_class_recall": [ + 0.42777777777777776, + 0.4777777777777778, + 0.5166666666666667, + 0.39444444444444443, + 0.4625, + 0.4777777777777778, + 0.49444444444444446, + 0.4666666666666667, + 0.5166666666666667 + ], + "balanced_accuracy": 0.4705246913580247, + "accuracy": 0.47023809523809523, + "weighted_f1": 0.4714215675991068, + "macro_f1": 0.47182307333007106, + "kappa": 0.40322812395229657, + "samples": 1680, + "reward": 0.4705246913580247, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 1415, + 660, + 126, + 754, + 1684, + 10848 + ], + "confusion_matrix": [ + [ + 45, + 38, + 15, + 0, + 4, + 17 + ], + [ + 17, + 164, + 0, + 61, + 49, + 0 + ], + [ + 130, + 126, + 111, + 89, + 213, + 0 + ], + [ + 7, + 2, + 0, + 76, + 0, + 1 + ], + [ + 4, + 0, + 0, + 24, + 435, + 37 + ], + [ + 1212, + 330, + 0, + 504, + 983, + 10793 + ] + ], + "per_class_recall": [ + 0.37815126050420167, + 0.563573883161512, + 0.16591928251121077, + 0.8837209302325582, + 0.87, + 0.7808566054116626 + ], + "balanced_accuracy": 0.6070369936368575, + "accuracy": 0.7505649899916058, + "weighted_f1": 0.8137799723660881, + "macro_f1": 0.3561849045209278, + "kappa": 0.32441309326581047, + "samples": 15487, + "reward": 0.6070369936368575, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2061, + 2339 + ], + "confusion_matrix": [ + [ + 1698, + 502 + ], + [ + 363, + 1837 + ] + ], + "per_class_recall": [ + 0.7718181818181818, + 0.835 + ], + "balanced_accuracy": 0.803409090909091, + "accuracy": 0.803409090909091, + "weighted_f1": 0.8032127000298179, + "macro_f1": 0.8032127000298179, + "kappa": 0.6068181818181818, + "samples": 4400, + "subject_scores": { + "19": 0.8425, + "35": 0.9525, + "34": 0.6425000000000001, + "51": 0.7475, + "20": 0.82, + "44": 0.94, + "24": 0.5974999999999999, + "15": 0.9, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.72 + }, + "reward": 0.803409090909091, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4573, + 3845 + ], + "confusion_matrix": [ + [ + 3657, + 603 + ], + [ + 916, + 3242 + ] + ], + "per_class_recall": [ + 0.8584507042253521, + 0.7797017797017797 + ], + "balanced_accuracy": 0.8190762419635659, + "accuracy": 0.8195533380850558, + "weighted_f1": 0.8192217642599872, + "macro_f1": 0.8191137114479841, + "kappa": 0.6387281046963751, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.837643455629449, + "sub-G2007": 0.7644167136410334, + "sub-G2019": 0.82505149822325, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8429774626319118, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9564871486872261, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8161693800038893, + "subjects": 9 + } + }, + "validation_method": "complete portable infer.sh on all five validation splits" + } + ], + "averaged_validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 158, + 189, + 178, + 213, + 242, + 166, + 182, + 176, + 176 + ], + "confusion_matrix": [ + [ + 77, + 14, + 5, + 22, + 19, + 9, + 14, + 10, + 10 + ], + [ + 12, + 86, + 9, + 13, + 19, + 11, + 14, + 6, + 10 + ], + [ + 6, + 7, + 93, + 21, + 17, + 5, + 7, + 10, + 14 + ], + [ + 14, + 18, + 9, + 71, + 21, + 8, + 16, + 15, + 8 + ], + [ + 13, + 13, + 17, + 26, + 111, + 17, + 14, + 18, + 11 + ], + [ + 6, + 11, + 11, + 15, + 11, + 86, + 10, + 14, + 16 + ], + [ + 8, + 11, + 9, + 13, + 17, + 14, + 89, + 10, + 9 + ], + [ + 8, + 16, + 14, + 17, + 15, + 11, + 10, + 84, + 5 + ], + [ + 14, + 13, + 11, + 15, + 12, + 5, + 8, + 9, + 93 + ] + ], + "per_class_recall": [ + 0.42777777777777776, + 0.4777777777777778, + 0.5166666666666667, + 0.39444444444444443, + 0.4625, + 0.4777777777777778, + 0.49444444444444446, + 0.4666666666666667, + 0.5166666666666667 + ], + "balanced_accuracy": 0.4705246913580247, + "accuracy": 0.47023809523809523, + "weighted_f1": 0.4714215675991068, + "macro_f1": 0.47182307333007106, + "kappa": 0.40322812395229657, + "samples": 1680, + "reward": 0.4705246913580247, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 1415, + 660, + 126, + 754, + 1684, + 10848 + ], + "confusion_matrix": [ + [ + 45, + 38, + 15, + 0, + 4, + 17 + ], + [ + 17, + 164, + 0, + 61, + 49, + 0 + ], + [ + 130, + 126, + 111, + 89, + 213, + 0 + ], + [ + 7, + 2, + 0, + 76, + 0, + 1 + ], + [ + 4, + 0, + 0, + 24, + 435, + 37 + ], + [ + 1212, + 330, + 0, + 504, + 983, + 10793 + ] + ], + "per_class_recall": [ + 0.37815126050420167, + 0.563573883161512, + 0.16591928251121077, + 0.8837209302325582, + 0.87, + 0.7808566054116626 + ], + "balanced_accuracy": 0.6070369936368575, + "accuracy": 0.7505649899916058, + "weighted_f1": 0.8137799723660881, + "macro_f1": 0.3561849045209278, + "kappa": 0.32441309326581047, + "samples": 15487, + "reward": 0.6070369936368575, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2061, + 2339 + ], + "confusion_matrix": [ + [ + 1698, + 502 + ], + [ + 363, + 1837 + ] + ], + "per_class_recall": [ + 0.7718181818181818, + 0.835 + ], + "balanced_accuracy": 0.803409090909091, + "accuracy": 0.803409090909091, + "weighted_f1": 0.8032127000298179, + "macro_f1": 0.8032127000298179, + "kappa": 0.6068181818181818, + "samples": 4400, + "subject_scores": { + "19": 0.8425, + "35": 0.9525, + "34": 0.6425000000000001, + "51": 0.7475, + "20": 0.82, + "44": 0.94, + "24": 0.5974999999999999, + "15": 0.9, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.72 + }, + "reward": 0.803409090909091, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4573, + 3845 + ], + "confusion_matrix": [ + [ + 3657, + 603 + ], + [ + 916, + 3242 + ] + ], + "per_class_recall": [ + 0.8584507042253521, + 0.7797017797017797 + ], + "balanced_accuracy": 0.8190762419635659, + "accuracy": 0.8195533380850558, + "weighted_f1": 0.8192217642599872, + "macro_f1": 0.8191137114479841, + "kappa": 0.6387281046963751, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.837643455629449, + "sub-G2007": 0.7644167136410334, + "sub-G2019": 0.82505149822325, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8429774626319118, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9564871486872261, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8161693800038893, + "subjects": 9 + } + }, + "settings": { + "source": "/workspace/research/runs/hybrid_biot_csp_stable1/epoch-001", + "head_arithmetic": "same linear head in fixed feature blocks, sum in bfloat16 on GPU for non-AD tracks; AD remains float32", + "weights_unchanged": true + } + }, + "selected_head_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 0, + "longitudinal": 16 + }, + "incumbent_heads": "/workspace/research/runs/head_refinement1/epoch-012", + "clinical_training_teacher": { + "source": "/workspace/research/runs/hybrid_biot_readout1/epoch-009", + "weights_sha256": "3216b27a1cfb7c1e927da0d91a61c7d516f71236a8adf89d84bc9cfbb932313f", + "manifest_sha256": "49b7880052e6d093633e6e03d52bfd7df9084271ebf8e4f60e4fbe12da398354", + "split": "train", + "count": 68445, + "source_trained_jointly_on_all_five_tracks": true + }, + "no_prediction_ensemble": true +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S016/config.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S016/config.json new file mode 100644 index 0000000000000000000000000000000000000000..9d13eae7eac928157833772830ad9a4e9052449d --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S016/config.json @@ -0,0 +1,205 @@ +{ + "schema": "bci-shared-biot-covariance-bf16head-v1", + "architecture": { + "channels": 32, + "width": 128, + "depth": 2, + "dropout": 0.5, + "wave_filters": 32, + "head_width": 64, + "head_dropout": 0.3 + }, + "initialization": { + "initialization": "continue joint training from a complete shared-model checkpoint", + "parent": "/workspace/research/runs/hybrid_biot_fusionshrink0100/epoch-001/weights.pt", + "parent_initialization": { + "initialization": "jointly trained parent plus audited pretrained BIOT in a single coupled backbone", + "parent": "/workspace/research/runs/hybrid_wide1/epoch-004/weights.pt", + "audited_biot": { + "initialization": "pretrained", + "repo": "braindecode/biot-pretrained-six-datasets-18chs", + "revision": "7e9aabf302870012f73773276803aab97993951c", + "sha256": "a218f4054ae29962c6fd9d23d94c446d354c4f53e805a6771c85749ccc20baaa", + "license": "BSD-3-Clause", + "source_braindecode": "1.3.0", + "loaded_core_tensors": 56, + "skipped_classifier_tensors": 3 + }, + "neural_channel_indices": { + "faced": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "tuev": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15 + ], + "ad65": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "openbmi": [ + 0, + 1, + 3, + 5, + 12, + 14, + 23, + 25, + 28, + 30, + 2, + 6, + 11, + 15, + 22, + 26, + 4, + 13 + ], + "longitudinal": [ + 0, + 2, + 7, + 11, + 23, + 27, + 41, + 45, + 55, + 57, + 5, + 13, + 21, + 29, + 39, + 47, + 9, + 25 + ] + }, + "rebase": "incumbent waveform, fusion and four heads; joint BIOT and TUEV head from readout epoch 9; zero initialized neural interaction", + "jointly_finetuned_neural_parent": "/workspace/research/runs/hybrid_biot_readout1/epoch-009/weights.pt", + "tuev_high_dimensional_spectral_projection_disabled": true, + "frozen_prior_representation": true, + "nonclinical_head_updates": "only the 256 added BIOT columns; original columns and biases fixed", + "faced_openbmi_neural_path": "common nonlinear fusion only; direct head columns masked", + "retention_teacher": "/workspace/research/runs/hybrid_wide1/epoch-004", + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "joint_covariance_parent": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "frozen_prior_representation": true, + "head_updates": "one linear head per track; added 128 shared covariance columns trainable; AD head initialized from the joint covariance parent", + "new_shared_representation": "one common covariance MLP inside the coupled backbone, trained by all five tasks; fixed spatial input adapters from the same jointly trained source", + "head_arithmetic": "one linear head evaluated in fixed feature blocks to preserve original bfloat16 accumulation dimensions", + "retention_teacher": { + "ad65": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "other_tracks": "/workspace/research/runs/hybrid_wide1/epoch-004" + }, + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "loader_scale": 0.01, + "tracks": [ + "faced", + "tuev", + "ad65", + "openbmi", + "longitudinal" + ], + "head_arithmetic": "same linear head in fixed feature blocks, sum in bfloat16 on GPU for non-AD tracks; AD remains float32", + "head_refinement": { + "source": "/workspace/research/runs/residual_heads1/epoch-018", + "source_weights_sha256": "e0b609137391b47f99438ccadaa22fc0bc10d2c10ead0ddf0a3c25be2c907c85", + "shared_backbone_unchanged": true, + "selected_head_epochs": { + "faced": 5, + "tuev": 24, + "ad65": 0, + "openbmi": 0, + "longitudinal": 0 + } + }, + "clinical_spectral_refinement": { + "source": "/workspace/research/runs/head_dropout1/epoch-016", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "head_estimation": { + "method": "class/subject-balanced Gaussian linear discriminant with shrunk within-class covariance", + "selected_shrinkage": { + "faced": "inherited", + "tuev": "inherited", + "ad65": "inherited", + "openbmi": "inherited", + "longitudinal": 0.9 + }, + "feature_scaling": "fitted on training data and folded into linear coefficients" + } +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S016/covariances.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S016/covariances.py new file mode 100644 index 0000000000000000000000000000000000000000..a65153f3b18f31995ff206a8e2fb8a7fd7a254dd --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S016/covariances.py @@ -0,0 +1,25 @@ +"""Shared neural filter-bank covariance decoder with spatial input adapters.""" +import torch +from torch import nn +SPECS={'faced':(32,10,9),'tuev':(16,5,6),'ad65':(19,10,3),'openbmi':(62,4,2),'longitudinal':(58,2,2)} +TRACKS=tuple(SPECS) +BANDS=[(1,4),(4,8),(8,12),(12,16),(16,20),(20,24),(24,28),(28,32),(32,40),(40,48)] + +@torch.no_grad() +def extract_covariances(t,x): + x=torch.nan_to_num(x.float().flatten(2)).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if t in ('faced','tuev'): + x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + else:x=x-x.mean(1,keepdim=True) + # Per-window normalization, preserving spatial and frequency power ratios. + x=x/x.square().mean((1,2),keepdim=True).clamp_min(1e-12).sqrt() + frames=x.unfold(-1,400,200);frames=frames-frames.mean(-1,keepdim=True) + z=torch.fft.rfft(frames*torch.hann_window(400,device=x.device),dim=-1)/200 + covs=[] + for lo,hi in BANDS: + v=z[...,2*lo:2*hi].flatten(2) + cov=(v.real@v.real.transpose(-1,-2)+v.imag@v.imag.transpose(-1,-2))/v.shape[-1] + covs.append(cov) + return torch.stack(covs,1) + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S016/data.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S016/data.py new file mode 100644 index 0000000000000000000000000000000000000000..e3cf61f3b1ac4d22858c6e6f387024abd27d953d --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S016/data.py @@ -0,0 +1,33 @@ +import json +from functools import lru_cache +from pathlib import Path +import numpy as np +import torch +@lru_cache(maxsize=8) +def array(path):return np.load(path,mmap_mode='r',allow_pickle=False) +class Dataset(torch.utils.data.Dataset): + def __init__(self,root,limit=None,cache=False): + self.root=Path(root) + self.rows=json.loads((self.root/'manifest.json').read_text())['samples'] + if limit:self.rows=self.rows[:limit] + self.cached=None + if cache and self.rows: + from collections import defaultdict + groups=defaultdict(list) + for i,r in enumerate(self.rows):groups[r['path']].append((i,r['index'])) + for name,indices in groups.items(): + path=(self.root/name).resolve() + if not path.is_relative_to(self.root.resolve()):raise ValueError('input outside root') + source=np.load(path,mmap_mode='r',allow_pickle=False) + if self.cached is None:self.cached=torch.empty((len(self.rows),*source.shape[1:]),dtype=torch.float32) + dst,src=zip(*indices) + self.cached[list(dst)]=torch.as_tensor(source[list(src)]/100,dtype=torch.float32) + def __len__(self):return len(self.rows) + def __getitem__(self,i): + r=self.rows[i] + if self.cached is not None:return self.cached[i],r.get('label',-1),r['id'] + p=(self.root/r['path']).resolve() + if not p.is_relative_to(self.root.resolve()):raise ValueError('input outside root') + # Division precedes float32 conversion, matching official FACED/TUEV collate. + x=np.asarray(array(str(p))[r['index']])/100 + return torch.as_tensor(x,dtype=torch.float32),r.get('label',-1),r['id'] diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S016/features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S016/features.py new file mode 100644 index 0000000000000000000000000000000000000000..88f7e8b14c9fab44733d5224ede6d6b5c7f76a45 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S016/features.py @@ -0,0 +1,63 @@ +"""One shared residual backbone, five linear input adapters and output heads.""" +import torch +from torch import nn + +SPECS = {'faced': (32, 10, 9), 'tuev': (16, 5, 6), 'ad65': (19, 10, 3), + 'openbmi': (62, 4, 2), 'longitudinal': (58, 2, 2)} +TRACKS = tuple(SPECS) +EDGES = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,18,20,22,25,28,32,36,40,45,50,60,70,80,95] +COV_BANDS = [(1,4),(4,8),(8,12),(12,16),(16,20),(20,28),(28,40)] + +def feature_dim(channels): + return channels * (4*(len(EDGES)-1)+4) + len(COV_BANDS)*channels*(channels-1)//2 + +@torch.no_grad() +def extract_features(track, x): + """Fixed features; no batch statistics or fitted inference transformations.""" + x = x.float().flatten(2) + x = torch.nan_to_num(x, nan=0., posinf=1e5, neginf=-1e5).clamp(-1e5,1e5) + x = x - x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'): + x = x - x.mean(1,keepdim=True) + rms = x.square().mean(-1).clamp_min(1e-12).sqrt() + norm = x / rms.unsqueeze(-1) + moments = torch.stack([rms.log(), norm.abs().amax(-1).clamp_min(1).log(), + norm.pow(4).mean(-1).clamp_min(1).log(), + (norm[...,1:]-norm[...,:-1]).square().mean(-1).clamp_min(1e-10).log()],-1) + frames = x.unfold(-1,400,200) + frames = frames - frames.mean(-1,keepdim=True) + window = torch.hann_window(400,device=x.device) + z = torch.fft.rfft(frames*window,dim=-1)/200 + power = z.abs().square() + bands = torch.stack([power[...,2*lo:2*hi].mean(-1) for lo,hi in zip(EDGES[:-1],EDGES[1:])],-1) + lp = bands.mean(-2).clamp_min(1e-12).log() + variation = bands.clamp_min(1e-12).log().std(-2,correction=0) + relative_frequency = lp - lp.mean(-1,keepdim=True) + relative_channel = lp - lp.mean(1,keepdim=True) + parts = [torch.cat([lp, relative_frequency, relative_channel, variation, moments],-1).flatten(1)] + ii,jj = torch.triu_indices(x.shape[1],x.shape[1],offset=1,device=x.device) + for lo,hi in COV_BANDS: + v = z[...,2*lo:2*hi].flatten(2) + cov = v.real @ v.real.transpose(-1,-2) + v.imag @ v.imag.transpose(-1,-2) + d = cov.diagonal(dim1=-2,dim2=-1).clamp_min(1e-12).sqrt() + cor = cov / (d.unsqueeze(1)*d.unsqueeze(2)).clamp_min(1e-12) + parts.append(cor[:,ii,jj].clamp(-1,1)) + result = torch.cat(parts,-1) + return torch.nan_to_num(result).clamp(-40,40) + +class Standardize(nn.Module): + def __init__(self, dim): + super().__init__() + self.register_buffer('mean',torch.zeros(dim)) + self.register_buffer('scale',torch.ones(dim)) + def forward(self,x): + return ((x-self.mean)/self.scale).clamp(-8,8) + +class Residual(nn.Module): + def __init__(self,width,dropout): + super().__init__() + self.net=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(), + nn.Dropout(dropout),nn.Linear(width*2,width),nn.Dropout(dropout)) + def forward(self,x): + return x+self.net(x) + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S016/infer.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S016/infer.py new file mode 100644 index 0000000000000000000000000000000000000000..aecb1722284d7707ed4097a3308cb15f870b6826 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S016/infer.py @@ -0,0 +1,24 @@ +import argparse,json +from pathlib import Path +import torch +from model import HybridModel,SPECS +from data import Dataset +from covariances import extract_covariances +p=argparse.ArgumentParser();p.add_argument('input',type=Path);p.add_argument('output',type=Path);a=p.parse_args() +root=Path(__file__).resolve().parent;c=json.loads((root/'config.json').read_text());t=json.loads((a.input/'manifest.json').read_text())['track'] +if t not in SPECS:raise ValueError('unknown track') +torch.set_num_threads(4);device='cuda' if torch.cuda.is_available() else 'cpu' +m=HybridModel(**c['architecture']).to(device);m.load_state_dict(torch.load(root/'weights.pt',map_location=device,weights_only=True));m.eval() +a.output.mkdir(parents=True,exist_ok=True) +with torch.inference_mode(),(a.output/'predictions.jsonl').open('w') as f: + for x,_,ids in torch.utils.data.DataLoader(Dataset(a.input),batch_size=64,num_workers=0): + # FFT features stay float32; convolutions can use bfloat16 on CUDA. + x=x.to(device) + from features import extract_features + torch.backends.cuda.matmul.allow_tf32=False + features=extract_features(t,x) + covariances=extract_covariances(t,x) + torch.backends.cuda.matmul.allow_tf32=True + with torch.autocast(device,dtype=torch.bfloat16,enabled=device=='cuda'):pred=m(t,x,features,covariances=covariances) + pp=pred.float().softmax(-1).cpu().numpy() + for sid,pr in zip(ids,pp):f.write(json.dumps({'id':sid,'probabilities':pr.tolist()})+'\n') diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S016/infer.sh b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S016/infer.sh new file mode 100644 index 0000000000000000000000000000000000000000..3aae9b42834f2f278e52148d5a07835d9960a4ea --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S016/infer.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -euo pipefail +exec python "$(dirname -- "$0")/infer.py" "$1" "$2" diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S016/model.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S016/model.py new file mode 100644 index 0000000000000000000000000000000000000000..377d792a634f0494b6a48161a1be75d14e1dad6a --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S016/model.py @@ -0,0 +1,111 @@ +"""One fused waveform/spectral backbone used identically by all five tasks.""" +import torch +from torch import nn +from braindecode.models import BIOT +from features import SPECS,TRACKS,feature_dim,extract_features,Standardize,Residual +from covariances import BANDS,extract_covariances + +class InputAdapter(nn.Module): + def __init__(self,c,width,channels,spectral_enabled=True): + super().__init__() + self.signal=nn.Conv1d(c,channels,1,bias=False) + self.neural=nn.Conv1d(c,18,1,bias=False) + self.normalizer=Standardize(feature_dim(c)) + self.spectral=nn.Linear(feature_dim(c),width) + self.dropout=nn.Dropout(.1) + self.register_buffer("spectral_enabled",torch.tensor(float(spectral_enabled))) + self.spatial_weight=nn.Parameter(torch.randn(len(BANDS),24,c)/c**.5) + def spatial_features(self,covariances): + with torch.autocast(covariances.device.type,enabled=False): + w=self.spatial_weight.float()/self.spatial_weight.float().norm(dim=-1,keepdim=True).clamp_min(1e-6) + power=torch.einsum('bfc,nbcd,bfd->nbf',w,covariances.float(),w).clamp_min(1e-8).log() + return torch.cat([power,power-power.mean(1,keepdim=True)],1).flatten(1) + def forward(self,x,features,covariance_features): + return self.signal(x).unsqueeze(1),self.spectral_enabled*self.spectral(self.dropout(self.normalizer(features))),self.neural(x),covariance_features + +class SharedBackbone(nn.Module): + def __init__(self,channels,width,depth,dropout,wave_filters): + super().__init__() + self.waveform=nn.Sequential( + nn.Conv2d(1,wave_filters,(1,64),padding=(0,32),bias=False),nn.GroupNorm(1,wave_filters), + nn.Conv2d(wave_filters,2*wave_filters,(channels,1),groups=wave_filters,bias=False),nn.GroupNorm(1,2*wave_filters),nn.ELU(), + nn.AvgPool2d((1,4)),nn.Dropout(.35), + nn.Conv2d(2*wave_filters,2*wave_filters,(1,16),padding=(0,8),groups=2*wave_filters,bias=False),nn.Conv2d(2*wave_filters,2*wave_filters,1,bias=False), + nn.GroupNorm(1,2*wave_filters),nn.ELU(),nn.AvgPool2d((1,8)),nn.Dropout(.35)) + self.wave_summary=nn.Sequential(nn.AdaptiveAvgPool2d((1,8)),nn.Flatten(),nn.Linear(2*wave_filters*8,width)) + self.fusion=nn.Sequential(nn.LayerNorm(width),nn.GELU(),nn.Dropout(dropout), + *[Residual(width,dropout) for _ in range(depth)],nn.LayerNorm(width)) + # Both representations interact before the shared residual stack. + self.wave_gain=nn.Parameter(torch.tensor(.1)) + self.biot=BIOT(n_chans=18,n_outputs=2,n_times=400,sfreq=200) + self.biot.final_layer=nn.Identity() + self.biot_projection=nn.Sequential(nn.LayerNorm(256),nn.Linear(256,width),nn.Dropout(.2)) + nn.init.normal_(self.biot_projection[1].weight,std=.001);nn.init.zeros_(self.biot_projection[1].bias) + self.covariance_encoder=nn.Sequential(nn.LayerNorm(len(BANDS)*24*2),nn.Linear(len(BANDS)*24*2,width),nn.GELU(),nn.Dropout(.4), + *[Residual(width,.4) for _ in range(2)],nn.LayerNorm(width)) + self.covariance_projection=nn.Linear(width,width) + nn.init.zeros_(self.covariance_projection.weight);nn.init.zeros_(self.covariance_projection.bias) + def forward(self,signal,spectral,neural_signal,covariance_features): + wave=self.waveform(signal) + neural=self.biot(neural_signal.float()) + neural=self.biot_projection[0](neural) + projected=self.biot_projection[2](self.biot_projection[1](neural)) + with torch.autocast(signal.device.type,enabled=False): + covariance_embedding=self.covariance_encoder(covariance_features.float()) + original=spectral+self.wave_gain*self.wave_summary(wave)+.01*projected + coupled=.001*self.covariance_projection(covariance_embedding).to(original.dtype) + fused=self.fusion(original+coupled) + return torch.cat([wave.flatten(1),fused,neural,covariance_embedding],-1) + +class ResidualHead(nn.Module): + """A small nonlinear classifier correction around an inherited linear readout.""" + def __init__(self,features,classes,width=64,dropout=.3,full_precision=False): + super().__init__();self.full_precision=full_precision + self.base=nn.Linear(features,classes) + self.delta=nn.Sequential(nn.LayerNorm(features),nn.Linear(features,width),nn.GELU(),nn.Dropout(dropout),nn.Linear(width,classes)) + nn.init.zeros_(self.delta[-1].weight);nn.init.zeros_(self.delta[-1].bias) + def forward(self,x): + if self.full_precision: + with torch.autocast(x.device.type,enabled=False):return self.base(x.float())+self.delta(x.float()) + prior=nn.functional.linear(x[:,:-128].contiguous(),self.base.weight[:,:-128].contiguous(),self.base.bias) + added=nn.functional.linear(x[:,-128:].contiguous(),self.base.weight[:,-128:].contiguous()) + value=prior+added + return value+self.delta(x).to(value.dtype) + +class HybridModel(nn.Module): + def __init__(self,channels=32,width=128,depth=2,dropout=.5,wave_filters=32,head_width=64,head_dropout=.3): + super().__init__() + self.adapters=nn.ModuleDict({t:InputAdapter(c,width,channels,spectral_enabled=t not in ("faced","tuev","openbmi")) for t,(c,s,k) in SPECS.items()}) + self.backbone=SharedBackbone(channels,width,depth,dropout,wave_filters) + self.heads=nn.ModuleDict({t:ResidualHead(2*wave_filters*(((s*200+1)//4+1)//8)+width+256+width,k,head_width,head_dropout,full_precision=t=='ad65') for t,(c,s,k) in SPECS.items()}) + def forward(self,t,x,features=None,covariances=None,covariance_features=None): + if features is None:features=extract_features(t,x) + if covariance_features is None: + if covariances is None:covariances=extract_covariances(t,x) + covariance_features=self.adapters[t].spatial_features(covariances) + signal=x.flatten(2);signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + adapted=self.adapters[t](signal,features,covariance_features) + representation=self.backbone(*adapted) + if t in ('faced','openbmi'): + representation=torch.cat([representation[:,:-384],torch.zeros_like(representation[:,-384:-128]),representation[:,-128:]],-1) + return self.heads[t](representation) + +def widen_state_dict(state,multiplier=2): + """Duplicate temporal features and divide downstream sums to preserve outputs.""" + result={} + for key,value in state.items(): + if key.startswith('backbone.waveform.'): + layer=int(key.split('.')[2]) + if layer in (0,2,7):value=value.repeat(multiplier,1,1,1) + elif layer in (1,3,9):value=value.repeat(multiplier) + elif layer==8:value=value.repeat(multiplier,multiplier,1,1)/multiplier + elif key=='backbone.wave_summary.2.weight':value=value.repeat(1,multiplier)/multiplier + elif key.startswith('heads.') and key.endswith('.weight'): + raw=value[:,:-128]/multiplier + value=torch.cat([raw]*multiplier+[value[:,-128:]],1) + result[key]=value + return result + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S016/training.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S016/training.json new file mode 100644 index 0000000000000000000000000000000000000000..f90443f6dad729a1e7b6d35b14e525d91137828b --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S016/training.json @@ -0,0 +1,11692 @@ +{ + "history": [ + { + "epoch": 1, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 155, + 190, + 184, + 218, + 261, + 152, + 179, + 171, + 170 + ], + "confusion_matrix": [ + [ + 81, + 11, + 4, + 25, + 19, + 7, + 13, + 9, + 11 + ], + [ + 8, + 92, + 8, + 17, + 20, + 8, + 13, + 5, + 9 + ], + [ + 8, + 7, + 95, + 19, + 20, + 6, + 6, + 7, + 12 + ], + [ + 13, + 19, + 11, + 71, + 21, + 5, + 18, + 15, + 7 + ], + [ + 12, + 14, + 18, + 27, + 118, + 13, + 10, + 20, + 8 + ], + [ + 6, + 11, + 10, + 13, + 13, + 92, + 9, + 13, + 13 + ], + [ + 7, + 11, + 10, + 10, + 19, + 12, + 93, + 7, + 11 + ], + [ + 6, + 14, + 16, + 23, + 17, + 6, + 7, + 88, + 3 + ], + [ + 14, + 11, + 12, + 13, + 14, + 3, + 10, + 7, + 96 + ] + ], + "per_class_recall": [ + 0.45, + 0.5111111111111111, + 0.5277777777777778, + 0.39444444444444443, + 0.49166666666666664, + 0.5111111111111111, + 0.5166666666666667, + 0.4888888888888889, + 0.5333333333333333 + ], + "balanced_accuracy": 0.49166666666666664, + "accuracy": 0.49166666666666664, + "weighted_f1": 0.49393255226238353, + "macro_f1": 0.4947797621894519, + "kappa": 0.4271065430412804, + "samples": 1680, + "reward": 0.49166666666666664, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 478, + 725, + 155, + 361, + 1525, + 12243 + ], + "confusion_matrix": [ + [ + 21, + 38, + 23, + 4, + 0, + 33 + ], + [ + 0, + 224, + 0, + 39, + 28, + 0 + ], + [ + 110, + 155, + 110, + 39, + 255, + 0 + ], + [ + 5, + 0, + 0, + 79, + 0, + 2 + ], + [ + 1, + 0, + 0, + 1, + 447, + 51 + ], + [ + 341, + 308, + 22, + 199, + 795, + 12157 + ] + ], + "per_class_recall": [ + 0.17647058823529413, + 0.7697594501718213, + 0.16442451420029897, + 0.9186046511627907, + 0.894, + 0.8795398639849515 + ], + "balanced_accuracy": 0.6337998446258595, + "accuracy": 0.8418673726351134, + "weighted_f1": 0.8691099038121964, + "macro_f1": 0.4176762944372105, + "kappa": 0.45395865853864836, + "samples": 15487, + "reward": 0.6337998446258595, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2019, + 2381 + ], + "confusion_matrix": [ + [ + 1680, + 520 + ], + [ + 339, + 1861 + ] + ], + "per_class_recall": [ + 0.7636363636363637, + 0.8459090909090909 + ], + "balanced_accuracy": 0.8047727272727273, + "accuracy": 0.8047727272727273, + "weighted_f1": 0.8044418036119902, + "macro_f1": 0.8044418036119902, + "kappa": 0.6095454545454546, + "samples": 4400, + "subject_scores": { + "19": 0.87, + "35": 0.9550000000000001, + "34": 0.6475, + "51": 0.7525, + "20": 0.815, + "44": 0.9325, + "24": 0.5925, + "15": 0.8925000000000001, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.72 + }, + "reward": 0.8047727272727273, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4591, + 3827 + ], + "confusion_matrix": [ + [ + 3668, + 592 + ], + [ + 923, + 3235 + ] + ], + "per_class_recall": [ + 0.8610328638497653, + 0.778018278018278 + ], + "balanced_accuracy": 0.8195255709340217, + "accuracy": 0.8200285103349965, + "weighted_f1": 0.8196635443916465, + "macro_f1": 0.8195510775450552, + "kappa": 0.6396607542670605, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8376331178226214, + "sub-G2007": 0.7653866879842162, + "sub-G2019": 0.8234381815392127, + "sub-G2031": 0.7876021763815796, + "sub-G2015": 0.8510738123772429, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.768266548982978, + "sub-G2035": 0.9556811201354545, + "sub-CTR003": 0.5749458874458875 + }, + "reward": 0.8167752064282013, + "subjects": 9 + } + } + } + ], + "settings": { + "source": "/workspace/research/runs/residual_timewarp1/epoch-024", + "features": "/workspace/research/head_features_clinical_v1", + "output": "/workspace/research/runs/lda_heads1" + }, + "selected_shrinkage": { + "faced": "inherited", + "tuev": "inherited", + "ad65": "inherited", + "openbmi": "inherited", + "longitudinal": 0.9 + }, + "trials": [ + { + "track": "faced", + "shrinkage": 0.01, + "validation": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 159, + 196, + 166, + 205, + 333, + 151, + 174, + 129, + 167 + ], + "confusion_matrix": [ + [ + 77, + 19, + 4, + 16, + 27, + 10, + 12, + 5, + 10 + ], + [ + 9, + 78, + 9, + 15, + 36, + 7, + 10, + 7, + 9 + ], + [ + 13, + 9, + 81, + 16, + 22, + 9, + 15, + 6, + 9 + ], + [ + 13, + 20, + 7, + 60, + 44, + 6, + 16, + 5, + 9 + ], + [ + 10, + 17, + 19, + 30, + 122, + 10, + 15, + 7, + 10 + ], + [ + 8, + 9, + 13, + 17, + 18, + 89, + 7, + 8, + 11 + ], + [ + 10, + 13, + 11, + 10, + 21, + 9, + 85, + 7, + 14 + ], + [ + 7, + 21, + 9, + 24, + 17, + 7, + 7, + 80, + 8 + ], + [ + 12, + 10, + 13, + 17, + 26, + 4, + 7, + 4, + 87 + ] + ], + "per_class_recall": [ + 0.42777777777777776, + 0.43333333333333335, + 0.45, + 0.3333333333333333, + 0.5083333333333333, + 0.49444444444444446, + 0.4722222222222222, + 0.4444444444444444, + 0.48333333333333334 + ], + "balanced_accuracy": 0.4496913580246913, + "accuracy": 0.4517857142857143, + "weighted_f1": 0.4557932016286817, + "macro_f1": 0.45690298797301854, + "kappa": 0.38109295125639, + "samples": 1680, + "reward": 0.4496913580246913, + "subjects": 20 + }, + "retained_feature_dimensions": 4224 + }, + { + "track": "faced", + "shrinkage": 0.1, + "validation": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 159, + 194, + 176, + 206, + 307, + 144, + 170, + 161, + 163 + ], + "confusion_matrix": [ + [ + 81, + 16, + 7, + 16, + 23, + 10, + 12, + 6, + 9 + ], + [ + 12, + 82, + 9, + 19, + 27, + 7, + 12, + 6, + 6 + ], + [ + 13, + 10, + 93, + 15, + 20, + 4, + 9, + 7, + 9 + ], + [ + 15, + 15, + 6, + 66, + 40, + 5, + 17, + 8, + 8 + ], + [ + 9, + 19, + 14, + 25, + 122, + 11, + 11, + 17, + 12 + ], + [ + 6, + 10, + 10, + 14, + 18, + 91, + 11, + 9, + 11 + ], + [ + 6, + 13, + 14, + 10, + 22, + 9, + 87, + 7, + 12 + ], + [ + 5, + 17, + 10, + 26, + 16, + 4, + 3, + 94, + 5 + ], + [ + 12, + 12, + 13, + 15, + 19, + 3, + 8, + 7, + 91 + ] + ], + "per_class_recall": [ + 0.45, + 0.45555555555555555, + 0.5166666666666667, + 0.36666666666666664, + 0.5083333333333333, + 0.5055555555555555, + 0.48333333333333334, + 0.5222222222222223, + 0.5055555555555555 + ], + "balanced_accuracy": 0.4793209876543209, + "accuracy": 0.48035714285714287, + "weighted_f1": 0.4838980757497801, + "macro_f1": 0.48529913522808804, + "kappa": 0.4137145324155135, + "samples": 1680, + "reward": 0.4793209876543209, + "subjects": 20 + }, + "retained_feature_dimensions": 4224 + }, + { + "track": "faced", + "shrinkage": 0.5, + "validation": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 158, + 193, + 174, + 220, + 305, + 128, + 179, + 157, + 166 + ], + "confusion_matrix": [ + [ + 80, + 13, + 8, + 20, + 21, + 7, + 12, + 12, + 7 + ], + [ + 7, + 82, + 6, + 23, + 32, + 5, + 13, + 4, + 8 + ], + [ + 11, + 7, + 84, + 20, + 23, + 3, + 12, + 8, + 12 + ], + [ + 13, + 16, + 10, + 72, + 33, + 4, + 12, + 11, + 9 + ], + [ + 9, + 21, + 18, + 21, + 122, + 10, + 12, + 16, + 11 + ], + [ + 7, + 13, + 13, + 17, + 16, + 88, + 6, + 8, + 12 + ], + [ + 8, + 10, + 13, + 12, + 22, + 3, + 93, + 6, + 13 + ], + [ + 6, + 15, + 10, + 26, + 16, + 7, + 10, + 87, + 3 + ], + [ + 17, + 16, + 12, + 9, + 20, + 1, + 9, + 5, + 91 + ] + ], + "per_class_recall": [ + 0.4444444444444444, + 0.45555555555555555, + 0.4666666666666667, + 0.4, + 0.5083333333333333, + 0.4888888888888889, + 0.5166666666666667, + 0.48333333333333334, + 0.5055555555555555 + ], + "balanced_accuracy": 0.47438271604938265, + "accuracy": 0.47559523809523807, + "weighted_f1": 0.47961810952930006, + "macro_f1": 0.4808000238815575, + "kappa": 0.4083703081904305, + "samples": 1680, + "reward": 0.47438271604938265, + "subjects": 20 + }, + "retained_feature_dimensions": 4224 + }, + { + "track": "faced", + "shrinkage": 0.9, + "validation": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 167, + 178, + 185, + 222, + 263, + 143, + 177, + 171, + 174 + ], + "confusion_matrix": [ + [ + 74, + 17, + 8, + 24, + 24, + 6, + 8, + 11, + 8 + ], + [ + 18, + 74, + 13, + 18, + 23, + 5, + 14, + 6, + 9 + ], + [ + 12, + 3, + 83, + 19, + 18, + 11, + 12, + 8, + 14 + ], + [ + 13, + 18, + 11, + 74, + 22, + 5, + 14, + 13, + 10 + ], + [ + 11, + 18, + 20, + 25, + 109, + 13, + 10, + 18, + 16 + ], + [ + 7, + 11, + 13, + 13, + 17, + 83, + 10, + 13, + 13 + ], + [ + 6, + 9, + 10, + 19, + 18, + 8, + 89, + 12, + 9 + ], + [ + 8, + 16, + 14, + 20, + 16, + 9, + 8, + 85, + 4 + ], + [ + 18, + 12, + 13, + 10, + 16, + 3, + 12, + 5, + 91 + ] + ], + "per_class_recall": [ + 0.4111111111111111, + 0.4111111111111111, + 0.46111111111111114, + 0.4111111111111111, + 0.45416666666666666, + 0.46111111111111114, + 0.49444444444444446, + 0.4722222222222222, + 0.5055555555555555 + ], + "balanced_accuracy": 0.45354938271604944, + "accuracy": 0.45357142857142857, + "weighted_f1": 0.45554215253653413, + "macro_f1": 0.4563622469865655, + "kappa": 0.3841435656611639, + "samples": 1680, + "reward": 0.45354938271604944, + "subjects": 20 + }, + "retained_feature_dimensions": 4224 + }, + { + "track": "faced", + "shrinkage": 1.0, + "validation": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 157, + 161, + 172, + 239, + 264, + 149, + 170, + 144, + 224 + ], + "confusion_matrix": [ + [ + 60, + 20, + 11, + 22, + 25, + 5, + 12, + 11, + 14 + ], + [ + 21, + 60, + 10, + 26, + 21, + 5, + 13, + 11, + 13 + ], + [ + 14, + 4, + 67, + 24, + 15, + 13, + 13, + 9, + 21 + ], + [ + 13, + 17, + 18, + 64, + 22, + 10, + 12, + 14, + 10 + ], + [ + 14, + 17, + 18, + 27, + 101, + 13, + 13, + 15, + 22 + ], + [ + 6, + 10, + 12, + 25, + 19, + 70, + 12, + 5, + 21 + ], + [ + 8, + 10, + 8, + 23, + 21, + 12, + 74, + 10, + 14 + ], + [ + 4, + 19, + 13, + 20, + 19, + 14, + 10, + 62, + 19 + ], + [ + 17, + 4, + 15, + 8, + 21, + 7, + 11, + 7, + 90 + ] + ], + "per_class_recall": [ + 0.3333333333333333, + 0.3333333333333333, + 0.37222222222222223, + 0.35555555555555557, + 0.42083333333333334, + 0.3888888888888889, + 0.4111111111111111, + 0.34444444444444444, + 0.5 + ], + "balanced_accuracy": 0.3844135802469136, + "accuracy": 0.38571428571428573, + "weighted_f1": 0.38627159129107025, + "macro_f1": 0.38573373723541915, + "kappa": 0.3076480736055205, + "samples": 1680, + "reward": 0.3844135802469136, + "subjects": 20 + }, + "retained_feature_dimensions": 4224 + }, + { + "track": "tuev", + "shrinkage": 0.01, + "validation": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 71, + 571, + 203, + 137, + 2011, + 12494 + ], + "confusion_matrix": [ + [ + 0, + 38, + 25, + 0, + 19, + 37 + ], + [ + 0, + 125, + 0, + 0, + 166, + 0 + ], + [ + 4, + 33, + 157, + 14, + 452, + 9 + ], + [ + 1, + 1, + 0, + 58, + 6, + 20 + ], + [ + 0, + 0, + 0, + 0, + 473, + 27 + ], + [ + 66, + 374, + 21, + 65, + 895, + 12401 + ] + ], + "per_class_recall": [ + 0.0, + 0.42955326460481097, + 0.23467862481315396, + 0.6744186046511628, + 0.946, + 0.8971928809144841 + ], + "balanced_accuracy": 0.5303072291639354, + "accuracy": 0.8532317427519855, + "weighted_f1": 0.877200476423402, + "macro_f1": 0.4149175185261038, + "kappa": 0.46523864028539363, + "samples": 15487, + "reward": 0.5303072291639354, + "subjects": 58 + }, + "retained_feature_dimensions": 2496 + }, + { + "track": "tuev", + "shrinkage": 0.1, + "validation": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 139, + 561, + 221, + 114, + 1924, + 12528 + ], + "confusion_matrix": [ + [ + 1, + 40, + 25, + 0, + 13, + 40 + ], + [ + 0, + 103, + 0, + 0, + 188, + 0 + ], + [ + 26, + 41, + 154, + 12, + 425, + 11 + ], + [ + 2, + 2, + 0, + 58, + 4, + 20 + ], + [ + 0, + 1, + 0, + 0, + 471, + 28 + ], + [ + 110, + 374, + 42, + 44, + 823, + 12429 + ] + ], + "per_class_recall": [ + 0.008403361344537815, + 0.3539518900343643, + 0.23019431988041852, + 0.6744186046511628, + 0.942, + 0.899218636955578 + ], + "balanced_accuracy": 0.5180311354776769, + "accuracy": 0.8533608833214954, + "weighted_f1": 0.8772746807296039, + "macro_f1": 0.4179324769613028, + "kappa": 0.46209992862660443, + "samples": 15487, + "reward": 0.5180311354776769, + "subjects": 58 + }, + "retained_feature_dimensions": 2496 + }, + { + "track": "tuev", + "shrinkage": 0.5, + "validation": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 218, + 565, + 228, + 145, + 1763, + 12568 + ], + "confusion_matrix": [ + [ + 14, + 40, + 25, + 0, + 3, + 37 + ], + [ + 0, + 103, + 0, + 0, + 188, + 0 + ], + [ + 67, + 46, + 161, + 9, + 377, + 9 + ], + [ + 3, + 1, + 0, + 65, + 1, + 16 + ], + [ + 0, + 1, + 0, + 0, + 468, + 31 + ], + [ + 134, + 374, + 42, + 71, + 726, + 12475 + ] + ], + "per_class_recall": [ + 0.11764705882352941, + 0.3539518900343643, + 0.2406576980568012, + 0.7558139534883721, + 0.936, + 0.9025466647373752 + ], + "balanced_accuracy": 0.551102877523407, + "accuracy": 0.8578808032543424, + "weighted_f1": 0.8809363915041424, + "macro_f1": 0.43408821818520976, + "kappa": 0.47474120436306955, + "samples": 15487, + "reward": 0.551102877523407, + "subjects": 58 + }, + "retained_feature_dimensions": 2496 + }, + { + "track": "tuev", + "shrinkage": 0.9, + "validation": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 325, + 503, + 193, + 149, + 1913, + 12404 + ], + "confusion_matrix": [ + [ + 16, + 38, + 29, + 0, + 3, + 33 + ], + [ + 0, + 54, + 0, + 0, + 237, + 0 + ], + [ + 30, + 36, + 163, + 0, + 440, + 0 + ], + [ + 9, + 0, + 1, + 74, + 0, + 2 + ], + [ + 0, + 1, + 0, + 0, + 468, + 31 + ], + [ + 270, + 374, + 0, + 75, + 765, + 12338 + ] + ], + "per_class_recall": [ + 0.13445378151260504, + 0.18556701030927836, + 0.2436472346786248, + 0.8604651162790697, + 0.936, + 0.8926349298220229 + ], + "balanced_accuracy": 0.5421280121002668, + "accuracy": 0.846710143991735, + "weighted_f1": 0.8752099044793021, + "macro_f1": 0.4241444897805214, + "kappa": 0.45219685282715627, + "samples": 15487, + "reward": 0.5421280121002668, + "subjects": 58 + }, + "retained_feature_dimensions": 2496 + }, + { + "track": "tuev", + "shrinkage": 1.0, + "validation": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 1442, + 534, + 127, + 277, + 2934, + 10173 + ], + "confusion_matrix": [ + [ + 23, + 38, + 46, + 0, + 0, + 12 + ], + [ + 0, + 12, + 0, + 0, + 279, + 0 + ], + [ + 1, + 0, + 21, + 0, + 647, + 0 + ], + [ + 9, + 0, + 4, + 69, + 0, + 4 + ], + [ + 1, + 0, + 0, + 1, + 469, + 29 + ], + [ + 1408, + 484, + 56, + 207, + 1539, + 10128 + ] + ], + "per_class_recall": [ + 0.19327731092436976, + 0.041237113402061855, + 0.03139013452914798, + 0.8023255813953488, + 0.938, + 0.7327448994356822 + ], + "balanced_accuracy": 0.4564958399477685, + "accuracy": 0.6923225931426358, + "weighted_f1": 0.7674010258841251, + "macro_f1": 0.2681358369116143, + "kappa": 0.24182534207808626, + "samples": 15487, + "reward": 0.4564958399477685, + "subjects": 58 + }, + "retained_feature_dimensions": 2496 + }, + { + "track": "ad65", + "shrinkage": 0.01, + "validation": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 569, + 345, + 429 + ], + "confusion_matrix": [ + [ + 294, + 132, + 38 + ], + [ + 163, + 185, + 45 + ], + [ + 112, + 28, + 346 + ] + ], + "per_class_recall": [ + 0.6336206896551724, + 0.4707379134860051, + 0.7119341563786008 + ], + "balanced_accuracy": 0.605430919839926, + "accuracy": 0.6142963514519731, + "weighted_f1": 0.617053451370948, + "macro_f1": 0.6089516808815537, + "kappa": 0.4181157856525092, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 7, + 6, + 5 + ], + "confusion_matrix": [ + [ + 4, + 3, + 0 + ], + [ + 2, + 3, + 0 + ], + [ + 1, + 0, + 5 + ] + ], + "per_class_recall": [ + 0.5714285714285714, + 0.6, + 0.8333333333333334 + ], + "balanced_accuracy": 0.6682539682539682, + "accuracy": 0.6666666666666666, + "weighted_f1": 0.6767676767676767, + "macro_f1": 0.6753246753246752, + "kappa": 0.4976744186046512 + }, + "reward": 0.6682539682539682, + "subjects": 18 + }, + "retained_feature_dimensions": 4480 + }, + { + "track": "ad65", + "shrinkage": 0.1, + "validation": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 573, + 344, + 426 + ], + "confusion_matrix": [ + [ + 301, + 130, + 33 + ], + [ + 162, + 188, + 43 + ], + [ + 110, + 26, + 350 + ] + ], + "per_class_recall": [ + 0.6487068965517241, + 0.47837150127226463, + 0.720164609053498 + ], + "balanced_accuracy": 0.6157476689591622, + "accuracy": 0.6247207743857036, + "weighted_f1": 0.627615232629398, + "macro_f1": 0.6194136611019486, + "kappa": 0.4338400182677582, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 7, + 6, + 5 + ], + "confusion_matrix": [ + [ + 4, + 3, + 0 + ], + [ + 2, + 3, + 0 + ], + [ + 1, + 0, + 5 + ] + ], + "per_class_recall": [ + 0.5714285714285714, + 0.6, + 0.8333333333333334 + ], + "balanced_accuracy": 0.6682539682539682, + "accuracy": 0.6666666666666666, + "weighted_f1": 0.6767676767676767, + "macro_f1": 0.6753246753246752, + "kappa": 0.4976744186046512 + }, + "reward": 0.6682539682539682, + "subjects": 18 + }, + "retained_feature_dimensions": 4480 + }, + { + "track": "ad65", + "shrinkage": 0.5, + "validation": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 589, + 312, + 442 + ], + "confusion_matrix": [ + [ + 333, + 106, + 25 + ], + [ + 153, + 182, + 58 + ], + [ + 103, + 24, + 359 + ] + ], + "per_class_recall": [ + 0.7176724137931034, + 0.4631043256997455, + 0.7386831275720165 + ], + "balanced_accuracy": 0.6398199556882885, + "accuracy": 0.6507818317200298, + "weighted_f1": 0.649592163434174, + "macro_f1": 0.640832528589315, + "kappa": 0.4719978204832659, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 8, + 5, + 5 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 2, + 3, + 0 + ], + [ + 1, + 0, + 5 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.6, + 0.8333333333333334 + ], + "balanced_accuracy": 0.7158730158730159, + "accuracy": 0.7222222222222222, + "weighted_f1": 0.7289562289562289, + "macro_f1": 0.7252525252525253, + "kappa": 0.5774647887323943 + }, + "reward": 0.7158730158730159, + "subjects": 18 + }, + "retained_feature_dimensions": 4480 + }, + { + "track": "ad65", + "shrinkage": 0.9, + "validation": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 563, + 308, + 472 + ], + "confusion_matrix": [ + [ + 338, + 98, + 28 + ], + [ + 141, + 185, + 67 + ], + [ + 84, + 25, + 377 + ] + ], + "per_class_recall": [ + 0.728448275862069, + 0.4707379134860051, + 0.7757201646090535 + ], + "balanced_accuracy": 0.6583021179857091, + "accuracy": 0.6701414743112435, + "weighted_f1": 0.6666860429997351, + "macro_f1": 0.6577005397474678, + "kappa": 0.5008737555380497, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 7, + 5, + 6 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 2, + 3, + 0 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.6, + 1.0 + ], + "balanced_accuracy": 0.7714285714285714, + "accuracy": 0.7777777777777778, + "weighted_f1": 0.7777777777777778, + "macro_f1": 0.7714285714285714, + "kappa": 0.6635514018691588 + }, + "reward": 0.7714285714285714, + "subjects": 18 + }, + "retained_feature_dimensions": 4480 + }, + { + "track": "ad65", + "shrinkage": 1.0, + "validation": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 445, + 338, + 560 + ], + "confusion_matrix": [ + [ + 311, + 97, + 56 + ], + [ + 104, + 207, + 82 + ], + [ + 30, + 34, + 422 + ] + ], + "per_class_recall": [ + 0.6702586206896551, + 0.5267175572519084, + 0.8683127572016461 + ], + "balanced_accuracy": 0.6884296450477366, + "accuracy": 0.6999255398361877, + "weighted_f1": 0.694132852528767, + "macro_f1": 0.6858330870878985, + "kappa": 0.5460154759158681, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 6, + 5, + 7 + ], + "confusion_matrix": [ + [ + 4, + 2, + 1 + ], + [ + 2, + 3, + 0 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.5714285714285714, + 0.6, + 1.0 + ], + "balanced_accuracy": 0.7238095238095238, + "accuracy": 0.7222222222222222, + "weighted_f1": 0.7136752136752137, + "macro_f1": 0.712820512820513, + "kappa": 0.5813953488372094 + }, + "reward": 0.7238095238095238, + "subjects": 18 + }, + "retained_feature_dimensions": 4480 + }, + { + "track": "openbmi", + "shrinkage": 0.01, + "validation": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 1987, + 2413 + ], + "confusion_matrix": [ + [ + 1605, + 595 + ], + [ + 382, + 1818 + ] + ], + "per_class_recall": [ + 0.7295454545454545, + 0.8263636363636364 + ], + "balanced_accuracy": 0.7779545454545455, + "accuracy": 0.7779545454545455, + "weighted_f1": 0.7774329729623103, + "macro_f1": 0.7774329729623103, + "kappa": 0.5559090909090909, + "samples": 4400, + "subject_scores": { + "19": 0.8125, + "35": 0.915, + "34": 0.61, + "51": 0.72, + "20": 0.8025, + "44": 0.925, + "24": 0.6074999999999999, + "15": 0.87, + "31": 0.885, + "26": 0.7725, + "23": 0.6375 + }, + "reward": 0.7779545454545453, + "subjects": 11 + }, + "retained_feature_dimensions": 1856 + }, + { + "track": "openbmi", + "shrinkage": 0.1, + "validation": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 1980, + 2420 + ], + "confusion_matrix": [ + [ + 1627, + 573 + ], + [ + 353, + 1847 + ] + ], + "per_class_recall": [ + 0.7395454545454545, + 0.8395454545454546 + ], + "balanced_accuracy": 0.7895454545454546, + "accuracy": 0.7895454545454546, + "weighted_f1": 0.7890179995443154, + "macro_f1": 0.7890179995443154, + "kappa": 0.5790909090909091, + "samples": 4400, + "subject_scores": { + "19": 0.8375, + "35": 0.9275, + "34": 0.62, + "51": 0.7475, + "20": 0.8075, + "44": 0.9225, + "24": 0.6025, + "15": 0.8875, + "31": 0.8825000000000001, + "26": 0.7975000000000001, + "23": 0.6525 + }, + "reward": 0.7895454545454546, + "subjects": 11 + }, + "retained_feature_dimensions": 1856 + }, + { + "track": "openbmi", + "shrinkage": 0.5, + "validation": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 1973, + 2427 + ], + "confusion_matrix": [ + [ + 1637, + 563 + ], + [ + 336, + 1864 + ] + ], + "per_class_recall": [ + 0.7440909090909091, + 0.8472727272727273 + ], + "balanced_accuracy": 0.7956818181818182, + "accuracy": 0.7956818181818182, + "weighted_f1": 0.7951365491343152, + "macro_f1": 0.7951365491343152, + "kappa": 0.5913636363636363, + "samples": 4400, + "subject_scores": { + "19": 0.8574999999999999, + "35": 0.95, + "34": 0.64, + "51": 0.7475, + "20": 0.7825, + "44": 0.9225, + "24": 0.5974999999999999, + "15": 0.885, + "31": 0.8999999999999999, + "26": 0.7925, + "23": 0.6775 + }, + "reward": 0.7956818181818183, + "subjects": 11 + }, + "retained_feature_dimensions": 1856 + }, + { + "track": "openbmi", + "shrinkage": 0.9, + "validation": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 1985, + 2415 + ], + "confusion_matrix": [ + [ + 1636, + 564 + ], + [ + 349, + 1851 + ] + ], + "per_class_recall": [ + 0.7436363636363637, + 0.8413636363636363 + ], + "balanced_accuracy": 0.7925, + "accuracy": 0.7925, + "weighted_f1": 0.7920033758289097, + "macro_f1": 0.7920033758289097, + "kappa": 0.585, + "samples": 4400, + "subject_scores": { + "19": 0.8600000000000001, + "35": 0.95, + "34": 0.63, + "51": 0.7424999999999999, + "20": 0.755, + "44": 0.9075, + "24": 0.5925, + "15": 0.895, + "31": 0.9025, + "26": 0.8, + "23": 0.6825 + }, + "reward": 0.7925, + "subjects": 11 + }, + "retained_feature_dimensions": 1856 + }, + { + "track": "openbmi", + "shrinkage": 1.0, + "validation": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2063, + 2337 + ], + "confusion_matrix": [ + [ + 1593, + 607 + ], + [ + 470, + 1730 + ] + ], + "per_class_recall": [ + 0.7240909090909091, + 0.7863636363636364 + ], + "balanced_accuracy": 0.7552272727272727, + "accuracy": 0.7552272727272727, + "weighted_f1": 0.7549897418628628, + "macro_f1": 0.7549897418628628, + "kappa": 0.5104545454545455, + "samples": 4400, + "subject_scores": { + "19": 0.8325, + "35": 0.9175, + "34": 0.575, + "51": 0.7125, + "20": 0.6925, + "44": 0.8825000000000001, + "24": 0.5700000000000001, + "15": 0.8325, + "31": 0.8500000000000001, + "26": 0.7725, + "23": 0.6699999999999999 + }, + "reward": 0.7552272727272729, + "subjects": 11 + }, + "retained_feature_dimensions": 1856 + }, + { + "track": "longitudinal", + "shrinkage": 0.01, + "validation": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4553, + 3865 + ], + "confusion_matrix": [ + [ + 3636, + 624 + ], + [ + 917, + 3241 + ] + ], + "per_class_recall": [ + 0.8535211267605634, + 0.7794612794612794 + ], + "balanced_accuracy": 0.8164912031109214, + "accuracy": 0.8169398907103825, + "weighted_f1": 0.8166402520333086, + "macro_f1": 0.8165359409580131, + "kappa": 0.6335168498243628, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8359883849990462, + "sub-G2007": 0.7554742322962686, + "sub-G2019": 0.8242874220777945, + "sub-G2031": 0.7898027353325326, + "sub-G2015": 0.8430092962482106, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.7683343435176955, + "sub-G2035": 0.9532673469655393, + "sub-CTR003": 0.5587121212121212 + }, + "reward": 0.812869467537092, + "subjects": 9 + }, + "retained_feature_dimensions": 1280 + }, + { + "track": "longitudinal", + "shrinkage": 0.1, + "validation": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4564, + 3854 + ], + "confusion_matrix": [ + [ + 3643, + 617 + ], + [ + 921, + 3237 + ] + ], + "per_class_recall": [ + 0.8551643192488263, + 0.7784992784992785 + ], + "balanced_accuracy": 0.8168317988740523, + "accuracy": 0.817296269897838, + "weighted_f1": 0.8169773066894302, + "macro_f1": 0.8168702861392407, + "kappa": 0.6342187201230269, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.835988453452625, + "sub-G2007": 0.757618085748164, + "sub-G2019": 0.8258844084954515, + "sub-G2031": 0.7876651926844462, + "sub-G2015": 0.8397834897965977, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.7683447497781017, + "sub-G2035": 0.9540790352772276, + "sub-CTR003": 0.5619588744588745 + }, + "reward": 0.8131412905417897, + "subjects": 9 + }, + "retained_feature_dimensions": 1280 + }, + { + "track": "longitudinal", + "shrinkage": 0.5, + "validation": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4554, + 3864 + ], + "confusion_matrix": [ + [ + 3640, + 620 + ], + [ + 914, + 3244 + ] + ], + "per_class_recall": [ + 0.8544600938967136, + 0.7801827801827802 + ], + "balanced_accuracy": 0.8173214370397469, + "accuracy": 0.8177714421477785, + "weighted_f1": 0.8174713855016015, + "macro_f1": 0.8173672842161931, + "kappa": 0.6351805500323595, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8351820018397218, + "sub-G2007": 0.7580890146730404, + "sub-G2019": 0.8217940662181898, + "sub-G2031": 0.7897682630344715, + "sub-G2015": 0.8397834897965977, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.7683447497781017, + "sub-G2035": 0.9556971053971828, + "sub-CTR003": 0.577922077922078 + }, + "reward": 0.814836677093778, + "subjects": 9 + }, + "retained_feature_dimensions": 1280 + }, + { + "track": "longitudinal", + "shrinkage": 0.9, + "validation": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4591, + 3827 + ], + "confusion_matrix": [ + [ + 3668, + 592 + ], + [ + 923, + 3235 + ] + ], + "per_class_recall": [ + 0.8610328638497653, + 0.778018278018278 + ], + "balanced_accuracy": 0.8195255709340217, + "accuracy": 0.8200285103349965, + "weighted_f1": 0.8196635443916465, + "macro_f1": 0.8195510775450552, + "kappa": 0.6396607542670605, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8376331178226214, + "sub-G2007": 0.7653866879842162, + "sub-G2019": 0.8234381815392127, + "sub-G2031": 0.7876021763815796, + "sub-G2015": 0.8510738123772429, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.768266548982978, + "sub-G2035": 0.9556811201354545, + "sub-CTR003": 0.5749458874458875 + }, + "reward": 0.8167752064282013, + "subjects": 9 + }, + "retained_feature_dimensions": 1280 + }, + { + "track": "longitudinal", + "shrinkage": 1.0, + "validation": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4876, + 3542 + ], + "confusion_matrix": [ + [ + 3812, + 448 + ], + [ + 1064, + 3094 + ] + ], + "per_class_recall": [ + 0.8948356807511737, + 0.7441077441077442 + ], + "balanced_accuracy": 0.8194717124294589, + "accuracy": 0.8203848895224519, + "weighted_f1": 0.8192556106317086, + "macro_f1": 0.8190686196465531, + "kappa": 0.6400786713286714, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8391134271936106, + "sub-G2007": 0.8008080709188401, + "sub-G2019": 0.8167119870237068, + "sub-G2031": 0.7936660176338526, + "sub-G2015": 0.8961710193415227, + "sub-CTR002": 0.983723792547322, + "sub-G2011": 0.7439401917581905, + "sub-G2035": 0.9359715074227458, + "sub-CTR003": 0.5213744588744589 + }, + "reward": 0.8146089414126945, + "subjects": 9 + }, + "retained_feature_dimensions": 1280 + } + ], + "shared_backbone_training": "inherited joint five-track training, fixed during final head estimation", + "parent_training_receipt": { + "settings": { + "source": "/workspace/research/runs/residual_heads1/epoch-018", + "features": "/workspace/research/head_features_clinical_v1", + "incumbent": null, + "augmentation": "/workspace/research/timewarp_features_v1", + "augmented_lr": 5e-05, + "output": "/workspace/research/runs/residual_timewarp1", + "epochs": 40, + "steps": 200, + "batch_size": 256, + "lr": 1e-05, + "clinical_lr": 1e-05, + "retention": 2.0, + "dropout": 0.0, + "seed": 7 + }, + "history": [ + { + "epoch": 4, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 156, + 189, + 183, + 220, + 261, + 151, + 179, + 171, + 170 + ], + "confusion_matrix": [ + [ + 81, + 11, + 4, + 25, + 19, + 7, + 13, + 9, + 11 + ], + [ + 8, + 92, + 8, + 17, + 20, + 8, + 13, + 5, + 9 + ], + [ + 8, + 7, + 95, + 19, + 20, + 6, + 6, + 7, + 12 + ], + [ + 13, + 19, + 11, + 71, + 21, + 5, + 18, + 15, + 7 + ], + [ + 12, + 14, + 18, + 27, + 118, + 13, + 10, + 20, + 8 + ], + [ + 6, + 11, + 10, + 14, + 13, + 91, + 9, + 13, + 13 + ], + [ + 8, + 11, + 9, + 10, + 19, + 12, + 93, + 7, + 11 + ], + [ + 6, + 13, + 16, + 24, + 17, + 6, + 7, + 88, + 3 + ], + [ + 14, + 11, + 12, + 13, + 14, + 3, + 10, + 7, + 96 + ] + ], + "per_class_recall": [ + 0.45, + 0.5111111111111111, + 0.5277777777777778, + 0.39444444444444443, + 0.49166666666666664, + 0.5055555555555555, + 0.5166666666666667, + 0.4888888888888889, + 0.5333333333333333 + ], + "balanced_accuracy": 0.49104938271604937, + "accuracy": 0.49107142857142855, + "weighted_f1": 0.4934176845756243, + "macro_f1": 0.49424582532910905, + "kappa": 0.42643570761158633, + "samples": 1680, + "reward": 0.49104938271604937, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 548, + 740, + 185, + 426, + 1467, + 12121 + ], + "confusion_matrix": [ + [ + 21, + 38, + 23, + 4, + 0, + 33 + ], + [ + 0, + 224, + 0, + 39, + 28, + 0 + ], + [ + 113, + 170, + 118, + 36, + 232, + 0 + ], + [ + 5, + 0, + 0, + 80, + 0, + 1 + ], + [ + 2, + 0, + 1, + 24, + 422, + 51 + ], + [ + 407, + 308, + 43, + 243, + 785, + 12036 + ] + ], + "per_class_recall": [ + 0.17647058823529413, + 0.7697594501718213, + 0.17638266068759342, + 0.9302325581395349, + 0.844, + 0.8707857039502243 + ], + "balanced_accuracy": 0.6279384935307446, + "accuracy": 0.8330212436236843, + "weighted_f1": 0.8642987272558901, + "macro_f1": 0.40721747882478493, + "kappa": 0.43700462495537074, + "samples": 15487, + "reward": 0.6279384935307446, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2019, + 2381 + ], + "confusion_matrix": [ + [ + 1680, + 520 + ], + [ + 339, + 1861 + ] + ], + "per_class_recall": [ + 0.7636363636363637, + 0.8459090909090909 + ], + "balanced_accuracy": 0.8047727272727273, + "accuracy": 0.8047727272727273, + "weighted_f1": 0.8044418036119902, + "macro_f1": 0.8044418036119902, + "kappa": 0.6095454545454546, + "samples": 4400, + "subject_scores": { + "19": 0.87, + "35": 0.9550000000000001, + "34": 0.6475, + "51": 0.7525, + "20": 0.815, + "44": 0.9325, + "24": 0.5925, + "15": 0.8925000000000001, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.72 + }, + "reward": 0.8047727272727273, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4574, + 3844 + ], + "confusion_matrix": [ + [ + 3658, + 602 + ], + [ + 916, + 3242 + ] + ], + "per_class_recall": [ + 0.8586854460093897, + 0.7797017797017797 + ], + "balanced_accuracy": 0.8191936128555847, + "accuracy": 0.819672131147541, + "weighted_f1": 0.8193389120476722, + "macro_f1": 0.819230668900581, + "kappa": 0.6389648996053923, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8368421735781668, + "sub-G2007": 0.7651266214233094, + "sub-G2019": 0.8242345047591977, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8446221994740171, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9573204820205594, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8163437913863759, + "subjects": 9 + } + }, + "selected_head_epochs": { + "faced": 4, + "tuev": 4, + "ad65": 0, + "openbmi": 0, + "longitudinal": 0 + } + }, + { + "epoch": 5, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 155, + 190, + 184, + 218, + 261, + 152, + 179, + 171, + 170 + ], + "confusion_matrix": [ + [ + 81, + 11, + 4, + 25, + 19, + 7, + 13, + 9, + 11 + ], + [ + 8, + 92, + 8, + 17, + 20, + 8, + 13, + 5, + 9 + ], + [ + 8, + 7, + 95, + 19, + 20, + 6, + 6, + 7, + 12 + ], + [ + 13, + 19, + 11, + 71, + 21, + 5, + 18, + 15, + 7 + ], + [ + 12, + 14, + 18, + 27, + 118, + 13, + 10, + 20, + 8 + ], + [ + 6, + 11, + 10, + 13, + 13, + 92, + 9, + 13, + 13 + ], + [ + 7, + 11, + 10, + 10, + 19, + 12, + 93, + 7, + 11 + ], + [ + 6, + 14, + 16, + 23, + 17, + 6, + 7, + 88, + 3 + ], + [ + 14, + 11, + 12, + 13, + 14, + 3, + 10, + 7, + 96 + ] + ], + "per_class_recall": [ + 0.45, + 0.5111111111111111, + 0.5277777777777778, + 0.39444444444444443, + 0.49166666666666664, + 0.5111111111111111, + 0.5166666666666667, + 0.4888888888888889, + 0.5333333333333333 + ], + "balanced_accuracy": 0.49166666666666664, + "accuracy": 0.49166666666666664, + "weighted_f1": 0.49393255226238353, + "macro_f1": 0.4947797621894519, + "kappa": 0.4271065430412804, + "samples": 1680, + "reward": 0.49166666666666664, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 548, + 740, + 185, + 426, + 1467, + 12121 + ], + "confusion_matrix": [ + [ + 21, + 38, + 23, + 4, + 0, + 33 + ], + [ + 0, + 224, + 0, + 39, + 28, + 0 + ], + [ + 113, + 170, + 118, + 36, + 232, + 0 + ], + [ + 5, + 0, + 0, + 80, + 0, + 1 + ], + [ + 2, + 0, + 1, + 24, + 422, + 51 + ], + [ + 407, + 308, + 43, + 243, + 785, + 12036 + ] + ], + "per_class_recall": [ + 0.17647058823529413, + 0.7697594501718213, + 0.17638266068759342, + 0.9302325581395349, + 0.844, + 0.8707857039502243 + ], + "balanced_accuracy": 0.6279384935307446, + "accuracy": 0.8330212436236843, + "weighted_f1": 0.8642987272558901, + "macro_f1": 0.40721747882478493, + "kappa": 0.43700462495537074, + "samples": 15487, + "reward": 0.6279384935307446, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2019, + 2381 + ], + "confusion_matrix": [ + [ + 1680, + 520 + ], + [ + 339, + 1861 + ] + ], + "per_class_recall": [ + 0.7636363636363637, + 0.8459090909090909 + ], + "balanced_accuracy": 0.8047727272727273, + "accuracy": 0.8047727272727273, + "weighted_f1": 0.8044418036119902, + "macro_f1": 0.8044418036119902, + "kappa": 0.6095454545454546, + "samples": 4400, + "subject_scores": { + "19": 0.87, + "35": 0.9550000000000001, + "34": 0.6475, + "51": 0.7525, + "20": 0.815, + "44": 0.9325, + "24": 0.5925, + "15": 0.8925000000000001, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.72 + }, + "reward": 0.8047727272727273, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4574, + 3844 + ], + "confusion_matrix": [ + [ + 3658, + 602 + ], + [ + 916, + 3242 + ] + ], + "per_class_recall": [ + 0.8586854460093897, + 0.7797017797017797 + ], + "balanced_accuracy": 0.8191936128555847, + "accuracy": 0.819672131147541, + "weighted_f1": 0.8193389120476722, + "macro_f1": 0.819230668900581, + "kappa": 0.6389648996053923, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8368421735781668, + "sub-G2007": 0.7651266214233094, + "sub-G2019": 0.8242345047591977, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8446221994740171, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9573204820205594, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8163437913863759, + "subjects": 9 + } + }, + "selected_head_epochs": { + "faced": 5, + "tuev": 4, + "ad65": 0, + "openbmi": 0, + "longitudinal": 0 + } + }, + { + "epoch": 19, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 155, + 190, + 184, + 218, + 261, + 152, + 179, + 171, + 170 + ], + "confusion_matrix": [ + [ + 81, + 11, + 4, + 25, + 19, + 7, + 13, + 9, + 11 + ], + [ + 8, + 92, + 8, + 17, + 20, + 8, + 13, + 5, + 9 + ], + [ + 8, + 7, + 95, + 19, + 20, + 6, + 6, + 7, + 12 + ], + [ + 13, + 19, + 11, + 71, + 21, + 5, + 18, + 15, + 7 + ], + [ + 12, + 14, + 18, + 27, + 118, + 13, + 10, + 20, + 8 + ], + [ + 6, + 11, + 10, + 13, + 13, + 92, + 9, + 13, + 13 + ], + [ + 7, + 11, + 10, + 10, + 19, + 12, + 93, + 7, + 11 + ], + [ + 6, + 14, + 16, + 23, + 17, + 6, + 7, + 88, + 3 + ], + [ + 14, + 11, + 12, + 13, + 14, + 3, + 10, + 7, + 96 + ] + ], + "per_class_recall": [ + 0.45, + 0.5111111111111111, + 0.5277777777777778, + 0.39444444444444443, + 0.49166666666666664, + 0.5111111111111111, + 0.5166666666666667, + 0.4888888888888889, + 0.5333333333333333 + ], + "balanced_accuracy": 0.49166666666666664, + "accuracy": 0.49166666666666664, + "weighted_f1": 0.49393255226238353, + "macro_f1": 0.4947797621894519, + "kappa": 0.4271065430412804, + "samples": 1680, + "reward": 0.49166666666666664, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 480, + 725, + 155, + 359, + 1496, + 12272 + ], + "confusion_matrix": [ + [ + 21, + 38, + 23, + 4, + 0, + 33 + ], + [ + 0, + 224, + 0, + 39, + 28, + 0 + ], + [ + 110, + 155, + 110, + 39, + 255, + 0 + ], + [ + 7, + 0, + 0, + 77, + 0, + 2 + ], + [ + 1, + 0, + 0, + 1, + 444, + 54 + ], + [ + 341, + 308, + 22, + 199, + 769, + 12183 + ] + ], + "per_class_recall": [ + 0.17647058823529413, + 0.7697594501718213, + 0.16442451420029897, + 0.8953488372093024, + 0.888, + 0.8814209231659673 + ], + "balanced_accuracy": 0.629237385497114, + "accuracy": 0.8432233486149674, + "weighted_f1": 0.8700303426426117, + "macro_f1": 0.4171311849749148, + "kappa": 0.45561248235035545, + "samples": 15487, + "reward": 0.629237385497114, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2019, + 2381 + ], + "confusion_matrix": [ + [ + 1680, + 520 + ], + [ + 339, + 1861 + ] + ], + "per_class_recall": [ + 0.7636363636363637, + 0.8459090909090909 + ], + "balanced_accuracy": 0.8047727272727273, + "accuracy": 0.8047727272727273, + "weighted_f1": 0.8044418036119902, + "macro_f1": 0.8044418036119902, + "kappa": 0.6095454545454546, + "samples": 4400, + "subject_scores": { + "19": 0.87, + "35": 0.9550000000000001, + "34": 0.6475, + "51": 0.7525, + "20": 0.815, + "44": 0.9325, + "24": 0.5925, + "15": 0.8925000000000001, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.72 + }, + "reward": 0.8047727272727273, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4574, + 3844 + ], + "confusion_matrix": [ + [ + 3658, + 602 + ], + [ + 916, + 3242 + ] + ], + "per_class_recall": [ + 0.8586854460093897, + 0.7797017797017797 + ], + "balanced_accuracy": 0.8191936128555847, + "accuracy": 0.819672131147541, + "weighted_f1": 0.8193389120476722, + "macro_f1": 0.819230668900581, + "kappa": 0.6389648996053923, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8368421735781668, + "sub-G2007": 0.7651266214233094, + "sub-G2019": 0.8242345047591977, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8446221994740171, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9573204820205594, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8163437913863759, + "subjects": 9 + } + }, + "selected_head_epochs": { + "faced": 5, + "tuev": 19, + "ad65": 0, + "openbmi": 0, + "longitudinal": 0 + } + }, + { + "epoch": 20, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 155, + 190, + 184, + 218, + 261, + 152, + 179, + 171, + 170 + ], + "confusion_matrix": [ + [ + 81, + 11, + 4, + 25, + 19, + 7, + 13, + 9, + 11 + ], + [ + 8, + 92, + 8, + 17, + 20, + 8, + 13, + 5, + 9 + ], + [ + 8, + 7, + 95, + 19, + 20, + 6, + 6, + 7, + 12 + ], + [ + 13, + 19, + 11, + 71, + 21, + 5, + 18, + 15, + 7 + ], + [ + 12, + 14, + 18, + 27, + 118, + 13, + 10, + 20, + 8 + ], + [ + 6, + 11, + 10, + 13, + 13, + 92, + 9, + 13, + 13 + ], + [ + 7, + 11, + 10, + 10, + 19, + 12, + 93, + 7, + 11 + ], + [ + 6, + 14, + 16, + 23, + 17, + 6, + 7, + 88, + 3 + ], + [ + 14, + 11, + 12, + 13, + 14, + 3, + 10, + 7, + 96 + ] + ], + "per_class_recall": [ + 0.45, + 0.5111111111111111, + 0.5277777777777778, + 0.39444444444444443, + 0.49166666666666664, + 0.5111111111111111, + 0.5166666666666667, + 0.4888888888888889, + 0.5333333333333333 + ], + "balanced_accuracy": 0.49166666666666664, + "accuracy": 0.49166666666666664, + "weighted_f1": 0.49393255226238353, + "macro_f1": 0.4947797621894519, + "kappa": 0.4271065430412804, + "samples": 1680, + "reward": 0.49166666666666664, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 478, + 725, + 155, + 380, + 1525, + 12224 + ], + "confusion_matrix": [ + [ + 21, + 38, + 23, + 4, + 0, + 33 + ], + [ + 0, + 224, + 0, + 39, + 28, + 0 + ], + [ + 110, + 155, + 110, + 39, + 255, + 0 + ], + [ + 5, + 0, + 0, + 79, + 0, + 2 + ], + [ + 1, + 0, + 0, + 1, + 447, + 51 + ], + [ + 341, + 308, + 22, + 218, + 795, + 12138 + ] + ], + "per_class_recall": [ + 0.17647058823529413, + 0.7697594501718213, + 0.16442451420029897, + 0.9186046511627907, + 0.894, + 0.8781652438142092 + ], + "balanced_accuracy": 0.6335707412640691, + "accuracy": 0.8406405372247692, + "weighted_f1": 0.8683350853549184, + "macro_f1": 0.4151445859020529, + "kappa": 0.4517821772706142, + "samples": 15487, + "reward": 0.6335707412640691, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2019, + 2381 + ], + "confusion_matrix": [ + [ + 1680, + 520 + ], + [ + 339, + 1861 + ] + ], + "per_class_recall": [ + 0.7636363636363637, + 0.8459090909090909 + ], + "balanced_accuracy": 0.8047727272727273, + "accuracy": 0.8047727272727273, + "weighted_f1": 0.8044418036119902, + "macro_f1": 0.8044418036119902, + "kappa": 0.6095454545454546, + "samples": 4400, + "subject_scores": { + "19": 0.87, + "35": 0.9550000000000001, + "34": 0.6475, + "51": 0.7525, + "20": 0.815, + "44": 0.9325, + "24": 0.5925, + "15": 0.8925000000000001, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.72 + }, + "reward": 0.8047727272727273, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4574, + 3844 + ], + "confusion_matrix": [ + [ + 3658, + 602 + ], + [ + 916, + 3242 + ] + ], + "per_class_recall": [ + 0.8586854460093897, + 0.7797017797017797 + ], + "balanced_accuracy": 0.8191936128555847, + "accuracy": 0.819672131147541, + "weighted_f1": 0.8193389120476722, + "macro_f1": 0.819230668900581, + "kappa": 0.6389648996053923, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8368421735781668, + "sub-G2007": 0.7651266214233094, + "sub-G2019": 0.8242345047591977, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8446221994740171, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9573204820205594, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8163437913863759, + "subjects": 9 + } + }, + "selected_head_epochs": { + "faced": 5, + "tuev": 20, + "ad65": 0, + "openbmi": 0, + "longitudinal": 0 + } + }, + { + "epoch": 24, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 155, + 190, + 184, + 218, + 261, + 152, + 179, + 171, + 170 + ], + "confusion_matrix": [ + [ + 81, + 11, + 4, + 25, + 19, + 7, + 13, + 9, + 11 + ], + [ + 8, + 92, + 8, + 17, + 20, + 8, + 13, + 5, + 9 + ], + [ + 8, + 7, + 95, + 19, + 20, + 6, + 6, + 7, + 12 + ], + [ + 13, + 19, + 11, + 71, + 21, + 5, + 18, + 15, + 7 + ], + [ + 12, + 14, + 18, + 27, + 118, + 13, + 10, + 20, + 8 + ], + [ + 6, + 11, + 10, + 13, + 13, + 92, + 9, + 13, + 13 + ], + [ + 7, + 11, + 10, + 10, + 19, + 12, + 93, + 7, + 11 + ], + [ + 6, + 14, + 16, + 23, + 17, + 6, + 7, + 88, + 3 + ], + [ + 14, + 11, + 12, + 13, + 14, + 3, + 10, + 7, + 96 + ] + ], + "per_class_recall": [ + 0.45, + 0.5111111111111111, + 0.5277777777777778, + 0.39444444444444443, + 0.49166666666666664, + 0.5111111111111111, + 0.5166666666666667, + 0.4888888888888889, + 0.5333333333333333 + ], + "balanced_accuracy": 0.49166666666666664, + "accuracy": 0.49166666666666664, + "weighted_f1": 0.49393255226238353, + "macro_f1": 0.4947797621894519, + "kappa": 0.4271065430412804, + "samples": 1680, + "reward": 0.49166666666666664, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 478, + 725, + 155, + 361, + 1525, + 12243 + ], + "confusion_matrix": [ + [ + 21, + 38, + 23, + 4, + 0, + 33 + ], + [ + 0, + 224, + 0, + 39, + 28, + 0 + ], + [ + 110, + 155, + 110, + 39, + 255, + 0 + ], + [ + 5, + 0, + 0, + 79, + 0, + 2 + ], + [ + 1, + 0, + 0, + 1, + 447, + 51 + ], + [ + 341, + 308, + 22, + 199, + 795, + 12157 + ] + ], + "per_class_recall": [ + 0.17647058823529413, + 0.7697594501718213, + 0.16442451420029897, + 0.9186046511627907, + 0.894, + 0.8795398639849515 + ], + "balanced_accuracy": 0.6337998446258595, + "accuracy": 0.8418673726351134, + "weighted_f1": 0.8691099038121964, + "macro_f1": 0.4176762944372105, + "kappa": 0.45395865853864836, + "samples": 15487, + "reward": 0.6337998446258595, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2019, + 2381 + ], + "confusion_matrix": [ + [ + 1680, + 520 + ], + [ + 339, + 1861 + ] + ], + "per_class_recall": [ + 0.7636363636363637, + 0.8459090909090909 + ], + "balanced_accuracy": 0.8047727272727273, + "accuracy": 0.8047727272727273, + "weighted_f1": 0.8044418036119902, + "macro_f1": 0.8044418036119902, + "kappa": 0.6095454545454546, + "samples": 4400, + "subject_scores": { + "19": 0.87, + "35": 0.9550000000000001, + "34": 0.6475, + "51": 0.7525, + "20": 0.815, + "44": 0.9325, + "24": 0.5925, + "15": 0.8925000000000001, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.72 + }, + "reward": 0.8047727272727273, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4574, + 3844 + ], + "confusion_matrix": [ + [ + 3658, + 602 + ], + [ + 916, + 3242 + ] + ], + "per_class_recall": [ + 0.8586854460093897, + 0.7797017797017797 + ], + "balanced_accuracy": 0.8191936128555847, + "accuracy": 0.819672131147541, + "weighted_f1": 0.8193389120476722, + "macro_f1": 0.819230668900581, + "kappa": 0.6389648996053923, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8368421735781668, + "sub-G2007": 0.7651266214233094, + "sub-G2019": 0.8242345047591977, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8446221994740171, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9573204820205594, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8163437913863759, + "subjects": 9 + } + }, + "selected_head_epochs": { + "faced": 5, + "tuev": 24, + "ad65": 0, + "openbmi": 0, + "longitudinal": 0 + } + } + ], + "shared_backbone_training": "inherited joint training on all five training splits; frozen during nonlinear classification-head refinement", + "parent_training_receipt": { + "settings": { + "source": "/workspace/research/runs/clinical_spectral_adapter1/epoch-007", + "features": "/workspace/research/head_features_clinical_v1", + "incumbent": null, + "output": "/workspace/research/runs/residual_heads1", + "epochs": 40, + "steps": 200, + "batch_size": 256, + "lr": 0.0001, + "clinical_lr": 0.0001, + "retention": 2.0, + "dropout": 0.0, + "seed": 7 + }, + "history": [ + { + "epoch": 3, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 157, + 194, + 179, + 214, + 244, + 162, + 180, + 173, + 177 + ], + "confusion_matrix": [ + [ + 78, + 14, + 5, + 23, + 19, + 9, + 13, + 9, + 10 + ], + [ + 11, + 88, + 9, + 13, + 19, + 11, + 13, + 6, + 10 + ], + [ + 6, + 7, + 94, + 20, + 17, + 5, + 7, + 10, + 14 + ], + [ + 14, + 18, + 9, + 71, + 21, + 8, + 16, + 15, + 8 + ], + [ + 13, + 13, + 16, + 26, + 113, + 17, + 13, + 18, + 11 + ], + [ + 6, + 12, + 12, + 15, + 12, + 83, + 10, + 14, + 16 + ], + [ + 8, + 12, + 8, + 14, + 16, + 14, + 90, + 9, + 9 + ], + [ + 8, + 16, + 15, + 17, + 15, + 10, + 10, + 83, + 6 + ], + [ + 13, + 14, + 11, + 15, + 12, + 5, + 8, + 9, + 93 + ] + ], + "per_class_recall": [ + 0.43333333333333335, + 0.4888888888888889, + 0.5222222222222223, + 0.39444444444444443, + 0.4708333333333333, + 0.46111111111111114, + 0.5, + 0.46111111111111114, + 0.5166666666666667 + ], + "balanced_accuracy": 0.472067901234568, + "accuracy": 0.4720238095238095, + "weighted_f1": 0.4732298815998091, + "macro_f1": 0.47346276059386383, + "kappa": 0.40521122712903535, + "samples": 1680, + "reward": 0.472067901234568, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 594, + 724, + 187, + 475, + 1457, + 12050 + ], + "confusion_matrix": [ + [ + 21, + 38, + 23, + 4, + 0, + 33 + ], + [ + 0, + 224, + 0, + 39, + 28, + 0 + ], + [ + 115, + 154, + 120, + 55, + 225, + 0 + ], + [ + 5, + 0, + 0, + 80, + 0, + 1 + ], + [ + 2, + 0, + 1, + 24, + 422, + 51 + ], + [ + 451, + 308, + 43, + 273, + 782, + 11965 + ] + ], + "per_class_recall": [ + 0.17647058823529413, + 0.7697594501718213, + 0.17937219730941703, + 0.9302325581395349, + 0.844, + 0.8656489654174504 + ], + "balanced_accuracy": 0.6275806265455862, + "accuracy": 0.8285658939755924, + "weighted_f1": 0.8618635180906945, + "macro_f1": 0.40367911279847074, + "kappa": 0.42983741832596223, + "samples": 15487, + "reward": 0.6275806265455862, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2019, + 2381 + ], + "confusion_matrix": [ + [ + 1680, + 520 + ], + [ + 339, + 1861 + ] + ], + "per_class_recall": [ + 0.7636363636363637, + 0.8459090909090909 + ], + "balanced_accuracy": 0.8047727272727273, + "accuracy": 0.8047727272727273, + "weighted_f1": 0.8044418036119902, + "macro_f1": 0.8044418036119902, + "kappa": 0.6095454545454546, + "samples": 4400, + "subject_scores": { + "19": 0.87, + "35": 0.9550000000000001, + "34": 0.6475, + "51": 0.7525, + "20": 0.815, + "44": 0.9325, + "24": 0.5925, + "15": 0.8925000000000001, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.72 + }, + "reward": 0.8047727272727273, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4574, + 3844 + ], + "confusion_matrix": [ + [ + 3658, + 602 + ], + [ + 916, + 3242 + ] + ], + "per_class_recall": [ + 0.8586854460093897, + 0.7797017797017797 + ], + "balanced_accuracy": 0.8191936128555847, + "accuracy": 0.819672131147541, + "weighted_f1": 0.8193389120476722, + "macro_f1": 0.819230668900581, + "kappa": 0.6389648996053923, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8368421735781668, + "sub-G2007": 0.7651266214233094, + "sub-G2019": 0.8242345047591977, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8446221994740171, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9573204820205594, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8163437913863759, + "subjects": 9 + } + }, + "selected_head_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 3, + "longitudinal": 0 + } + }, + { + "epoch": 5, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 157, + 191, + 187, + 214, + 246, + 157, + 180, + 175, + 173 + ], + "confusion_matrix": [ + [ + 79, + 11, + 5, + 25, + 19, + 9, + 13, + 9, + 10 + ], + [ + 9, + 91, + 9, + 14, + 20, + 10, + 13, + 6, + 8 + ], + [ + 7, + 6, + 95, + 18, + 19, + 5, + 6, + 9, + 15 + ], + [ + 15, + 19, + 11, + 68, + 21, + 6, + 17, + 15, + 8 + ], + [ + 12, + 15, + 19, + 27, + 109, + 16, + 13, + 19, + 10 + ], + [ + 7, + 13, + 12, + 13, + 13, + 83, + 10, + 14, + 15 + ], + [ + 8, + 10, + 11, + 13, + 17, + 14, + 90, + 8, + 9 + ], + [ + 7, + 13, + 14, + 19, + 16, + 9, + 10, + 86, + 6 + ], + [ + 13, + 13, + 11, + 17, + 12, + 5, + 8, + 9, + 92 + ] + ], + "per_class_recall": [ + 0.4388888888888889, + 0.5055555555555555, + 0.5277777777777778, + 0.37777777777777777, + 0.45416666666666666, + 0.46111111111111114, + 0.5, + 0.4777777777777778, + 0.5111111111111111 + ], + "balanced_accuracy": 0.47268518518518515, + "accuracy": 0.4720238095238095, + "weighted_f1": 0.4734334573860391, + "macro_f1": 0.4743547087417483, + "kappa": 0.405182736983283, + "samples": 1680, + "reward": 0.47268518518518515, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 594, + 724, + 187, + 475, + 1457, + 12050 + ], + "confusion_matrix": [ + [ + 21, + 38, + 23, + 4, + 0, + 33 + ], + [ + 0, + 224, + 0, + 39, + 28, + 0 + ], + [ + 115, + 154, + 120, + 55, + 225, + 0 + ], + [ + 5, + 0, + 0, + 80, + 0, + 1 + ], + [ + 2, + 0, + 1, + 24, + 422, + 51 + ], + [ + 451, + 308, + 43, + 273, + 782, + 11965 + ] + ], + "per_class_recall": [ + 0.17647058823529413, + 0.7697594501718213, + 0.17937219730941703, + 0.9302325581395349, + 0.844, + 0.8656489654174504 + ], + "balanced_accuracy": 0.6275806265455862, + "accuracy": 0.8285658939755924, + "weighted_f1": 0.8618635180906945, + "macro_f1": 0.40367911279847074, + "kappa": 0.42983741832596223, + "samples": 15487, + "reward": 0.6275806265455862, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2019, + 2381 + ], + "confusion_matrix": [ + [ + 1680, + 520 + ], + [ + 339, + 1861 + ] + ], + "per_class_recall": [ + 0.7636363636363637, + 0.8459090909090909 + ], + "balanced_accuracy": 0.8047727272727273, + "accuracy": 0.8047727272727273, + "weighted_f1": 0.8044418036119902, + "macro_f1": 0.8044418036119902, + "kappa": 0.6095454545454546, + "samples": 4400, + "subject_scores": { + "19": 0.87, + "35": 0.9550000000000001, + "34": 0.6475, + "51": 0.7525, + "20": 0.815, + "44": 0.9325, + "24": 0.5925, + "15": 0.8925000000000001, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.72 + }, + "reward": 0.8047727272727273, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4574, + 3844 + ], + "confusion_matrix": [ + [ + 3658, + 602 + ], + [ + 916, + 3242 + ] + ], + "per_class_recall": [ + 0.8586854460093897, + 0.7797017797017797 + ], + "balanced_accuracy": 0.8191936128555847, + "accuracy": 0.819672131147541, + "weighted_f1": 0.8193389120476722, + "macro_f1": 0.819230668900581, + "kappa": 0.6389648996053923, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8368421735781668, + "sub-G2007": 0.7651266214233094, + "sub-G2019": 0.8242345047591977, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8446221994740171, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9573204820205594, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8163437913863759, + "subjects": 9 + } + }, + "selected_head_epochs": { + "faced": 5, + "tuev": 0, + "ad65": 0, + "openbmi": 3, + "longitudinal": 0 + } + }, + { + "epoch": 7, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 159, + 192, + 185, + 212, + 248, + 154, + 177, + 176, + 177 + ], + "confusion_matrix": [ + [ + 80, + 13, + 5, + 23, + 19, + 8, + 13, + 9, + 10 + ], + [ + 9, + 89, + 9, + 17, + 21, + 9, + 12, + 6, + 8 + ], + [ + 8, + 6, + 94, + 20, + 18, + 5, + 6, + 9, + 14 + ], + [ + 15, + 20, + 11, + 67, + 21, + 6, + 17, + 15, + 8 + ], + [ + 11, + 14, + 19, + 28, + 110, + 16, + 11, + 20, + 11 + ], + [ + 7, + 13, + 12, + 12, + 13, + 84, + 10, + 14, + 15 + ], + [ + 8, + 11, + 11, + 13, + 18, + 12, + 90, + 8, + 9 + ], + [ + 7, + 14, + 13, + 19, + 15, + 10, + 10, + 86, + 6 + ], + [ + 14, + 12, + 11, + 13, + 13, + 4, + 8, + 9, + 96 + ] + ], + "per_class_recall": [ + 0.4444444444444444, + 0.49444444444444446, + 0.5222222222222223, + 0.37222222222222223, + 0.4583333333333333, + 0.4666666666666667, + 0.5, + 0.4777777777777778, + 0.5333333333333333 + ], + "balanced_accuracy": 0.47438271604938276, + "accuracy": 0.4738095238095238, + "weighted_f1": 0.4753527894610444, + "macro_f1": 0.4762614234362258, + "kappa": 0.4071661237785017, + "samples": 1680, + "reward": 0.47438271604938276, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 594, + 724, + 187, + 475, + 1457, + 12050 + ], + "confusion_matrix": [ + [ + 21, + 38, + 23, + 4, + 0, + 33 + ], + [ + 0, + 224, + 0, + 39, + 28, + 0 + ], + [ + 115, + 154, + 120, + 55, + 225, + 0 + ], + [ + 5, + 0, + 0, + 80, + 0, + 1 + ], + [ + 2, + 0, + 1, + 24, + 422, + 51 + ], + [ + 451, + 308, + 43, + 273, + 782, + 11965 + ] + ], + "per_class_recall": [ + 0.17647058823529413, + 0.7697594501718213, + 0.17937219730941703, + 0.9302325581395349, + 0.844, + 0.8656489654174504 + ], + "balanced_accuracy": 0.6275806265455862, + "accuracy": 0.8285658939755924, + "weighted_f1": 0.8618635180906945, + "macro_f1": 0.40367911279847074, + "kappa": 0.42983741832596223, + "samples": 15487, + "reward": 0.6275806265455862, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2019, + 2381 + ], + "confusion_matrix": [ + [ + 1680, + 520 + ], + [ + 339, + 1861 + ] + ], + "per_class_recall": [ + 0.7636363636363637, + 0.8459090909090909 + ], + "balanced_accuracy": 0.8047727272727273, + "accuracy": 0.8047727272727273, + "weighted_f1": 0.8044418036119902, + "macro_f1": 0.8044418036119902, + "kappa": 0.6095454545454546, + "samples": 4400, + "subject_scores": { + "19": 0.87, + "35": 0.9550000000000001, + "34": 0.6475, + "51": 0.7525, + "20": 0.815, + "44": 0.9325, + "24": 0.5925, + "15": 0.8925000000000001, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.72 + }, + "reward": 0.8047727272727273, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4574, + 3844 + ], + "confusion_matrix": [ + [ + 3658, + 602 + ], + [ + 916, + 3242 + ] + ], + "per_class_recall": [ + 0.8586854460093897, + 0.7797017797017797 + ], + "balanced_accuracy": 0.8191936128555847, + "accuracy": 0.819672131147541, + "weighted_f1": 0.8193389120476722, + "macro_f1": 0.819230668900581, + "kappa": 0.6389648996053923, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8368421735781668, + "sub-G2007": 0.7651266214233094, + "sub-G2019": 0.8242345047591977, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8446221994740171, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9573204820205594, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8163437913863759, + "subjects": 9 + } + }, + "selected_head_epochs": { + "faced": 7, + "tuev": 0, + "ad65": 0, + "openbmi": 3, + "longitudinal": 0 + } + }, + { + "epoch": 8, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 163, + 189, + 187, + 208, + 247, + 159, + 177, + 172, + 178 + ], + "confusion_matrix": [ + [ + 81, + 12, + 5, + 23, + 19, + 8, + 13, + 9, + 10 + ], + [ + 10, + 88, + 9, + 17, + 21, + 10, + 12, + 5, + 8 + ], + [ + 8, + 6, + 95, + 20, + 18, + 6, + 5, + 8, + 14 + ], + [ + 15, + 21, + 11, + 66, + 21, + 6, + 19, + 14, + 7 + ], + [ + 13, + 13, + 20, + 26, + 111, + 16, + 11, + 19, + 11 + ], + [ + 7, + 13, + 12, + 12, + 12, + 85, + 10, + 14, + 15 + ], + [ + 8, + 11, + 11, + 12, + 16, + 13, + 90, + 8, + 11 + ], + [ + 7, + 14, + 13, + 19, + 16, + 10, + 9, + 86, + 6 + ], + [ + 14, + 11, + 11, + 13, + 13, + 5, + 8, + 9, + 96 + ] + ], + "per_class_recall": [ + 0.45, + 0.4888888888888889, + 0.5277777777777778, + 0.36666666666666664, + 0.4625, + 0.4722222222222222, + 0.5, + 0.4777777777777778, + 0.5333333333333333 + ], + "balanced_accuracy": 0.475462962962963, + "accuracy": 0.475, + "weighted_f1": 0.4763157887508829, + "macro_f1": 0.4770737010728603, + "kappa": 0.4085215433621536, + "samples": 1680, + "reward": 0.475462962962963, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 594, + 724, + 187, + 475, + 1457, + 12050 + ], + "confusion_matrix": [ + [ + 21, + 38, + 23, + 4, + 0, + 33 + ], + [ + 0, + 224, + 0, + 39, + 28, + 0 + ], + [ + 115, + 154, + 120, + 55, + 225, + 0 + ], + [ + 5, + 0, + 0, + 80, + 0, + 1 + ], + [ + 2, + 0, + 1, + 24, + 422, + 51 + ], + [ + 451, + 308, + 43, + 273, + 782, + 11965 + ] + ], + "per_class_recall": [ + 0.17647058823529413, + 0.7697594501718213, + 0.17937219730941703, + 0.9302325581395349, + 0.844, + 0.8656489654174504 + ], + "balanced_accuracy": 0.6275806265455862, + "accuracy": 0.8285658939755924, + "weighted_f1": 0.8618635180906945, + "macro_f1": 0.40367911279847074, + "kappa": 0.42983741832596223, + "samples": 15487, + "reward": 0.6275806265455862, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2019, + 2381 + ], + "confusion_matrix": [ + [ + 1680, + 520 + ], + [ + 339, + 1861 + ] + ], + "per_class_recall": [ + 0.7636363636363637, + 0.8459090909090909 + ], + "balanced_accuracy": 0.8047727272727273, + "accuracy": 0.8047727272727273, + "weighted_f1": 0.8044418036119902, + "macro_f1": 0.8044418036119902, + "kappa": 0.6095454545454546, + "samples": 4400, + "subject_scores": { + "19": 0.87, + "35": 0.9550000000000001, + "34": 0.6475, + "51": 0.7525, + "20": 0.815, + "44": 0.9325, + "24": 0.5925, + "15": 0.8925000000000001, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.72 + }, + "reward": 0.8047727272727273, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4574, + 3844 + ], + "confusion_matrix": [ + [ + 3658, + 602 + ], + [ + 916, + 3242 + ] + ], + "per_class_recall": [ + 0.8586854460093897, + 0.7797017797017797 + ], + "balanced_accuracy": 0.8191936128555847, + "accuracy": 0.819672131147541, + "weighted_f1": 0.8193389120476722, + "macro_f1": 0.819230668900581, + "kappa": 0.6389648996053923, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8368421735781668, + "sub-G2007": 0.7651266214233094, + "sub-G2019": 0.8242345047591977, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8446221994740171, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9573204820205594, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8163437913863759, + "subjects": 9 + } + }, + "selected_head_epochs": { + "faced": 8, + "tuev": 0, + "ad65": 0, + "openbmi": 3, + "longitudinal": 0 + } + }, + { + "epoch": 9, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 158, + 190, + 187, + 211, + 253, + 155, + 179, + 169, + 178 + ], + "confusion_matrix": [ + [ + 80, + 11, + 5, + 24, + 20, + 8, + 13, + 9, + 10 + ], + [ + 9, + 89, + 9, + 16, + 21, + 9, + 12, + 6, + 9 + ], + [ + 7, + 6, + 95, + 20, + 19, + 6, + 6, + 7, + 14 + ], + [ + 15, + 21, + 11, + 66, + 22, + 6, + 19, + 14, + 6 + ], + [ + 12, + 14, + 19, + 26, + 113, + 17, + 11, + 18, + 10 + ], + [ + 6, + 13, + 12, + 13, + 13, + 83, + 10, + 14, + 16 + ], + [ + 7, + 11, + 11, + 12, + 17, + 12, + 91, + 8, + 11 + ], + [ + 7, + 14, + 14, + 21, + 15, + 10, + 9, + 85, + 5 + ], + [ + 15, + 11, + 11, + 13, + 13, + 4, + 8, + 8, + 97 + ] + ], + "per_class_recall": [ + 0.4444444444444444, + 0.49444444444444446, + 0.5277777777777778, + 0.36666666666666664, + 0.4708333333333333, + 0.46111111111111114, + 0.5055555555555555, + 0.4722222222222222, + 0.5388888888888889 + ], + "balanced_accuracy": 0.4757716049382716, + "accuracy": 0.47559523809523807, + "weighted_f1": 0.4770510403387236, + "macro_f1": 0.47774115850317345, + "kappa": 0.4091072412388914, + "samples": 1680, + "reward": 0.4757716049382716, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 594, + 724, + 187, + 475, + 1457, + 12050 + ], + "confusion_matrix": [ + [ + 21, + 38, + 23, + 4, + 0, + 33 + ], + [ + 0, + 224, + 0, + 39, + 28, + 0 + ], + [ + 115, + 154, + 120, + 55, + 225, + 0 + ], + [ + 5, + 0, + 0, + 80, + 0, + 1 + ], + [ + 2, + 0, + 1, + 24, + 422, + 51 + ], + [ + 451, + 308, + 43, + 273, + 782, + 11965 + ] + ], + "per_class_recall": [ + 0.17647058823529413, + 0.7697594501718213, + 0.17937219730941703, + 0.9302325581395349, + 0.844, + 0.8656489654174504 + ], + "balanced_accuracy": 0.6275806265455862, + "accuracy": 0.8285658939755924, + "weighted_f1": 0.8618635180906945, + "macro_f1": 0.40367911279847074, + "kappa": 0.42983741832596223, + "samples": 15487, + "reward": 0.6275806265455862, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2019, + 2381 + ], + "confusion_matrix": [ + [ + 1680, + 520 + ], + [ + 339, + 1861 + ] + ], + "per_class_recall": [ + 0.7636363636363637, + 0.8459090909090909 + ], + "balanced_accuracy": 0.8047727272727273, + "accuracy": 0.8047727272727273, + "weighted_f1": 0.8044418036119902, + "macro_f1": 0.8044418036119902, + "kappa": 0.6095454545454546, + "samples": 4400, + "subject_scores": { + "19": 0.87, + "35": 0.9550000000000001, + "34": 0.6475, + "51": 0.7525, + "20": 0.815, + "44": 0.9325, + "24": 0.5925, + "15": 0.8925000000000001, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.72 + }, + "reward": 0.8047727272727273, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4574, + 3844 + ], + "confusion_matrix": [ + [ + 3658, + 602 + ], + [ + 916, + 3242 + ] + ], + "per_class_recall": [ + 0.8586854460093897, + 0.7797017797017797 + ], + "balanced_accuracy": 0.8191936128555847, + "accuracy": 0.819672131147541, + "weighted_f1": 0.8193389120476722, + "macro_f1": 0.819230668900581, + "kappa": 0.6389648996053923, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8368421735781668, + "sub-G2007": 0.7651266214233094, + "sub-G2019": 0.8242345047591977, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8446221994740171, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9573204820205594, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8163437913863759, + "subjects": 9 + } + }, + "selected_head_epochs": { + "faced": 9, + "tuev": 0, + "ad65": 0, + "openbmi": 3, + "longitudinal": 0 + } + }, + { + "epoch": 10, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 162, + 188, + 183, + 212, + 252, + 158, + 179, + 173, + 173 + ], + "confusion_matrix": [ + [ + 81, + 11, + 5, + 24, + 19, + 8, + 13, + 9, + 10 + ], + [ + 10, + 89, + 9, + 15, + 21, + 10, + 12, + 6, + 8 + ], + [ + 7, + 6, + 93, + 21, + 19, + 6, + 6, + 8, + 14 + ], + [ + 14, + 20, + 10, + 68, + 22, + 6, + 19, + 15, + 6 + ], + [ + 12, + 14, + 19, + 27, + 113, + 16, + 11, + 19, + 9 + ], + [ + 8, + 12, + 11, + 11, + 13, + 87, + 10, + 14, + 14 + ], + [ + 7, + 11, + 11, + 12, + 17, + 12, + 91, + 8, + 11 + ], + [ + 7, + 14, + 14, + 21, + 15, + 9, + 9, + 86, + 5 + ], + [ + 16, + 11, + 11, + 13, + 13, + 4, + 8, + 8, + 96 + ] + ], + "per_class_recall": [ + 0.45, + 0.49444444444444446, + 0.5166666666666667, + 0.37777777777777777, + 0.4708333333333333, + 0.48333333333333334, + 0.5055555555555555, + 0.4777777777777778, + 0.5333333333333333 + ], + "balanced_accuracy": 0.4788580246913581, + "accuracy": 0.4785714285714286, + "weighted_f1": 0.4802249590589458, + "macro_f1": 0.48099812074646464, + "kappa": 0.41247484909456744, + "samples": 1680, + "reward": 0.4788580246913581, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 594, + 724, + 187, + 475, + 1457, + 12050 + ], + "confusion_matrix": [ + [ + 21, + 38, + 23, + 4, + 0, + 33 + ], + [ + 0, + 224, + 0, + 39, + 28, + 0 + ], + [ + 115, + 154, + 120, + 55, + 225, + 0 + ], + [ + 5, + 0, + 0, + 80, + 0, + 1 + ], + [ + 2, + 0, + 1, + 24, + 422, + 51 + ], + [ + 451, + 308, + 43, + 273, + 782, + 11965 + ] + ], + "per_class_recall": [ + 0.17647058823529413, + 0.7697594501718213, + 0.17937219730941703, + 0.9302325581395349, + 0.844, + 0.8656489654174504 + ], + "balanced_accuracy": 0.6275806265455862, + "accuracy": 0.8285658939755924, + "weighted_f1": 0.8618635180906945, + "macro_f1": 0.40367911279847074, + "kappa": 0.42983741832596223, + "samples": 15487, + "reward": 0.6275806265455862, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2019, + 2381 + ], + "confusion_matrix": [ + [ + 1680, + 520 + ], + [ + 339, + 1861 + ] + ], + "per_class_recall": [ + 0.7636363636363637, + 0.8459090909090909 + ], + "balanced_accuracy": 0.8047727272727273, + "accuracy": 0.8047727272727273, + "weighted_f1": 0.8044418036119902, + "macro_f1": 0.8044418036119902, + "kappa": 0.6095454545454546, + "samples": 4400, + "subject_scores": { + "19": 0.87, + "35": 0.9550000000000001, + "34": 0.6475, + "51": 0.7525, + "20": 0.815, + "44": 0.9325, + "24": 0.5925, + "15": 0.8925000000000001, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.72 + }, + "reward": 0.8047727272727273, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4574, + 3844 + ], + "confusion_matrix": [ + [ + 3658, + 602 + ], + [ + 916, + 3242 + ] + ], + "per_class_recall": [ + 0.8586854460093897, + 0.7797017797017797 + ], + "balanced_accuracy": 0.8191936128555847, + "accuracy": 0.819672131147541, + "weighted_f1": 0.8193389120476722, + "macro_f1": 0.819230668900581, + "kappa": 0.6389648996053923, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8368421735781668, + "sub-G2007": 0.7651266214233094, + "sub-G2019": 0.8242345047591977, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8446221994740171, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9573204820205594, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8163437913863759, + "subjects": 9 + } + }, + "selected_head_epochs": { + "faced": 10, + "tuev": 0, + "ad65": 0, + "openbmi": 3, + "longitudinal": 0 + } + }, + { + "epoch": 11, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 161, + 189, + 182, + 209, + 259, + 154, + 180, + 173, + 173 + ], + "confusion_matrix": [ + [ + 81, + 11, + 6, + 23, + 20, + 7, + 13, + 9, + 10 + ], + [ + 10, + 89, + 8, + 15, + 21, + 10, + 13, + 6, + 8 + ], + [ + 7, + 6, + 94, + 20, + 21, + 6, + 5, + 8, + 13 + ], + [ + 14, + 20, + 10, + 68, + 23, + 6, + 19, + 14, + 6 + ], + [ + 12, + 13, + 18, + 26, + 116, + 15, + 11, + 19, + 10 + ], + [ + 7, + 13, + 11, + 12, + 13, + 86, + 10, + 13, + 15 + ], + [ + 8, + 11, + 10, + 12, + 17, + 12, + 91, + 8, + 11 + ], + [ + 7, + 14, + 14, + 20, + 15, + 9, + 9, + 88, + 4 + ], + [ + 15, + 12, + 11, + 13, + 13, + 3, + 9, + 8, + 96 + ] + ], + "per_class_recall": [ + 0.45, + 0.49444444444444446, + 0.5222222222222223, + 0.37777777777777777, + 0.48333333333333334, + 0.4777777777777778, + 0.5055555555555555, + 0.4888888888888889, + 0.5333333333333333 + ], + "balanced_accuracy": 0.48148148148148157, + "accuracy": 0.48154761904761906, + "weighted_f1": 0.4831429888930118, + "macro_f1": 0.4838175492327738, + "kappa": 0.4157303370786517, + "samples": 1680, + "reward": 0.48148148148148157, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 594, + 724, + 187, + 475, + 1457, + 12050 + ], + "confusion_matrix": [ + [ + 21, + 38, + 23, + 4, + 0, + 33 + ], + [ + 0, + 224, + 0, + 39, + 28, + 0 + ], + [ + 115, + 154, + 120, + 55, + 225, + 0 + ], + [ + 5, + 0, + 0, + 80, + 0, + 1 + ], + [ + 2, + 0, + 1, + 24, + 422, + 51 + ], + [ + 451, + 308, + 43, + 273, + 782, + 11965 + ] + ], + "per_class_recall": [ + 0.17647058823529413, + 0.7697594501718213, + 0.17937219730941703, + 0.9302325581395349, + 0.844, + 0.8656489654174504 + ], + "balanced_accuracy": 0.6275806265455862, + "accuracy": 0.8285658939755924, + "weighted_f1": 0.8618635180906945, + "macro_f1": 0.40367911279847074, + "kappa": 0.42983741832596223, + "samples": 15487, + "reward": 0.6275806265455862, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2019, + 2381 + ], + "confusion_matrix": [ + [ + 1680, + 520 + ], + [ + 339, + 1861 + ] + ], + "per_class_recall": [ + 0.7636363636363637, + 0.8459090909090909 + ], + "balanced_accuracy": 0.8047727272727273, + "accuracy": 0.8047727272727273, + "weighted_f1": 0.8044418036119902, + "macro_f1": 0.8044418036119902, + "kappa": 0.6095454545454546, + "samples": 4400, + "subject_scores": { + "19": 0.87, + "35": 0.9550000000000001, + "34": 0.6475, + "51": 0.7525, + "20": 0.815, + "44": 0.9325, + "24": 0.5925, + "15": 0.8925000000000001, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.72 + }, + "reward": 0.8047727272727273, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4574, + 3844 + ], + "confusion_matrix": [ + [ + 3658, + 602 + ], + [ + 916, + 3242 + ] + ], + "per_class_recall": [ + 0.8586854460093897, + 0.7797017797017797 + ], + "balanced_accuracy": 0.8191936128555847, + "accuracy": 0.819672131147541, + "weighted_f1": 0.8193389120476722, + "macro_f1": 0.819230668900581, + "kappa": 0.6389648996053923, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8368421735781668, + "sub-G2007": 0.7651266214233094, + "sub-G2019": 0.8242345047591977, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8446221994740171, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9573204820205594, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8163437913863759, + "subjects": 9 + } + }, + "selected_head_epochs": { + "faced": 11, + "tuev": 0, + "ad65": 0, + "openbmi": 3, + "longitudinal": 0 + } + }, + { + "epoch": 12, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 158, + 190, + 185, + 208, + 261, + 151, + 178, + 173, + 176 + ], + "confusion_matrix": [ + [ + 80, + 12, + 5, + 23, + 20, + 7, + 13, + 9, + 11 + ], + [ + 10, + 89, + 8, + 15, + 21, + 10, + 13, + 6, + 8 + ], + [ + 7, + 6, + 96, + 19, + 20, + 6, + 5, + 7, + 14 + ], + [ + 13, + 20, + 11, + 67, + 23, + 6, + 19, + 14, + 7 + ], + [ + 12, + 13, + 18, + 26, + 118, + 14, + 10, + 20, + 9 + ], + [ + 7, + 13, + 11, + 12, + 14, + 85, + 10, + 13, + 15 + ], + [ + 8, + 11, + 10, + 12, + 17, + 12, + 91, + 8, + 11 + ], + [ + 6, + 14, + 15, + 21, + 15, + 8, + 8, + 88, + 5 + ], + [ + 15, + 12, + 11, + 13, + 13, + 3, + 9, + 8, + 96 + ] + ], + "per_class_recall": [ + 0.4444444444444444, + 0.49444444444444446, + 0.5333333333333333, + 0.37222222222222223, + 0.49166666666666664, + 0.4722222222222222, + 0.5055555555555555, + 0.4888888888888889, + 0.5333333333333333 + ], + "balanced_accuracy": 0.4817901234567901, + "accuracy": 0.48214285714285715, + "weighted_f1": 0.4836218281775486, + "macro_f1": 0.4840871594348084, + "kappa": 0.41637317616617553, + "samples": 1680, + "reward": 0.4817901234567901, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 594, + 724, + 187, + 475, + 1457, + 12050 + ], + "confusion_matrix": [ + [ + 21, + 38, + 23, + 4, + 0, + 33 + ], + [ + 0, + 224, + 0, + 39, + 28, + 0 + ], + [ + 115, + 154, + 120, + 55, + 225, + 0 + ], + [ + 5, + 0, + 0, + 80, + 0, + 1 + ], + [ + 2, + 0, + 1, + 24, + 422, + 51 + ], + [ + 451, + 308, + 43, + 273, + 782, + 11965 + ] + ], + "per_class_recall": [ + 0.17647058823529413, + 0.7697594501718213, + 0.17937219730941703, + 0.9302325581395349, + 0.844, + 0.8656489654174504 + ], + "balanced_accuracy": 0.6275806265455862, + "accuracy": 0.8285658939755924, + "weighted_f1": 0.8618635180906945, + "macro_f1": 0.40367911279847074, + "kappa": 0.42983741832596223, + "samples": 15487, + "reward": 0.6275806265455862, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2019, + 2381 + ], + "confusion_matrix": [ + [ + 1680, + 520 + ], + [ + 339, + 1861 + ] + ], + "per_class_recall": [ + 0.7636363636363637, + 0.8459090909090909 + ], + "balanced_accuracy": 0.8047727272727273, + "accuracy": 0.8047727272727273, + "weighted_f1": 0.8044418036119902, + "macro_f1": 0.8044418036119902, + "kappa": 0.6095454545454546, + "samples": 4400, + "subject_scores": { + "19": 0.87, + "35": 0.9550000000000001, + "34": 0.6475, + "51": 0.7525, + "20": 0.815, + "44": 0.9325, + "24": 0.5925, + "15": 0.8925000000000001, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.72 + }, + "reward": 0.8047727272727273, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4574, + 3844 + ], + "confusion_matrix": [ + [ + 3658, + 602 + ], + [ + 916, + 3242 + ] + ], + "per_class_recall": [ + 0.8586854460093897, + 0.7797017797017797 + ], + "balanced_accuracy": 0.8191936128555847, + "accuracy": 0.819672131147541, + "weighted_f1": 0.8193389120476722, + "macro_f1": 0.819230668900581, + "kappa": 0.6389648996053923, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8368421735781668, + "sub-G2007": 0.7651266214233094, + "sub-G2019": 0.8242345047591977, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8446221994740171, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9573204820205594, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8163437913863759, + "subjects": 9 + } + }, + "selected_head_epochs": { + "faced": 12, + "tuev": 0, + "ad65": 0, + "openbmi": 3, + "longitudinal": 0 + } + }, + { + "epoch": 13, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 155, + 188, + 189, + 215, + 253, + 152, + 181, + 173, + 174 + ], + "confusion_matrix": [ + [ + 80, + 11, + 5, + 25, + 19, + 7, + 13, + 9, + 11 + ], + [ + 9, + 89, + 9, + 16, + 20, + 9, + 13, + 6, + 9 + ], + [ + 7, + 6, + 98, + 21, + 18, + 6, + 5, + 7, + 12 + ], + [ + 13, + 20, + 11, + 67, + 21, + 6, + 20, + 15, + 7 + ], + [ + 12, + 13, + 18, + 26, + 118, + 15, + 10, + 19, + 9 + ], + [ + 5, + 13, + 11, + 14, + 13, + 86, + 10, + 13, + 15 + ], + [ + 7, + 11, + 11, + 10, + 16, + 13, + 93, + 8, + 11 + ], + [ + 6, + 14, + 15, + 22, + 15, + 7, + 8, + 89, + 4 + ], + [ + 16, + 11, + 11, + 14, + 13, + 3, + 9, + 7, + 96 + ] + ], + "per_class_recall": [ + 0.4444444444444444, + 0.49444444444444446, + 0.5444444444444444, + 0.37222222222222223, + 0.49166666666666664, + 0.4777777777777778, + 0.5166666666666667, + 0.49444444444444446, + 0.5333333333333333 + ], + "balanced_accuracy": 0.48549382716049383, + "accuracy": 0.4857142857142857, + "weighted_f1": 0.48749061755993245, + "macro_f1": 0.4878161283748259, + "kappa": 0.42050925815028617, + "samples": 1680, + "reward": 0.48549382716049383, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 594, + 724, + 187, + 475, + 1457, + 12050 + ], + "confusion_matrix": [ + [ + 21, + 38, + 23, + 4, + 0, + 33 + ], + [ + 0, + 224, + 0, + 39, + 28, + 0 + ], + [ + 115, + 154, + 120, + 55, + 225, + 0 + ], + [ + 5, + 0, + 0, + 80, + 0, + 1 + ], + [ + 2, + 0, + 1, + 24, + 422, + 51 + ], + [ + 451, + 308, + 43, + 273, + 782, + 11965 + ] + ], + "per_class_recall": [ + 0.17647058823529413, + 0.7697594501718213, + 0.17937219730941703, + 0.9302325581395349, + 0.844, + 0.8656489654174504 + ], + "balanced_accuracy": 0.6275806265455862, + "accuracy": 0.8285658939755924, + "weighted_f1": 0.8618635180906945, + "macro_f1": 0.40367911279847074, + "kappa": 0.42983741832596223, + "samples": 15487, + "reward": 0.6275806265455862, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2019, + 2381 + ], + "confusion_matrix": [ + [ + 1680, + 520 + ], + [ + 339, + 1861 + ] + ], + "per_class_recall": [ + 0.7636363636363637, + 0.8459090909090909 + ], + "balanced_accuracy": 0.8047727272727273, + "accuracy": 0.8047727272727273, + "weighted_f1": 0.8044418036119902, + "macro_f1": 0.8044418036119902, + "kappa": 0.6095454545454546, + "samples": 4400, + "subject_scores": { + "19": 0.87, + "35": 0.9550000000000001, + "34": 0.6475, + "51": 0.7525, + "20": 0.815, + "44": 0.9325, + "24": 0.5925, + "15": 0.8925000000000001, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.72 + }, + "reward": 0.8047727272727273, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4574, + 3844 + ], + "confusion_matrix": [ + [ + 3658, + 602 + ], + [ + 916, + 3242 + ] + ], + "per_class_recall": [ + 0.8586854460093897, + 0.7797017797017797 + ], + "balanced_accuracy": 0.8191936128555847, + "accuracy": 0.819672131147541, + "weighted_f1": 0.8193389120476722, + "macro_f1": 0.819230668900581, + "kappa": 0.6389648996053923, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8368421735781668, + "sub-G2007": 0.7651266214233094, + "sub-G2019": 0.8242345047591977, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8446221994740171, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9573204820205594, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8163437913863759, + "subjects": 9 + } + }, + "selected_head_epochs": { + "faced": 13, + "tuev": 0, + "ad65": 0, + "openbmi": 3, + "longitudinal": 0 + } + }, + { + "epoch": 16, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 158, + 190, + 182, + 211, + 259, + 153, + 183, + 172, + 172 + ], + "confusion_matrix": [ + [ + 81, + 12, + 4, + 24, + 19, + 7, + 13, + 9, + 11 + ], + [ + 9, + 90, + 8, + 16, + 21, + 8, + 14, + 6, + 8 + ], + [ + 7, + 7, + 96, + 19, + 20, + 6, + 6, + 7, + 12 + ], + [ + 13, + 20, + 11, + 68, + 21, + 6, + 19, + 15, + 7 + ], + [ + 12, + 14, + 18, + 26, + 118, + 14, + 10, + 19, + 9 + ], + [ + 6, + 12, + 10, + 13, + 13, + 89, + 9, + 13, + 15 + ], + [ + 8, + 11, + 8, + 10, + 17, + 12, + 95, + 8, + 11 + ], + [ + 6, + 13, + 16, + 22, + 16, + 8, + 8, + 88, + 3 + ], + [ + 16, + 11, + 11, + 13, + 14, + 3, + 9, + 7, + 96 + ] + ], + "per_class_recall": [ + 0.45, + 0.5, + 0.5333333333333333, + 0.37777777777777777, + 0.49166666666666664, + 0.49444444444444446, + 0.5277777777777778, + 0.4888888888888889, + 0.5333333333333333 + ], + "balanced_accuracy": 0.48858024691358026, + "accuracy": 0.4886904761904762, + "weighted_f1": 0.4904988037426612, + "macro_f1": 0.49114891159299806, + "kappa": 0.4237799765218849, + "samples": 1680, + "reward": 0.48858024691358026, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 594, + 724, + 187, + 475, + 1457, + 12050 + ], + "confusion_matrix": [ + [ + 21, + 38, + 23, + 4, + 0, + 33 + ], + [ + 0, + 224, + 0, + 39, + 28, + 0 + ], + [ + 115, + 154, + 120, + 55, + 225, + 0 + ], + [ + 5, + 0, + 0, + 80, + 0, + 1 + ], + [ + 2, + 0, + 1, + 24, + 422, + 51 + ], + [ + 451, + 308, + 43, + 273, + 782, + 11965 + ] + ], + "per_class_recall": [ + 0.17647058823529413, + 0.7697594501718213, + 0.17937219730941703, + 0.9302325581395349, + 0.844, + 0.8656489654174504 + ], + "balanced_accuracy": 0.6275806265455862, + "accuracy": 0.8285658939755924, + "weighted_f1": 0.8618635180906945, + "macro_f1": 0.40367911279847074, + "kappa": 0.42983741832596223, + "samples": 15487, + "reward": 0.6275806265455862, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2019, + 2381 + ], + "confusion_matrix": [ + [ + 1680, + 520 + ], + [ + 339, + 1861 + ] + ], + "per_class_recall": [ + 0.7636363636363637, + 0.8459090909090909 + ], + "balanced_accuracy": 0.8047727272727273, + "accuracy": 0.8047727272727273, + "weighted_f1": 0.8044418036119902, + "macro_f1": 0.8044418036119902, + "kappa": 0.6095454545454546, + "samples": 4400, + "subject_scores": { + "19": 0.87, + "35": 0.9550000000000001, + "34": 0.6475, + "51": 0.7525, + "20": 0.815, + "44": 0.9325, + "24": 0.5925, + "15": 0.8925000000000001, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.72 + }, + "reward": 0.8047727272727273, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4574, + 3844 + ], + "confusion_matrix": [ + [ + 3658, + 602 + ], + [ + 916, + 3242 + ] + ], + "per_class_recall": [ + 0.8586854460093897, + 0.7797017797017797 + ], + "balanced_accuracy": 0.8191936128555847, + "accuracy": 0.819672131147541, + "weighted_f1": 0.8193389120476722, + "macro_f1": 0.819230668900581, + "kappa": 0.6389648996053923, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8368421735781668, + "sub-G2007": 0.7651266214233094, + "sub-G2019": 0.8242345047591977, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8446221994740171, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9573204820205594, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8163437913863759, + "subjects": 9 + } + }, + "selected_head_epochs": { + "faced": 16, + "tuev": 0, + "ad65": 0, + "openbmi": 3, + "longitudinal": 0 + } + }, + { + "epoch": 18, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 159, + 189, + 184, + 216, + 260, + 152, + 180, + 171, + 169 + ], + "confusion_matrix": [ + [ + 82, + 11, + 4, + 25, + 19, + 7, + 13, + 9, + 10 + ], + [ + 9, + 92, + 8, + 16, + 21, + 8, + 13, + 5, + 8 + ], + [ + 8, + 7, + 96, + 19, + 19, + 6, + 6, + 7, + 12 + ], + [ + 13, + 19, + 11, + 70, + 21, + 5, + 19, + 15, + 7 + ], + [ + 12, + 14, + 18, + 26, + 119, + 14, + 10, + 19, + 8 + ], + [ + 6, + 11, + 11, + 13, + 13, + 89, + 10, + 13, + 14 + ], + [ + 8, + 11, + 8, + 10, + 18, + 13, + 93, + 8, + 11 + ], + [ + 6, + 13, + 16, + 23, + 17, + 7, + 7, + 88, + 3 + ], + [ + 15, + 11, + 12, + 14, + 13, + 3, + 9, + 7, + 96 + ] + ], + "per_class_recall": [ + 0.45555555555555555, + 0.5111111111111111, + 0.5333333333333333, + 0.3888888888888889, + 0.49583333333333335, + 0.49444444444444446, + 0.5166666666666667, + 0.4888888888888889, + 0.5333333333333333 + ], + "balanced_accuracy": 0.49089506172839503, + "accuracy": 0.49107142857142855, + "weighted_f1": 0.49312225266577686, + "macro_f1": 0.4937564101719168, + "kappa": 0.4264494489698132, + "samples": 1680, + "reward": 0.49089506172839503, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 594, + 724, + 187, + 475, + 1457, + 12050 + ], + "confusion_matrix": [ + [ + 21, + 38, + 23, + 4, + 0, + 33 + ], + [ + 0, + 224, + 0, + 39, + 28, + 0 + ], + [ + 115, + 154, + 120, + 55, + 225, + 0 + ], + [ + 5, + 0, + 0, + 80, + 0, + 1 + ], + [ + 2, + 0, + 1, + 24, + 422, + 51 + ], + [ + 451, + 308, + 43, + 273, + 782, + 11965 + ] + ], + "per_class_recall": [ + 0.17647058823529413, + 0.7697594501718213, + 0.17937219730941703, + 0.9302325581395349, + 0.844, + 0.8656489654174504 + ], + "balanced_accuracy": 0.6275806265455862, + "accuracy": 0.8285658939755924, + "weighted_f1": 0.8618635180906945, + "macro_f1": 0.40367911279847074, + "kappa": 0.42983741832596223, + "samples": 15487, + "reward": 0.6275806265455862, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2019, + 2381 + ], + "confusion_matrix": [ + [ + 1680, + 520 + ], + [ + 339, + 1861 + ] + ], + "per_class_recall": [ + 0.7636363636363637, + 0.8459090909090909 + ], + "balanced_accuracy": 0.8047727272727273, + "accuracy": 0.8047727272727273, + "weighted_f1": 0.8044418036119902, + "macro_f1": 0.8044418036119902, + "kappa": 0.6095454545454546, + "samples": 4400, + "subject_scores": { + "19": 0.87, + "35": 0.9550000000000001, + "34": 0.6475, + "51": 0.7525, + "20": 0.815, + "44": 0.9325, + "24": 0.5925, + "15": 0.8925000000000001, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.72 + }, + "reward": 0.8047727272727273, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4574, + 3844 + ], + "confusion_matrix": [ + [ + 3658, + 602 + ], + [ + 916, + 3242 + ] + ], + "per_class_recall": [ + 0.8586854460093897, + 0.7797017797017797 + ], + "balanced_accuracy": 0.8191936128555847, + "accuracy": 0.819672131147541, + "weighted_f1": 0.8193389120476722, + "macro_f1": 0.819230668900581, + "kappa": 0.6389648996053923, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8368421735781668, + "sub-G2007": 0.7651266214233094, + "sub-G2019": 0.8242345047591977, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8446221994740171, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9573204820205594, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8163437913863759, + "subjects": 9 + } + }, + "selected_head_epochs": { + "faced": 18, + "tuev": 0, + "ad65": 0, + "openbmi": 3, + "longitudinal": 0 + } + } + ], + "shared_backbone_training": "inherited joint training on all five training splits; frozen during nonlinear classification-head refinement", + "parent_training_receipt": { + "history": [ + { + "epoch": 7, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 157, + 194, + 179, + 214, + 244, + 162, + 180, + 173, + 177 + ], + "confusion_matrix": [ + [ + 78, + 14, + 5, + 23, + 19, + 9, + 13, + 9, + 10 + ], + [ + 11, + 88, + 9, + 13, + 19, + 11, + 13, + 6, + 10 + ], + [ + 6, + 7, + 94, + 20, + 17, + 5, + 7, + 10, + 14 + ], + [ + 14, + 18, + 9, + 71, + 21, + 8, + 16, + 15, + 8 + ], + [ + 13, + 13, + 16, + 26, + 113, + 17, + 13, + 18, + 11 + ], + [ + 6, + 12, + 12, + 15, + 12, + 83, + 10, + 14, + 16 + ], + [ + 8, + 12, + 8, + 14, + 16, + 14, + 90, + 9, + 9 + ], + [ + 8, + 16, + 15, + 17, + 15, + 10, + 10, + 83, + 6 + ], + [ + 13, + 14, + 11, + 15, + 12, + 5, + 8, + 9, + 93 + ] + ], + "per_class_recall": [ + 0.43333333333333335, + 0.4888888888888889, + 0.5222222222222223, + 0.39444444444444443, + 0.4708333333333333, + 0.46111111111111114, + 0.5, + 0.46111111111111114, + 0.5166666666666667 + ], + "balanced_accuracy": 0.472067901234568, + "accuracy": 0.4720238095238095, + "weighted_f1": 0.4732298815998091, + "macro_f1": 0.47346276059386383, + "kappa": 0.40521122712903535, + "samples": 1680, + "reward": 0.472067901234568, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 594, + 724, + 187, + 475, + 1457, + 12050 + ], + "confusion_matrix": [ + [ + 21, + 38, + 23, + 4, + 0, + 33 + ], + [ + 0, + 224, + 0, + 39, + 28, + 0 + ], + [ + 115, + 154, + 120, + 55, + 225, + 0 + ], + [ + 5, + 0, + 0, + 80, + 0, + 1 + ], + [ + 2, + 0, + 1, + 24, + 422, + 51 + ], + [ + 451, + 308, + 43, + 273, + 782, + 11965 + ] + ], + "per_class_recall": [ + 0.17647058823529413, + 0.7697594501718213, + 0.17937219730941703, + 0.9302325581395349, + 0.844, + 0.8656489654174504 + ], + "balanced_accuracy": 0.6275806265455862, + "accuracy": 0.8285658939755924, + "weighted_f1": 0.8618635180906945, + "macro_f1": 0.40367911279847074, + "kappa": 0.42983741832596223, + "samples": 15487, + "reward": 0.6275806265455862, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2040, + 2360 + ], + "confusion_matrix": [ + [ + 1690, + 510 + ], + [ + 350, + 1850 + ] + ], + "per_class_recall": [ + 0.7681818181818182, + 0.8409090909090909 + ], + "balanced_accuracy": 0.8045454545454546, + "accuracy": 0.8045454545454546, + "weighted_f1": 0.8042866600463423, + "macro_f1": 0.8042866600463423, + "kappa": 0.6090909090909091, + "samples": 4400, + "subject_scores": { + "19": 0.8574999999999999, + "35": 0.9525, + "34": 0.6475, + "51": 0.75, + "20": 0.815, + "44": 0.935, + "24": 0.595, + "15": 0.8975, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.725 + }, + "reward": 0.8045454545454546, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4574, + 3844 + ], + "confusion_matrix": [ + [ + 3658, + 602 + ], + [ + 916, + 3242 + ] + ], + "per_class_recall": [ + 0.8586854460093897, + 0.7797017797017797 + ], + "balanced_accuracy": 0.8191936128555847, + "accuracy": 0.819672131147541, + "weighted_f1": 0.8193389120476722, + "macro_f1": 0.819230668900581, + "kappa": 0.6389648996053923, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8368421735781668, + "sub-G2007": 0.7651266214233094, + "sub-G2019": 0.8242345047591977, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8446221994740171, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9573204820205594, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8163437913863759, + "subjects": 9 + } + }, + "clinical_training_loss": 0.6892783784866333 + } + ], + "settings": { + "source": "/workspace/research/runs/head_dropout1/epoch-016", + "cache": "/workspace/research/clinical_fusion_v1", + "output": "/workspace/research/runs/clinical_spectral_adapter1", + "epochs": 30, + "steps": 100, + "batch_size": 128, + "lr": 0.0001, + "head_lr": 1e-05, + "retention": 1.0, + "seed": 7 + }, + "parent_training_receipt": { + "settings": { + "source": "/workspace/research/runs/hybrid_biot_csp_bf16head/epoch-001", + "features": "/workspace/research/head_features_v1", + "incumbent": "/workspace/research/runs/head_refinement1/epoch-012", + "output": "/workspace/research/runs/head_dropout1", + "epochs": 30, + "steps": 200, + "batch_size": 256, + "lr": 1e-05, + "clinical_lr": 0.0001, + "retention": 2.0, + "dropout": 0.2, + "seed": 7 + }, + "history": [ + { + "epoch": 14, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 157, + 194, + 179, + 214, + 244, + 162, + 180, + 173, + 177 + ], + "confusion_matrix": [ + [ + 78, + 14, + 5, + 23, + 19, + 9, + 13, + 9, + 10 + ], + [ + 11, + 88, + 9, + 13, + 19, + 11, + 13, + 6, + 10 + ], + [ + 6, + 7, + 94, + 20, + 17, + 5, + 7, + 10, + 14 + ], + [ + 14, + 18, + 9, + 71, + 21, + 8, + 16, + 15, + 8 + ], + [ + 13, + 13, + 16, + 26, + 113, + 17, + 13, + 18, + 11 + ], + [ + 6, + 12, + 12, + 15, + 12, + 83, + 10, + 14, + 16 + ], + [ + 8, + 12, + 8, + 14, + 16, + 14, + 90, + 9, + 9 + ], + [ + 8, + 16, + 15, + 17, + 15, + 10, + 10, + 83, + 6 + ], + [ + 13, + 14, + 11, + 15, + 12, + 5, + 8, + 9, + 93 + ] + ], + "per_class_recall": [ + 0.43333333333333335, + 0.4888888888888889, + 0.5222222222222223, + 0.39444444444444443, + 0.4708333333333333, + 0.46111111111111114, + 0.5, + 0.46111111111111114, + 0.5166666666666667 + ], + "balanced_accuracy": 0.472067901234568, + "accuracy": 0.4720238095238095, + "weighted_f1": 0.4732298815998091, + "macro_f1": 0.47346276059386383, + "kappa": 0.40521122712903535, + "samples": 1680, + "reward": 0.472067901234568, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 995, + 658, + 146, + 706, + 1616, + 11366 + ], + "confusion_matrix": [ + [ + 42, + 38, + 18, + 4, + 0, + 17 + ], + [ + 0, + 185, + 0, + 78, + 28, + 0 + ], + [ + 110, + 127, + 128, + 61, + 243, + 0 + ], + [ + 6, + 0, + 0, + 79, + 0, + 1 + ], + [ + 2, + 0, + 0, + 25, + 420, + 53 + ], + [ + 835, + 308, + 0, + 459, + 925, + 11295 + ] + ], + "per_class_recall": [ + 0.35294117647058826, + 0.6357388316151202, + 0.19133034379671152, + 0.9186046511627907, + 0.84, + 0.8171755172912748 + ], + "balanced_accuracy": 0.6259650867227476, + "accuracy": 0.7844643894879576, + "weighted_f1": 0.8358334233956254, + "macro_f1": 0.3787874146773398, + "kappa": 0.36546485724249755, + "samples": 15487, + "reward": 0.6259650867227476, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2040, + 2360 + ], + "confusion_matrix": [ + [ + 1690, + 510 + ], + [ + 350, + 1850 + ] + ], + "per_class_recall": [ + 0.7681818181818182, + 0.8409090909090909 + ], + "balanced_accuracy": 0.8045454545454546, + "accuracy": 0.8045454545454546, + "weighted_f1": 0.8042866600463423, + "macro_f1": 0.8042866600463423, + "kappa": 0.6090909090909091, + "samples": 4400, + "subject_scores": { + "19": 0.8574999999999999, + "35": 0.9525, + "34": 0.6475, + "51": 0.75, + "20": 0.815, + "44": 0.935, + "24": 0.595, + "15": 0.8975, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.725 + }, + "reward": 0.8045454545454546, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4576, + 3842 + ], + "confusion_matrix": [ + [ + 3659, + 601 + ], + [ + 917, + 3241 + ] + ], + "per_class_recall": [ + 0.8589201877934273, + 0.7794612794612794 + ], + "balanced_accuracy": 0.8191907336273534, + "accuracy": 0.819672131147541, + "weighted_f1": 0.8193351694632243, + "macro_f1": 0.8192264033499321, + "kappa": 0.6389628187072087, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.837643455629449, + "sub-G2007": 0.7651266214233094, + "sub-G2019": 0.8242345047591977, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8446221994740171, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9564871486872261, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8163402301328146, + "subjects": 9 + } + }, + "selected_head_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 0, + "longitudinal": 14 + } + }, + { + "epoch": 16, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 157, + 194, + 179, + 214, + 244, + 162, + 180, + 173, + 177 + ], + "confusion_matrix": [ + [ + 78, + 14, + 5, + 23, + 19, + 9, + 13, + 9, + 10 + ], + [ + 11, + 88, + 9, + 13, + 19, + 11, + 13, + 6, + 10 + ], + [ + 6, + 7, + 94, + 20, + 17, + 5, + 7, + 10, + 14 + ], + [ + 14, + 18, + 9, + 71, + 21, + 8, + 16, + 15, + 8 + ], + [ + 13, + 13, + 16, + 26, + 113, + 17, + 13, + 18, + 11 + ], + [ + 6, + 12, + 12, + 15, + 12, + 83, + 10, + 14, + 16 + ], + [ + 8, + 12, + 8, + 14, + 16, + 14, + 90, + 9, + 9 + ], + [ + 8, + 16, + 15, + 17, + 15, + 10, + 10, + 83, + 6 + ], + [ + 13, + 14, + 11, + 15, + 12, + 5, + 8, + 9, + 93 + ] + ], + "per_class_recall": [ + 0.43333333333333335, + 0.4888888888888889, + 0.5222222222222223, + 0.39444444444444443, + 0.4708333333333333, + 0.46111111111111114, + 0.5, + 0.46111111111111114, + 0.5166666666666667 + ], + "balanced_accuracy": 0.472067901234568, + "accuracy": 0.4720238095238095, + "weighted_f1": 0.4732298815998091, + "macro_f1": 0.47346276059386383, + "kappa": 0.40521122712903535, + "samples": 1680, + "reward": 0.472067901234568, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 995, + 658, + 146, + 706, + 1616, + 11366 + ], + "confusion_matrix": [ + [ + 42, + 38, + 18, + 4, + 0, + 17 + ], + [ + 0, + 185, + 0, + 78, + 28, + 0 + ], + [ + 110, + 127, + 128, + 61, + 243, + 0 + ], + [ + 6, + 0, + 0, + 79, + 0, + 1 + ], + [ + 2, + 0, + 0, + 25, + 420, + 53 + ], + [ + 835, + 308, + 0, + 459, + 925, + 11295 + ] + ], + "per_class_recall": [ + 0.35294117647058826, + 0.6357388316151202, + 0.19133034379671152, + 0.9186046511627907, + 0.84, + 0.8171755172912748 + ], + "balanced_accuracy": 0.6259650867227476, + "accuracy": 0.7844643894879576, + "weighted_f1": 0.8358334233956254, + "macro_f1": 0.3787874146773398, + "kappa": 0.36546485724249755, + "samples": 15487, + "reward": 0.6259650867227476, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2040, + 2360 + ], + "confusion_matrix": [ + [ + 1690, + 510 + ], + [ + 350, + 1850 + ] + ], + "per_class_recall": [ + 0.7681818181818182, + 0.8409090909090909 + ], + "balanced_accuracy": 0.8045454545454546, + "accuracy": 0.8045454545454546, + "weighted_f1": 0.8042866600463423, + "macro_f1": 0.8042866600463423, + "kappa": 0.6090909090909091, + "samples": 4400, + "subject_scores": { + "19": 0.8574999999999999, + "35": 0.9525, + "34": 0.6475, + "51": 0.75, + "20": 0.815, + "44": 0.935, + "24": 0.595, + "15": 0.8975, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.725 + }, + "reward": 0.8045454545454546, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4574, + 3844 + ], + "confusion_matrix": [ + [ + 3658, + 602 + ], + [ + 916, + 3242 + ] + ], + "per_class_recall": [ + 0.8586854460093897, + 0.7797017797017797 + ], + "balanced_accuracy": 0.8191936128555847, + "accuracy": 0.819672131147541, + "weighted_f1": 0.8193389120476722, + "macro_f1": 0.819230668900581, + "kappa": 0.6389648996053923, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8368421735781668, + "sub-G2007": 0.7651266214233094, + "sub-G2019": 0.8242345047591977, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8446221994740171, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9573204820205594, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8163437913863759, + "subjects": 9 + } + }, + "selected_head_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 0, + "longitudinal": 16 + } + } + ], + "shared_backbone_training": "inherited joint training on all five training splits; frozen during final linear-head refinement", + "parent_training_receipt": { + "all_tracks_update_shared_backbone": true, + "parameters": 10427373, + "source_training_settings": { + "output": "/workspace/research/runs/hybrid_biot_csp_stable1", + "epochs": 30, + "steps": 100, + "batch_size": 64, + "seed": 7, + "hidden": 32, + "dropout": 0.5, + "lr": 1e-06, + "head_lr": 1e-07, + "weight_decay": 0.05, + "init": "/workspace/research/runs/hybrid_biot_fusionshrink0100/epoch-001/weights.pt", + "mixup": 0.0, + "clinical_lr": 0.0001, + "neural_lr": 1e-05, + "covariance_parent": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "ad_pool": 8 + }, + "parent_training_history": [ + { + "epoch": 1, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 157, + 190, + 178, + 212, + 242, + 166, + 182, + 175, + 178 + ], + "confusion_matrix": [ + [ + 77, + 14, + 5, + 22, + 19, + 9, + 14, + 10, + 10 + ], + [ + 12, + 86, + 9, + 13, + 19, + 11, + 14, + 6, + 10 + ], + [ + 6, + 7, + 93, + 20, + 17, + 5, + 7, + 10, + 15 + ], + [ + 14, + 18, + 9, + 71, + 21, + 8, + 16, + 15, + 8 + ], + [ + 13, + 13, + 17, + 26, + 111, + 17, + 14, + 18, + 11 + ], + [ + 6, + 11, + 11, + 15, + 11, + 86, + 10, + 14, + 16 + ], + [ + 8, + 11, + 9, + 13, + 17, + 14, + 89, + 10, + 9 + ], + [ + 8, + 16, + 14, + 17, + 15, + 11, + 10, + 83, + 6 + ], + [ + 13, + 14, + 11, + 15, + 12, + 5, + 8, + 9, + 93 + ] + ], + "per_class_recall": [ + 0.42777777777777776, + 0.4777777777777778, + 0.5166666666666667, + 0.39444444444444443, + 0.4625, + 0.4777777777777778, + 0.49444444444444446, + 0.46111111111111114, + 0.5166666666666667 + ], + "balanced_accuracy": 0.46990740740740744, + "accuracy": 0.46964285714285714, + "weighted_f1": 0.4707562771324448, + "macro_f1": 0.471133142475755, + "kappa": 0.4025575937544903, + "samples": 1680, + "reward": 0.46990740740740744, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 1415, + 660, + 126, + 754, + 1618, + 10914 + ], + "confusion_matrix": [ + [ + 45, + 38, + 15, + 0, + 4, + 17 + ], + [ + 17, + 164, + 0, + 61, + 49, + 0 + ], + [ + 130, + 126, + 111, + 89, + 213, + 0 + ], + [ + 7, + 2, + 0, + 76, + 0, + 1 + ], + [ + 4, + 0, + 0, + 24, + 435, + 37 + ], + [ + 1212, + 330, + 0, + 504, + 917, + 10859 + ] + ], + "per_class_recall": [ + 0.37815126050420167, + 0.563573883161512, + 0.16591928251121077, + 0.8837209302325582, + 0.87, + 0.7856316017942411 + ], + "balanced_accuracy": 0.6078328263672873, + "accuracy": 0.7548266287854329, + "weighted_f1": 0.8168597460216521, + "macro_f1": 0.3587540627106629, + "kappa": 0.32929623559334475, + "samples": 15487, + "reward": 0.6078328263672873, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2059, + 2341 + ], + "confusion_matrix": [ + [ + 1696, + 504 + ], + [ + 363, + 1837 + ] + ], + "per_class_recall": [ + 0.7709090909090909, + 0.835 + ], + "balanced_accuracy": 0.8029545454545455, + "accuracy": 0.8029545454545455, + "weighted_f1": 0.8027519892716276, + "macro_f1": 0.8027519892716275, + "kappa": 0.605909090909091, + "samples": 4400, + "subject_scores": { + "19": 0.8425, + "35": 0.9525, + "34": 0.64, + "51": 0.7475, + "20": 0.82, + "44": 0.94, + "24": 0.5974999999999999, + "15": 0.9, + "31": 0.8825000000000001, + "26": 0.79, + "23": 0.72 + }, + "reward": 0.8029545454545456, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4572, + 3846 + ], + "confusion_matrix": [ + [ + 3656, + 604 + ], + [ + 916, + 3242 + ] + ], + "per_class_recall": [ + 0.8582159624413146, + 0.7797017797017797 + ], + "balanced_accuracy": 0.8189588710715472, + "accuracy": 0.8194345450225707, + "weighted_f1": 0.8191046137658184, + "macro_f1": 0.8189967516241878, + "kappa": 0.6384913111521573, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.837643455629449, + "sub-G2007": 0.7644167136410334, + "sub-G2019": 0.8242345047591977, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8429774626319118, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9564871486872261, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8160786029523278, + "subjects": 9 + } + }, + "losses": { + "faced": 1.1245228350162506, + "tuev": 0.8237144947052002, + "ad65": 0.5528117254376411, + "openbmi": 0.41377417743206024, + "longitudinal": 0.23846278339624405 + }, + "seconds": 33.64874625205994 + } + ], + "history": [ + { + "epoch": 1, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 158, + 189, + 178, + 213, + 242, + 166, + 182, + 176, + 176 + ], + "confusion_matrix": [ + [ + 77, + 14, + 5, + 22, + 19, + 9, + 14, + 10, + 10 + ], + [ + 12, + 86, + 9, + 13, + 19, + 11, + 14, + 6, + 10 + ], + [ + 6, + 7, + 93, + 21, + 17, + 5, + 7, + 10, + 14 + ], + [ + 14, + 18, + 9, + 71, + 21, + 8, + 16, + 15, + 8 + ], + [ + 13, + 13, + 17, + 26, + 111, + 17, + 14, + 18, + 11 + ], + [ + 6, + 11, + 11, + 15, + 11, + 86, + 10, + 14, + 16 + ], + [ + 8, + 11, + 9, + 13, + 17, + 14, + 89, + 10, + 9 + ], + [ + 8, + 16, + 14, + 17, + 15, + 11, + 10, + 84, + 5 + ], + [ + 14, + 13, + 11, + 15, + 12, + 5, + 8, + 9, + 93 + ] + ], + "per_class_recall": [ + 0.42777777777777776, + 0.4777777777777778, + 0.5166666666666667, + 0.39444444444444443, + 0.4625, + 0.4777777777777778, + 0.49444444444444446, + 0.4666666666666667, + 0.5166666666666667 + ], + "balanced_accuracy": 0.4705246913580247, + "accuracy": 0.47023809523809523, + "weighted_f1": 0.4714215675991068, + "macro_f1": 0.47182307333007106, + "kappa": 0.40322812395229657, + "samples": 1680, + "reward": 0.4705246913580247, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 1415, + 660, + 126, + 754, + 1684, + 10848 + ], + "confusion_matrix": [ + [ + 45, + 38, + 15, + 0, + 4, + 17 + ], + [ + 17, + 164, + 0, + 61, + 49, + 0 + ], + [ + 130, + 126, + 111, + 89, + 213, + 0 + ], + [ + 7, + 2, + 0, + 76, + 0, + 1 + ], + [ + 4, + 0, + 0, + 24, + 435, + 37 + ], + [ + 1212, + 330, + 0, + 504, + 983, + 10793 + ] + ], + "per_class_recall": [ + 0.37815126050420167, + 0.563573883161512, + 0.16591928251121077, + 0.8837209302325582, + 0.87, + 0.7808566054116626 + ], + "balanced_accuracy": 0.6070369936368575, + "accuracy": 0.7505649899916058, + "weighted_f1": 0.8137799723660881, + "macro_f1": 0.3561849045209278, + "kappa": 0.32441309326581047, + "samples": 15487, + "reward": 0.6070369936368575, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2061, + 2339 + ], + "confusion_matrix": [ + [ + 1698, + 502 + ], + [ + 363, + 1837 + ] + ], + "per_class_recall": [ + 0.7718181818181818, + 0.835 + ], + "balanced_accuracy": 0.803409090909091, + "accuracy": 0.803409090909091, + "weighted_f1": 0.8032127000298179, + "macro_f1": 0.8032127000298179, + "kappa": 0.6068181818181818, + "samples": 4400, + "subject_scores": { + "19": 0.8425, + "35": 0.9525, + "34": 0.6425000000000001, + "51": 0.7475, + "20": 0.82, + "44": 0.94, + "24": 0.5974999999999999, + "15": 0.9, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.72 + }, + "reward": 0.803409090909091, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4573, + 3845 + ], + "confusion_matrix": [ + [ + 3657, + 603 + ], + [ + 916, + 3242 + ] + ], + "per_class_recall": [ + 0.8584507042253521, + 0.7797017797017797 + ], + "balanced_accuracy": 0.8190762419635659, + "accuracy": 0.8195533380850558, + "weighted_f1": 0.8192217642599872, + "macro_f1": 0.8191137114479841, + "kappa": 0.6387281046963751, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.837643455629449, + "sub-G2007": 0.7644167136410334, + "sub-G2019": 0.82505149822325, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8429774626319118, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9564871486872261, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8161693800038893, + "subjects": 9 + } + }, + "validation_method": "complete portable infer.sh on all five validation splits" + } + ], + "averaged_validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 158, + 189, + 178, + 213, + 242, + 166, + 182, + 176, + 176 + ], + "confusion_matrix": [ + [ + 77, + 14, + 5, + 22, + 19, + 9, + 14, + 10, + 10 + ], + [ + 12, + 86, + 9, + 13, + 19, + 11, + 14, + 6, + 10 + ], + [ + 6, + 7, + 93, + 21, + 17, + 5, + 7, + 10, + 14 + ], + [ + 14, + 18, + 9, + 71, + 21, + 8, + 16, + 15, + 8 + ], + [ + 13, + 13, + 17, + 26, + 111, + 17, + 14, + 18, + 11 + ], + [ + 6, + 11, + 11, + 15, + 11, + 86, + 10, + 14, + 16 + ], + [ + 8, + 11, + 9, + 13, + 17, + 14, + 89, + 10, + 9 + ], + [ + 8, + 16, + 14, + 17, + 15, + 11, + 10, + 84, + 5 + ], + [ + 14, + 13, + 11, + 15, + 12, + 5, + 8, + 9, + 93 + ] + ], + "per_class_recall": [ + 0.42777777777777776, + 0.4777777777777778, + 0.5166666666666667, + 0.39444444444444443, + 0.4625, + 0.4777777777777778, + 0.49444444444444446, + 0.4666666666666667, + 0.5166666666666667 + ], + "balanced_accuracy": 0.4705246913580247, + "accuracy": 0.47023809523809523, + "weighted_f1": 0.4714215675991068, + "macro_f1": 0.47182307333007106, + "kappa": 0.40322812395229657, + "samples": 1680, + "reward": 0.4705246913580247, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 1415, + 660, + 126, + 754, + 1684, + 10848 + ], + "confusion_matrix": [ + [ + 45, + 38, + 15, + 0, + 4, + 17 + ], + [ + 17, + 164, + 0, + 61, + 49, + 0 + ], + [ + 130, + 126, + 111, + 89, + 213, + 0 + ], + [ + 7, + 2, + 0, + 76, + 0, + 1 + ], + [ + 4, + 0, + 0, + 24, + 435, + 37 + ], + [ + 1212, + 330, + 0, + 504, + 983, + 10793 + ] + ], + "per_class_recall": [ + 0.37815126050420167, + 0.563573883161512, + 0.16591928251121077, + 0.8837209302325582, + 0.87, + 0.7808566054116626 + ], + "balanced_accuracy": 0.6070369936368575, + "accuracy": 0.7505649899916058, + "weighted_f1": 0.8137799723660881, + "macro_f1": 0.3561849045209278, + "kappa": 0.32441309326581047, + "samples": 15487, + "reward": 0.6070369936368575, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2061, + 2339 + ], + "confusion_matrix": [ + [ + 1698, + 502 + ], + [ + 363, + 1837 + ] + ], + "per_class_recall": [ + 0.7718181818181818, + 0.835 + ], + "balanced_accuracy": 0.803409090909091, + "accuracy": 0.803409090909091, + "weighted_f1": 0.8032127000298179, + "macro_f1": 0.8032127000298179, + "kappa": 0.6068181818181818, + "samples": 4400, + "subject_scores": { + "19": 0.8425, + "35": 0.9525, + "34": 0.6425000000000001, + "51": 0.7475, + "20": 0.82, + "44": 0.94, + "24": 0.5974999999999999, + "15": 0.9, + "31": 0.8825000000000001, + "26": 0.7925, + "23": 0.72 + }, + "reward": 0.803409090909091, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4573, + 3845 + ], + "confusion_matrix": [ + [ + 3657, + 603 + ], + [ + 916, + 3242 + ] + ], + "per_class_recall": [ + 0.8584507042253521, + 0.7797017797017797 + ], + "balanced_accuracy": 0.8190762419635659, + "accuracy": 0.8195533380850558, + "weighted_f1": 0.8192217642599872, + "macro_f1": 0.8191137114479841, + "kappa": 0.6387281046963751, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.837643455629449, + "sub-G2007": 0.7644167136410334, + "sub-G2019": 0.82505149822325, + "sub-G2031": 0.788678938415735, + "sub-G2015": 0.8429774626319118, + "sub-CTR002": 0.9869493251846193, + "sub-G2011": 0.765938925240826, + "sub-G2035": 0.9564871486872261, + "sub-CTR003": 0.5773809523809523 + }, + "reward": 0.8161693800038893, + "subjects": 9 + } + }, + "settings": { + "source": "/workspace/research/runs/hybrid_biot_csp_stable1/epoch-001", + "head_arithmetic": "same linear head in fixed feature blocks, sum in bfloat16 on GPU for non-AD tracks; AD remains float32", + "weights_unchanged": true + } + }, + "selected_head_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 0, + "longitudinal": 16 + }, + "incumbent_heads": "/workspace/research/runs/head_refinement1/epoch-012", + "clinical_training_teacher": { + "source": "/workspace/research/runs/hybrid_biot_readout1/epoch-009", + "weights_sha256": "3216b27a1cfb7c1e927da0d91a61c7d516f71236a8adf89d84bc9cfbb932313f", + "manifest_sha256": "49b7880052e6d093633e6e03d52bfd7df9084271ebf8e4f60e4fbe12da398354", + "split": "train", + "count": 68445, + "source_trained_jointly_on_all_five_tracks": true + }, + "no_prediction_ensemble": true + }, + "shared_backbone_training": "inherited joint training on all five training splits; fixed during input-adapter/head refinement", + "updated_parameters": [ + "adapters.tuev.spectral", + "heads.tuev" + ], + "initialization_maximum_logit_error": 0.0, + "training_target_provenance": { + "source": "/workspace/research/runs/hybrid_biot_readout1/epoch-009", + "weights_sha256": "3216b27a1cfb7c1e927da0d91a61c7d516f71236a8adf89d84bc9cfbb932313f", + "manifest_sha256": "49b7880052e6d093633e6e03d52bfd7df9084271ebf8e4f60e4fbe12da398354", + "split": "train", + "count": 68445, + "source_trained_jointly_on_all_five_tracks": true + } + }, + "selected_head_epochs": { + "faced": 18, + "tuev": 0, + "ad65": 0, + "openbmi": 3, + "longitudinal": 0 + }, + "incumbent_heads": null, + "training_teacher": { + "source": "/workspace/research/runs/clinical_spectral_adapter1/epoch-007", + "weights_sha256": "aa430806105fcab702edf8f7f1868715a82c0a279179ed79881abd0e3a1f4b0f", + "split": "train" + }, + "head_architecture": "frozen original linear readout plus LayerNorm, 64-unit GELU, dropout .3, zero-initialized output layer", + "no_prediction_ensemble": true + }, + "selected_head_epochs": { + "faced": 5, + "tuev": 24, + "ad65": 0, + "openbmi": 0, + "longitudinal": 0 + }, + "incumbent_heads": null, + "training_teacher": { + "source": "/workspace/research/runs/residual_heads1/epoch-018", + "weights_sha256": "e0b609137391b47f99438ccadaa22fc0bc10d2c10ead0ddf0a3c25be2c907c85", + "split": "train" + }, + "head_architecture": "continued 64-unit residual heads; inherited linear base fixed", + "augmentation": { + "source": "/workspace/research/runs/residual_heads1/epoch-018", + "weights_sha256": "e0b609137391b47f99438ccadaa22fc0bc10d2c10ead0ddf0a3c25be2c907c85", + "split": "train", + "transformation": "centered temporal resampling, linear interpolation, reflection outside original window", + "rates": [ + 0.9, + 1.1 + ], + "manifests": { + "openbmi": "35446de7b6e3e536f735e935c7eb74cc720f198a60d700da1db5fa39f315f5d5", + "longitudinal": "6ec8c8090a099cd4e4bf5faaf4bf97be7701916f7333a4e3b5c87b1d0b9f1acc" + } + }, + "no_prediction_ensemble": true + }, + "fit_split": "train", + "selection_split": "val", + "no_prediction_ensemble": true +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S021/alpha_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S021/alpha_features.py new file mode 100644 index 0000000000000000000000000000000000000000..455154d715e86d45e4e17113bed69adbcd946b29 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S021/alpha_features.py @@ -0,0 +1,45 @@ +"""Fixed alpha prominence features from each individual two-second window.""" +import torch + +REGION_NAMES=('occipital','parietal','central','frontal','left_posterior','right_posterior') +REGIONS=(('PO7','PO5','PO3','POZ','PO4','PO6','PO8','O1','OZ','O2'), + ('P7','P5','P3','P1','PZ','P2','P4','P6','P8'), + ('FC5','FC3','FC1','FCZ','FC2','FC4','FC6','C5','C3','C1','CZ','C2','C4','C6'), + ('FP1','FPZ','FP2','AF3','AF4','F7','F5','F3','F1','FZ','F2','F4','F6','F8'), + ('P7','P5','P3','P1','PO7','PO5','PO3','O1'), + ('P2','P4','P6','P8','PO4','PO6','PO8','O2')) +ALPHA_DIM=58*7+6*22 + +def region_matrix(channels): + result=torch.zeros(len(REGIONS),len(channels)) + for i,names in enumerate(REGIONS): + for name in names:result[i,channels.index(name)]=1/len(names) + return result.tolist() + +@torch.no_grad() +def extract_alpha_features(signal,regions): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();x=x-x.mean(-1,keepdim=True) + spectrum=torch.fft.rfft(x*torch.hann_window(400,device=x.device),dim=-1)/200 + power=spectrum.abs().square().clamp_min(1e-12) + lp=power.log() + # Geometric regional means resist domination by one high-amplitude channel. + regional=torch.einsum('rc,ncf->nrf',regions.float(),lp) + lp=torch.cat([lp,regional],1) + low=lp[...,8:13].mean(-1,keepdim=True) + high=lp[...,36:49].mean(-1,keepdim=True) + freq=torch.arange(7.,14.5,.5,device=x.device) + alpha=lp[...,14:29] + baseline=low+(high-low)*((freq-5)/16) + prominence=alpha-baseline + normalized=alpha.softmax(-1) + center=(normalized*freq).sum(-1) + entropy=-(normalized*normalized.clamp_min(1e-12).log()).sum(-1) + alpha_mean=torch.logsumexp(alpha,-1)-torch.log(torch.tensor(15.,device=x.device)) + def log_band(lo,hi): + return torch.logsumexp(lp[...,lo:hi],-1)-torch.log(torch.tensor(float(hi-lo),device=x.device)) + summaries=torch.stack([alpha_mean-log_band(2,81),alpha_mean-log_band(8,14), + alpha_mean-log_band(30,61),prominence.max(-1).values, + prominence.mean(-1),center,entropy],-1) + return torch.cat([summaries[:,:58].flatten(1),summaries[:,58:].flatten(1), + prominence[:,58:].flatten(1)],1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S021/config.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S021/config.json new file mode 100644 index 0000000000000000000000000000000000000000..6c0f300568d1abf4d1d69571d6ade4f219e13ed5 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S021/config.json @@ -0,0 +1,611 @@ +{ + "schema": "bci-shared-biot-covariance-bf16head-v1", + "architecture": { + "channels": 32, + "width": 128, + "depth": 2, + "dropout": 0.5, + "wave_filters": 32, + "head_width": 64, + "head_dropout": 0.3, + "clinical_asymmetry": true, + "alpha_regions": [ + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.125 + ] + ], + "clinical_envelope": true + }, + "initialization": { + "initialization": "continue joint training from a complete shared-model checkpoint", + "parent": "/workspace/research/runs/hybrid_biot_fusionshrink0100/epoch-001/weights.pt", + "parent_initialization": { + "initialization": "jointly trained parent plus audited pretrained BIOT in a single coupled backbone", + "parent": "/workspace/research/runs/hybrid_wide1/epoch-004/weights.pt", + "audited_biot": { + "initialization": "pretrained", + "repo": "braindecode/biot-pretrained-six-datasets-18chs", + "revision": "7e9aabf302870012f73773276803aab97993951c", + "sha256": "a218f4054ae29962c6fd9d23d94c446d354c4f53e805a6771c85749ccc20baaa", + "license": "BSD-3-Clause", + "source_braindecode": "1.3.0", + "loaded_core_tensors": 56, + "skipped_classifier_tensors": 3 + }, + "neural_channel_indices": { + "faced": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "tuev": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15 + ], + "ad65": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "openbmi": [ + 0, + 1, + 3, + 5, + 12, + 14, + 23, + 25, + 28, + 30, + 2, + 6, + 11, + 15, + 22, + 26, + 4, + 13 + ], + "longitudinal": [ + 0, + 2, + 7, + 11, + 23, + 27, + 41, + 45, + 55, + 57, + 5, + 13, + 21, + 29, + 39, + 47, + 9, + 25 + ] + }, + "rebase": "incumbent waveform, fusion and four heads; joint BIOT and TUEV head from readout epoch 9; zero initialized neural interaction", + "jointly_finetuned_neural_parent": "/workspace/research/runs/hybrid_biot_readout1/epoch-009/weights.pt", + "tuev_high_dimensional_spectral_projection_disabled": true, + "frozen_prior_representation": true, + "nonclinical_head_updates": "only the 256 added BIOT columns; original columns and biases fixed", + "faced_openbmi_neural_path": "common nonlinear fusion only; direct head columns masked", + "retention_teacher": "/workspace/research/runs/hybrid_wide1/epoch-004", + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "joint_covariance_parent": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "frozen_prior_representation": true, + "head_updates": "one linear head per track; added 128 shared covariance columns trainable; AD head initialized from the joint covariance parent", + "new_shared_representation": "one common covariance MLP inside the coupled backbone, trained by all five tasks; fixed spatial input adapters from the same jointly trained source", + "head_arithmetic": "one linear head evaluated in fixed feature blocks to preserve original bfloat16 accumulation dimensions", + "retention_teacher": { + "ad65": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "other_tracks": "/workspace/research/runs/hybrid_wide1/epoch-004" + }, + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "loader_scale": 0.01, + "tracks": [ + "faced", + "tuev", + "ad65", + "openbmi", + "longitudinal" + ], + "head_arithmetic": "same linear head in fixed feature blocks, sum in bfloat16 on GPU for non-AD tracks; AD remains float32", + "head_refinement": { + "source": "/workspace/research/runs/residual_heads1/epoch-018", + "source_weights_sha256": "e0b609137391b47f99438ccadaa22fc0bc10d2c10ead0ddf0a3c25be2c907c85", + "shared_backbone_unchanged": true, + "selected_head_epochs": { + "faced": 5, + "tuev": 24, + "ad65": 0, + "openbmi": 0, + "longitudinal": 0 + } + }, + "clinical_spectral_refinement": { + "source": "/workspace/research/runs/head_dropout1/epoch-016", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "head_estimation": { + "method": "class/subject-balanced Gaussian linear discriminant; covariance augmented by class-conditional subject/session mean variation before shrinkage", + "selected_shrinkage": { + "faced": "inherited", + "tuev": "inherited", + "ad65": "inherited", + "openbmi": "inherited", + "longitudinal": { + "shrinkage": 0.9, + "domain_strength": 1.0 + } + }, + "feature_scaling": "fitted on training data and folded into linear coefficients" + }, + "clinical_asymmetry_refinement": { + "source": "/workspace/research/runs/domain_lda_heads1/epoch-001", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "alpha_rhythm_adapter": { + "training_normalization_only": true, + "regions": [ + "occipital", + "parietal", + "central", + "frontal", + "left_posterior", + "right_posterior" + ], + "features": "per-window alpha prominence relative to adjacent frequencies", + "shared_backbone_unchanged": true + }, + "clinical_envelope_refinement": { + "source": "/workspace/research/runs/clinical_asymmetry1/epoch-001", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "independent_adapter_merge": { + "alpha_source": "/workspace/research/runs/alpha_calibrated1/epoch-003", + "clinical_source": "/workspace/research/runs/clinical_envelope1/epoch-002", + "all_shared_and_head_tensors_equal": true + }, + "frequency_montage_refinement": { + "six_frequency_bands": true, + "shared_encoder_unchanged": true, + "selected_track_epochs": { + "faced": 0, + "tuev": 2, + "ad65": 0, + "openbmi": 0, + "longitudinal": 2 + } + } +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S021/covariances.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S021/covariances.py new file mode 100644 index 0000000000000000000000000000000000000000..a65153f3b18f31995ff206a8e2fb8a7fd7a254dd --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S021/covariances.py @@ -0,0 +1,25 @@ +"""Shared neural filter-bank covariance decoder with spatial input adapters.""" +import torch +from torch import nn +SPECS={'faced':(32,10,9),'tuev':(16,5,6),'ad65':(19,10,3),'openbmi':(62,4,2),'longitudinal':(58,2,2)} +TRACKS=tuple(SPECS) +BANDS=[(1,4),(4,8),(8,12),(12,16),(16,20),(20,24),(24,28),(28,32),(32,40),(40,48)] + +@torch.no_grad() +def extract_covariances(t,x): + x=torch.nan_to_num(x.float().flatten(2)).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if t in ('faced','tuev'): + x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + else:x=x-x.mean(1,keepdim=True) + # Per-window normalization, preserving spatial and frequency power ratios. + x=x/x.square().mean((1,2),keepdim=True).clamp_min(1e-12).sqrt() + frames=x.unfold(-1,400,200);frames=frames-frames.mean(-1,keepdim=True) + z=torch.fft.rfft(frames*torch.hann_window(400,device=x.device),dim=-1)/200 + covs=[] + for lo,hi in BANDS: + v=z[...,2*lo:2*hi].flatten(2) + cov=(v.real@v.real.transpose(-1,-2)+v.imag@v.imag.transpose(-1,-2))/v.shape[-1] + covs.append(cov) + return torch.stack(covs,1) + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S021/data.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S021/data.py new file mode 100644 index 0000000000000000000000000000000000000000..e3cf61f3b1ac4d22858c6e6f387024abd27d953d --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S021/data.py @@ -0,0 +1,33 @@ +import json +from functools import lru_cache +from pathlib import Path +import numpy as np +import torch +@lru_cache(maxsize=8) +def array(path):return np.load(path,mmap_mode='r',allow_pickle=False) +class Dataset(torch.utils.data.Dataset): + def __init__(self,root,limit=None,cache=False): + self.root=Path(root) + self.rows=json.loads((self.root/'manifest.json').read_text())['samples'] + if limit:self.rows=self.rows[:limit] + self.cached=None + if cache and self.rows: + from collections import defaultdict + groups=defaultdict(list) + for i,r in enumerate(self.rows):groups[r['path']].append((i,r['index'])) + for name,indices in groups.items(): + path=(self.root/name).resolve() + if not path.is_relative_to(self.root.resolve()):raise ValueError('input outside root') + source=np.load(path,mmap_mode='r',allow_pickle=False) + if self.cached is None:self.cached=torch.empty((len(self.rows),*source.shape[1:]),dtype=torch.float32) + dst,src=zip(*indices) + self.cached[list(dst)]=torch.as_tensor(source[list(src)]/100,dtype=torch.float32) + def __len__(self):return len(self.rows) + def __getitem__(self,i): + r=self.rows[i] + if self.cached is not None:return self.cached[i],r.get('label',-1),r['id'] + p=(self.root/r['path']).resolve() + if not p.is_relative_to(self.root.resolve()):raise ValueError('input outside root') + # Division precedes float32 conversion, matching official FACED/TUEV collate. + x=np.asarray(array(str(p))[r['index']])/100 + return torch.as_tensor(x,dtype=torch.float32),r.get('label',-1),r['id'] diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S021/envelope_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S021/envelope_features.py new file mode 100644 index 0000000000000000000000000000000000000000..2251a6f03a3a6daaa3faed0bbc803bf182224da6 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S021/envelope_features.py @@ -0,0 +1,44 @@ +"""Per-window burst-envelope regularity and bilateral synchrony, without fitting.""" +import torch +import torch.nn.functional as F + +BANDS=((1,4),(4,8),(8,13),(13,30),(30,45)) +ENVELOPE_DIM=16*5*12+8*5*2 + +@torch.no_grad() +def extract_envelope_features(signal): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();x=x-x.mean(-1,keepdim=True) + spectrum=torch.fft.fft(x,dim=-1) + frequency=torch.fft.fftfreq(x.shape[-1],1/200,device=x.device) + envelopes=[] + for lo,hi in BANDS: + mask=((frequency>=lo)&(frequency2).float().mean(-1),(relative>4).float().mean(-1), + ((relative[...,1:]>2)&(relative[...,:-1]<=2)).float().mean(-1), + acf_peak,(acf_index.float()+4)/40, + acf[...,0],acf[...,6],acf[...,16],acf[...,36]] + left=torch.tensor([0,1,2,3,8,9,10,11],device=x.device);right=left+4 + synchrony=(normalized[:,left]*normalized[:,right]).mean(-1).clamp(-1,1) + imbalance=(std[:,left].squeeze(-1).log()-std[:,right].squeeze(-1).log()).abs() + return torch.cat([torch.stack(summaries,-1).flatten(1),synchrony.flatten(1),imbalance.flatten(1)],1) + +def mirrored_features(features): + channels=torch.tensor([4,5,6,7,0,1,2,3,12,13,14,15,8,9,10,11],device=features.device) + return torch.cat([features[:,:16*5*12].reshape(-1,16,5,12)[:,channels].flatten(1),features[:,16*5*12:]],1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S021/features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S021/features.py new file mode 100644 index 0000000000000000000000000000000000000000..88f7e8b14c9fab44733d5224ede6d6b5c7f76a45 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S021/features.py @@ -0,0 +1,63 @@ +"""One shared residual backbone, five linear input adapters and output heads.""" +import torch +from torch import nn + +SPECS = {'faced': (32, 10, 9), 'tuev': (16, 5, 6), 'ad65': (19, 10, 3), + 'openbmi': (62, 4, 2), 'longitudinal': (58, 2, 2)} +TRACKS = tuple(SPECS) +EDGES = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,18,20,22,25,28,32,36,40,45,50,60,70,80,95] +COV_BANDS = [(1,4),(4,8),(8,12),(12,16),(16,20),(20,28),(28,40)] + +def feature_dim(channels): + return channels * (4*(len(EDGES)-1)+4) + len(COV_BANDS)*channels*(channels-1)//2 + +@torch.no_grad() +def extract_features(track, x): + """Fixed features; no batch statistics or fitted inference transformations.""" + x = x.float().flatten(2) + x = torch.nan_to_num(x, nan=0., posinf=1e5, neginf=-1e5).clamp(-1e5,1e5) + x = x - x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'): + x = x - x.mean(1,keepdim=True) + rms = x.square().mean(-1).clamp_min(1e-12).sqrt() + norm = x / rms.unsqueeze(-1) + moments = torch.stack([rms.log(), norm.abs().amax(-1).clamp_min(1).log(), + norm.pow(4).mean(-1).clamp_min(1).log(), + (norm[...,1:]-norm[...,:-1]).square().mean(-1).clamp_min(1e-10).log()],-1) + frames = x.unfold(-1,400,200) + frames = frames - frames.mean(-1,keepdim=True) + window = torch.hann_window(400,device=x.device) + z = torch.fft.rfft(frames*window,dim=-1)/200 + power = z.abs().square() + bands = torch.stack([power[...,2*lo:2*hi].mean(-1) for lo,hi in zip(EDGES[:-1],EDGES[1:])],-1) + lp = bands.mean(-2).clamp_min(1e-12).log() + variation = bands.clamp_min(1e-12).log().std(-2,correction=0) + relative_frequency = lp - lp.mean(-1,keepdim=True) + relative_channel = lp - lp.mean(1,keepdim=True) + parts = [torch.cat([lp, relative_frequency, relative_channel, variation, moments],-1).flatten(1)] + ii,jj = torch.triu_indices(x.shape[1],x.shape[1],offset=1,device=x.device) + for lo,hi in COV_BANDS: + v = z[...,2*lo:2*hi].flatten(2) + cov = v.real @ v.real.transpose(-1,-2) + v.imag @ v.imag.transpose(-1,-2) + d = cov.diagonal(dim1=-2,dim2=-1).clamp_min(1e-12).sqrt() + cor = cov / (d.unsqueeze(1)*d.unsqueeze(2)).clamp_min(1e-12) + parts.append(cor[:,ii,jj].clamp(-1,1)) + result = torch.cat(parts,-1) + return torch.nan_to_num(result).clamp(-40,40) + +class Standardize(nn.Module): + def __init__(self, dim): + super().__init__() + self.register_buffer('mean',torch.zeros(dim)) + self.register_buffer('scale',torch.ones(dim)) + def forward(self,x): + return ((x-self.mean)/self.scale).clamp(-8,8) + +class Residual(nn.Module): + def __init__(self,width,dropout): + super().__init__() + self.net=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(), + nn.Dropout(dropout),nn.Linear(width*2,width),nn.Dropout(dropout)) + def forward(self,x): + return x+self.net(x) + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S021/frequency_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S021/frequency_features.py new file mode 100644 index 0000000000000000000000000000000000000000..9194c9e81f801b3833e551e4967991774fa9e398 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S021/frequency_features.py @@ -0,0 +1,11 @@ +"""Fixed per-window frequency decomposition for a linear montage adapter.""" +import torch + +FREQUENCY_BANDS=((1,4),(4,8),(8,13),(13,20),(20,30),(30,45)) + +def frequency_components(signal): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();spectrum=torch.fft.rfft(x,dim=-1) + frequency=torch.fft.rfftfreq(x.shape[-1],d=1/200,device=x.device) + masks=torch.stack([((frequency>=lo)&(frequencynbf',w,covariances.float(),w).clamp_min(1e-8).log() + return torch.cat([power,power-power.mean(1,keepdim=True)],1).flatten(1) + def wave_signal(self,x,components=None): + if components is None:components=frequency_components(x) + correction=torch.einsum('blc,nbct->nlt',self.frequency_weight,components.to(self.frequency_weight.dtype)) + return (self.signal(x)+correction.to(x.dtype)).unsqueeze(1) + def forward(self,x,features,covariance_features): + return self.wave_signal(x),self.spectral_features(features,signal=x),self.neural(x),covariance_features + +class SharedBackbone(nn.Module): + def __init__(self,channels,width,depth,dropout,wave_filters): + super().__init__() + self.waveform=nn.Sequential( + nn.Conv2d(1,wave_filters,(1,64),padding=(0,32),bias=False),nn.GroupNorm(1,wave_filters), + nn.Conv2d(wave_filters,2*wave_filters,(channels,1),groups=wave_filters,bias=False),nn.GroupNorm(1,2*wave_filters),nn.ELU(), + nn.AvgPool2d((1,4)),nn.Dropout(.35), + nn.Conv2d(2*wave_filters,2*wave_filters,(1,16),padding=(0,8),groups=2*wave_filters,bias=False),nn.Conv2d(2*wave_filters,2*wave_filters,1,bias=False), + nn.GroupNorm(1,2*wave_filters),nn.ELU(),nn.AvgPool2d((1,8)),nn.Dropout(.35)) + self.wave_summary=nn.Sequential(nn.AdaptiveAvgPool2d((1,8)),nn.Flatten(),nn.Linear(2*wave_filters*8,width)) + self.fusion=nn.Sequential(nn.LayerNorm(width),nn.GELU(),nn.Dropout(dropout), + *[Residual(width,dropout) for _ in range(depth)],nn.LayerNorm(width)) + # Both representations interact before the shared residual stack. + self.wave_gain=nn.Parameter(torch.tensor(.1)) + self.biot=BIOT(n_chans=18,n_outputs=2,n_times=400,sfreq=200) + self.biot.final_layer=nn.Identity() + self.biot_projection=nn.Sequential(nn.LayerNorm(256),nn.Linear(256,width),nn.Dropout(.2)) + nn.init.normal_(self.biot_projection[1].weight,std=.001);nn.init.zeros_(self.biot_projection[1].bias) + self.covariance_encoder=nn.Sequential(nn.LayerNorm(len(BANDS)*24*2),nn.Linear(len(BANDS)*24*2,width),nn.GELU(),nn.Dropout(.4), + *[Residual(width,.4) for _ in range(2)],nn.LayerNorm(width)) + self.covariance_projection=nn.Linear(width,width) + nn.init.zeros_(self.covariance_projection.weight);nn.init.zeros_(self.covariance_projection.bias) + def forward(self,signal,spectral,neural_signal,covariance_features): + wave=self.waveform(signal) + neural=self.biot(neural_signal.float()) + neural=self.biot_projection[0](neural) + projected=self.biot_projection[2](self.biot_projection[1](neural)) + with torch.autocast(signal.device.type,enabled=False): + covariance_embedding=self.covariance_encoder(covariance_features.float()) + original=spectral+self.wave_gain*self.wave_summary(wave)+.01*projected + coupled=.001*self.covariance_projection(covariance_embedding).to(original.dtype) + fused=self.fusion(original+coupled) + return torch.cat([wave.flatten(1),fused,neural,covariance_embedding],-1) + +class ResidualHead(nn.Module): + """A small nonlinear classifier correction around an inherited linear readout.""" + def __init__(self,features,classes,width=64,dropout=.3,full_precision=False): + super().__init__();self.full_precision=full_precision + self.base=nn.Linear(features,classes) + self.delta=nn.Sequential(nn.LayerNorm(features),nn.Linear(features,width),nn.GELU(),nn.Dropout(dropout),nn.Linear(width,classes)) + nn.init.zeros_(self.delta[-1].weight);nn.init.zeros_(self.delta[-1].bias) + def forward(self,x): + if self.full_precision: + with torch.autocast(x.device.type,enabled=False):return self.base(x.float())+self.delta(x.float()) + prior=nn.functional.linear(x[:,:-128].contiguous(),self.base.weight[:,:-128].contiguous(),self.base.bias) + added=nn.functional.linear(x[:,-128:].contiguous(),self.base.weight[:,-128:].contiguous()) + value=prior+added + return value+self.delta(x).to(value.dtype) + +class HybridModel(nn.Module): + def __init__(self,channels=32,width=128,depth=2,dropout=.5,wave_filters=32,head_width=64,head_dropout=.3,clinical_asymmetry=True,alpha_regions=None,clinical_envelope=False): + super().__init__() + self.adapters=nn.ModuleDict({t:InputAdapter(c,width,channels,spectral_enabled=t not in ("faced","tuev","openbmi"),asymmetry=clinical_asymmetry and t=="tuev",alpha_regions=alpha_regions if t=="longitudinal" else None,envelope=clinical_envelope and t=="tuev") for t,(c,s,k) in SPECS.items()}) + self.backbone=SharedBackbone(channels,width,depth,dropout,wave_filters) + self.heads=nn.ModuleDict({t:ResidualHead(2*wave_filters*(((s*200+1)//4+1)//8)+width+256+width,k,head_width,head_dropout,full_precision=t=='ad65') for t,(c,s,k) in SPECS.items()}) + def forward(self,t,x,features=None,covariances=None,covariance_features=None): + if features is None:features=extract_features(t,x) + if covariance_features is None: + if covariances is None:covariances=extract_covariances(t,x) + covariance_features=self.adapters[t].spatial_features(covariances) + signal=x.flatten(2);signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + adapted=self.adapters[t](signal,features,covariance_features) + representation=self.backbone(*adapted) + if t in ('faced','openbmi'): + representation=torch.cat([representation[:,:-384],torch.zeros_like(representation[:,-384:-128]),representation[:,-128:]],-1) + return self.heads[t](representation) + +def widen_state_dict(state,multiplier=2): + """Duplicate temporal features and divide downstream sums to preserve outputs.""" + result={} + for key,value in state.items(): + if key.startswith('backbone.waveform.'): + layer=int(key.split('.')[2]) + if layer in (0,2,7):value=value.repeat(multiplier,1,1,1) + elif layer in (1,3,9):value=value.repeat(multiplier) + elif layer==8:value=value.repeat(multiplier,multiplier,1,1)/multiplier + elif key=='backbone.wave_summary.2.weight':value=value.repeat(1,multiplier)/multiplier + elif key.startswith('heads.') and key.endswith('.weight'): + raw=value[:,:-128]/multiplier + value=torch.cat([raw]*multiplier+[value[:,-128:]],1) + result[key]=value + return result + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S027/alpha_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S027/alpha_features.py new file mode 100644 index 0000000000000000000000000000000000000000..455154d715e86d45e4e17113bed69adbcd946b29 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S027/alpha_features.py @@ -0,0 +1,45 @@ +"""Fixed alpha prominence features from each individual two-second window.""" +import torch + +REGION_NAMES=('occipital','parietal','central','frontal','left_posterior','right_posterior') +REGIONS=(('PO7','PO5','PO3','POZ','PO4','PO6','PO8','O1','OZ','O2'), + ('P7','P5','P3','P1','PZ','P2','P4','P6','P8'), + ('FC5','FC3','FC1','FCZ','FC2','FC4','FC6','C5','C3','C1','CZ','C2','C4','C6'), + ('FP1','FPZ','FP2','AF3','AF4','F7','F5','F3','F1','FZ','F2','F4','F6','F8'), + ('P7','P5','P3','P1','PO7','PO5','PO3','O1'), + ('P2','P4','P6','P8','PO4','PO6','PO8','O2')) +ALPHA_DIM=58*7+6*22 + +def region_matrix(channels): + result=torch.zeros(len(REGIONS),len(channels)) + for i,names in enumerate(REGIONS): + for name in names:result[i,channels.index(name)]=1/len(names) + return result.tolist() + +@torch.no_grad() +def extract_alpha_features(signal,regions): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();x=x-x.mean(-1,keepdim=True) + spectrum=torch.fft.rfft(x*torch.hann_window(400,device=x.device),dim=-1)/200 + power=spectrum.abs().square().clamp_min(1e-12) + lp=power.log() + # Geometric regional means resist domination by one high-amplitude channel. + regional=torch.einsum('rc,ncf->nrf',regions.float(),lp) + lp=torch.cat([lp,regional],1) + low=lp[...,8:13].mean(-1,keepdim=True) + high=lp[...,36:49].mean(-1,keepdim=True) + freq=torch.arange(7.,14.5,.5,device=x.device) + alpha=lp[...,14:29] + baseline=low+(high-low)*((freq-5)/16) + prominence=alpha-baseline + normalized=alpha.softmax(-1) + center=(normalized*freq).sum(-1) + entropy=-(normalized*normalized.clamp_min(1e-12).log()).sum(-1) + alpha_mean=torch.logsumexp(alpha,-1)-torch.log(torch.tensor(15.,device=x.device)) + def log_band(lo,hi): + return torch.logsumexp(lp[...,lo:hi],-1)-torch.log(torch.tensor(float(hi-lo),device=x.device)) + summaries=torch.stack([alpha_mean-log_band(2,81),alpha_mean-log_band(8,14), + alpha_mean-log_band(30,61),prominence.max(-1).values, + prominence.mean(-1),center,entropy],-1) + return torch.cat([summaries[:,:58].flatten(1),summaries[:,58:].flatten(1), + prominence[:,58:].flatten(1)],1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S027/config.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S027/config.json new file mode 100644 index 0000000000000000000000000000000000000000..3775caf713844ffe1ed22a97b764c31effc7ba1a --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S027/config.json @@ -0,0 +1,637 @@ +{ + "schema": "bci-shared-biot-covariance-bf16head-v1", + "architecture": { + "channels": 32, + "width": 128, + "depth": 2, + "dropout": 0.5, + "wave_filters": 32, + "head_width": 64, + "head_dropout": 0.3, + "clinical_asymmetry": true, + "alpha_regions": [ + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.125 + ] + ], + "clinical_envelope": true, + "temporal_pool": true + }, + "initialization": { + "initialization": "continue joint training from a complete shared-model checkpoint", + "parent": "/workspace/research/runs/hybrid_biot_fusionshrink0100/epoch-001/weights.pt", + "parent_initialization": { + "initialization": "jointly trained parent plus audited pretrained BIOT in a single coupled backbone", + "parent": "/workspace/research/runs/hybrid_wide1/epoch-004/weights.pt", + "audited_biot": { + "initialization": "pretrained", + "repo": "braindecode/biot-pretrained-six-datasets-18chs", + "revision": "7e9aabf302870012f73773276803aab97993951c", + "sha256": "a218f4054ae29962c6fd9d23d94c446d354c4f53e805a6771c85749ccc20baaa", + "license": "BSD-3-Clause", + "source_braindecode": "1.3.0", + "loaded_core_tensors": 56, + "skipped_classifier_tensors": 3 + }, + "neural_channel_indices": { + "faced": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "tuev": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15 + ], + "ad65": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "openbmi": [ + 0, + 1, + 3, + 5, + 12, + 14, + 23, + 25, + 28, + 30, + 2, + 6, + 11, + 15, + 22, + 26, + 4, + 13 + ], + "longitudinal": [ + 0, + 2, + 7, + 11, + 23, + 27, + 41, + 45, + 55, + 57, + 5, + 13, + 21, + 29, + 39, + 47, + 9, + 25 + ] + }, + "rebase": "incumbent waveform, fusion and four heads; joint BIOT and TUEV head from readout epoch 9; zero initialized neural interaction", + "jointly_finetuned_neural_parent": "/workspace/research/runs/hybrid_biot_readout1/epoch-009/weights.pt", + "tuev_high_dimensional_spectral_projection_disabled": true, + "frozen_prior_representation": true, + "nonclinical_head_updates": "only the 256 added BIOT columns; original columns and biases fixed", + "faced_openbmi_neural_path": "common nonlinear fusion only; direct head columns masked", + "retention_teacher": "/workspace/research/runs/hybrid_wide1/epoch-004", + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "joint_covariance_parent": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "frozen_prior_representation": true, + "head_updates": "one linear head per track; added 128 shared covariance columns trainable; AD head initialized from the joint covariance parent", + "new_shared_representation": "one common covariance MLP inside the coupled backbone, trained by all five tasks; fixed spatial input adapters from the same jointly trained source", + "head_arithmetic": "one linear head evaluated in fixed feature blocks to preserve original bfloat16 accumulation dimensions", + "retention_teacher": { + "ad65": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "other_tracks": "/workspace/research/runs/hybrid_wide1/epoch-004" + }, + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "loader_scale": 0.01, + "tracks": [ + "faced", + "tuev", + "ad65", + "openbmi", + "longitudinal" + ], + "head_arithmetic": "same linear head in fixed feature blocks, sum in bfloat16 on GPU for non-AD tracks; AD remains float32", + "head_refinement": { + "source": "/workspace/research/runs/residual_heads1/epoch-018", + "source_weights_sha256": "e0b609137391b47f99438ccadaa22fc0bc10d2c10ead0ddf0a3c25be2c907c85", + "shared_backbone_unchanged": true, + "selected_head_epochs": { + "faced": 5, + "tuev": 24, + "ad65": 0, + "openbmi": 0, + "longitudinal": 0 + } + }, + "clinical_spectral_refinement": { + "source": "/workspace/research/runs/head_dropout1/epoch-016", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "head_estimation": { + "method": "class/subject-balanced Gaussian linear discriminant; covariance augmented by class-conditional subject/session mean variation before shrinkage", + "selected_shrinkage": { + "faced": "inherited", + "tuev": "inherited", + "ad65": "inherited", + "openbmi": "inherited", + "longitudinal": { + "shrinkage": 0.9, + "domain_strength": 1.0 + } + }, + "feature_scaling": "fitted on training data and folded into linear coefficients" + }, + "clinical_asymmetry_refinement": { + "source": "/workspace/research/runs/domain_lda_heads1/epoch-001", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "alpha_rhythm_adapter": { + "training_normalization_only": true, + "regions": [ + "occipital", + "parietal", + "central", + "frontal", + "left_posterior", + "right_posterior" + ], + "features": "per-window alpha prominence relative to adjacent frequencies", + "shared_backbone_unchanged": true + }, + "clinical_envelope_refinement": { + "source": "/workspace/research/runs/clinical_asymmetry1/epoch-001", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "independent_adapter_merge": { + "alpha_source": "/workspace/research/runs/alpha_calibrated1/epoch-003", + "clinical_source": "/workspace/research/runs/clinical_envelope1/epoch-002", + "all_shared_and_head_tensors_equal": true + }, + "frequency_montage_refinement": { + "six_frequency_bands": true, + "shared_encoder_unchanged": true, + "selected_track_epochs": { + "faced": 0, + "tuev": 1, + "ad65": 0, + "openbmi": 10, + "longitudinal": 2 + } + }, + "private_track_selection": { + "track": "tuev", + "donor": "/workspace/research/replicates/frequency_head_control1/epoch-001" + }, + "clinical_sampling_refinement": { + "subject_exponent": 0.0, + "class_balanced": true, + "only_clinical_head_updated": true + }, + "temporal_statistics_readout": { + "statistics": [ + "mean", + "standard deviation", + "maximum", + "minimum" + ], + "shared_encoder_and_prior_heads_unchanged": true, + "selected_pool_epochs": { + "faced": 2, + "tuev": 0, + "ad65": 0, + "openbmi": 33, + "longitudinal": 3 + } + } +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S027/covariances.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S027/covariances.py new file mode 100644 index 0000000000000000000000000000000000000000..a65153f3b18f31995ff206a8e2fb8a7fd7a254dd --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S027/covariances.py @@ -0,0 +1,25 @@ +"""Shared neural filter-bank covariance decoder with spatial input adapters.""" +import torch +from torch import nn +SPECS={'faced':(32,10,9),'tuev':(16,5,6),'ad65':(19,10,3),'openbmi':(62,4,2),'longitudinal':(58,2,2)} +TRACKS=tuple(SPECS) +BANDS=[(1,4),(4,8),(8,12),(12,16),(16,20),(20,24),(24,28),(28,32),(32,40),(40,48)] + +@torch.no_grad() +def extract_covariances(t,x): + x=torch.nan_to_num(x.float().flatten(2)).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if t in ('faced','tuev'): + x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + else:x=x-x.mean(1,keepdim=True) + # Per-window normalization, preserving spatial and frequency power ratios. + x=x/x.square().mean((1,2),keepdim=True).clamp_min(1e-12).sqrt() + frames=x.unfold(-1,400,200);frames=frames-frames.mean(-1,keepdim=True) + z=torch.fft.rfft(frames*torch.hann_window(400,device=x.device),dim=-1)/200 + covs=[] + for lo,hi in BANDS: + v=z[...,2*lo:2*hi].flatten(2) + cov=(v.real@v.real.transpose(-1,-2)+v.imag@v.imag.transpose(-1,-2))/v.shape[-1] + covs.append(cov) + return torch.stack(covs,1) + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S027/envelope_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S027/envelope_features.py new file mode 100644 index 0000000000000000000000000000000000000000..2251a6f03a3a6daaa3faed0bbc803bf182224da6 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S027/envelope_features.py @@ -0,0 +1,44 @@ +"""Per-window burst-envelope regularity and bilateral synchrony, without fitting.""" +import torch +import torch.nn.functional as F + +BANDS=((1,4),(4,8),(8,13),(13,30),(30,45)) +ENVELOPE_DIM=16*5*12+8*5*2 + +@torch.no_grad() +def extract_envelope_features(signal): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();x=x-x.mean(-1,keepdim=True) + spectrum=torch.fft.fft(x,dim=-1) + frequency=torch.fft.fftfreq(x.shape[-1],1/200,device=x.device) + envelopes=[] + for lo,hi in BANDS: + mask=((frequency>=lo)&(frequency2).float().mean(-1),(relative>4).float().mean(-1), + ((relative[...,1:]>2)&(relative[...,:-1]<=2)).float().mean(-1), + acf_peak,(acf_index.float()+4)/40, + acf[...,0],acf[...,6],acf[...,16],acf[...,36]] + left=torch.tensor([0,1,2,3,8,9,10,11],device=x.device);right=left+4 + synchrony=(normalized[:,left]*normalized[:,right]).mean(-1).clamp(-1,1) + imbalance=(std[:,left].squeeze(-1).log()-std[:,right].squeeze(-1).log()).abs() + return torch.cat([torch.stack(summaries,-1).flatten(1),synchrony.flatten(1),imbalance.flatten(1)],1) + +def mirrored_features(features): + channels=torch.tensor([4,5,6,7,0,1,2,3,12,13,14,15,8,9,10,11],device=features.device) + return torch.cat([features[:,:16*5*12].reshape(-1,16,5,12)[:,channels].flatten(1),features[:,16*5*12:]],1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S027/frequency_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S027/frequency_features.py new file mode 100644 index 0000000000000000000000000000000000000000..9194c9e81f801b3833e551e4967991774fa9e398 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S027/frequency_features.py @@ -0,0 +1,11 @@ +"""Fixed per-window frequency decomposition for a linear montage adapter.""" +import torch + +FREQUENCY_BANDS=((1,4),(4,8),(8,13),(13,20),(20,30),(30,45)) + +def frequency_components(signal): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();spectrum=torch.fft.rfft(x,dim=-1) + frequency=torch.fft.rfftfreq(x.shape[-1],d=1/200,device=x.device) + masks=torch.stack([((frequency>=lo)&(frequencynbf',w,covariances.float(),w).clamp_min(1e-8).log() + return torch.cat([power,power-power.mean(1,keepdim=True)],1).flatten(1) + def wave_signal(self,x,components=None): + if components is None:components=frequency_components(x) + correction=torch.einsum('blc,nbct->nlt',self.frequency_weight,components.to(self.frequency_weight.dtype)) + return (self.signal(x)+correction.to(x.dtype)).unsqueeze(1) + def forward(self,x,features,covariance_features): + return self.wave_signal(x),self.spectral_features(features,signal=x),self.neural(x),covariance_features + +class SharedBackbone(nn.Module): + def __init__(self,channels,width,depth,dropout,wave_filters): + super().__init__() + self.waveform=nn.Sequential( + nn.Conv2d(1,wave_filters,(1,64),padding=(0,32),bias=False),nn.GroupNorm(1,wave_filters), + nn.Conv2d(wave_filters,2*wave_filters,(channels,1),groups=wave_filters,bias=False),nn.GroupNorm(1,2*wave_filters),nn.ELU(), + nn.AvgPool2d((1,4)),nn.Dropout(.35), + nn.Conv2d(2*wave_filters,2*wave_filters,(1,16),padding=(0,8),groups=2*wave_filters,bias=False),nn.Conv2d(2*wave_filters,2*wave_filters,1,bias=False), + nn.GroupNorm(1,2*wave_filters),nn.ELU(),nn.AvgPool2d((1,8)),nn.Dropout(.35)) + self.wave_summary=nn.Sequential(nn.AdaptiveAvgPool2d((1,8)),nn.Flatten(),nn.Linear(2*wave_filters*8,width)) + self.fusion=nn.Sequential(nn.LayerNorm(width),nn.GELU(),nn.Dropout(dropout), + *[Residual(width,dropout) for _ in range(depth)],nn.LayerNorm(width)) + # Both representations interact before the shared residual stack. + self.wave_gain=nn.Parameter(torch.tensor(.1)) + self.biot=BIOT(n_chans=18,n_outputs=2,n_times=400,sfreq=200) + self.biot.final_layer=nn.Identity() + self.biot_projection=nn.Sequential(nn.LayerNorm(256),nn.Linear(256,width),nn.Dropout(.2)) + nn.init.normal_(self.biot_projection[1].weight,std=.001);nn.init.zeros_(self.biot_projection[1].bias) + self.covariance_encoder=nn.Sequential(nn.LayerNorm(len(BANDS)*24*2),nn.Linear(len(BANDS)*24*2,width),nn.GELU(),nn.Dropout(.4), + *[Residual(width,.4) for _ in range(2)],nn.LayerNorm(width)) + self.covariance_projection=nn.Linear(width,width) + nn.init.zeros_(self.covariance_projection.weight);nn.init.zeros_(self.covariance_projection.bias) + def forward(self,signal,spectral,neural_signal,covariance_features): + wave=self.waveform(signal) + neural=self.biot(neural_signal.float()) + neural=self.biot_projection[0](neural) + projected=self.biot_projection[2](self.biot_projection[1](neural)) + with torch.autocast(signal.device.type,enabled=False): + covariance_embedding=self.covariance_encoder(covariance_features.float()) + original=spectral+self.wave_gain*self.wave_summary(wave)+.01*projected + coupled=.001*self.covariance_projection(covariance_embedding).to(original.dtype) + fused=self.fusion(original+coupled) + return torch.cat([wave.flatten(1),fused,neural,covariance_embedding],-1) + +class ResidualHead(nn.Module): + """A small nonlinear classifier correction around an inherited linear readout.""" + def __init__(self,features,classes,width=64,dropout=.3,full_precision=False): + super().__init__();self.full_precision=full_precision + self.base=nn.Linear(features,classes) + self.delta=nn.Sequential(nn.LayerNorm(features),nn.Linear(features,width),nn.GELU(),nn.Dropout(dropout),nn.Linear(width,classes)) + nn.init.zeros_(self.delta[-1].weight);nn.init.zeros_(self.delta[-1].bias) + def forward(self,x): + if self.full_precision: + with torch.autocast(x.device.type,enabled=False):return self.base(x.float())+self.delta(x.float()) + prior=nn.functional.linear(x[:,:-128].contiguous(),self.base.weight[:,:-128].contiguous(),self.base.bias) + added=nn.functional.linear(x[:,-128:].contiguous(),self.base.weight[:,-128:].contiguous()) + value=prior+added + return value+self.delta(x).to(value.dtype) + +class TemporalPoolHead(nn.Module): + def __init__(self,prior,channels=64): + super().__init__();self.prior=prior;self.channels=channels + self.register_buffer('pool_output_scale',torch.ones(()));self.register_buffer('pool_mean',torch.zeros(channels*4));self.register_buffer('pool_scale',torch.ones(channels*4)) + self.pool_projection=nn.Linear(channels*4,prior.base.out_features) + nn.init.zeros_(self.pool_projection.weight);nn.init.zeros_(self.pool_projection.bias) + def statistics(self,x): + with torch.autocast(x.device.type,enabled=False): + wave=x[:,:-512].float().reshape(len(x),self.channels,-1) + return torch.cat([wave.mean(-1),wave.std(-1,correction=0),wave.amax(-1),wave.amin(-1)],-1) + def forward(self,x): + prior=self.prior(x) + with torch.autocast(x.device.type,enabled=False): + values=((self.statistics(x)-self.pool_mean)/self.pool_scale).clamp(-8,8) + added=self.pool_output_scale*self.pool_projection(values) + return prior+added.to(prior.dtype) + +class HybridModel(nn.Module): + def __init__(self,channels=32,width=128,depth=2,dropout=.5,wave_filters=32,head_width=64,head_dropout=.3,clinical_asymmetry=True,alpha_regions=None,clinical_envelope=False,temporal_pool=True): + super().__init__() + self.adapters=nn.ModuleDict({t:InputAdapter(c,width,channels,spectral_enabled=t not in ("faced","tuev","openbmi"),asymmetry=clinical_asymmetry and t=="tuev",alpha_regions=alpha_regions if t=="longitudinal" else None,envelope=clinical_envelope and t=="tuev") for t,(c,s,k) in SPECS.items()}) + self.backbone=SharedBackbone(channels,width,depth,dropout,wave_filters) + self.heads=nn.ModuleDict({t:ResidualHead(2*wave_filters*(((s*200+1)//4+1)//8)+width+256+width,k,head_width,head_dropout,full_precision=t=='ad65') for t,(c,s,k) in SPECS.items()}) + if temporal_pool:self.heads=nn.ModuleDict({t:TemporalPoolHead(head,wave_filters*2) for t,head in self.heads.items()}) + def forward(self,t,x,features=None,covariances=None,covariance_features=None): + if features is None:features=extract_features(t,x) + if covariance_features is None: + if covariances is None:covariances=extract_covariances(t,x) + covariance_features=self.adapters[t].spatial_features(covariances) + signal=x.flatten(2);signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + adapted=self.adapters[t](signal,features,covariance_features) + representation=self.backbone(*adapted) + if t in ('faced','openbmi'): + representation=torch.cat([representation[:,:-384],torch.zeros_like(representation[:,-384:-128]),representation[:,-128:]],-1) + return self.heads[t](representation) + +def widen_state_dict(state,multiplier=2): + """Duplicate temporal features and divide downstream sums to preserve outputs.""" + result={} + for key,value in state.items(): + if key.startswith('backbone.waveform.'): + layer=int(key.split('.')[2]) + if layer in (0,2,7):value=value.repeat(multiplier,1,1,1) + elif layer in (1,3,9):value=value.repeat(multiplier) + elif layer==8:value=value.repeat(multiplier,multiplier,1,1)/multiplier + elif key=='backbone.wave_summary.2.weight':value=value.repeat(1,multiplier)/multiplier + elif key.startswith('heads.') and key.endswith('.weight'): + raw=value[:,:-128]/multiplier + value=torch.cat([raw]*multiplier+[value[:,-128:]],1) + result[key]=value + return result + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S032/infer.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S032/infer.py new file mode 100644 index 0000000000000000000000000000000000000000..aecb1722284d7707ed4097a3308cb15f870b6826 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S032/infer.py @@ -0,0 +1,24 @@ +import argparse,json +from pathlib import Path +import torch +from model import HybridModel,SPECS +from data import Dataset +from covariances import extract_covariances +p=argparse.ArgumentParser();p.add_argument('input',type=Path);p.add_argument('output',type=Path);a=p.parse_args() +root=Path(__file__).resolve().parent;c=json.loads((root/'config.json').read_text());t=json.loads((a.input/'manifest.json').read_text())['track'] +if t not in SPECS:raise ValueError('unknown track') +torch.set_num_threads(4);device='cuda' if torch.cuda.is_available() else 'cpu' +m=HybridModel(**c['architecture']).to(device);m.load_state_dict(torch.load(root/'weights.pt',map_location=device,weights_only=True));m.eval() +a.output.mkdir(parents=True,exist_ok=True) +with torch.inference_mode(),(a.output/'predictions.jsonl').open('w') as f: + for x,_,ids in torch.utils.data.DataLoader(Dataset(a.input),batch_size=64,num_workers=0): + # FFT features stay float32; convolutions can use bfloat16 on CUDA. + x=x.to(device) + from features import extract_features + torch.backends.cuda.matmul.allow_tf32=False + features=extract_features(t,x) + covariances=extract_covariances(t,x) + torch.backends.cuda.matmul.allow_tf32=True + with torch.autocast(device,dtype=torch.bfloat16,enabled=device=='cuda'):pred=m(t,x,features,covariances=covariances) + pp=pred.float().softmax(-1).cpu().numpy() + for sid,pr in zip(ids,pp):f.write(json.dumps({'id':sid,'probabilities':pr.tolist()})+'\n') diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S033/alpha_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S033/alpha_features.py new file mode 100644 index 0000000000000000000000000000000000000000..455154d715e86d45e4e17113bed69adbcd946b29 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S033/alpha_features.py @@ -0,0 +1,45 @@ +"""Fixed alpha prominence features from each individual two-second window.""" +import torch + +REGION_NAMES=('occipital','parietal','central','frontal','left_posterior','right_posterior') +REGIONS=(('PO7','PO5','PO3','POZ','PO4','PO6','PO8','O1','OZ','O2'), + ('P7','P5','P3','P1','PZ','P2','P4','P6','P8'), + ('FC5','FC3','FC1','FCZ','FC2','FC4','FC6','C5','C3','C1','CZ','C2','C4','C6'), + ('FP1','FPZ','FP2','AF3','AF4','F7','F5','F3','F1','FZ','F2','F4','F6','F8'), + ('P7','P5','P3','P1','PO7','PO5','PO3','O1'), + ('P2','P4','P6','P8','PO4','PO6','PO8','O2')) +ALPHA_DIM=58*7+6*22 + +def region_matrix(channels): + result=torch.zeros(len(REGIONS),len(channels)) + for i,names in enumerate(REGIONS): + for name in names:result[i,channels.index(name)]=1/len(names) + return result.tolist() + +@torch.no_grad() +def extract_alpha_features(signal,regions): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();x=x-x.mean(-1,keepdim=True) + spectrum=torch.fft.rfft(x*torch.hann_window(400,device=x.device),dim=-1)/200 + power=spectrum.abs().square().clamp_min(1e-12) + lp=power.log() + # Geometric regional means resist domination by one high-amplitude channel. + regional=torch.einsum('rc,ncf->nrf',regions.float(),lp) + lp=torch.cat([lp,regional],1) + low=lp[...,8:13].mean(-1,keepdim=True) + high=lp[...,36:49].mean(-1,keepdim=True) + freq=torch.arange(7.,14.5,.5,device=x.device) + alpha=lp[...,14:29] + baseline=low+(high-low)*((freq-5)/16) + prominence=alpha-baseline + normalized=alpha.softmax(-1) + center=(normalized*freq).sum(-1) + entropy=-(normalized*normalized.clamp_min(1e-12).log()).sum(-1) + alpha_mean=torch.logsumexp(alpha,-1)-torch.log(torch.tensor(15.,device=x.device)) + def log_band(lo,hi): + return torch.logsumexp(lp[...,lo:hi],-1)-torch.log(torch.tensor(float(hi-lo),device=x.device)) + summaries=torch.stack([alpha_mean-log_band(2,81),alpha_mean-log_band(8,14), + alpha_mean-log_band(30,61),prominence.max(-1).values, + prominence.mean(-1),center,entropy],-1) + return torch.cat([summaries[:,:58].flatten(1),summaries[:,58:].flatten(1), + prominence[:,58:].flatten(1)],1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S033/covariances.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S033/covariances.py new file mode 100644 index 0000000000000000000000000000000000000000..a65153f3b18f31995ff206a8e2fb8a7fd7a254dd --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S033/covariances.py @@ -0,0 +1,25 @@ +"""Shared neural filter-bank covariance decoder with spatial input adapters.""" +import torch +from torch import nn +SPECS={'faced':(32,10,9),'tuev':(16,5,6),'ad65':(19,10,3),'openbmi':(62,4,2),'longitudinal':(58,2,2)} +TRACKS=tuple(SPECS) +BANDS=[(1,4),(4,8),(8,12),(12,16),(16,20),(20,24),(24,28),(28,32),(32,40),(40,48)] + +@torch.no_grad() +def extract_covariances(t,x): + x=torch.nan_to_num(x.float().flatten(2)).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if t in ('faced','tuev'): + x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + else:x=x-x.mean(1,keepdim=True) + # Per-window normalization, preserving spatial and frequency power ratios. + x=x/x.square().mean((1,2),keepdim=True).clamp_min(1e-12).sqrt() + frames=x.unfold(-1,400,200);frames=frames-frames.mean(-1,keepdim=True) + z=torch.fft.rfft(frames*torch.hann_window(400,device=x.device),dim=-1)/200 + covs=[] + for lo,hi in BANDS: + v=z[...,2*lo:2*hi].flatten(2) + cov=(v.real@v.real.transpose(-1,-2)+v.imag@v.imag.transpose(-1,-2))/v.shape[-1] + covs.append(cov) + return torch.stack(covs,1) + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S033/data.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S033/data.py new file mode 100644 index 0000000000000000000000000000000000000000..e3cf61f3b1ac4d22858c6e6f387024abd27d953d --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S033/data.py @@ -0,0 +1,33 @@ +import json +from functools import lru_cache +from pathlib import Path +import numpy as np +import torch +@lru_cache(maxsize=8) +def array(path):return np.load(path,mmap_mode='r',allow_pickle=False) +class Dataset(torch.utils.data.Dataset): + def __init__(self,root,limit=None,cache=False): + self.root=Path(root) + self.rows=json.loads((self.root/'manifest.json').read_text())['samples'] + if limit:self.rows=self.rows[:limit] + self.cached=None + if cache and self.rows: + from collections import defaultdict + groups=defaultdict(list) + for i,r in enumerate(self.rows):groups[r['path']].append((i,r['index'])) + for name,indices in groups.items(): + path=(self.root/name).resolve() + if not path.is_relative_to(self.root.resolve()):raise ValueError('input outside root') + source=np.load(path,mmap_mode='r',allow_pickle=False) + if self.cached is None:self.cached=torch.empty((len(self.rows),*source.shape[1:]),dtype=torch.float32) + dst,src=zip(*indices) + self.cached[list(dst)]=torch.as_tensor(source[list(src)]/100,dtype=torch.float32) + def __len__(self):return len(self.rows) + def __getitem__(self,i): + r=self.rows[i] + if self.cached is not None:return self.cached[i],r.get('label',-1),r['id'] + p=(self.root/r['path']).resolve() + if not p.is_relative_to(self.root.resolve()):raise ValueError('input outside root') + # Division precedes float32 conversion, matching official FACED/TUEV collate. + x=np.asarray(array(str(p))[r['index']])/100 + return torch.as_tensor(x,dtype=torch.float32),r.get('label',-1),r['id'] diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S033/features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S033/features.py new file mode 100644 index 0000000000000000000000000000000000000000..88f7e8b14c9fab44733d5224ede6d6b5c7f76a45 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S033/features.py @@ -0,0 +1,63 @@ +"""One shared residual backbone, five linear input adapters and output heads.""" +import torch +from torch import nn + +SPECS = {'faced': (32, 10, 9), 'tuev': (16, 5, 6), 'ad65': (19, 10, 3), + 'openbmi': (62, 4, 2), 'longitudinal': (58, 2, 2)} +TRACKS = tuple(SPECS) +EDGES = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,18,20,22,25,28,32,36,40,45,50,60,70,80,95] +COV_BANDS = [(1,4),(4,8),(8,12),(12,16),(16,20),(20,28),(28,40)] + +def feature_dim(channels): + return channels * (4*(len(EDGES)-1)+4) + len(COV_BANDS)*channels*(channels-1)//2 + +@torch.no_grad() +def extract_features(track, x): + """Fixed features; no batch statistics or fitted inference transformations.""" + x = x.float().flatten(2) + x = torch.nan_to_num(x, nan=0., posinf=1e5, neginf=-1e5).clamp(-1e5,1e5) + x = x - x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'): + x = x - x.mean(1,keepdim=True) + rms = x.square().mean(-1).clamp_min(1e-12).sqrt() + norm = x / rms.unsqueeze(-1) + moments = torch.stack([rms.log(), norm.abs().amax(-1).clamp_min(1).log(), + norm.pow(4).mean(-1).clamp_min(1).log(), + (norm[...,1:]-norm[...,:-1]).square().mean(-1).clamp_min(1e-10).log()],-1) + frames = x.unfold(-1,400,200) + frames = frames - frames.mean(-1,keepdim=True) + window = torch.hann_window(400,device=x.device) + z = torch.fft.rfft(frames*window,dim=-1)/200 + power = z.abs().square() + bands = torch.stack([power[...,2*lo:2*hi].mean(-1) for lo,hi in zip(EDGES[:-1],EDGES[1:])],-1) + lp = bands.mean(-2).clamp_min(1e-12).log() + variation = bands.clamp_min(1e-12).log().std(-2,correction=0) + relative_frequency = lp - lp.mean(-1,keepdim=True) + relative_channel = lp - lp.mean(1,keepdim=True) + parts = [torch.cat([lp, relative_frequency, relative_channel, variation, moments],-1).flatten(1)] + ii,jj = torch.triu_indices(x.shape[1],x.shape[1],offset=1,device=x.device) + for lo,hi in COV_BANDS: + v = z[...,2*lo:2*hi].flatten(2) + cov = v.real @ v.real.transpose(-1,-2) + v.imag @ v.imag.transpose(-1,-2) + d = cov.diagonal(dim1=-2,dim2=-1).clamp_min(1e-12).sqrt() + cor = cov / (d.unsqueeze(1)*d.unsqueeze(2)).clamp_min(1e-12) + parts.append(cor[:,ii,jj].clamp(-1,1)) + result = torch.cat(parts,-1) + return torch.nan_to_num(result).clamp(-40,40) + +class Standardize(nn.Module): + def __init__(self, dim): + super().__init__() + self.register_buffer('mean',torch.zeros(dim)) + self.register_buffer('scale',torch.ones(dim)) + def forward(self,x): + return ((x-self.mean)/self.scale).clamp(-8,8) + +class Residual(nn.Module): + def __init__(self,width,dropout): + super().__init__() + self.net=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(), + nn.Dropout(dropout),nn.Linear(width*2,width),nn.Dropout(dropout)) + def forward(self,x): + return x+self.net(x) + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S033/infer.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S033/infer.py new file mode 100644 index 0000000000000000000000000000000000000000..aecb1722284d7707ed4097a3308cb15f870b6826 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S033/infer.py @@ -0,0 +1,24 @@ +import argparse,json +from pathlib import Path +import torch +from model import HybridModel,SPECS +from data import Dataset +from covariances import extract_covariances +p=argparse.ArgumentParser();p.add_argument('input',type=Path);p.add_argument('output',type=Path);a=p.parse_args() +root=Path(__file__).resolve().parent;c=json.loads((root/'config.json').read_text());t=json.loads((a.input/'manifest.json').read_text())['track'] +if t not in SPECS:raise ValueError('unknown track') +torch.set_num_threads(4);device='cuda' if torch.cuda.is_available() else 'cpu' +m=HybridModel(**c['architecture']).to(device);m.load_state_dict(torch.load(root/'weights.pt',map_location=device,weights_only=True));m.eval() +a.output.mkdir(parents=True,exist_ok=True) +with torch.inference_mode(),(a.output/'predictions.jsonl').open('w') as f: + for x,_,ids in torch.utils.data.DataLoader(Dataset(a.input),batch_size=64,num_workers=0): + # FFT features stay float32; convolutions can use bfloat16 on CUDA. + x=x.to(device) + from features import extract_features + torch.backends.cuda.matmul.allow_tf32=False + features=extract_features(t,x) + covariances=extract_covariances(t,x) + torch.backends.cuda.matmul.allow_tf32=True + with torch.autocast(device,dtype=torch.bfloat16,enabled=device=='cuda'):pred=m(t,x,features,covariances=covariances) + pp=pred.float().softmax(-1).cpu().numpy() + for sid,pr in zip(ids,pp):f.write(json.dumps({'id':sid,'probabilities':pr.tolist()})+'\n') diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S033/infer.sh b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S033/infer.sh new file mode 100644 index 0000000000000000000000000000000000000000..3aae9b42834f2f278e52148d5a07835d9960a4ea --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S033/infer.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -euo pipefail +exec python "$(dirname -- "$0")/infer.py" "$1" "$2" diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S033/tangent_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S033/tangent_features.py new file mode 100644 index 0000000000000000000000000000000000000000..314f0cf2f58e4b4a1c1d808edbd4acc3b7b6f85b --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S033/tangent_features.py @@ -0,0 +1,25 @@ +"""Window-local log-correlation geometry in the existing spatial-filter basis.""" +import torch + +TANGENT_DIM=10*24*25//2 + +@torch.no_grad() +def extract_tangent_features(covariances,spatial_weight): + old_tf32=torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(covariances.device.type,enabled=False): + w=spatial_weight.float() + w=w/w.norm(dim=-1,keepdim=True).clamp_min(1e-6) + projected=torch.einsum('bfc,nbcd,bgd->nbfg',w,covariances.float(),w) + d=projected.diagonal(dim1=-2,dim2=-1).clamp_min(1e-10).sqrt() + correlation=(projected/(d.unsqueeze(-1)*d.unsqueeze(-2))).clamp(-1,1) + correlation=(correlation+correlation.transpose(-1,-2))/2 + correlation=.95*correlation+.05*torch.eye(24,device=correlation.device) + values,vectors=torch.linalg.eigh(correlation) + logarithm=(vectors*values.clamp_min(1e-6).log().unsqueeze(-2))@vectors.transpose(-1,-2) + i,j=torch.triu_indices(24,24,device=correlation.device) + scale=torch.where(i==j,1.,2.**.5) + return (logarithm[...,i,j]*scale).flatten(1) + finally: + torch.backends.cuda.matmul.allow_tf32=old_tf32 diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S035/alpha_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S035/alpha_features.py new file mode 100644 index 0000000000000000000000000000000000000000..455154d715e86d45e4e17113bed69adbcd946b29 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S035/alpha_features.py @@ -0,0 +1,45 @@ +"""Fixed alpha prominence features from each individual two-second window.""" +import torch + +REGION_NAMES=('occipital','parietal','central','frontal','left_posterior','right_posterior') +REGIONS=(('PO7','PO5','PO3','POZ','PO4','PO6','PO8','O1','OZ','O2'), + ('P7','P5','P3','P1','PZ','P2','P4','P6','P8'), + ('FC5','FC3','FC1','FCZ','FC2','FC4','FC6','C5','C3','C1','CZ','C2','C4','C6'), + ('FP1','FPZ','FP2','AF3','AF4','F7','F5','F3','F1','FZ','F2','F4','F6','F8'), + ('P7','P5','P3','P1','PO7','PO5','PO3','O1'), + ('P2','P4','P6','P8','PO4','PO6','PO8','O2')) +ALPHA_DIM=58*7+6*22 + +def region_matrix(channels): + result=torch.zeros(len(REGIONS),len(channels)) + for i,names in enumerate(REGIONS): + for name in names:result[i,channels.index(name)]=1/len(names) + return result.tolist() + +@torch.no_grad() +def extract_alpha_features(signal,regions): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();x=x-x.mean(-1,keepdim=True) + spectrum=torch.fft.rfft(x*torch.hann_window(400,device=x.device),dim=-1)/200 + power=spectrum.abs().square().clamp_min(1e-12) + lp=power.log() + # Geometric regional means resist domination by one high-amplitude channel. + regional=torch.einsum('rc,ncf->nrf',regions.float(),lp) + lp=torch.cat([lp,regional],1) + low=lp[...,8:13].mean(-1,keepdim=True) + high=lp[...,36:49].mean(-1,keepdim=True) + freq=torch.arange(7.,14.5,.5,device=x.device) + alpha=lp[...,14:29] + baseline=low+(high-low)*((freq-5)/16) + prominence=alpha-baseline + normalized=alpha.softmax(-1) + center=(normalized*freq).sum(-1) + entropy=-(normalized*normalized.clamp_min(1e-12).log()).sum(-1) + alpha_mean=torch.logsumexp(alpha,-1)-torch.log(torch.tensor(15.,device=x.device)) + def log_band(lo,hi): + return torch.logsumexp(lp[...,lo:hi],-1)-torch.log(torch.tensor(float(hi-lo),device=x.device)) + summaries=torch.stack([alpha_mean-log_band(2,81),alpha_mean-log_band(8,14), + alpha_mean-log_band(30,61),prominence.max(-1).values, + prominence.mean(-1),center,entropy],-1) + return torch.cat([summaries[:,:58].flatten(1),summaries[:,58:].flatten(1), + prominence[:,58:].flatten(1)],1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S035/config.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S035/config.json new file mode 100644 index 0000000000000000000000000000000000000000..5cb1b1fa136e9655d26691f14518ae2dbbf81a93 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S035/config.json @@ -0,0 +1,682 @@ +{ + "schema": "bci-shared-biot-covariance-bf16head-v1", + "architecture": { + "channels": 32, + "width": 128, + "depth": 2, + "dropout": 0.5, + "wave_filters": 32, + "head_width": 64, + "head_dropout": 0.3, + "clinical_asymmetry": true, + "alpha_regions": [ + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.125 + ] + ], + "clinical_envelope": true, + "temporal_pool": true, + "temporal_evidence": true, + "evidence_temperature": 0.25, + "random_fourier": true, + "fourier_features": 256, + "tangent_readout": true + }, + "initialization": { + "initialization": "continue joint training from a complete shared-model checkpoint", + "parent": "/workspace/research/runs/hybrid_biot_fusionshrink0100/epoch-001/weights.pt", + "parent_initialization": { + "initialization": "jointly trained parent plus audited pretrained BIOT in a single coupled backbone", + "parent": "/workspace/research/runs/hybrid_wide1/epoch-004/weights.pt", + "audited_biot": { + "initialization": "pretrained", + "repo": "braindecode/biot-pretrained-six-datasets-18chs", + "revision": "7e9aabf302870012f73773276803aab97993951c", + "sha256": "a218f4054ae29962c6fd9d23d94c446d354c4f53e805a6771c85749ccc20baaa", + "license": "BSD-3-Clause", + "source_braindecode": "1.3.0", + "loaded_core_tensors": 56, + "skipped_classifier_tensors": 3 + }, + "neural_channel_indices": { + "faced": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "tuev": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15 + ], + "ad65": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "openbmi": [ + 0, + 1, + 3, + 5, + 12, + 14, + 23, + 25, + 28, + 30, + 2, + 6, + 11, + 15, + 22, + 26, + 4, + 13 + ], + "longitudinal": [ + 0, + 2, + 7, + 11, + 23, + 27, + 41, + 45, + 55, + 57, + 5, + 13, + 21, + 29, + 39, + 47, + 9, + 25 + ] + }, + "rebase": "incumbent waveform, fusion and four heads; joint BIOT and TUEV head from readout epoch 9; zero initialized neural interaction", + "jointly_finetuned_neural_parent": "/workspace/research/runs/hybrid_biot_readout1/epoch-009/weights.pt", + "tuev_high_dimensional_spectral_projection_disabled": true, + "frozen_prior_representation": true, + "nonclinical_head_updates": "only the 256 added BIOT columns; original columns and biases fixed", + "faced_openbmi_neural_path": "common nonlinear fusion only; direct head columns masked", + "retention_teacher": "/workspace/research/runs/hybrid_wide1/epoch-004", + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "joint_covariance_parent": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "frozen_prior_representation": true, + "head_updates": "one linear head per track; added 128 shared covariance columns trainable; AD head initialized from the joint covariance parent", + "new_shared_representation": "one common covariance MLP inside the coupled backbone, trained by all five tasks; fixed spatial input adapters from the same jointly trained source", + "head_arithmetic": "one linear head evaluated in fixed feature blocks to preserve original bfloat16 accumulation dimensions", + "retention_teacher": { + "ad65": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "other_tracks": "/workspace/research/runs/hybrid_wide1/epoch-004" + }, + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "loader_scale": 0.01, + "tracks": [ + "faced", + "tuev", + "ad65", + "openbmi", + "longitudinal" + ], + "head_arithmetic": "same linear head in fixed feature blocks, sum in bfloat16 on GPU for non-AD tracks; AD remains float32", + "head_refinement": { + "source": "/workspace/research/runs/residual_heads1/epoch-018", + "source_weights_sha256": "e0b609137391b47f99438ccadaa22fc0bc10d2c10ead0ddf0a3c25be2c907c85", + "shared_backbone_unchanged": true, + "selected_head_epochs": { + "faced": 5, + "tuev": 24, + "ad65": 0, + "openbmi": 0, + "longitudinal": 0 + } + }, + "clinical_spectral_refinement": { + "source": "/workspace/research/runs/head_dropout1/epoch-016", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "head_estimation": { + "method": "class/subject-balanced Gaussian linear discriminant; covariance augmented by class-conditional subject/session mean variation before shrinkage", + "selected_shrinkage": { + "faced": "inherited", + "tuev": "inherited", + "ad65": "inherited", + "openbmi": "inherited", + "longitudinal": { + "shrinkage": 0.9, + "domain_strength": 1.0 + } + }, + "feature_scaling": "fitted on training data and folded into linear coefficients" + }, + "clinical_asymmetry_refinement": { + "source": "/workspace/research/runs/domain_lda_heads1/epoch-001", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "alpha_rhythm_adapter": { + "training_normalization_only": true, + "regions": [ + "occipital", + "parietal", + "central", + "frontal", + "left_posterior", + "right_posterior" + ], + "features": "per-window alpha prominence relative to adjacent frequencies", + "shared_backbone_unchanged": true + }, + "clinical_envelope_refinement": { + "source": "/workspace/research/runs/clinical_asymmetry1/epoch-001", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "independent_adapter_merge": { + "alpha_source": "/workspace/research/runs/alpha_calibrated1/epoch-003", + "clinical_source": "/workspace/research/runs/clinical_envelope1/epoch-002", + "all_shared_and_head_tensors_equal": true + }, + "frequency_montage_refinement": { + "six_frequency_bands": true, + "shared_encoder_unchanged": true, + "selected_track_epochs": { + "faced": 0, + "tuev": 1, + "ad65": 0, + "openbmi": 10, + "longitudinal": 2 + } + }, + "private_track_selection": { + "track": "tuev", + "donor": "/workspace/research/replicates/frequency_head_control1/epoch-001" + }, + "clinical_sampling_refinement": { + "subject_exponent": 0.0, + "class_balanced": true, + "only_clinical_head_updated": true + }, + "temporal_statistics_readout": { + "statistics": [ + "mean", + "standard deviation", + "maximum", + "minimum" + ], + "shared_encoder_and_prior_heads_unchanged": true, + "selected_pool_epochs": { + "faced": 2, + "tuev": 0, + "ad65": 0, + "openbmi": 33, + "longitudinal": 3 + } + }, + "temporal_evidence_readout": { + "pooling": "log mean exp of per-patch class evidence", + "temperature": 0.25, + "shared_encoder_and_prior_heads_unchanged": true, + "selected_evidence_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 6, + "longitudinal": 8 + } + }, + "fourier_basis_readout": { + "basis_functions": 256, + "bandwidths": [ + 0.5, + 1.0, + 2.0 + ], + "shared_encoder_and_prior_heads_unchanged": true, + "selected_fourier_epochs": { + "faced": 21, + "tuev": 0, + "ad65": 0, + "openbmi": 0, + "longitudinal": 2 + } + }, + "shared_tangent_readout": { + "one_shared_tangent_module": true, + "original_and_corrected_shared_features_retained": true, + "private_head_scalar_gains": { + "faced": 0.0, + "tuev": 0.1, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 0.1 + }, + "all_common_weights_fixed_during_gain_refinement": true + } +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S035/covariances.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S035/covariances.py new file mode 100644 index 0000000000000000000000000000000000000000..a65153f3b18f31995ff206a8e2fb8a7fd7a254dd --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S035/covariances.py @@ -0,0 +1,25 @@ +"""Shared neural filter-bank covariance decoder with spatial input adapters.""" +import torch +from torch import nn +SPECS={'faced':(32,10,9),'tuev':(16,5,6),'ad65':(19,10,3),'openbmi':(62,4,2),'longitudinal':(58,2,2)} +TRACKS=tuple(SPECS) +BANDS=[(1,4),(4,8),(8,12),(12,16),(16,20),(20,24),(24,28),(28,32),(32,40),(40,48)] + +@torch.no_grad() +def extract_covariances(t,x): + x=torch.nan_to_num(x.float().flatten(2)).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if t in ('faced','tuev'): + x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + else:x=x-x.mean(1,keepdim=True) + # Per-window normalization, preserving spatial and frequency power ratios. + x=x/x.square().mean((1,2),keepdim=True).clamp_min(1e-12).sqrt() + frames=x.unfold(-1,400,200);frames=frames-frames.mean(-1,keepdim=True) + z=torch.fft.rfft(frames*torch.hann_window(400,device=x.device),dim=-1)/200 + covs=[] + for lo,hi in BANDS: + v=z[...,2*lo:2*hi].flatten(2) + cov=(v.real@v.real.transpose(-1,-2)+v.imag@v.imag.transpose(-1,-2))/v.shape[-1] + covs.append(cov) + return torch.stack(covs,1) + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S035/data.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S035/data.py new file mode 100644 index 0000000000000000000000000000000000000000..e3cf61f3b1ac4d22858c6e6f387024abd27d953d --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S035/data.py @@ -0,0 +1,33 @@ +import json +from functools import lru_cache +from pathlib import Path +import numpy as np +import torch +@lru_cache(maxsize=8) +def array(path):return np.load(path,mmap_mode='r',allow_pickle=False) +class Dataset(torch.utils.data.Dataset): + def __init__(self,root,limit=None,cache=False): + self.root=Path(root) + self.rows=json.loads((self.root/'manifest.json').read_text())['samples'] + if limit:self.rows=self.rows[:limit] + self.cached=None + if cache and self.rows: + from collections import defaultdict + groups=defaultdict(list) + for i,r in enumerate(self.rows):groups[r['path']].append((i,r['index'])) + for name,indices in groups.items(): + path=(self.root/name).resolve() + if not path.is_relative_to(self.root.resolve()):raise ValueError('input outside root') + source=np.load(path,mmap_mode='r',allow_pickle=False) + if self.cached is None:self.cached=torch.empty((len(self.rows),*source.shape[1:]),dtype=torch.float32) + dst,src=zip(*indices) + self.cached[list(dst)]=torch.as_tensor(source[list(src)]/100,dtype=torch.float32) + def __len__(self):return len(self.rows) + def __getitem__(self,i): + r=self.rows[i] + if self.cached is not None:return self.cached[i],r.get('label',-1),r['id'] + p=(self.root/r['path']).resolve() + if not p.is_relative_to(self.root.resolve()):raise ValueError('input outside root') + # Division precedes float32 conversion, matching official FACED/TUEV collate. + x=np.asarray(array(str(p))[r['index']])/100 + return torch.as_tensor(x,dtype=torch.float32),r.get('label',-1),r['id'] diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S035/envelope_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S035/envelope_features.py new file mode 100644 index 0000000000000000000000000000000000000000..2251a6f03a3a6daaa3faed0bbc803bf182224da6 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S035/envelope_features.py @@ -0,0 +1,44 @@ +"""Per-window burst-envelope regularity and bilateral synchrony, without fitting.""" +import torch +import torch.nn.functional as F + +BANDS=((1,4),(4,8),(8,13),(13,30),(30,45)) +ENVELOPE_DIM=16*5*12+8*5*2 + +@torch.no_grad() +def extract_envelope_features(signal): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();x=x-x.mean(-1,keepdim=True) + spectrum=torch.fft.fft(x,dim=-1) + frequency=torch.fft.fftfreq(x.shape[-1],1/200,device=x.device) + envelopes=[] + for lo,hi in BANDS: + mask=((frequency>=lo)&(frequency2).float().mean(-1),(relative>4).float().mean(-1), + ((relative[...,1:]>2)&(relative[...,:-1]<=2)).float().mean(-1), + acf_peak,(acf_index.float()+4)/40, + acf[...,0],acf[...,6],acf[...,16],acf[...,36]] + left=torch.tensor([0,1,2,3,8,9,10,11],device=x.device);right=left+4 + synchrony=(normalized[:,left]*normalized[:,right]).mean(-1).clamp(-1,1) + imbalance=(std[:,left].squeeze(-1).log()-std[:,right].squeeze(-1).log()).abs() + return torch.cat([torch.stack(summaries,-1).flatten(1),synchrony.flatten(1),imbalance.flatten(1)],1) + +def mirrored_features(features): + channels=torch.tensor([4,5,6,7,0,1,2,3,12,13,14,15,8,9,10,11],device=features.device) + return torch.cat([features[:,:16*5*12].reshape(-1,16,5,12)[:,channels].flatten(1),features[:,16*5*12:]],1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S035/features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S035/features.py new file mode 100644 index 0000000000000000000000000000000000000000..88f7e8b14c9fab44733d5224ede6d6b5c7f76a45 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S035/features.py @@ -0,0 +1,63 @@ +"""One shared residual backbone, five linear input adapters and output heads.""" +import torch +from torch import nn + +SPECS = {'faced': (32, 10, 9), 'tuev': (16, 5, 6), 'ad65': (19, 10, 3), + 'openbmi': (62, 4, 2), 'longitudinal': (58, 2, 2)} +TRACKS = tuple(SPECS) +EDGES = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,18,20,22,25,28,32,36,40,45,50,60,70,80,95] +COV_BANDS = [(1,4),(4,8),(8,12),(12,16),(16,20),(20,28),(28,40)] + +def feature_dim(channels): + return channels * (4*(len(EDGES)-1)+4) + len(COV_BANDS)*channels*(channels-1)//2 + +@torch.no_grad() +def extract_features(track, x): + """Fixed features; no batch statistics or fitted inference transformations.""" + x = x.float().flatten(2) + x = torch.nan_to_num(x, nan=0., posinf=1e5, neginf=-1e5).clamp(-1e5,1e5) + x = x - x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'): + x = x - x.mean(1,keepdim=True) + rms = x.square().mean(-1).clamp_min(1e-12).sqrt() + norm = x / rms.unsqueeze(-1) + moments = torch.stack([rms.log(), norm.abs().amax(-1).clamp_min(1).log(), + norm.pow(4).mean(-1).clamp_min(1).log(), + (norm[...,1:]-norm[...,:-1]).square().mean(-1).clamp_min(1e-10).log()],-1) + frames = x.unfold(-1,400,200) + frames = frames - frames.mean(-1,keepdim=True) + window = torch.hann_window(400,device=x.device) + z = torch.fft.rfft(frames*window,dim=-1)/200 + power = z.abs().square() + bands = torch.stack([power[...,2*lo:2*hi].mean(-1) for lo,hi in zip(EDGES[:-1],EDGES[1:])],-1) + lp = bands.mean(-2).clamp_min(1e-12).log() + variation = bands.clamp_min(1e-12).log().std(-2,correction=0) + relative_frequency = lp - lp.mean(-1,keepdim=True) + relative_channel = lp - lp.mean(1,keepdim=True) + parts = [torch.cat([lp, relative_frequency, relative_channel, variation, moments],-1).flatten(1)] + ii,jj = torch.triu_indices(x.shape[1],x.shape[1],offset=1,device=x.device) + for lo,hi in COV_BANDS: + v = z[...,2*lo:2*hi].flatten(2) + cov = v.real @ v.real.transpose(-1,-2) + v.imag @ v.imag.transpose(-1,-2) + d = cov.diagonal(dim1=-2,dim2=-1).clamp_min(1e-12).sqrt() + cor = cov / (d.unsqueeze(1)*d.unsqueeze(2)).clamp_min(1e-12) + parts.append(cor[:,ii,jj].clamp(-1,1)) + result = torch.cat(parts,-1) + return torch.nan_to_num(result).clamp(-40,40) + +class Standardize(nn.Module): + def __init__(self, dim): + super().__init__() + self.register_buffer('mean',torch.zeros(dim)) + self.register_buffer('scale',torch.ones(dim)) + def forward(self,x): + return ((x-self.mean)/self.scale).clamp(-8,8) + +class Residual(nn.Module): + def __init__(self,width,dropout): + super().__init__() + self.net=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(), + nn.Dropout(dropout),nn.Linear(width*2,width),nn.Dropout(dropout)) + def forward(self,x): + return x+self.net(x) + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S035/frequency_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S035/frequency_features.py new file mode 100644 index 0000000000000000000000000000000000000000..9194c9e81f801b3833e551e4967991774fa9e398 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S035/frequency_features.py @@ -0,0 +1,11 @@ +"""Fixed per-window frequency decomposition for a linear montage adapter.""" +import torch + +FREQUENCY_BANDS=((1,4),(4,8),(8,13),(13,20),(20,30),(30,45)) + +def frequency_components(signal): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();spectrum=torch.fft.rfft(x,dim=-1) + frequency=torch.fft.rfftfreq(x.shape[-1],d=1/200,device=x.device) + masks=torch.stack([((frequency>=lo)&(frequencynbf',w,covariances.float(),w).clamp_min(1e-8).log() + return torch.cat([power,power-power.mean(1,keepdim=True)],1).flatten(1) + def wave_signal(self,x,components=None): + if components is None:components=frequency_components(x) + correction=torch.einsum('blc,nbct->nlt',self.frequency_weight,components.to(self.frequency_weight.dtype)) + return (self.signal(x)+correction.to(x.dtype)).unsqueeze(1) + def forward(self,x,features,covariance_features): + return self.wave_signal(x),self.spectral_features(features,signal=x),self.neural(x),covariance_features + +class SharedBackbone(nn.Module): + def __init__(self,channels,width,depth,dropout,wave_filters): + super().__init__() + self.waveform=nn.Sequential( + nn.Conv2d(1,wave_filters,(1,64),padding=(0,32),bias=False),nn.GroupNorm(1,wave_filters), + nn.Conv2d(wave_filters,2*wave_filters,(channels,1),groups=wave_filters,bias=False),nn.GroupNorm(1,2*wave_filters),nn.ELU(), + nn.AvgPool2d((1,4)),nn.Dropout(.35), + nn.Conv2d(2*wave_filters,2*wave_filters,(1,16),padding=(0,8),groups=2*wave_filters,bias=False),nn.Conv2d(2*wave_filters,2*wave_filters,1,bias=False), + nn.GroupNorm(1,2*wave_filters),nn.ELU(),nn.AvgPool2d((1,8)),nn.Dropout(.35)) + self.wave_summary=nn.Sequential(nn.AdaptiveAvgPool2d((1,8)),nn.Flatten(),nn.Linear(2*wave_filters*8,width)) + self.fusion=nn.Sequential(nn.LayerNorm(width),nn.GELU(),nn.Dropout(dropout), + *[Residual(width,dropout) for _ in range(depth)],nn.LayerNorm(width)) + # Both representations interact before the shared residual stack. + self.wave_gain=nn.Parameter(torch.tensor(.1)) + self.biot=BIOT(n_chans=18,n_outputs=2,n_times=400,sfreq=200) + self.biot.final_layer=nn.Identity() + self.biot_projection=nn.Sequential(nn.LayerNorm(256),nn.Linear(256,width),nn.Dropout(.2)) + nn.init.normal_(self.biot_projection[1].weight,std=.001);nn.init.zeros_(self.biot_projection[1].bias) + self.covariance_encoder=nn.Sequential(nn.LayerNorm(len(BANDS)*24*2),nn.Linear(len(BANDS)*24*2,width),nn.GELU(),nn.Dropout(.4), + *[Residual(width,.4) for _ in range(2)],nn.LayerNorm(width)) + self.covariance_projection=nn.Linear(width,width) + nn.init.zeros_(self.covariance_projection.weight);nn.init.zeros_(self.covariance_projection.bias) + self.tangent_encoder=nn.Sequential(nn.LayerNorm(TANGENT_DIM),nn.Linear(TANGENT_DIM,width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width),nn.Linear(width,width)) + def forward(self,signal,spectral,neural_signal,covariance_features,tangent_features): + wave=self.waveform(signal) + neural=self.biot(neural_signal.float()) + neural=self.biot_projection[0](neural) + projected=self.biot_projection[2](self.biot_projection[1](neural)) + with torch.autocast(signal.device.type,enabled=False): + covariance_embedding=self.covariance_encoder(covariance_features.float()) + original=spectral+self.wave_gain*self.wave_summary(wave)+.01*projected + coupled=.001*self.covariance_projection(covariance_embedding).to(original.dtype) + fused=self.fusion(original+coupled) + with torch.autocast(signal.device.type,enabled=False):delta=self.tangent_encoder(tangent_features.float()) + added=.001*nn.functional.linear(delta,self.covariance_projection.weight,None) + corrected=self.fusion((original+coupled)+added.to(original.dtype)) + return torch.cat([wave.flatten(1),fused,neural,covariance_embedding],-1),corrected-fused,delta + +class ResidualHead(nn.Module): + """A small nonlinear classifier correction around an inherited linear readout.""" + def __init__(self,features,classes,width=64,dropout=.3,full_precision=False): + super().__init__();self.full_precision=full_precision + self.base=nn.Linear(features,classes) + self.delta=nn.Sequential(nn.LayerNorm(features),nn.Linear(features,width),nn.GELU(),nn.Dropout(dropout),nn.Linear(width,classes)) + nn.init.zeros_(self.delta[-1].weight);nn.init.zeros_(self.delta[-1].bias) + def forward(self,x): + if self.full_precision: + with torch.autocast(x.device.type,enabled=False):return self.base(x.float())+self.delta(x.float()) + prior=nn.functional.linear(x[:,:-128].contiguous(),self.base.weight[:,:-128].contiguous(),self.base.bias) + added=nn.functional.linear(x[:,-128:].contiguous(),self.base.weight[:,-128:].contiguous()) + value=prior+added + return value+self.delta(x).to(value.dtype) + +class TemporalPoolHead(nn.Module): + def __init__(self,prior,channels=64): + super().__init__();self.prior=prior;self.channels=channels + self.register_buffer('pool_output_scale',torch.ones(()));self.register_buffer('pool_mean',torch.zeros(channels*4));self.register_buffer('pool_scale',torch.ones(channels*4)) + self.pool_projection=nn.Linear(channels*4,prior.base.out_features) + nn.init.zeros_(self.pool_projection.weight);nn.init.zeros_(self.pool_projection.bias) + def statistics(self,x): + with torch.autocast(x.device.type,enabled=False): + wave=x[:,:-512].float().reshape(len(x),self.channels,-1) + return torch.cat([wave.mean(-1),wave.std(-1,correction=0),wave.amax(-1),wave.amin(-1)],-1) + def forward(self,x): + prior=self.prior(x) + with torch.autocast(x.device.type,enabled=False): + values=((self.statistics(x)-self.pool_mean)/self.pool_scale).clamp(-8,8) + added=self.pool_output_scale*self.pool_projection(values) + return prior+added.to(prior.dtype) + +class TemporalEvidenceHead(nn.Module): + """Pool class evidence over the shared waveform time axis.""" + def __init__(self,prior,channels=64,temperature=.25): + super().__init__();self.prior=prior;self.channels=channels;self.temperature=temperature + self.register_buffer('evidence_output_scale',torch.ones(())) + self.register_buffer('evidence_mean',torch.zeros(channels)) + self.register_buffer('evidence_scale',torch.ones(channels)) + self.evidence_projection=nn.Linear(channels,prior.prior.base.out_features,bias=False) + nn.init.zeros_(self.evidence_projection.weight) + def patches(self,x): + with torch.autocast(x.device.type,enabled=False): + wave=x[:,:-512].float().reshape(len(x),self.channels,-1).transpose(1,2) + return ((wave-self.evidence_mean)/self.evidence_scale).clamp(-8,8) + def evidence(self,patches): + with torch.autocast(patches.device.type,enabled=False): + values=self.evidence_projection(patches.float())/self.temperature + maximum=values.amax(1,keepdim=True) + pooled=self.temperature*((values-maximum).exp().mean(1).log()+maximum.squeeze(1)) + return self.evidence_output_scale*pooled + def forward(self,x): + prior=self.prior(x) + return prior+self.evidence(self.patches(x)).to(prior.dtype) + +class FourierResidualHead(nn.Module): + """A fixed random Fourier basis and trainable linear classifier correction.""" + def __init__(self,prior,features,classes,basis=256): + super().__init__();self.prior=prior + self.register_buffer('rff_mean',torch.zeros(features));self.register_buffer('rff_scale',torch.ones(features)) + self.register_buffer('rff_frequency',torch.randn(features,basis)/features**.5) + self.register_buffer('rff_phase',torch.rand(basis)*2*torch.pi) + self.register_buffer('rff_output_scale',torch.ones(())) + self.rff_projection=nn.Linear(3*basis,classes);nn.init.zeros_(self.rff_projection.weight);nn.init.zeros_(self.rff_projection.bias) + def basis(self,x): + with torch.autocast(x.device.type,enabled=False): + values=((x.float()-self.rff_mean)/self.rff_scale).clamp(-8,8)@self.rff_frequency + return 2**.5*torch.cat([(values/sigma+self.rff_phase).cos() for sigma in (.5,1.,2.)],-1) + def forward(self,x): + prior=self.prior(x) + with torch.autocast(x.device.type,enabled=False):added=self.rff_output_scale*self.rff_projection(self.basis(x)) + return prior+added.to(prior.dtype) + +class TangentFeatureHead(nn.Module): + """Select a shared feature correction before the inherited classifier.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.feature_gain=nn.Parameter(torch.zeros(())) + def forward(self,values): + old=values[:,:-256];fusion_delta=values[:,-256:-128];covariance_delta=values[:,-128:] + adjusted=torch.cat([old[:,:-512],old[:,-512:-384]+self.feature_gain*fusion_delta,old[:,-384:-128],old[:,-128:]+self.feature_gain*covariance_delta],-1) + return self.prior(adjusted) + +class HybridModel(nn.Module): + def __init__(self,channels=32,width=128,depth=2,dropout=.5,wave_filters=32,head_width=64,head_dropout=.3,clinical_asymmetry=True,alpha_regions=None,clinical_envelope=False,temporal_pool=True,temporal_evidence=False,evidence_temperature=.25,random_fourier=False,fourier_features=256,tangent_readout=True): + super().__init__() + self.adapters=nn.ModuleDict({t:InputAdapter(c,width,channels,spectral_enabled=t not in ("faced","tuev","openbmi"),asymmetry=clinical_asymmetry and t=="tuev",alpha_regions=alpha_regions if t=="longitudinal" else None,envelope=clinical_envelope and t=="tuev") for t,(c,s,k) in SPECS.items()}) + self.backbone=SharedBackbone(channels,width,depth,dropout,wave_filters) + self.heads=nn.ModuleDict({t:ResidualHead(2*wave_filters*(((s*200+1)//4+1)//8)+width+256+width,k,head_width,head_dropout,full_precision=t=='ad65') for t,(c,s,k) in SPECS.items()}) + if temporal_pool:self.heads=nn.ModuleDict({t:TemporalPoolHead(head,wave_filters*2) for t,head in self.heads.items()}) + if temporal_evidence:self.heads=nn.ModuleDict({t:TemporalEvidenceHead(head,wave_filters*2,evidence_temperature) for t,head in self.heads.items()}) + if random_fourier:self.heads=nn.ModuleDict({t:FourierResidualHead(head,2*wave_filters*(((SPECS[t][1]*200+1)//4+1)//8)+width+256+width,SPECS[t][2],fourier_features) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:TangentFeatureHead(head) for t,head in self.heads.items()}) + def forward(self,t,x,features=None,covariances=None,covariance_features=None): + if features is None:features=extract_features(t,x) + if covariance_features is None: + if covariances is None:covariances=extract_covariances(t,x) + covariance_features=self.adapters[t].spatial_features(covariances) + signal=x.flatten(2);signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + adapted=self.adapters[t](signal,features,covariance_features) + if covariances is None:covariances=extract_covariances(t,x) + tangent=extract_tangent_features(covariances,self.adapters[t].spatial_weight) + representation,fusion_delta,covariance_delta=self.backbone(*adapted,tangent_features=tangent) + if t in ('faced','openbmi'): + representation=torch.cat([representation[:,:-384],torch.zeros_like(representation[:,-384:-128]),representation[:,-128:]],-1) + return self.heads[t](torch.cat([representation,fusion_delta,covariance_delta],-1)) + +def widen_state_dict(state,multiplier=2): + """Duplicate temporal features and divide downstream sums to preserve outputs.""" + result={} + for key,value in state.items(): + if key.startswith('backbone.waveform.'): + layer=int(key.split('.')[2]) + if layer in (0,2,7):value=value.repeat(multiplier,1,1,1) + elif layer in (1,3,9):value=value.repeat(multiplier) + elif layer==8:value=value.repeat(multiplier,multiplier,1,1)/multiplier + elif key=='backbone.wave_summary.2.weight':value=value.repeat(1,multiplier)/multiplier + elif key.startswith('heads.') and key.endswith('.weight'): + raw=value[:,:-128]/multiplier + value=torch.cat([raw]*multiplier+[value[:,-128:]],1) + result[key]=value + return result + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S035/tangent_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S035/tangent_features.py new file mode 100644 index 0000000000000000000000000000000000000000..314f0cf2f58e4b4a1c1d808edbd4acc3b7b6f85b --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S035/tangent_features.py @@ -0,0 +1,25 @@ +"""Window-local log-correlation geometry in the existing spatial-filter basis.""" +import torch + +TANGENT_DIM=10*24*25//2 + +@torch.no_grad() +def extract_tangent_features(covariances,spatial_weight): + old_tf32=torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(covariances.device.type,enabled=False): + w=spatial_weight.float() + w=w/w.norm(dim=-1,keepdim=True).clamp_min(1e-6) + projected=torch.einsum('bfc,nbcd,bgd->nbfg',w,covariances.float(),w) + d=projected.diagonal(dim1=-2,dim2=-1).clamp_min(1e-10).sqrt() + correlation=(projected/(d.unsqueeze(-1)*d.unsqueeze(-2))).clamp(-1,1) + correlation=(correlation+correlation.transpose(-1,-2))/2 + correlation=.95*correlation+.05*torch.eye(24,device=correlation.device) + values,vectors=torch.linalg.eigh(correlation) + logarithm=(vectors*values.clamp_min(1e-6).log().unsqueeze(-2))@vectors.transpose(-1,-2) + i,j=torch.triu_indices(24,24,device=correlation.device) + scale=torch.where(i==j,1.,2.**.5) + return (logarithm[...,i,j]*scale).flatten(1) + finally: + torch.backends.cuda.matmul.allow_tf32=old_tf32 diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S044/alpha_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S044/alpha_features.py new file mode 100644 index 0000000000000000000000000000000000000000..455154d715e86d45e4e17113bed69adbcd946b29 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S044/alpha_features.py @@ -0,0 +1,45 @@ +"""Fixed alpha prominence features from each individual two-second window.""" +import torch + +REGION_NAMES=('occipital','parietal','central','frontal','left_posterior','right_posterior') +REGIONS=(('PO7','PO5','PO3','POZ','PO4','PO6','PO8','O1','OZ','O2'), + ('P7','P5','P3','P1','PZ','P2','P4','P6','P8'), + ('FC5','FC3','FC1','FCZ','FC2','FC4','FC6','C5','C3','C1','CZ','C2','C4','C6'), + ('FP1','FPZ','FP2','AF3','AF4','F7','F5','F3','F1','FZ','F2','F4','F6','F8'), + ('P7','P5','P3','P1','PO7','PO5','PO3','O1'), + ('P2','P4','P6','P8','PO4','PO6','PO8','O2')) +ALPHA_DIM=58*7+6*22 + +def region_matrix(channels): + result=torch.zeros(len(REGIONS),len(channels)) + for i,names in enumerate(REGIONS): + for name in names:result[i,channels.index(name)]=1/len(names) + return result.tolist() + +@torch.no_grad() +def extract_alpha_features(signal,regions): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();x=x-x.mean(-1,keepdim=True) + spectrum=torch.fft.rfft(x*torch.hann_window(400,device=x.device),dim=-1)/200 + power=spectrum.abs().square().clamp_min(1e-12) + lp=power.log() + # Geometric regional means resist domination by one high-amplitude channel. + regional=torch.einsum('rc,ncf->nrf',regions.float(),lp) + lp=torch.cat([lp,regional],1) + low=lp[...,8:13].mean(-1,keepdim=True) + high=lp[...,36:49].mean(-1,keepdim=True) + freq=torch.arange(7.,14.5,.5,device=x.device) + alpha=lp[...,14:29] + baseline=low+(high-low)*((freq-5)/16) + prominence=alpha-baseline + normalized=alpha.softmax(-1) + center=(normalized*freq).sum(-1) + entropy=-(normalized*normalized.clamp_min(1e-12).log()).sum(-1) + alpha_mean=torch.logsumexp(alpha,-1)-torch.log(torch.tensor(15.,device=x.device)) + def log_band(lo,hi): + return torch.logsumexp(lp[...,lo:hi],-1)-torch.log(torch.tensor(float(hi-lo),device=x.device)) + summaries=torch.stack([alpha_mean-log_band(2,81),alpha_mean-log_band(8,14), + alpha_mean-log_band(30,61),prominence.max(-1).values, + prominence.mean(-1),center,entropy],-1) + return torch.cat([summaries[:,:58].flatten(1),summaries[:,58:].flatten(1), + prominence[:,58:].flatten(1)],1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S044/config.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S044/config.json new file mode 100644 index 0000000000000000000000000000000000000000..28ea5340518be1b2fd933a066f6a2c4ca8ba2aa6 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S044/config.json @@ -0,0 +1,714 @@ +{ + "schema": "bci-shared-biot-covariance-bf16head-v1", + "architecture": { + "channels": 32, + "width": 128, + "depth": 2, + "dropout": 0.5, + "wave_filters": 32, + "head_width": 64, + "head_dropout": 0.3, + "clinical_asymmetry": true, + "alpha_regions": [ + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.125 + ] + ], + "clinical_envelope": true, + "temporal_pool": true, + "temporal_evidence": true, + "evidence_temperature": 0.25, + "random_fourier": true, + "fourier_features": 256, + "tangent_readout": true, + "shared_context_correction": true, + "wave_coactivation": true + }, + "initialization": { + "initialization": "continue joint training from a complete shared-model checkpoint", + "parent": "/workspace/research/runs/hybrid_biot_fusionshrink0100/epoch-001/weights.pt", + "parent_initialization": { + "initialization": "jointly trained parent plus audited pretrained BIOT in a single coupled backbone", + "parent": "/workspace/research/runs/hybrid_wide1/epoch-004/weights.pt", + "audited_biot": { + "initialization": "pretrained", + "repo": "braindecode/biot-pretrained-six-datasets-18chs", + "revision": "7e9aabf302870012f73773276803aab97993951c", + "sha256": "a218f4054ae29962c6fd9d23d94c446d354c4f53e805a6771c85749ccc20baaa", + "license": "BSD-3-Clause", + "source_braindecode": "1.3.0", + "loaded_core_tensors": 56, + "skipped_classifier_tensors": 3 + }, + "neural_channel_indices": { + "faced": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "tuev": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15 + ], + "ad65": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "openbmi": [ + 0, + 1, + 3, + 5, + 12, + 14, + 23, + 25, + 28, + 30, + 2, + 6, + 11, + 15, + 22, + 26, + 4, + 13 + ], + "longitudinal": [ + 0, + 2, + 7, + 11, + 23, + 27, + 41, + 45, + 55, + 57, + 5, + 13, + 21, + 29, + 39, + 47, + 9, + 25 + ] + }, + "rebase": "incumbent waveform, fusion and four heads; joint BIOT and TUEV head from readout epoch 9; zero initialized neural interaction", + "jointly_finetuned_neural_parent": "/workspace/research/runs/hybrid_biot_readout1/epoch-009/weights.pt", + "tuev_high_dimensional_spectral_projection_disabled": true, + "frozen_prior_representation": true, + "nonclinical_head_updates": "only the 256 added BIOT columns; original columns and biases fixed", + "faced_openbmi_neural_path": "common nonlinear fusion only; direct head columns masked", + "retention_teacher": "/workspace/research/runs/hybrid_wide1/epoch-004", + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "joint_covariance_parent": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "frozen_prior_representation": true, + "head_updates": "one linear head per track; added 128 shared covariance columns trainable; AD head initialized from the joint covariance parent", + "new_shared_representation": "one common covariance MLP inside the coupled backbone, trained by all five tasks; fixed spatial input adapters from the same jointly trained source", + "head_arithmetic": "one linear head evaluated in fixed feature blocks to preserve original bfloat16 accumulation dimensions", + "retention_teacher": { + "ad65": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "other_tracks": "/workspace/research/runs/hybrid_wide1/epoch-004" + }, + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "loader_scale": 0.01, + "tracks": [ + "faced", + "tuev", + "ad65", + "openbmi", + "longitudinal" + ], + "head_arithmetic": "same linear head in fixed feature blocks, sum in bfloat16 on GPU for non-AD tracks; AD remains float32", + "head_refinement": { + "source": "/workspace/research/runs/residual_heads1/epoch-018", + "source_weights_sha256": "e0b609137391b47f99438ccadaa22fc0bc10d2c10ead0ddf0a3c25be2c907c85", + "shared_backbone_unchanged": true, + "selected_head_epochs": { + "faced": 5, + "tuev": 24, + "ad65": 0, + "openbmi": 0, + "longitudinal": 0 + } + }, + "clinical_spectral_refinement": { + "source": "/workspace/research/runs/head_dropout1/epoch-016", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "head_estimation": { + "method": "class/subject-balanced Gaussian linear discriminant; covariance augmented by class-conditional subject/session mean variation before shrinkage", + "selected_shrinkage": { + "faced": "inherited", + "tuev": "inherited", + "ad65": "inherited", + "openbmi": "inherited", + "longitudinal": { + "shrinkage": 0.9, + "domain_strength": 1.0 + } + }, + "feature_scaling": "fitted on training data and folded into linear coefficients" + }, + "clinical_asymmetry_refinement": { + "source": "/workspace/research/runs/domain_lda_heads1/epoch-001", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "alpha_rhythm_adapter": { + "training_normalization_only": true, + "regions": [ + "occipital", + "parietal", + "central", + "frontal", + "left_posterior", + "right_posterior" + ], + "features": "per-window alpha prominence relative to adjacent frequencies", + "shared_backbone_unchanged": true + }, + "clinical_envelope_refinement": { + "source": "/workspace/research/runs/clinical_asymmetry1/epoch-001", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "independent_adapter_merge": { + "alpha_source": "/workspace/research/runs/alpha_calibrated1/epoch-003", + "clinical_source": "/workspace/research/runs/clinical_envelope1/epoch-002", + "all_shared_and_head_tensors_equal": true + }, + "frequency_montage_refinement": { + "six_frequency_bands": true, + "shared_encoder_unchanged": true, + "selected_track_epochs": { + "faced": 0, + "tuev": 1, + "ad65": 0, + "openbmi": 10, + "longitudinal": 2 + } + }, + "private_track_selection": { + "track": "tuev", + "donor": "/workspace/research/replicates/frequency_head_control1/epoch-001" + }, + "clinical_sampling_refinement": { + "subject_exponent": 0.0, + "class_balanced": true, + "only_clinical_head_updated": true + }, + "temporal_statistics_readout": { + "statistics": [ + "mean", + "standard deviation", + "maximum", + "minimum" + ], + "shared_encoder_and_prior_heads_unchanged": true, + "selected_pool_epochs": { + "faced": 2, + "tuev": 0, + "ad65": 0, + "openbmi": 33, + "longitudinal": 3 + } + }, + "temporal_evidence_readout": { + "pooling": "log mean exp of per-patch class evidence", + "temperature": 0.25, + "shared_encoder_and_prior_heads_unchanged": true, + "selected_evidence_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 6, + "longitudinal": 8 + } + }, + "fourier_basis_readout": { + "basis_functions": 256, + "bandwidths": [ + 0.5, + 1.0, + 2.0 + ], + "shared_encoder_and_prior_heads_unchanged": true, + "selected_fourier_epochs": { + "faced": 21, + "tuev": 0, + "ad65": 0, + "openbmi": 0, + "longitudinal": 2 + } + }, + "shared_tangent_readout": { + "one_shared_tangent_module": true, + "original_and_corrected_shared_features_retained": true, + "private_head_scalar_gains": { + "faced": 0.0, + "tuev": 0.1, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 0.1 + }, + "all_common_weights_fixed_during_gain_refinement": true + }, + "shared_context_correction": { + "source": "/workspace/research/runs/hybrid_codebrain_fusion_control1/epoch-002", + "zero_token_input_preserved": true, + "unused_native_CodeBrain_core_and_input_parameters_removed": true, + "common_patch_and_context_layers_retained": true, + "same_one_shared_backbone_and_five_classifiers": true + }, + "shared_wave_coactivation": { + "channels": 64, + "statistics": 2080, + "diagonal_only_control": false, + "common_encoder_updated_by_all_five_tracks": true, + "gain_selection_within_one_common_checkpoint": { + "faced": 0.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 1.0 + } + }, + "fixed_common_coactivation_readouts": { + "all_common_weights_exactly_unchanged": true, + "selected_private_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 8, + "longitudinal": 2 + } + } +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S044/data.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S044/data.py new file mode 100644 index 0000000000000000000000000000000000000000..e3cf61f3b1ac4d22858c6e6f387024abd27d953d --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S044/data.py @@ -0,0 +1,33 @@ +import json +from functools import lru_cache +from pathlib import Path +import numpy as np +import torch +@lru_cache(maxsize=8) +def array(path):return np.load(path,mmap_mode='r',allow_pickle=False) +class Dataset(torch.utils.data.Dataset): + def __init__(self,root,limit=None,cache=False): + self.root=Path(root) + self.rows=json.loads((self.root/'manifest.json').read_text())['samples'] + if limit:self.rows=self.rows[:limit] + self.cached=None + if cache and self.rows: + from collections import defaultdict + groups=defaultdict(list) + for i,r in enumerate(self.rows):groups[r['path']].append((i,r['index'])) + for name,indices in groups.items(): + path=(self.root/name).resolve() + if not path.is_relative_to(self.root.resolve()):raise ValueError('input outside root') + source=np.load(path,mmap_mode='r',allow_pickle=False) + if self.cached is None:self.cached=torch.empty((len(self.rows),*source.shape[1:]),dtype=torch.float32) + dst,src=zip(*indices) + self.cached[list(dst)]=torch.as_tensor(source[list(src)]/100,dtype=torch.float32) + def __len__(self):return len(self.rows) + def __getitem__(self,i): + r=self.rows[i] + if self.cached is not None:return self.cached[i],r.get('label',-1),r['id'] + p=(self.root/r['path']).resolve() + if not p.is_relative_to(self.root.resolve()):raise ValueError('input outside root') + # Division precedes float32 conversion, matching official FACED/TUEV collate. + x=np.asarray(array(str(p))[r['index']])/100 + return torch.as_tensor(x,dtype=torch.float32),r.get('label',-1),r['id'] diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S044/envelope_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S044/envelope_features.py new file mode 100644 index 0000000000000000000000000000000000000000..2251a6f03a3a6daaa3faed0bbc803bf182224da6 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S044/envelope_features.py @@ -0,0 +1,44 @@ +"""Per-window burst-envelope regularity and bilateral synchrony, without fitting.""" +import torch +import torch.nn.functional as F + +BANDS=((1,4),(4,8),(8,13),(13,30),(30,45)) +ENVELOPE_DIM=16*5*12+8*5*2 + +@torch.no_grad() +def extract_envelope_features(signal): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();x=x-x.mean(-1,keepdim=True) + spectrum=torch.fft.fft(x,dim=-1) + frequency=torch.fft.fftfreq(x.shape[-1],1/200,device=x.device) + envelopes=[] + for lo,hi in BANDS: + mask=((frequency>=lo)&(frequency2).float().mean(-1),(relative>4).float().mean(-1), + ((relative[...,1:]>2)&(relative[...,:-1]<=2)).float().mean(-1), + acf_peak,(acf_index.float()+4)/40, + acf[...,0],acf[...,6],acf[...,16],acf[...,36]] + left=torch.tensor([0,1,2,3,8,9,10,11],device=x.device);right=left+4 + synchrony=(normalized[:,left]*normalized[:,right]).mean(-1).clamp(-1,1) + imbalance=(std[:,left].squeeze(-1).log()-std[:,right].squeeze(-1).log()).abs() + return torch.cat([torch.stack(summaries,-1).flatten(1),synchrony.flatten(1),imbalance.flatten(1)],1) + +def mirrored_features(features): + channels=torch.tensor([4,5,6,7,0,1,2,3,12,13,14,15,8,9,10,11],device=features.device) + return torch.cat([features[:,:16*5*12].reshape(-1,16,5,12)[:,channels].flatten(1),features[:,16*5*12:]],1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S044/frequency_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S044/frequency_features.py new file mode 100644 index 0000000000000000000000000000000000000000..9194c9e81f801b3833e551e4967991774fa9e398 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S044/frequency_features.py @@ -0,0 +1,11 @@ +"""Fixed per-window frequency decomposition for a linear montage adapter.""" +import torch + +FREQUENCY_BANDS=((1,4),(4,8),(8,13),(13,20),(20,30),(30,45)) + +def frequency_components(signal): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();spectrum=torch.fft.rfft(x,dim=-1) + frequency=torch.fft.rfftfreq(x.shape[-1],d=1/200,device=x.device) + masks=torch.stack([((frequency>=lo)&(frequencynbfg',w,covariances.float(),w) + d=projected.diagonal(dim1=-2,dim2=-1).clamp_min(1e-10).sqrt() + correlation=(projected/(d.unsqueeze(-1)*d.unsqueeze(-2))).clamp(-1,1) + correlation=(correlation+correlation.transpose(-1,-2))/2 + correlation=.95*correlation+.05*torch.eye(24,device=correlation.device) + values,vectors=torch.linalg.eigh(correlation) + logarithm=(vectors*values.clamp_min(1e-6).log().unsqueeze(-2))@vectors.transpose(-1,-2) + i,j=torch.triu_indices(24,24,device=correlation.device) + scale=torch.where(i==j,1.,2.**.5) + return (logarithm[...,i,j]*scale).flatten(1) + finally: + torch.backends.cuda.matmul.allow_tf32=old_tf32 diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S062/data.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S062/data.py new file mode 100644 index 0000000000000000000000000000000000000000..e3cf61f3b1ac4d22858c6e6f387024abd27d953d --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S062/data.py @@ -0,0 +1,33 @@ +import json +from functools import lru_cache +from pathlib import Path +import numpy as np +import torch +@lru_cache(maxsize=8) +def array(path):return np.load(path,mmap_mode='r',allow_pickle=False) +class Dataset(torch.utils.data.Dataset): + def __init__(self,root,limit=None,cache=False): + self.root=Path(root) + self.rows=json.loads((self.root/'manifest.json').read_text())['samples'] + if limit:self.rows=self.rows[:limit] + self.cached=None + if cache and self.rows: + from collections import defaultdict + groups=defaultdict(list) + for i,r in enumerate(self.rows):groups[r['path']].append((i,r['index'])) + for name,indices in groups.items(): + path=(self.root/name).resolve() + if not path.is_relative_to(self.root.resolve()):raise ValueError('input outside root') + source=np.load(path,mmap_mode='r',allow_pickle=False) + if self.cached is None:self.cached=torch.empty((len(self.rows),*source.shape[1:]),dtype=torch.float32) + dst,src=zip(*indices) + self.cached[list(dst)]=torch.as_tensor(source[list(src)]/100,dtype=torch.float32) + def __len__(self):return len(self.rows) + def __getitem__(self,i): + r=self.rows[i] + if self.cached is not None:return self.cached[i],r.get('label',-1),r['id'] + p=(self.root/r['path']).resolve() + if not p.is_relative_to(self.root.resolve()):raise ValueError('input outside root') + # Division precedes float32 conversion, matching official FACED/TUEV collate. + x=np.asarray(array(str(p))[r['index']])/100 + return torch.as_tensor(x,dtype=torch.float32),r.get('label',-1),r['id'] diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S062/model.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S062/model.py new file mode 100644 index 0000000000000000000000000000000000000000..dbf330c374a0189521e061b974138a148f6415e2 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S062/model.py @@ -0,0 +1,402 @@ +from student_features import CBraModFeatures,FrequencyAdapter +"""One fused waveform/spectral backbone used identically by all five tasks.""" +import torch +from torch import nn +from braindecode.models import BIOT +from features import SPECS,TRACKS,feature_dim,extract_features,Standardize,Residual,EDGES,COV_BANDS +from covariances import BANDS,extract_covariances +from alpha_features import extract_alpha_features,ALPHA_DIM +from envelope_features import extract_envelope_features,ENVELOPE_DIM +from frequency_features import frequency_components,FREQUENCY_BANDS +from tangent_features import extract_tangent_features,TANGENT_DIM +from phase_features import phase_features,PHASE_DIM,PHASE_HALF +from coupling_features import coupling_features,PER_CHANNEL as COUPLING_PER_CHANNEL +from ordinal_features import ordinal_features,PER_CHANNEL as ORDINAL_PER_CHANNEL + +def clinical_asymmetry_features(features): + """Bipolar homologous-channel amplitude and coherence, invariant to mirroring.""" + bands=len(EDGES)-1;per_channel=4*bands+4 + block=features[:,:16*per_channel].reshape(-1,16,per_channel) + left=torch.tensor([0,1,2,3,8,9,10,11],device=features.device);right=left+4 + pair_power=(block[:,left,:bands]-block[:,right,:bands]).abs().flatten(1) + pair_rms=(block[:,left,4*bands]-block[:,right,4*bands]).abs() + hemisphere=(block[:,left,:bands].mean(1)-block[:,right,:bands].mean(1)).abs() + index=left*(32-left-1)//2+(right-left-1) + correlations=features[:,16*per_channel:].reshape(-1,len(COV_BANDS),120)[:,:,index].flatten(1) + return torch.cat([pair_power,pair_rms,hemisphere,correlations],1) + +class InputAdapter(nn.Module): + def __init__(self,c,width,channels,spectral_enabled=True,asymmetry=False,alpha_regions=None,envelope=False): + super().__init__() + self.ordinal_normalizer=Standardize(c*ORDINAL_PER_CHANNEL) + self.ordinal_projection=nn.Linear(c*ORDINAL_PER_CHANNEL,width) + self.ordinal_dropout=nn.Dropout(.3) + self.register_buffer('ordinal_probabilities_enabled',torch.ones(())) + self.coupling_normalizer=Standardize(c*COUPLING_PER_CHANNEL) + self.coupling_projection=nn.Linear(c*COUPLING_PER_CHANNEL,width) + self.coupling_dropout=nn.Dropout(.3) + self.register_buffer('coupling_dependence_enabled',torch.ones(())) + self.phase_normalizer=Standardize(PHASE_DIM) + self.signal=nn.Conv1d(c,channels,1,bias=False) + self.frequency_weight=nn.Parameter(torch.zeros(len(FREQUENCY_BANDS),channels,c)) + self.neural=nn.Conv1d(c,18,1,bias=False) + self.normalizer=Standardize(feature_dim(c)) + self.spectral=nn.Linear(feature_dim(c),width) + self.dropout=nn.Dropout(.1) + self.register_buffer("spectral_enabled",torch.tensor(float(spectral_enabled))) + self.spatial_weight=nn.Parameter(torch.randn(len(BANDS),24,c)/c**.5) + self.asymmetry_projection=nn.Linear(316,width,bias=False) if asymmetry else None + if asymmetry: + nn.init.zeros_(self.asymmetry_projection.weight) + self.asymmetry_normalizer=Standardize(316) + self.asymmetry_dropout=nn.Dropout(.1) + self.alpha_projection=None + if alpha_regions is not None: + self.register_buffer('alpha_regions',torch.tensor(alpha_regions,dtype=torch.float32)) + self.alpha_normalizer=Standardize(ALPHA_DIM) + self.alpha_projection=nn.Linear(ALPHA_DIM,width,bias=False) + nn.init.zeros_(self.alpha_projection.weight) + self.alpha_dropout=nn.Dropout(.3) + self.envelope_projection=None + if envelope: + self.envelope_normalizer=Standardize(ENVELOPE_DIM) + self.envelope_projection=nn.Linear(ENVELOPE_DIM,width,bias=False) + nn.init.zeros_(self.envelope_projection.weight) + self.envelope_dropout=nn.Dropout(.3) + def coupling_embedding(self,features): + values=self.coupling_normalizer(features).reshape(len(features),-1,COUPLING_PER_CHANNEL) + values=torch.cat([values[...,:10],self.coupling_dependence_enabled*values[...,10:]],-1).flatten(1) + return self.coupling_projection(self.coupling_dropout(values)) + def ordinal_embedding(self,features): + values=self.ordinal_normalizer(features).reshape(len(features),-1,5,26) + values=torch.cat([self.ordinal_probabilities_enabled*values[...,:24],values[...,24:]],-1).flatten(1) + return self.ordinal_projection(self.ordinal_dropout(values)) + def spectral_features(self,features,signal=None,alpha_features=None,envelope_features=None): + value=self.spectral_enabled*self.spectral(self.dropout(self.normalizer(features))) + if self.asymmetry_projection is not None: + extra=self.asymmetry_dropout(self.asymmetry_normalizer(clinical_asymmetry_features(features))) + value=value+self.asymmetry_projection(extra) + if self.alpha_projection is not None: + if alpha_features is None:alpha_features=extract_alpha_features(signal,self.alpha_regions) + value=value+self.alpha_projection(self.alpha_dropout(self.alpha_normalizer(alpha_features))) + if self.envelope_projection is not None: + if envelope_features is None:envelope_features=extract_envelope_features(signal) + value=value+self.envelope_projection(self.envelope_dropout(self.envelope_normalizer(envelope_features))) + return value + def spatial_features(self,covariances): + with torch.autocast(covariances.device.type,enabled=False): + w=self.spatial_weight.float()/self.spatial_weight.float().norm(dim=-1,keepdim=True).clamp_min(1e-6) + power=torch.einsum('bfc,nbcd,bfd->nbf',w,covariances.float(),w).clamp_min(1e-8).log() + return torch.cat([power,power-power.mean(1,keepdim=True)],1).flatten(1) + def wave_signal(self,x,components=None): + if components is None:components=frequency_components(x) + correction=torch.einsum('blc,nbct->nlt',self.frequency_weight,components.to(self.frequency_weight.dtype)) + return (self.signal(x)+correction.to(x.dtype)).unsqueeze(1) + def forward(self,x,features,covariance_features): + return self.wave_signal(x),self.spectral_features(features,signal=x),self.neural(x),covariance_features + +class SharedBackbone(nn.Module): + def __init__(self,channels,width,depth,dropout,wave_filters): + super().__init__() + self.waveform=nn.Sequential( + nn.Conv2d(1,wave_filters,(1,64),padding=(0,32),bias=False),nn.GroupNorm(1,wave_filters), + nn.Conv2d(wave_filters,2*wave_filters,(channels,1),groups=wave_filters,bias=False),nn.GroupNorm(1,2*wave_filters),nn.ELU(), + nn.AvgPool2d((1,4)),nn.Dropout(.35), + nn.Conv2d(2*wave_filters,2*wave_filters,(1,16),padding=(0,8),groups=2*wave_filters,bias=False),nn.Conv2d(2*wave_filters,2*wave_filters,1,bias=False), + nn.GroupNorm(1,2*wave_filters),nn.ELU(),nn.AvgPool2d((1,8)),nn.Dropout(.35)) + self.wave_summary=nn.Sequential(nn.AdaptiveAvgPool2d((1,8)),nn.Flatten(),nn.Linear(2*wave_filters*8,width)) + self.fusion=nn.Sequential(nn.LayerNorm(width),nn.GELU(),nn.Dropout(dropout), + *[Residual(width,dropout) for _ in range(depth)],nn.LayerNorm(width)) + # Both representations interact before the shared residual stack. + self.phase_encoder=nn.Sequential(nn.LayerNorm(PHASE_DIM),nn.Linear(PHASE_DIM,width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width)) + self.register_buffer('phase_imaginary_enabled',torch.ones(())) + self.coupling_encoder=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width),nn.LayerNorm(width)) + self.wave_gain=nn.Parameter(torch.tensor(.1)) + self.biot=BIOT(n_chans=18,n_outputs=2,n_times=400,sfreq=200) + self.biot.final_layer=nn.Identity() + self.biot_projection=nn.Sequential(nn.LayerNorm(256),nn.Linear(256,width),nn.Dropout(.2)) + nn.init.normal_(self.biot_projection[1].weight,std=.001);nn.init.zeros_(self.biot_projection[1].bias) + self.covariance_encoder=nn.Sequential(nn.LayerNorm(len(BANDS)*24*2),nn.Linear(len(BANDS)*24*2,width),nn.GELU(),nn.Dropout(.4), + *[Residual(width,.4) for _ in range(2)],nn.LayerNorm(width)) + self.covariance_projection=nn.Linear(width,width) + nn.init.zeros_(self.covariance_projection.weight);nn.init.zeros_(self.covariance_projection.bias) + self.tangent_encoder=nn.Sequential(nn.LayerNorm(TANGENT_DIM),nn.Linear(TANGENT_DIM,width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width),nn.Linear(width,width)) + self.ordinal_context=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width)) + nn.init.zeros_(self.ordinal_context[-1].weight);nn.init.zeros_(self.ordinal_context[-1].bias) + self.register_buffer('codebrain_enabled',torch.ones(())) + self.codebrain_patch_encoder=nn.Sequential(nn.LayerNorm(24*64),nn.Linear(24*64,width),nn.GELU(),nn.Dropout(.3)) + self.codebrain_context=nn.Sequential(nn.LayerNorm(width*4),nn.Linear(width*4,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width)) + nn.init.zeros_(self.codebrain_context[-1].weight);nn.init.zeros_(self.codebrain_context[-1].bias) + def codebrain_correction(self,tokens,representation,fusion_input): + with torch.autocast(tokens.device.type,enabled=False): + encoded=self.codebrain_patch_encoder(self.codebrain_enabled*tokens.float()) + pooled=torch.cat([encoded.mean(1),encoded.std(1,correction=0),representation[:,-512:-384].float(),representation[:,-128:].float()],-1) + delta=self.codebrain_context(pooled) + added=.001*nn.functional.linear(delta,self.covariance_projection.weight,None) + corrected=self.fusion(fusion_input+added.to(fusion_input.dtype)) + return corrected-representation[:,-512:-384],delta + def forward(self,signal,spectral,neural_signal,covariance_features,tangent_features): + wave=self.waveform(signal) + neural=self.biot(neural_signal.float()) + neural=self.biot_projection[0](neural) + projected=self.biot_projection[2](self.biot_projection[1](neural)) + with torch.autocast(signal.device.type,enabled=False): + covariance_embedding=self.covariance_encoder(covariance_features.float()) + original=spectral+self.wave_gain*self.wave_summary(wave)+.01*projected + coupled=.001*self.covariance_projection(covariance_embedding).to(original.dtype) + fused=self.fusion(original+coupled) + with torch.autocast(signal.device.type,enabled=False):delta=self.tangent_encoder(tangent_features.float()) + added=.001*nn.functional.linear(delta,self.covariance_projection.weight,None) + corrected=self.fusion((original+coupled)+added.to(original.dtype)) + return torch.cat([wave.flatten(1),fused,neural,covariance_embedding],-1),corrected-fused,delta,original+coupled + +class ResidualHead(nn.Module): + """A small nonlinear classifier correction around an inherited linear readout.""" + def __init__(self,features,classes,width=64,dropout=.3,full_precision=False): + super().__init__();self.full_precision=full_precision + self.base=nn.Linear(features,classes) + self.delta=nn.Sequential(nn.LayerNorm(features),nn.Linear(features,width),nn.GELU(),nn.Dropout(dropout),nn.Linear(width,classes)) + nn.init.zeros_(self.delta[-1].weight);nn.init.zeros_(self.delta[-1].bias) + def forward(self,x): + if self.full_precision: + with torch.autocast(x.device.type,enabled=False):return self.base(x.float())+self.delta(x.float()) + prior=nn.functional.linear(x[:,:-128].contiguous(),self.base.weight[:,:-128].contiguous(),self.base.bias) + added=nn.functional.linear(x[:,-128:].contiguous(),self.base.weight[:,-128:].contiguous()) + value=prior+added + return value+self.delta(x).to(value.dtype) + +class TemporalPoolHead(nn.Module): + def __init__(self,prior,channels=64): + super().__init__();self.prior=prior;self.channels=channels + self.register_buffer('pool_output_scale',torch.ones(()));self.register_buffer('pool_mean',torch.zeros(channels*4));self.register_buffer('pool_scale',torch.ones(channels*4)) + self.pool_projection=nn.Linear(channels*4,prior.base.out_features) + nn.init.zeros_(self.pool_projection.weight);nn.init.zeros_(self.pool_projection.bias) + def statistics(self,x): + with torch.autocast(x.device.type,enabled=False): + wave=x[:,:-512].float().reshape(len(x),self.channels,-1) + return torch.cat([wave.mean(-1),wave.std(-1,correction=0),wave.amax(-1),wave.amin(-1)],-1) + def forward(self,x): + prior=self.prior(x) + with torch.autocast(x.device.type,enabled=False): + values=((self.statistics(x)-self.pool_mean)/self.pool_scale).clamp(-8,8) + added=self.pool_output_scale*self.pool_projection(values) + return prior+added.to(prior.dtype) + +class TemporalEvidenceHead(nn.Module): + """Pool class evidence over the shared waveform time axis.""" + def __init__(self,prior,channels=64,temperature=.25): + super().__init__();self.prior=prior;self.channels=channels;self.temperature=temperature + self.register_buffer('evidence_output_scale',torch.ones(())) + self.register_buffer('evidence_mean',torch.zeros(channels)) + self.register_buffer('evidence_scale',torch.ones(channels)) + self.evidence_projection=nn.Linear(channels,prior.prior.base.out_features,bias=False) + nn.init.zeros_(self.evidence_projection.weight) + def patches(self,x): + with torch.autocast(x.device.type,enabled=False): + wave=x[:,:-512].float().reshape(len(x),self.channels,-1).transpose(1,2) + return ((wave-self.evidence_mean)/self.evidence_scale).clamp(-8,8) + def evidence(self,patches): + with torch.autocast(patches.device.type,enabled=False): + values=self.evidence_projection(patches.float())/self.temperature + maximum=values.amax(1,keepdim=True) + pooled=self.temperature*((values-maximum).exp().mean(1).log()+maximum.squeeze(1)) + return self.evidence_output_scale*pooled + def forward(self,x): + prior=self.prior(x) + return prior+self.evidence(self.patches(x)).to(prior.dtype) + +class FourierResidualHead(nn.Module): + """A fixed random Fourier basis and trainable linear classifier correction.""" + def __init__(self,prior,features,classes,basis=256): + super().__init__();self.prior=prior + self.register_buffer('rff_mean',torch.zeros(features));self.register_buffer('rff_scale',torch.ones(features)) + self.register_buffer('rff_frequency',torch.randn(features,basis)/features**.5) + self.register_buffer('rff_phase',torch.rand(basis)*2*torch.pi) + self.register_buffer('rff_output_scale',torch.ones(())) + self.rff_projection=nn.Linear(3*basis,classes);nn.init.zeros_(self.rff_projection.weight);nn.init.zeros_(self.rff_projection.bias) + def basis(self,x): + with torch.autocast(x.device.type,enabled=False): + values=((x.float()-self.rff_mean)/self.rff_scale).clamp(-8,8)@self.rff_frequency + return 2**.5*torch.cat([(values/sigma+self.rff_phase).cos() for sigma in (.5,1.,2.)],-1) + def forward(self,x): + prior=self.prior(x) + with torch.autocast(x.device.type,enabled=False):added=self.rff_output_scale*self.rff_projection(self.basis(x)) + return prior+added.to(prior.dtype) + +class TangentFeatureHead(nn.Module): + """Select a shared feature correction before the inherited classifier.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.feature_gain=nn.Parameter(torch.zeros(())) + def forward(self,values): + old=values[:,:-256];fusion_delta=values[:,-256:-128];covariance_delta=values[:,-128:] + adjusted=torch.cat([old[:,:-512],old[:,-512:-384]+self.feature_gain*fusion_delta,old[:,-384:-128],old[:,-128:]+self.feature_gain*covariance_delta],-1) + return self.prior(adjusted) + +class CodeBrainFeatureHead(nn.Module): + """Private use of a jointly trained common feature correction.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.codebrain_gain=nn.Parameter(torch.ones(())) + def forward(self,values): + previous=values[:,:-256];native=previous[:,:-256] + fusion_delta=values[:,-256:-128];covariance_delta=values[:,-128:] + adjusted=torch.cat([native[:,:-512],native[:,-512:-384]+self.codebrain_gain*fusion_delta,native[:,-384:-128],native[:,-128:]+self.codebrain_gain*covariance_delta],-1) + return self.prior(torch.cat([adjusted,previous[:,-256:]],-1)) + +class WaveCoactivationContext(nn.Module): + """One common encoder of coactivation among the learned waveform channels.""" + def __init__(self,channels=64,width=128): + super().__init__();self.channels=channels + ii,jj=torch.triu_indices(channels,channels,offset=1) + self.register_buffer('pair_i',ii);self.register_buffer('pair_j',jj) + self.register_buffer('offdiagonal_enabled',torch.ones(())) + self.encoder=nn.Sequential(nn.LayerNorm(channels+len(ii)),nn.Linear(channels+len(ii),width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width)) + def statistics(self,native): + with torch.autocast(native.device.type,enabled=False): + wave=native[:,:-512].float().reshape(len(native),self.channels,-1) + centered=wave-wave.mean(-1,keepdim=True) + previous_tf32=torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32=False + covariance=centered@centered.transpose(-1,-2)/wave.shape[-1] + torch.backends.cuda.matmul.allow_tf32=previous_tf32 + variance=covariance.diagonal(dim1=-2,dim2=-1).clamp_min(1e-8) + correlation=covariance/(variance.sqrt()[:,:,None]*variance.sqrt()[:,None,:]) + return torch.cat([variance.log(),correlation[:,self.pair_i,self.pair_j].clamp(-1,1)],-1) + def encode_statistics(self,values): + with torch.autocast(values.device.type,enabled=False): + value=torch.cat([values[:,:self.channels],self.offdiagonal_enabled*values[:,self.channels:]],-1) + return self.encoder(value.float()) + def forward(self,native):return self.encode_statistics(self.statistics(native)) + +class WaveCoactivationHead(nn.Module): + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=self.correction_gain*self.output_scale*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class OrdinalFeatureHead(nn.Module): + """Private strength of one common ordinal-dynamics feature correction.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.ordinal_gain=nn.Parameter(torch.ones(())) + def forward(self,values): + previous=values[:,:-256];native=previous[:,:-640] + adjusted=torch.cat([native[:,:-512],native[:,-512:-384]+self.ordinal_gain*values[:,-256:-128],native[:,-384:-128],native[:,-128:]+self.ordinal_gain*values[:,-128:],previous[:,-640:]],-1) + return self.prior(adjusted) + +class PhaseReadoutHead(nn.Module): + """Private class evidence from the common complex-coherence encoder.""" + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=(self.correction_gain*self.output_scale)*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class CouplingReadoutHead(nn.Module): + """Private class evidence from the common cross-frequency coupling encoder.""" + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=(self.correction_gain*self.output_scale)*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class HybridModel(nn.Module): + def __init__(self,channels=32,width=128,depth=2,dropout=.5,wave_filters=32,head_width=64,head_dropout=.3,clinical_asymmetry=True,alpha_regions=None,clinical_envelope=False,temporal_pool=True,temporal_evidence=False,evidence_temperature=.25,random_fourier=False,fourier_features=256,tangent_readout=True,shared_context_correction=True,wave_coactivation=True,ordinal_context=True,phase_coherence=True,cross_frequency=True,cbramod_feature_transfer=True,student_architecture=None): + super().__init__() + self.adapters=nn.ModuleDict({t:InputAdapter(c,width,channels,spectral_enabled=t not in ("faced","tuev","openbmi"),asymmetry=clinical_asymmetry and t=="tuev",alpha_regions=alpha_regions if t=="longitudinal" else None,envelope=clinical_envelope and t=="tuev") for t,(c,s,k) in SPECS.items()}) + self.backbone=SharedBackbone(channels,width,depth,dropout,wave_filters) + self.backbone.student_encoder=CBraModFeatures(**(student_architecture or {})) + self.backbone.register_buffer('student_ordered_enabled',torch.ones(())) + self.backbone.student_readout=nn.Sequential(nn.Linear(self.backbone.student_encoder.output_dim,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + for t,(c,s,k) in SPECS.items(): + self.adapters[t].student_input=FrequencyAdapter(c,32) + self.adapters[t].student_normalizer=Standardize(self.backbone.student_encoder.output_dim) + self.backbone.wave_coactivation=WaveCoactivationContext(2*wave_filters,width) + self.heads=nn.ModuleDict({t:ResidualHead(2*wave_filters*(((s*200+1)//4+1)//8)+width+256+width,k,head_width,head_dropout,full_precision=t=='ad65') for t,(c,s,k) in SPECS.items()}) + if temporal_pool:self.heads=nn.ModuleDict({t:TemporalPoolHead(head,wave_filters*2) for t,head in self.heads.items()}) + if temporal_evidence:self.heads=nn.ModuleDict({t:TemporalEvidenceHead(head,wave_filters*2,evidence_temperature) for t,head in self.heads.items()}) + if random_fourier:self.heads=nn.ModuleDict({t:FourierResidualHead(head,2*wave_filters*(((SPECS[t][1]*200+1)//4+1)//8)+width+256+width,SPECS[t][2],fourier_features) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:TangentFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CodeBrainFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:WaveCoactivationHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:OrdinalFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:PhaseReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + def student_features(self,t,x): + outputs=[];old_fastpath=torch.backends.mha.get_fastpath_enabled();torch.backends.mha.set_fastpath_enabled(False) + try: + for raw in x.split(16): + signal=torch.nan_to_num(raw.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + with torch.autocast(signal.device.type,dtype=torch.bfloat16,enabled=signal.device.type=='cuda'): + outputs.append(self.backbone.student_encoder(self.adapters[t].student_input(signal))) + finally:torch.backends.mha.set_fastpath_enabled(old_fastpath) + return torch.cat(outputs).float() + def student_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].student_normalizer(values.float()) + normalized=torch.cat([normalized[:,:256],self.backbone.student_ordered_enabled*normalized[:,256:]],-1) + return self.backbone.student_readout(normalized) + def coupling_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False):return self.backbone.coupling_encoder(self.adapters[t].coupling_embedding(values.float())) + def phase_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].phase_normalizer(values.float()) + normalized=torch.cat([normalized[:,:PHASE_HALF],self.backbone.phase_imaginary_enabled*normalized[:,PHASE_HALF:]],-1) + return self.backbone.phase_encoder(normalized) + def forward(self,t,x,features=None,covariances=None,covariance_features=None): + if features is None:features=extract_features(t,x) + if covariance_features is None: + if covariances is None:covariances=extract_covariances(t,x) + covariance_features=self.adapters[t].spatial_features(covariances) + signal=x.flatten(2);signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + adapted=self.adapters[t](signal,features,covariance_features) + if covariances is None:covariances=extract_covariances(t,x) + tangent=extract_tangent_features(covariances,self.adapters[t].spatial_weight) + representation,fusion_delta,covariance_delta,fusion_input=self.backbone(*adapted,tangent_features=tangent) + if t in ('faced','openbmi'): + representation=torch.cat([representation[:,:-384],torch.zeros_like(representation[:,-384:-128]),representation[:,-128:]],-1) + tokens=torch.zeros(len(signal),signal.shape[-1]//200,24*64,device=signal.device,dtype=torch.bfloat16) + code_fusion,code_covariance=self.backbone.codebrain_correction(tokens,representation,fusion_input) + coactivation=self.backbone.wave_coactivation(representation) + with torch.autocast(signal.device.type,enabled=False): + ordinal=self.adapters[t].ordinal_embedding(ordinal_features(t,x)) + ordinal_covariance=self.backbone.ordinal_context(ordinal.float()) + added=.001*nn.functional.linear(ordinal_covariance,self.backbone.covariance_projection.weight,None) + ordinal_fusion=self.backbone.fusion(fusion_input+added.to(fusion_input.dtype))-representation[:,-512:-384] + phase=self.phase_embedding(t,phase_features(t,x,self.adapters[t].spatial_weight)) + coupling=self.coupling_embedding(t,coupling_features(t,x)) + student=self.student_embedding(t,self.student_features(t,x)) + return self.heads[t](torch.cat([representation,fusion_delta,covariance_delta,code_fusion,code_covariance,coactivation,ordinal_fusion,ordinal_covariance,phase,coupling,student],-1)) + +def widen_state_dict(state,multiplier=2): + """Duplicate temporal features and divide downstream sums to preserve outputs.""" + result={} + for key,value in state.items(): + if key.startswith('backbone.waveform.'): + layer=int(key.split('.')[2]) + if layer in (0,2,7):value=value.repeat(multiplier,1,1,1) + elif layer in (1,3,9):value=value.repeat(multiplier) + elif layer==8:value=value.repeat(multiplier,multiplier,1,1)/multiplier + elif key=='backbone.wave_summary.2.weight':value=value.repeat(1,multiplier)/multiplier + elif key.startswith('heads.') and key.endswith('.weight'): + raw=value[:,:-128]/multiplier + value=torch.cat([raw]*multiplier+[value[:,-128:]],1) + result[key]=value + return result + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/alpha_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/alpha_features.py new file mode 100644 index 0000000000000000000000000000000000000000..455154d715e86d45e4e17113bed69adbcd946b29 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/alpha_features.py @@ -0,0 +1,45 @@ +"""Fixed alpha prominence features from each individual two-second window.""" +import torch + +REGION_NAMES=('occipital','parietal','central','frontal','left_posterior','right_posterior') +REGIONS=(('PO7','PO5','PO3','POZ','PO4','PO6','PO8','O1','OZ','O2'), + ('P7','P5','P3','P1','PZ','P2','P4','P6','P8'), + ('FC5','FC3','FC1','FCZ','FC2','FC4','FC6','C5','C3','C1','CZ','C2','C4','C6'), + ('FP1','FPZ','FP2','AF3','AF4','F7','F5','F3','F1','FZ','F2','F4','F6','F8'), + ('P7','P5','P3','P1','PO7','PO5','PO3','O1'), + ('P2','P4','P6','P8','PO4','PO6','PO8','O2')) +ALPHA_DIM=58*7+6*22 + +def region_matrix(channels): + result=torch.zeros(len(REGIONS),len(channels)) + for i,names in enumerate(REGIONS): + for name in names:result[i,channels.index(name)]=1/len(names) + return result.tolist() + +@torch.no_grad() +def extract_alpha_features(signal,regions): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();x=x-x.mean(-1,keepdim=True) + spectrum=torch.fft.rfft(x*torch.hann_window(400,device=x.device),dim=-1)/200 + power=spectrum.abs().square().clamp_min(1e-12) + lp=power.log() + # Geometric regional means resist domination by one high-amplitude channel. + regional=torch.einsum('rc,ncf->nrf',regions.float(),lp) + lp=torch.cat([lp,regional],1) + low=lp[...,8:13].mean(-1,keepdim=True) + high=lp[...,36:49].mean(-1,keepdim=True) + freq=torch.arange(7.,14.5,.5,device=x.device) + alpha=lp[...,14:29] + baseline=low+(high-low)*((freq-5)/16) + prominence=alpha-baseline + normalized=alpha.softmax(-1) + center=(normalized*freq).sum(-1) + entropy=-(normalized*normalized.clamp_min(1e-12).log()).sum(-1) + alpha_mean=torch.logsumexp(alpha,-1)-torch.log(torch.tensor(15.,device=x.device)) + def log_band(lo,hi): + return torch.logsumexp(lp[...,lo:hi],-1)-torch.log(torch.tensor(float(hi-lo),device=x.device)) + summaries=torch.stack([alpha_mean-log_band(2,81),alpha_mean-log_band(8,14), + alpha_mean-log_band(30,61),prominence.max(-1).values, + prominence.mean(-1),center,entropy],-1) + return torch.cat([summaries[:,:58].flatten(1),summaries[:,58:].flatten(1), + prominence[:,58:].flatten(1)],1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/config.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/config.json new file mode 100644 index 0000000000000000000000000000000000000000..9f73d0186bf28b0e9e653ab1aeb570a9cfc67c06 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/config.json @@ -0,0 +1,833 @@ +{ + "schema": "bci-shared-biot-covariance-bf16head-v1", + "architecture": { + "channels": 32, + "width": 128, + "depth": 2, + "dropout": 0.5, + "wave_filters": 32, + "head_width": 64, + "head_dropout": 0.3, + "clinical_asymmetry": true, + "alpha_regions": [ + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.125 + ] + ], + "clinical_envelope": true, + "temporal_pool": true, + "temporal_evidence": true, + "evidence_temperature": 0.25, + "random_fourier": true, + "fourier_features": 256, + "tangent_readout": true, + "shared_context_correction": true, + "wave_coactivation": true, + "ordinal_context": true, + "phase_coherence": true, + "cross_frequency": true, + "cbramod_feature_transfer": true, + "student_architecture": { + "virtual_channels": 32, + "token_width": 64, + "summary_width": 256, + "head_width": 128, + "dropout": 0.3 + } + }, + "initialization": { + "initialization": "continue joint training from a complete shared-model checkpoint", + "parent": "/workspace/research/runs/hybrid_biot_fusionshrink0100/epoch-001/weights.pt", + "parent_initialization": { + "initialization": "jointly trained parent plus audited pretrained BIOT in a single coupled backbone", + "parent": "/workspace/research/runs/hybrid_wide1/epoch-004/weights.pt", + "audited_biot": { + "initialization": "pretrained", + "repo": "braindecode/biot-pretrained-six-datasets-18chs", + "revision": "7e9aabf302870012f73773276803aab97993951c", + "sha256": "a218f4054ae29962c6fd9d23d94c446d354c4f53e805a6771c85749ccc20baaa", + "license": "BSD-3-Clause", + "source_braindecode": "1.3.0", + "loaded_core_tensors": 56, + "skipped_classifier_tensors": 3 + }, + "neural_channel_indices": { + "faced": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "tuev": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15 + ], + "ad65": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "openbmi": [ + 0, + 1, + 3, + 5, + 12, + 14, + 23, + 25, + 28, + 30, + 2, + 6, + 11, + 15, + 22, + 26, + 4, + 13 + ], + "longitudinal": [ + 0, + 2, + 7, + 11, + 23, + 27, + 41, + 45, + 55, + 57, + 5, + 13, + 21, + 29, + 39, + 47, + 9, + 25 + ] + }, + "rebase": "incumbent waveform, fusion and four heads; joint BIOT and TUEV head from readout epoch 9; zero initialized neural interaction", + "jointly_finetuned_neural_parent": "/workspace/research/runs/hybrid_biot_readout1/epoch-009/weights.pt", + "tuev_high_dimensional_spectral_projection_disabled": true, + "frozen_prior_representation": true, + "nonclinical_head_updates": "only the 256 added BIOT columns; original columns and biases fixed", + "faced_openbmi_neural_path": "common nonlinear fusion only; direct head columns masked", + "retention_teacher": "/workspace/research/runs/hybrid_wide1/epoch-004", + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "joint_covariance_parent": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "frozen_prior_representation": true, + "head_updates": "one linear head per track; added 128 shared covariance columns trainable; AD head initialized from the joint covariance parent", + "new_shared_representation": "one common covariance MLP inside the coupled backbone, trained by all five tasks; fixed spatial input adapters from the same jointly trained source", + "head_arithmetic": "one linear head evaluated in fixed feature blocks to preserve original bfloat16 accumulation dimensions", + "retention_teacher": { + "ad65": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "other_tracks": "/workspace/research/runs/hybrid_wide1/epoch-004" + }, + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "loader_scale": 0.01, + "tracks": [ + "faced", + "tuev", + "ad65", + "openbmi", + "longitudinal" + ], + "head_arithmetic": "same linear head in fixed feature blocks, sum in bfloat16 on GPU for non-AD tracks; AD remains float32", + "head_refinement": { + "source": "/workspace/research/runs/residual_heads1/epoch-018", + "source_weights_sha256": "e0b609137391b47f99438ccadaa22fc0bc10d2c10ead0ddf0a3c25be2c907c85", + "shared_backbone_unchanged": true, + "selected_head_epochs": { + "faced": 5, + "tuev": 24, + "ad65": 0, + "openbmi": 0, + "longitudinal": 0 + } + }, + "clinical_spectral_refinement": { + "source": "/workspace/research/runs/head_dropout1/epoch-016", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "head_estimation": { + "method": "class/subject-balanced Gaussian linear discriminant; covariance augmented by class-conditional subject/session mean variation before shrinkage", + "selected_shrinkage": { + "faced": "inherited", + "tuev": "inherited", + "ad65": "inherited", + "openbmi": "inherited", + "longitudinal": { + "shrinkage": 0.9, + "domain_strength": 1.0 + } + }, + "feature_scaling": "fitted on training data and folded into linear coefficients" + }, + "clinical_asymmetry_refinement": { + "source": "/workspace/research/runs/domain_lda_heads1/epoch-001", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "alpha_rhythm_adapter": { + "training_normalization_only": true, + "regions": [ + "occipital", + "parietal", + "central", + "frontal", + "left_posterior", + "right_posterior" + ], + "features": "per-window alpha prominence relative to adjacent frequencies", + "shared_backbone_unchanged": true + }, + "clinical_envelope_refinement": { + "source": "/workspace/research/runs/clinical_asymmetry1/epoch-001", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "independent_adapter_merge": { + "alpha_source": "/workspace/research/runs/alpha_calibrated1/epoch-003", + "clinical_source": "/workspace/research/runs/clinical_envelope1/epoch-002", + "all_shared_and_head_tensors_equal": true + }, + "frequency_montage_refinement": { + "six_frequency_bands": true, + "shared_encoder_unchanged": true, + "selected_track_epochs": { + "faced": 0, + "tuev": 1, + "ad65": 0, + "openbmi": 10, + "longitudinal": 2 + } + }, + "private_track_selection": { + "track": "tuev", + "donor": "/workspace/research/replicates/frequency_head_control1/epoch-001" + }, + "clinical_sampling_refinement": { + "subject_exponent": 0.0, + "class_balanced": true, + "only_clinical_head_updated": true + }, + "temporal_statistics_readout": { + "statistics": [ + "mean", + "standard deviation", + "maximum", + "minimum" + ], + "shared_encoder_and_prior_heads_unchanged": true, + "selected_pool_epochs": { + "faced": 2, + "tuev": 0, + "ad65": 0, + "openbmi": 33, + "longitudinal": 3 + } + }, + "temporal_evidence_readout": { + "pooling": "log mean exp of per-patch class evidence", + "temperature": 0.25, + "shared_encoder_and_prior_heads_unchanged": true, + "selected_evidence_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 6, + "longitudinal": 8 + } + }, + "fourier_basis_readout": { + "basis_functions": 256, + "bandwidths": [ + 0.5, + 1.0, + 2.0 + ], + "shared_encoder_and_prior_heads_unchanged": true, + "selected_fourier_epochs": { + "faced": 21, + "tuev": 0, + "ad65": 0, + "openbmi": 0, + "longitudinal": 2 + } + }, + "shared_tangent_readout": { + "one_shared_tangent_module": true, + "original_and_corrected_shared_features_retained": true, + "private_head_scalar_gains": { + "faced": 0.0, + "tuev": 0.1, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 0.1 + }, + "all_common_weights_fixed_during_gain_refinement": true + }, + "shared_context_correction": { + "source": "/workspace/research/runs/hybrid_codebrain_fusion_control1/epoch-002", + "zero_token_input_preserved": true, + "unused_native_CodeBrain_core_and_input_parameters_removed": true, + "common_patch_and_context_layers_retained": true, + "same_one_shared_backbone_and_five_classifiers": true + }, + "shared_wave_coactivation": { + "channels": 64, + "statistics": 2080, + "diagonal_only_control": false, + "common_encoder_updated_by_all_five_tracks": true, + "gain_selection_within_one_common_checkpoint": { + "faced": 1.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 1.0 + } + }, + "fixed_common_coactivation_readouts": { + "all_common_weights_exactly_unchanged": true, + "selected_private_epochs": { + "faced": 25, + "tuev": 0, + "ad65": 0, + "openbmi": 8, + "longitudinal": 2 + } + }, + "shared_ordinal_context": { + "per_channel_features": 130, + "normalization_fit_on_training_only": true, + "entropy_only_control": false, + "new_common_layers_trained_on_all_five_tracks": true, + "gains_within_one_common_checkpoint": { + "faced": 1.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 0.0 + } + }, + "shared_complex_coherence": { + "features": 5520, + "normalization_fit_on_training_only": true, + "real_only_control": false, + "all_five_tracks_update_common_encoder": true, + "gains_within_one_common_checkpoint": { + "faced": 0.1, + "tuev": 1.0, + "ad65": 0.0, + "openbmi": 0.3, + "longitudinal": 0.0 + } + }, + "shared_cross_frequency": { + "per_channel_features": 30, + "normalization_fit_on_training_only": true, + "amplitude_only_control": false, + "all_five_tracks_update_common_encoder": true, + "gains_within_one_common_checkpoint": { + "faced": 0.3, + "tuev": 0.1, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 0.0 + } + }, + "inherited_private_readout_refresh": { + "child": "/workspace/research/runs/coupling_patient1/epoch-007", + "donor": "/workspace/research/runs/phase_readout1/epoch-016", + "common_ancestor": "/workspace/research/runs/phase_coherence1/epoch-007", + "source_weight_sha256": { + "child": "f8466c6838ff01e54d1619f55668c1a4af26a243b54c67a956a3422d9604632a", + "donor": "ffd219d1480b81720b5aa4014cb2ed2b9cd31b7c92ad4717abc2a9625d30dc1a", + "ancestor": "e53ede409be523d8f4746251f7d46353621049f0378a88d4f7cfe2ba71a57d95" + }, + "changed_private_tensors": [ + "heads.openbmi.prior.projection.weight", + "heads.openbmi.prior.projection.bias" + ], + "all_ancestor_common_and_input_tensors_equal": true, + "all_child_common_and_input_tensors_unchanged": true, + "new_branch_gain_for_refreshed_track": 0.0, + "donor_changes_only_requested_private_projection": true, + "prediction_sources": { + "faced": { + "source": "/workspace/research/runs/coupling_patient1/faced-e007.npy", + "sha256": "68b617c8ecf347c79b23c20b70f6b4981c2f26b7b8c71dc7cd5fa0d7f4285ea6" + }, + "tuev": { + "source": "/workspace/research/runs/coupling_patient1/tuev-e007.npy", + "sha256": "9f0743450f1104d395e9daac0600aaf20755b5590b9f5c3e3137732c479dd647" + }, + "ad65": { + "source": "/workspace/research/runs/coupling_patient1/ad65-e007.npy", + "sha256": "7a3b74c58580b7ba952322bf6d527ebc9a40a6e04c7cdbbaea14e84a7a298d54" + }, + "openbmi": { + "source": "/workspace/research/runs/phase_readout1/openbmi-e016.npy", + "sha256": "14f630543e1df88c88d8f3e0effb4506ba33f533b3484de3c7aaf6554507341c" + }, + "longitudinal": { + "source": "/workspace/research/runs/coupling_patient1/longitudinal-e007.npy", + "sha256": "e93b0a319eaa3ddca9d71b0e786b808ba1630c1d3ce125f8e08036e517741b74" + } + } + }, + "shared_student_residual": { + "dimension": 8448, + "summary_dimension": 256, + "ordered_time_bins": 4, + "student_weights_sha256": "19dfe912cceed997699b5b526c8c2ece55945c5f9bd111c4c13704d0fc460e8b", + "summary_only_control": false, + "normalization_fit_on_training_only": true, + "new_common_readout_jointly_trained_on_all_five": true, + "class_projection_initialized_zero": true, + "student_classifiers_discarded": true, + "gains_within_one_common_checkpoint": { + "faced": 1.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 1.0 + }, + "zero_gain_preserves_complete_parent": true + }, + "fixed_common_student_readouts": { + "all_common_weights_exactly_unchanged": true, + "selected_private_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 0, + "longitudinal": 1 + } + } +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/coupling_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/coupling_features.py new file mode 100644 index 0000000000000000000000000000000000000000..3a4e51bd7ce07bcec1f0f5b80054d6ff387ac87f --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/coupling_features.py @@ -0,0 +1,34 @@ +"""Per-window cross-frequency envelope and phase-amplitude relationships.""" +import torch +BANDS=((1,4),(4,8),(8,13),(13,30),(30,48)) +PAIRS=tuple((i,j) for i in range(5) for j in range(i+1,5)) +PER_CHANNEL=30 + +@torch.no_grad() +def coupling_features(track,x): + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + n=x.shape[-1];spectrum=torch.fft.fft(x,dim=-1);frequency=torch.fft.fftfreq(n,1/200,device=x.device) + masks=torch.stack([2*((frequency>=lo)&(frequency=lo)&(frequency2).float().mean(-1),(relative>4).float().mean(-1), + ((relative[...,1:]>2)&(relative[...,:-1]<=2)).float().mean(-1), + acf_peak,(acf_index.float()+4)/40, + acf[...,0],acf[...,6],acf[...,16],acf[...,36]] + left=torch.tensor([0,1,2,3,8,9,10,11],device=x.device);right=left+4 + synchrony=(normalized[:,left]*normalized[:,right]).mean(-1).clamp(-1,1) + imbalance=(std[:,left].squeeze(-1).log()-std[:,right].squeeze(-1).log()).abs() + return torch.cat([torch.stack(summaries,-1).flatten(1),synchrony.flatten(1),imbalance.flatten(1)],1) + +def mirrored_features(features): + channels=torch.tensor([4,5,6,7,0,1,2,3,12,13,14,15,8,9,10,11],device=features.device) + return torch.cat([features[:,:16*5*12].reshape(-1,16,5,12)[:,channels].flatten(1),features[:,16*5*12:]],1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/features.py new file mode 100644 index 0000000000000000000000000000000000000000..88f7e8b14c9fab44733d5224ede6d6b5c7f76a45 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/features.py @@ -0,0 +1,63 @@ +"""One shared residual backbone, five linear input adapters and output heads.""" +import torch +from torch import nn + +SPECS = {'faced': (32, 10, 9), 'tuev': (16, 5, 6), 'ad65': (19, 10, 3), + 'openbmi': (62, 4, 2), 'longitudinal': (58, 2, 2)} +TRACKS = tuple(SPECS) +EDGES = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,18,20,22,25,28,32,36,40,45,50,60,70,80,95] +COV_BANDS = [(1,4),(4,8),(8,12),(12,16),(16,20),(20,28),(28,40)] + +def feature_dim(channels): + return channels * (4*(len(EDGES)-1)+4) + len(COV_BANDS)*channels*(channels-1)//2 + +@torch.no_grad() +def extract_features(track, x): + """Fixed features; no batch statistics or fitted inference transformations.""" + x = x.float().flatten(2) + x = torch.nan_to_num(x, nan=0., posinf=1e5, neginf=-1e5).clamp(-1e5,1e5) + x = x - x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'): + x = x - x.mean(1,keepdim=True) + rms = x.square().mean(-1).clamp_min(1e-12).sqrt() + norm = x / rms.unsqueeze(-1) + moments = torch.stack([rms.log(), norm.abs().amax(-1).clamp_min(1).log(), + norm.pow(4).mean(-1).clamp_min(1).log(), + (norm[...,1:]-norm[...,:-1]).square().mean(-1).clamp_min(1e-10).log()],-1) + frames = x.unfold(-1,400,200) + frames = frames - frames.mean(-1,keepdim=True) + window = torch.hann_window(400,device=x.device) + z = torch.fft.rfft(frames*window,dim=-1)/200 + power = z.abs().square() + bands = torch.stack([power[...,2*lo:2*hi].mean(-1) for lo,hi in zip(EDGES[:-1],EDGES[1:])],-1) + lp = bands.mean(-2).clamp_min(1e-12).log() + variation = bands.clamp_min(1e-12).log().std(-2,correction=0) + relative_frequency = lp - lp.mean(-1,keepdim=True) + relative_channel = lp - lp.mean(1,keepdim=True) + parts = [torch.cat([lp, relative_frequency, relative_channel, variation, moments],-1).flatten(1)] + ii,jj = torch.triu_indices(x.shape[1],x.shape[1],offset=1,device=x.device) + for lo,hi in COV_BANDS: + v = z[...,2*lo:2*hi].flatten(2) + cov = v.real @ v.real.transpose(-1,-2) + v.imag @ v.imag.transpose(-1,-2) + d = cov.diagonal(dim1=-2,dim2=-1).clamp_min(1e-12).sqrt() + cor = cov / (d.unsqueeze(1)*d.unsqueeze(2)).clamp_min(1e-12) + parts.append(cor[:,ii,jj].clamp(-1,1)) + result = torch.cat(parts,-1) + return torch.nan_to_num(result).clamp(-40,40) + +class Standardize(nn.Module): + def __init__(self, dim): + super().__init__() + self.register_buffer('mean',torch.zeros(dim)) + self.register_buffer('scale',torch.ones(dim)) + def forward(self,x): + return ((x-self.mean)/self.scale).clamp(-8,8) + +class Residual(nn.Module): + def __init__(self,width,dropout): + super().__init__() + self.net=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(), + nn.Dropout(dropout),nn.Linear(width*2,width),nn.Dropout(dropout)) + def forward(self,x): + return x+self.net(x) + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/frequency_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/frequency_features.py new file mode 100644 index 0000000000000000000000000000000000000000..9194c9e81f801b3833e551e4967991774fa9e398 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/frequency_features.py @@ -0,0 +1,11 @@ +"""Fixed per-window frequency decomposition for a linear montage adapter.""" +import torch + +FREQUENCY_BANDS=((1,4),(4,8),(8,13),(13,20),(20,30),(30,45)) + +def frequency_components(signal): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();spectrum=torch.fft.rfft(x,dim=-1) + frequency=torch.fft.rfftfreq(x.shape[-1],d=1/200,device=x.device) + masks=torch.stack([((frequency>=lo)&(frequencynbf',w,covariances.float(),w).clamp_min(1e-8).log() + return torch.cat([power,power-power.mean(1,keepdim=True)],1).flatten(1) + def wave_signal(self,x,components=None): + if components is None:components=frequency_components(x) + correction=torch.einsum('blc,nbct->nlt',self.frequency_weight,components.to(self.frequency_weight.dtype)) + return (self.signal(x)+correction.to(x.dtype)).unsqueeze(1) + def forward(self,x,features,covariance_features): + return self.wave_signal(x),self.spectral_features(features,signal=x),self.neural(x),covariance_features + +class SharedBackbone(nn.Module): + def __init__(self,channels,width,depth,dropout,wave_filters): + super().__init__() + self.waveform=nn.Sequential( + nn.Conv2d(1,wave_filters,(1,64),padding=(0,32),bias=False),nn.GroupNorm(1,wave_filters), + nn.Conv2d(wave_filters,2*wave_filters,(channels,1),groups=wave_filters,bias=False),nn.GroupNorm(1,2*wave_filters),nn.ELU(), + nn.AvgPool2d((1,4)),nn.Dropout(.35), + nn.Conv2d(2*wave_filters,2*wave_filters,(1,16),padding=(0,8),groups=2*wave_filters,bias=False),nn.Conv2d(2*wave_filters,2*wave_filters,1,bias=False), + nn.GroupNorm(1,2*wave_filters),nn.ELU(),nn.AvgPool2d((1,8)),nn.Dropout(.35)) + self.wave_summary=nn.Sequential(nn.AdaptiveAvgPool2d((1,8)),nn.Flatten(),nn.Linear(2*wave_filters*8,width)) + self.fusion=nn.Sequential(nn.LayerNorm(width),nn.GELU(),nn.Dropout(dropout), + *[Residual(width,dropout) for _ in range(depth)],nn.LayerNorm(width)) + # Both representations interact before the shared residual stack. + self.phase_encoder=nn.Sequential(nn.LayerNorm(PHASE_DIM),nn.Linear(PHASE_DIM,width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width)) + self.register_buffer('phase_imaginary_enabled',torch.ones(())) + self.coupling_encoder=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width),nn.LayerNorm(width)) + self.wave_gain=nn.Parameter(torch.tensor(.1)) + self.biot=BIOT(n_chans=18,n_outputs=2,n_times=400,sfreq=200) + self.biot.final_layer=nn.Identity() + self.biot_projection=nn.Sequential(nn.LayerNorm(256),nn.Linear(256,width),nn.Dropout(.2)) + nn.init.normal_(self.biot_projection[1].weight,std=.001);nn.init.zeros_(self.biot_projection[1].bias) + self.covariance_encoder=nn.Sequential(nn.LayerNorm(len(BANDS)*24*2),nn.Linear(len(BANDS)*24*2,width),nn.GELU(),nn.Dropout(.4), + *[Residual(width,.4) for _ in range(2)],nn.LayerNorm(width)) + self.covariance_projection=nn.Linear(width,width) + nn.init.zeros_(self.covariance_projection.weight);nn.init.zeros_(self.covariance_projection.bias) + self.tangent_encoder=nn.Sequential(nn.LayerNorm(TANGENT_DIM),nn.Linear(TANGENT_DIM,width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width),nn.Linear(width,width)) + self.ordinal_context=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width)) + nn.init.zeros_(self.ordinal_context[-1].weight);nn.init.zeros_(self.ordinal_context[-1].bias) + self.register_buffer('codebrain_enabled',torch.ones(())) + self.codebrain_patch_encoder=nn.Sequential(nn.LayerNorm(24*64),nn.Linear(24*64,width),nn.GELU(),nn.Dropout(.3)) + self.codebrain_context=nn.Sequential(nn.LayerNorm(width*4),nn.Linear(width*4,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width)) + nn.init.zeros_(self.codebrain_context[-1].weight);nn.init.zeros_(self.codebrain_context[-1].bias) + def codebrain_correction(self,tokens,representation,fusion_input): + with torch.autocast(tokens.device.type,enabled=False): + encoded=self.codebrain_patch_encoder(self.codebrain_enabled*tokens.float()) + pooled=torch.cat([encoded.mean(1),encoded.std(1,correction=0),representation[:,-512:-384].float(),representation[:,-128:].float()],-1) + delta=self.codebrain_context(pooled) + added=.001*nn.functional.linear(delta,self.covariance_projection.weight,None) + corrected=self.fusion(fusion_input+added.to(fusion_input.dtype)) + return corrected-representation[:,-512:-384],delta + def forward(self,signal,spectral,neural_signal,covariance_features,tangent_features): + wave=self.waveform(signal) + neural=self.biot(neural_signal.float()) + neural=self.biot_projection[0](neural) + projected=self.biot_projection[2](self.biot_projection[1](neural)) + with torch.autocast(signal.device.type,enabled=False): + covariance_embedding=self.covariance_encoder(covariance_features.float()) + original=spectral+self.wave_gain*self.wave_summary(wave)+.01*projected + coupled=.001*self.covariance_projection(covariance_embedding).to(original.dtype) + fused=self.fusion(original+coupled) + with torch.autocast(signal.device.type,enabled=False):delta=self.tangent_encoder(tangent_features.float()) + added=.001*nn.functional.linear(delta,self.covariance_projection.weight,None) + corrected=self.fusion((original+coupled)+added.to(original.dtype)) + return torch.cat([wave.flatten(1),fused,neural,covariance_embedding],-1),corrected-fused,delta,original+coupled + +class ResidualHead(nn.Module): + """A small nonlinear classifier correction around an inherited linear readout.""" + def __init__(self,features,classes,width=64,dropout=.3,full_precision=False): + super().__init__();self.full_precision=full_precision + self.base=nn.Linear(features,classes) + self.delta=nn.Sequential(nn.LayerNorm(features),nn.Linear(features,width),nn.GELU(),nn.Dropout(dropout),nn.Linear(width,classes)) + nn.init.zeros_(self.delta[-1].weight);nn.init.zeros_(self.delta[-1].bias) + def forward(self,x): + if self.full_precision: + with torch.autocast(x.device.type,enabled=False):return self.base(x.float())+self.delta(x.float()) + prior=nn.functional.linear(x[:,:-128].contiguous(),self.base.weight[:,:-128].contiguous(),self.base.bias) + added=nn.functional.linear(x[:,-128:].contiguous(),self.base.weight[:,-128:].contiguous()) + value=prior+added + return value+self.delta(x).to(value.dtype) + +class TemporalPoolHead(nn.Module): + def __init__(self,prior,channels=64): + super().__init__();self.prior=prior;self.channels=channels + self.register_buffer('pool_output_scale',torch.ones(()));self.register_buffer('pool_mean',torch.zeros(channels*4));self.register_buffer('pool_scale',torch.ones(channels*4)) + self.pool_projection=nn.Linear(channels*4,prior.base.out_features) + nn.init.zeros_(self.pool_projection.weight);nn.init.zeros_(self.pool_projection.bias) + def statistics(self,x): + with torch.autocast(x.device.type,enabled=False): + wave=x[:,:-512].float().reshape(len(x),self.channels,-1) + return torch.cat([wave.mean(-1),wave.std(-1,correction=0),wave.amax(-1),wave.amin(-1)],-1) + def forward(self,x): + prior=self.prior(x) + with torch.autocast(x.device.type,enabled=False): + values=((self.statistics(x)-self.pool_mean)/self.pool_scale).clamp(-8,8) + added=self.pool_output_scale*self.pool_projection(values) + return prior+added.to(prior.dtype) + +class TemporalEvidenceHead(nn.Module): + """Pool class evidence over the shared waveform time axis.""" + def __init__(self,prior,channels=64,temperature=.25): + super().__init__();self.prior=prior;self.channels=channels;self.temperature=temperature + self.register_buffer('evidence_output_scale',torch.ones(())) + self.register_buffer('evidence_mean',torch.zeros(channels)) + self.register_buffer('evidence_scale',torch.ones(channels)) + self.evidence_projection=nn.Linear(channels,prior.prior.base.out_features,bias=False) + nn.init.zeros_(self.evidence_projection.weight) + def patches(self,x): + with torch.autocast(x.device.type,enabled=False): + wave=x[:,:-512].float().reshape(len(x),self.channels,-1).transpose(1,2) + return ((wave-self.evidence_mean)/self.evidence_scale).clamp(-8,8) + def evidence(self,patches): + with torch.autocast(patches.device.type,enabled=False): + values=self.evidence_projection(patches.float())/self.temperature + maximum=values.amax(1,keepdim=True) + pooled=self.temperature*((values-maximum).exp().mean(1).log()+maximum.squeeze(1)) + return self.evidence_output_scale*pooled + def forward(self,x): + prior=self.prior(x) + return prior+self.evidence(self.patches(x)).to(prior.dtype) + +class FourierResidualHead(nn.Module): + """A fixed random Fourier basis and trainable linear classifier correction.""" + def __init__(self,prior,features,classes,basis=256): + super().__init__();self.prior=prior + self.register_buffer('rff_mean',torch.zeros(features));self.register_buffer('rff_scale',torch.ones(features)) + self.register_buffer('rff_frequency',torch.randn(features,basis)/features**.5) + self.register_buffer('rff_phase',torch.rand(basis)*2*torch.pi) + self.register_buffer('rff_output_scale',torch.ones(())) + self.rff_projection=nn.Linear(3*basis,classes);nn.init.zeros_(self.rff_projection.weight);nn.init.zeros_(self.rff_projection.bias) + def basis(self,x): + with torch.autocast(x.device.type,enabled=False): + values=((x.float()-self.rff_mean)/self.rff_scale).clamp(-8,8)@self.rff_frequency + return 2**.5*torch.cat([(values/sigma+self.rff_phase).cos() for sigma in (.5,1.,2.)],-1) + def forward(self,x): + prior=self.prior(x) + with torch.autocast(x.device.type,enabled=False):added=self.rff_output_scale*self.rff_projection(self.basis(x)) + return prior+added.to(prior.dtype) + +class TangentFeatureHead(nn.Module): + """Select a shared feature correction before the inherited classifier.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.feature_gain=nn.Parameter(torch.zeros(())) + def forward(self,values): + old=values[:,:-256];fusion_delta=values[:,-256:-128];covariance_delta=values[:,-128:] + adjusted=torch.cat([old[:,:-512],old[:,-512:-384]+self.feature_gain*fusion_delta,old[:,-384:-128],old[:,-128:]+self.feature_gain*covariance_delta],-1) + return self.prior(adjusted) + +class CodeBrainFeatureHead(nn.Module): + """Private use of a jointly trained common feature correction.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.codebrain_gain=nn.Parameter(torch.ones(())) + def forward(self,values): + previous=values[:,:-256];native=previous[:,:-256] + fusion_delta=values[:,-256:-128];covariance_delta=values[:,-128:] + adjusted=torch.cat([native[:,:-512],native[:,-512:-384]+self.codebrain_gain*fusion_delta,native[:,-384:-128],native[:,-128:]+self.codebrain_gain*covariance_delta],-1) + return self.prior(torch.cat([adjusted,previous[:,-256:]],-1)) + +class WaveCoactivationContext(nn.Module): + """One common encoder of coactivation among the learned waveform channels.""" + def __init__(self,channels=64,width=128): + super().__init__();self.channels=channels + ii,jj=torch.triu_indices(channels,channels,offset=1) + self.register_buffer('pair_i',ii);self.register_buffer('pair_j',jj) + self.register_buffer('offdiagonal_enabled',torch.ones(())) + self.encoder=nn.Sequential(nn.LayerNorm(channels+len(ii)),nn.Linear(channels+len(ii),width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width)) + def statistics(self,native): + with torch.autocast(native.device.type,enabled=False): + wave=native[:,:-512].float().reshape(len(native),self.channels,-1) + centered=wave-wave.mean(-1,keepdim=True) + previous_tf32=torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32=False + covariance=centered@centered.transpose(-1,-2)/wave.shape[-1] + torch.backends.cuda.matmul.allow_tf32=previous_tf32 + variance=covariance.diagonal(dim1=-2,dim2=-1).clamp_min(1e-8) + correlation=covariance/(variance.sqrt()[:,:,None]*variance.sqrt()[:,None,:]) + return torch.cat([variance.log(),correlation[:,self.pair_i,self.pair_j].clamp(-1,1)],-1) + def encode_statistics(self,values): + with torch.autocast(values.device.type,enabled=False): + value=torch.cat([values[:,:self.channels],self.offdiagonal_enabled*values[:,self.channels:]],-1) + return self.encoder(value.float()) + def forward(self,native):return self.encode_statistics(self.statistics(native)) + +class WaveCoactivationHead(nn.Module): + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=self.correction_gain*self.output_scale*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class OrdinalFeatureHead(nn.Module): + """Private strength of one common ordinal-dynamics feature correction.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.ordinal_gain=nn.Parameter(torch.ones(())) + def forward(self,values): + previous=values[:,:-256];native=previous[:,:-640] + adjusted=torch.cat([native[:,:-512],native[:,-512:-384]+self.ordinal_gain*values[:,-256:-128],native[:,-384:-128],native[:,-128:]+self.ordinal_gain*values[:,-128:],previous[:,-640:]],-1) + return self.prior(adjusted) + +class PhaseReadoutHead(nn.Module): + """Private class evidence from the common complex-coherence encoder.""" + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=(self.correction_gain*self.output_scale)*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class CouplingReadoutHead(nn.Module): + """Private class evidence from the common cross-frequency coupling encoder.""" + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=(self.correction_gain*self.output_scale)*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class HybridModel(nn.Module): + def __init__(self,channels=32,width=128,depth=2,dropout=.5,wave_filters=32,head_width=64,head_dropout=.3,clinical_asymmetry=True,alpha_regions=None,clinical_envelope=False,temporal_pool=True,temporal_evidence=False,evidence_temperature=.25,random_fourier=False,fourier_features=256,tangent_readout=True,shared_context_correction=True,wave_coactivation=True,ordinal_context=True,phase_coherence=True,cross_frequency=True,cbramod_feature_transfer=True,student_architecture=None): + super().__init__() + self.adapters=nn.ModuleDict({t:InputAdapter(c,width,channels,spectral_enabled=t not in ("faced","tuev","openbmi"),asymmetry=clinical_asymmetry and t=="tuev",alpha_regions=alpha_regions if t=="longitudinal" else None,envelope=clinical_envelope and t=="tuev") for t,(c,s,k) in SPECS.items()}) + self.backbone=SharedBackbone(channels,width,depth,dropout,wave_filters) + self.backbone.student_encoder=CBraModFeatures(**(student_architecture or {})) + self.backbone.register_buffer('student_ordered_enabled',torch.ones(())) + self.backbone.student_readout=nn.Sequential(nn.Linear(self.backbone.student_encoder.output_dim,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + for t,(c,s,k) in SPECS.items(): + self.adapters[t].student_input=FrequencyAdapter(c,32) + self.adapters[t].student_normalizer=Standardize(self.backbone.student_encoder.output_dim) + self.backbone.wave_coactivation=WaveCoactivationContext(2*wave_filters,width) + self.heads=nn.ModuleDict({t:ResidualHead(2*wave_filters*(((s*200+1)//4+1)//8)+width+256+width,k,head_width,head_dropout,full_precision=t=='ad65') for t,(c,s,k) in SPECS.items()}) + if temporal_pool:self.heads=nn.ModuleDict({t:TemporalPoolHead(head,wave_filters*2) for t,head in self.heads.items()}) + if temporal_evidence:self.heads=nn.ModuleDict({t:TemporalEvidenceHead(head,wave_filters*2,evidence_temperature) for t,head in self.heads.items()}) + if random_fourier:self.heads=nn.ModuleDict({t:FourierResidualHead(head,2*wave_filters*(((SPECS[t][1]*200+1)//4+1)//8)+width+256+width,SPECS[t][2],fourier_features) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:TangentFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CodeBrainFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:WaveCoactivationHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:OrdinalFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:PhaseReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + def student_features(self,t,x): + outputs=[];old_fastpath=torch.backends.mha.get_fastpath_enabled();torch.backends.mha.set_fastpath_enabled(False) + try: + for raw in x.split(16): + signal=torch.nan_to_num(raw.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + with torch.autocast(signal.device.type,dtype=torch.bfloat16,enabled=signal.device.type=='cuda'): + outputs.append(self.backbone.student_encoder(self.adapters[t].student_input(signal))) + finally:torch.backends.mha.set_fastpath_enabled(old_fastpath) + return torch.cat(outputs).float() + def student_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].student_normalizer(values.float()) + normalized=torch.cat([normalized[:,:256],self.backbone.student_ordered_enabled*normalized[:,256:]],-1) + return self.backbone.student_readout(normalized) + def coupling_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False):return self.backbone.coupling_encoder(self.adapters[t].coupling_embedding(values.float())) + def phase_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].phase_normalizer(values.float()) + normalized=torch.cat([normalized[:,:PHASE_HALF],self.backbone.phase_imaginary_enabled*normalized[:,PHASE_HALF:]],-1) + return self.backbone.phase_encoder(normalized) + def forward(self,t,x,features=None,covariances=None,covariance_features=None): + if features is None:features=extract_features(t,x) + if covariance_features is None: + if covariances is None:covariances=extract_covariances(t,x) + covariance_features=self.adapters[t].spatial_features(covariances) + signal=x.flatten(2);signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + adapted=self.adapters[t](signal,features,covariance_features) + if covariances is None:covariances=extract_covariances(t,x) + tangent=extract_tangent_features(covariances,self.adapters[t].spatial_weight) + representation,fusion_delta,covariance_delta,fusion_input=self.backbone(*adapted,tangent_features=tangent) + if t in ('faced','openbmi'): + representation=torch.cat([representation[:,:-384],torch.zeros_like(representation[:,-384:-128]),representation[:,-128:]],-1) + tokens=torch.zeros(len(signal),signal.shape[-1]//200,24*64,device=signal.device,dtype=torch.bfloat16) + code_fusion,code_covariance=self.backbone.codebrain_correction(tokens,representation,fusion_input) + coactivation=self.backbone.wave_coactivation(representation) + with torch.autocast(signal.device.type,enabled=False): + ordinal=self.adapters[t].ordinal_embedding(ordinal_features(t,x)) + ordinal_covariance=self.backbone.ordinal_context(ordinal.float()) + added=.001*nn.functional.linear(ordinal_covariance,self.backbone.covariance_projection.weight,None) + ordinal_fusion=self.backbone.fusion(fusion_input+added.to(fusion_input.dtype))-representation[:,-512:-384] + phase=self.phase_embedding(t,phase_features(t,x,self.adapters[t].spatial_weight)) + coupling=self.coupling_embedding(t,coupling_features(t,x)) + student=self.student_embedding(t,self.student_features(t,x)) + return self.heads[t](torch.cat([representation,fusion_delta,covariance_delta,code_fusion,code_covariance,coactivation,ordinal_fusion,ordinal_covariance,phase,coupling,student],-1)) + +def widen_state_dict(state,multiplier=2): + """Duplicate temporal features and divide downstream sums to preserve outputs.""" + result={} + for key,value in state.items(): + if key.startswith('backbone.waveform.'): + layer=int(key.split('.')[2]) + if layer in (0,2,7):value=value.repeat(multiplier,1,1,1) + elif layer in (1,3,9):value=value.repeat(multiplier) + elif layer==8:value=value.repeat(multiplier,multiplier,1,1)/multiplier + elif key=='backbone.wave_summary.2.weight':value=value.repeat(1,multiplier)/multiplier + elif key.startswith('heads.') and key.endswith('.weight'): + raw=value[:,:-128]/multiplier + value=torch.cat([raw]*multiplier+[value[:,-128:]],1) + result[key]=value + return result + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/ordinal_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/ordinal_features.py new file mode 100644 index 0000000000000000000000000000000000000000..6e3d5ff8264253f058f71b04d9cc8454196592b1 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/ordinal_features.py @@ -0,0 +1,25 @@ +"""Fixed within-window ordinal dynamics, independent of amplitude scaling.""" +import math +import torch +LAGS=(1,2,4,8,16) +PATTERNS=24 +PER_CHANNEL=len(LAGS)*(PATTERNS+2) + +def ordinal_features(track,x): + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + parts=[];uniform=1/PATTERNS;maximum_entropy=math.log(PATTERNS);m0=(1+uniform)/2;mr=uniform/2;maximum_js=-m0*math.log(m0)-(PATTERNS-1)*mr*math.log(mr)-maximum_entropy/2 + for lag in LAGS: + length=x.shape[-1]-3*lag + if length<=0:raise ValueError('window too short for ordinal dynamics') + samples=torch.stack([x[...,i*lag:i*lag+length] for i in range(4)],-1) + order=samples.argsort(dim=-1,stable=True) + code=6*((order[...,0,None]>order[...,1:]).sum(-1))+2*((order[...,1,None]>order[...,2:]).sum(-1))+(order[...,2]>order[...,3]).long() + histogram=torch.zeros(*x.shape[:2],PATTERNS,device=x.device,dtype=torch.float32) + histogram.scatter_add_(-1,code,torch.ones_like(code,dtype=torch.float32));probability=histogram/length + entropy=-(probability*probability.clamp_min(1e-12).log()).sum(-1) + mixture=(probability+uniform)/2;mixture_entropy=-(mixture*mixture.log()).sum(-1) + complexity=((mixture_entropy-.5*entropy-.5*maximum_entropy)/maximum_js).clamp(0,1)*(entropy/maximum_entropy) + parts.append(torch.cat([probability,(entropy/maximum_entropy)[...,None],complexity[...,None]],-1)) + return torch.cat(parts,-1).flatten(1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/phase_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/phase_features.py new file mode 100644 index 0000000000000000000000000000000000000000..8d98822995bf37b499795dfd7e2e401040a01969 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/phase_features.py @@ -0,0 +1,37 @@ +"""Complex spectral coherence of the existing 24 spatial filters in ten bands.""" +import torch +from covariances import BANDS +CHANNELS=24 +PHASE_HALF=len(BANDS)*CHANNELS*(CHANNELS-1)//2 +PHASE_DIM=2*PHASE_HALF + +@torch.no_grad() +def phase_features(track,x,spatial_weight): + previous_tf32=torch.backends.cuda.matmul.allow_tf32 + try: + torch.backends.cuda.matmul.allow_tf32=False + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if track in ('faced','tuev'):x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + else:x=x-x.mean(1,keepdim=True) + x=x/x.square().mean((1,2),keepdim=True).clamp_min(1e-12).sqrt() + frames=x.unfold(-1,400,200);frames=frames-frames.mean(-1,keepdim=True) + z=torch.fft.rfft(frames*torch.hann_window(400,device=x.device),dim=-1)/200 + w=spatial_weight.float()/spatial_weight.float().norm(dim=-1,keepdim=True).clamp_min(1e-6) + index=torch.triu_indices(CHANNELS,CHANNELS,1,device=x.device) + real_parts=[];imaginary_parts=[] + for band,(lo,hi) in enumerate(BANDS): + v=z[...,2*lo:2*hi].flatten(2) + vr=w[band][None]@v.real;vi=w[band][None]@v.imag + real=(vr@vr.transpose(-1,-2)+vi@vi.transpose(-1,-2))/v.shape[-1] + imaginary=(vi@vr.transpose(-1,-2)-vr@vi.transpose(-1,-2))/v.shape[-1] + # Signals have unit global RMS; this floor suppresses phase of numerical silence. + power=real.diagonal(dim1=-2,dim2=-1).clamp_min(1e-6) + denominator=(power[:,:,None]*power[:,None,:]).sqrt().clamp_min(1e-12) + real=(real/denominator).clamp(-.999,.999) + imaginary=(imaginary/denominator).clamp(-.999,.999) + real_parts.append(torch.atanh(real[:,index[0],index[1]])) + imaginary_parts.append(torch.atanh(imaginary[:,index[0],index[1]])) + return torch.cat(real_parts+imaginary_parts,-1) + finally:torch.backends.cuda.matmul.allow_tf32=previous_tf32 diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/private-readout-refresh-audit.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/private-readout-refresh-audit.json new file mode 100644 index 0000000000000000000000000000000000000000..1d02ef9e4aa8d0782c67157b160ef5667bfa1193 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/private-readout-refresh-audit.json @@ -0,0 +1,40 @@ +{ + "child": "/workspace/research/runs/coupling_patient1/epoch-007", + "donor": "/workspace/research/runs/phase_readout1/epoch-016", + "common_ancestor": "/workspace/research/runs/phase_coherence1/epoch-007", + "source_weight_sha256": { + "child": "f8466c6838ff01e54d1619f55668c1a4af26a243b54c67a956a3422d9604632a", + "donor": "ffd219d1480b81720b5aa4014cb2ed2b9cd31b7c92ad4717abc2a9625d30dc1a", + "ancestor": "e53ede409be523d8f4746251f7d46353621049f0378a88d4f7cfe2ba71a57d95" + }, + "changed_private_tensors": [ + "heads.openbmi.prior.projection.weight", + "heads.openbmi.prior.projection.bias" + ], + "all_ancestor_common_and_input_tensors_equal": true, + "all_child_common_and_input_tensors_unchanged": true, + "new_branch_gain_for_refreshed_track": 0.0, + "donor_changes_only_requested_private_projection": true, + "prediction_sources": { + "faced": { + "source": "/workspace/research/runs/coupling_patient1/faced-e007.npy", + "sha256": "68b617c8ecf347c79b23c20b70f6b4981c2f26b7b8c71dc7cd5fa0d7f4285ea6" + }, + "tuev": { + "source": "/workspace/research/runs/coupling_patient1/tuev-e007.npy", + "sha256": "9f0743450f1104d395e9daac0600aaf20755b5590b9f5c3e3137732c479dd647" + }, + "ad65": { + "source": "/workspace/research/runs/coupling_patient1/ad65-e007.npy", + "sha256": "7a3b74c58580b7ba952322bf6d527ebc9a40a6e04c7cdbbaea14e84a7a298d54" + }, + "openbmi": { + "source": "/workspace/research/runs/phase_readout1/openbmi-e016.npy", + "sha256": "14f630543e1df88c88d8f3e0effb4506ba33f533b3484de3c7aaf6554507341c" + }, + "longitudinal": { + "source": "/workspace/research/runs/coupling_patient1/longitudinal-e007.npy", + "sha256": "e93b0a319eaa3ddca9d71b0e786b808ba1630c1d3ce125f8e08036e517741b74" + } + } +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/student_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/student_features.py new file mode 100644 index 0000000000000000000000000000000000000000..57401f6d2ab760cb1a58af564aef2e62290e8907 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/student_features.py @@ -0,0 +1,34 @@ +"""One audited CBraMod core with full-window shared and ordered representations.""" +import torch +from torch import nn +from braindecode.models import CBraMod +from frequency_features import frequency_components,FREQUENCY_BANDS +SPECS={'faced':(32,10,9),'tuev':(16,5,6),'ad65':(19,10,3),'openbmi':(62,4,2),'longitudinal':(58,2,2)} +TRACKS=tuple(SPECS) + +class FrequencyAdapter(nn.Module): + def __init__(self,channels,virtual_channels=32): + super().__init__();self.signal=nn.Conv1d(channels,virtual_channels,1,bias=False) + self.frequency_weight=nn.Parameter(torch.zeros(len(FREQUENCY_BANDS),virtual_channels,channels)) + def forward(self,x): + components=frequency_components(x) + correction=torch.einsum('blc,nbct->nlt',self.frequency_weight,components.to(self.frequency_weight.dtype)) + return self.signal(x)+correction.to(x.dtype) + +class CBraModFeatures(nn.Module): + def __init__(self,virtual_channels=32,token_width=64,summary_width=256,head_width=128,dropout=.3): + super().__init__();self.virtual_channels=virtual_channels;self.output_dim=summary_width+virtual_channels*token_width*4 + self.backbone=CBraMod(n_chans=virtual_channels,n_outputs=2,n_times=400,sfreq=200) + self.backbone.final_layer=nn.Identity() + self.token_projection=nn.Sequential(nn.LayerNorm(200),nn.Linear(200,token_width),nn.GELU()) + self.summary_projection=nn.Sequential(nn.LayerNorm(virtual_channels*token_width*2),nn.Linear(virtual_channels*token_width*2,summary_width),nn.GELU(),nn.Dropout(dropout)) + def forward(self,signal): + tokens=self.token_projection(self.backbone(signal)) + moments=torch.cat([tokens.mean(2),tokens.float().std(2,correction=0).to(tokens.dtype)],-1).flatten(1) + summary=self.summary_projection(moments) + ordered=torch.nn.functional.adaptive_avg_pool1d(tokens.permute(0,1,3,2).flatten(1,2),4).flatten(1) + return torch.cat([summary,ordered],-1) + + def named_shared_parameters(self): + for prefix,module in [('backbone',self.backbone),('token_projection',self.token_projection),('summary_projection',self.summary_projection)]: + for name,p in module.named_parameters():yield f'{prefix}.{name}',p diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/tangent_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/tangent_features.py new file mode 100644 index 0000000000000000000000000000000000000000..314f0cf2f58e4b4a1c1d808edbd4acc3b7b6f85b --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S063/tangent_features.py @@ -0,0 +1,25 @@ +"""Window-local log-correlation geometry in the existing spatial-filter basis.""" +import torch + +TANGENT_DIM=10*24*25//2 + +@torch.no_grad() +def extract_tangent_features(covariances,spatial_weight): + old_tf32=torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(covariances.device.type,enabled=False): + w=spatial_weight.float() + w=w/w.norm(dim=-1,keepdim=True).clamp_min(1e-6) + projected=torch.einsum('bfc,nbcd,bgd->nbfg',w,covariances.float(),w) + d=projected.diagonal(dim1=-2,dim2=-1).clamp_min(1e-10).sqrt() + correlation=(projected/(d.unsqueeze(-1)*d.unsqueeze(-2))).clamp(-1,1) + correlation=(correlation+correlation.transpose(-1,-2))/2 + correlation=.95*correlation+.05*torch.eye(24,device=correlation.device) + values,vectors=torch.linalg.eigh(correlation) + logarithm=(vectors*values.clamp_min(1e-6).log().unsqueeze(-2))@vectors.transpose(-1,-2) + i,j=torch.triu_indices(24,24,device=correlation.device) + scale=torch.where(i==j,1.,2.**.5) + return (logarithm[...,i,j]*scale).flatten(1) + finally: + torch.backends.cuda.matmul.allow_tf32=old_tf32 diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S064/config.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S064/config.json new file mode 100644 index 0000000000000000000000000000000000000000..f18fdae2c7b34f053a6e270430df091cbb761828 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S064/config.json @@ -0,0 +1,833 @@ +{ + "schema": "bci-shared-biot-covariance-bf16head-v1", + "architecture": { + "channels": 32, + "width": 128, + "depth": 2, + "dropout": 0.5, + "wave_filters": 32, + "head_width": 64, + "head_dropout": 0.3, + "clinical_asymmetry": true, + "alpha_regions": [ + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.125 + ] + ], + "clinical_envelope": true, + "temporal_pool": true, + "temporal_evidence": true, + "evidence_temperature": 0.25, + "random_fourier": true, + "fourier_features": 256, + "tangent_readout": true, + "shared_context_correction": true, + "wave_coactivation": true, + "ordinal_context": true, + "phase_coherence": true, + "cross_frequency": true, + "cbramod_feature_transfer": true, + "student_architecture": { + "virtual_channels": 32, + "token_width": 64, + "summary_width": 256, + "head_width": 128, + "dropout": 0.3 + } + }, + "initialization": { + "initialization": "continue joint training from a complete shared-model checkpoint", + "parent": "/workspace/research/runs/hybrid_biot_fusionshrink0100/epoch-001/weights.pt", + "parent_initialization": { + "initialization": "jointly trained parent plus audited pretrained BIOT in a single coupled backbone", + "parent": "/workspace/research/runs/hybrid_wide1/epoch-004/weights.pt", + "audited_biot": { + "initialization": "pretrained", + "repo": "braindecode/biot-pretrained-six-datasets-18chs", + "revision": "7e9aabf302870012f73773276803aab97993951c", + "sha256": "a218f4054ae29962c6fd9d23d94c446d354c4f53e805a6771c85749ccc20baaa", + "license": "BSD-3-Clause", + "source_braindecode": "1.3.0", + "loaded_core_tensors": 56, + "skipped_classifier_tensors": 3 + }, + "neural_channel_indices": { + "faced": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "tuev": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15 + ], + "ad65": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "openbmi": [ + 0, + 1, + 3, + 5, + 12, + 14, + 23, + 25, + 28, + 30, + 2, + 6, + 11, + 15, + 22, + 26, + 4, + 13 + ], + "longitudinal": [ + 0, + 2, + 7, + 11, + 23, + 27, + 41, + 45, + 55, + 57, + 5, + 13, + 21, + 29, + 39, + 47, + 9, + 25 + ] + }, + "rebase": "incumbent waveform, fusion and four heads; joint BIOT and TUEV head from readout epoch 9; zero initialized neural interaction", + "jointly_finetuned_neural_parent": "/workspace/research/runs/hybrid_biot_readout1/epoch-009/weights.pt", + "tuev_high_dimensional_spectral_projection_disabled": true, + "frozen_prior_representation": true, + "nonclinical_head_updates": "only the 256 added BIOT columns; original columns and biases fixed", + "faced_openbmi_neural_path": "common nonlinear fusion only; direct head columns masked", + "retention_teacher": "/workspace/research/runs/hybrid_wide1/epoch-004", + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "joint_covariance_parent": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "frozen_prior_representation": true, + "head_updates": "one linear head per track; added 128 shared covariance columns trainable; AD head initialized from the joint covariance parent", + "new_shared_representation": "one common covariance MLP inside the coupled backbone, trained by all five tasks; fixed spatial input adapters from the same jointly trained source", + "head_arithmetic": "one linear head evaluated in fixed feature blocks to preserve original bfloat16 accumulation dimensions", + "retention_teacher": { + "ad65": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "other_tracks": "/workspace/research/runs/hybrid_wide1/epoch-004" + }, + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "loader_scale": 0.01, + "tracks": [ + "faced", + "tuev", + "ad65", + "openbmi", + "longitudinal" + ], + "head_arithmetic": "same linear head in fixed feature blocks, sum in bfloat16 on GPU for non-AD tracks; AD remains float32", + "head_refinement": { + "source": "/workspace/research/runs/residual_heads1/epoch-018", + "source_weights_sha256": "e0b609137391b47f99438ccadaa22fc0bc10d2c10ead0ddf0a3c25be2c907c85", + "shared_backbone_unchanged": true, + "selected_head_epochs": { + "faced": 5, + "tuev": 24, + "ad65": 0, + "openbmi": 0, + "longitudinal": 0 + } + }, + "clinical_spectral_refinement": { + "source": "/workspace/research/runs/head_dropout1/epoch-016", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "head_estimation": { + "method": "class/subject-balanced Gaussian linear discriminant; covariance augmented by class-conditional subject/session mean variation before shrinkage", + "selected_shrinkage": { + "faced": "inherited", + "tuev": "inherited", + "ad65": "inherited", + "openbmi": "inherited", + "longitudinal": { + "shrinkage": 0.9, + "domain_strength": 1.0 + } + }, + "feature_scaling": "fitted on training data and folded into linear coefficients" + }, + "clinical_asymmetry_refinement": { + "source": "/workspace/research/runs/domain_lda_heads1/epoch-001", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "alpha_rhythm_adapter": { + "training_normalization_only": true, + "regions": [ + "occipital", + "parietal", + "central", + "frontal", + "left_posterior", + "right_posterior" + ], + "features": "per-window alpha prominence relative to adjacent frequencies", + "shared_backbone_unchanged": true + }, + "clinical_envelope_refinement": { + "source": "/workspace/research/runs/clinical_asymmetry1/epoch-001", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "independent_adapter_merge": { + "alpha_source": "/workspace/research/runs/alpha_calibrated1/epoch-003", + "clinical_source": "/workspace/research/runs/clinical_envelope1/epoch-002", + "all_shared_and_head_tensors_equal": true + }, + "frequency_montage_refinement": { + "six_frequency_bands": true, + "shared_encoder_unchanged": true, + "selected_track_epochs": { + "faced": 0, + "tuev": 1, + "ad65": 0, + "openbmi": 10, + "longitudinal": 2 + } + }, + "private_track_selection": { + "track": "tuev", + "donor": "/workspace/research/replicates/frequency_head_control1/epoch-001" + }, + "clinical_sampling_refinement": { + "subject_exponent": 0.0, + "class_balanced": true, + "only_clinical_head_updated": true + }, + "temporal_statistics_readout": { + "statistics": [ + "mean", + "standard deviation", + "maximum", + "minimum" + ], + "shared_encoder_and_prior_heads_unchanged": true, + "selected_pool_epochs": { + "faced": 2, + "tuev": 0, + "ad65": 0, + "openbmi": 33, + "longitudinal": 3 + } + }, + "temporal_evidence_readout": { + "pooling": "log mean exp of per-patch class evidence", + "temperature": 0.25, + "shared_encoder_and_prior_heads_unchanged": true, + "selected_evidence_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 6, + "longitudinal": 8 + } + }, + "fourier_basis_readout": { + "basis_functions": 256, + "bandwidths": [ + 0.5, + 1.0, + 2.0 + ], + "shared_encoder_and_prior_heads_unchanged": true, + "selected_fourier_epochs": { + "faced": 21, + "tuev": 0, + "ad65": 0, + "openbmi": 0, + "longitudinal": 2 + } + }, + "shared_tangent_readout": { + "one_shared_tangent_module": true, + "original_and_corrected_shared_features_retained": true, + "private_head_scalar_gains": { + "faced": 0.0, + "tuev": 0.1, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 0.1 + }, + "all_common_weights_fixed_during_gain_refinement": true + }, + "shared_context_correction": { + "source": "/workspace/research/runs/hybrid_codebrain_fusion_control1/epoch-002", + "zero_token_input_preserved": true, + "unused_native_CodeBrain_core_and_input_parameters_removed": true, + "common_patch_and_context_layers_retained": true, + "same_one_shared_backbone_and_five_classifiers": true + }, + "shared_wave_coactivation": { + "channels": 64, + "statistics": 2080, + "diagonal_only_control": false, + "common_encoder_updated_by_all_five_tracks": true, + "gain_selection_within_one_common_checkpoint": { + "faced": 1.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 1.0 + } + }, + "fixed_common_coactivation_readouts": { + "all_common_weights_exactly_unchanged": true, + "selected_private_epochs": { + "faced": 25, + "tuev": 0, + "ad65": 0, + "openbmi": 8, + "longitudinal": 2 + } + }, + "shared_ordinal_context": { + "per_channel_features": 130, + "normalization_fit_on_training_only": true, + "entropy_only_control": false, + "new_common_layers_trained_on_all_five_tracks": true, + "gains_within_one_common_checkpoint": { + "faced": 1.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 0.0 + } + }, + "shared_complex_coherence": { + "features": 5520, + "normalization_fit_on_training_only": true, + "real_only_control": false, + "all_five_tracks_update_common_encoder": true, + "gains_within_one_common_checkpoint": { + "faced": 0.1, + "tuev": 1.0, + "ad65": 0.0, + "openbmi": 0.3, + "longitudinal": 0.0 + } + }, + "shared_cross_frequency": { + "per_channel_features": 30, + "normalization_fit_on_training_only": true, + "amplitude_only_control": false, + "all_five_tracks_update_common_encoder": true, + "gains_within_one_common_checkpoint": { + "faced": 0.3, + "tuev": 0.1, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 0.0 + } + }, + "inherited_private_readout_refresh": { + "child": "/workspace/research/runs/coupling_patient1/epoch-007", + "donor": "/workspace/research/runs/phase_readout1/epoch-016", + "common_ancestor": "/workspace/research/runs/phase_coherence1/epoch-007", + "source_weight_sha256": { + "child": "f8466c6838ff01e54d1619f55668c1a4af26a243b54c67a956a3422d9604632a", + "donor": "ffd219d1480b81720b5aa4014cb2ed2b9cd31b7c92ad4717abc2a9625d30dc1a", + "ancestor": "e53ede409be523d8f4746251f7d46353621049f0378a88d4f7cfe2ba71a57d95" + }, + "changed_private_tensors": [ + "heads.openbmi.prior.projection.weight", + "heads.openbmi.prior.projection.bias" + ], + "all_ancestor_common_and_input_tensors_equal": true, + "all_child_common_and_input_tensors_unchanged": true, + "new_branch_gain_for_refreshed_track": 0.0, + "donor_changes_only_requested_private_projection": true, + "prediction_sources": { + "faced": { + "source": "/workspace/research/runs/coupling_patient1/faced-e007.npy", + "sha256": "68b617c8ecf347c79b23c20b70f6b4981c2f26b7b8c71dc7cd5fa0d7f4285ea6" + }, + "tuev": { + "source": "/workspace/research/runs/coupling_patient1/tuev-e007.npy", + "sha256": "9f0743450f1104d395e9daac0600aaf20755b5590b9f5c3e3137732c479dd647" + }, + "ad65": { + "source": "/workspace/research/runs/coupling_patient1/ad65-e007.npy", + "sha256": "7a3b74c58580b7ba952322bf6d527ebc9a40a6e04c7cdbbaea14e84a7a298d54" + }, + "openbmi": { + "source": "/workspace/research/runs/phase_readout1/openbmi-e016.npy", + "sha256": "14f630543e1df88c88d8f3e0effb4506ba33f533b3484de3c7aaf6554507341c" + }, + "longitudinal": { + "source": "/workspace/research/runs/coupling_patient1/longitudinal-e007.npy", + "sha256": "e93b0a319eaa3ddca9d71b0e786b808ba1630c1d3ce125f8e08036e517741b74" + } + } + }, + "shared_student_residual": { + "dimension": 8448, + "summary_dimension": 256, + "ordered_time_bins": 4, + "student_weights_sha256": "19dfe912cceed997699b5b526c8c2ece55945c5f9bd111c4c13704d0fc460e8b", + "summary_only_control": false, + "normalization_fit_on_training_only": true, + "new_common_readout_jointly_trained_on_all_five": true, + "class_projection_initialized_zero": true, + "student_classifiers_discarded": true, + "gains_within_one_common_checkpoint": { + "faced": 1.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 1.0 + }, + "zero_gain_preserves_complete_parent": true + }, + "fixed_common_student_readouts": { + "all_common_weights_exactly_unchanged": true, + "selected_private_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 0, + "longitudinal": 7 + } + } +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S064/coupling_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S064/coupling_features.py new file mode 100644 index 0000000000000000000000000000000000000000..3a4e51bd7ce07bcec1f0f5b80054d6ff387ac87f --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S064/coupling_features.py @@ -0,0 +1,34 @@ +"""Per-window cross-frequency envelope and phase-amplitude relationships.""" +import torch +BANDS=((1,4),(4,8),(8,13),(13,30),(30,48)) +PAIRS=tuple((i,j) for i in range(5) for j in range(i+1,5)) +PER_CHANNEL=30 + +@torch.no_grad() +def coupling_features(track,x): + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + n=x.shape[-1];spectrum=torch.fft.fft(x,dim=-1);frequency=torch.fft.fftfreq(n,1/200,device=x.device) + masks=torch.stack([2*((frequency>=lo)&(frequencynrf',regions.float(),lp) + lp=torch.cat([lp,regional],1) + low=lp[...,8:13].mean(-1,keepdim=True) + high=lp[...,36:49].mean(-1,keepdim=True) + freq=torch.arange(7.,14.5,.5,device=x.device) + alpha=lp[...,14:29] + baseline=low+(high-low)*((freq-5)/16) + prominence=alpha-baseline + normalized=alpha.softmax(-1) + center=(normalized*freq).sum(-1) + entropy=-(normalized*normalized.clamp_min(1e-12).log()).sum(-1) + alpha_mean=torch.logsumexp(alpha,-1)-torch.log(torch.tensor(15.,device=x.device)) + def log_band(lo,hi): + return torch.logsumexp(lp[...,lo:hi],-1)-torch.log(torch.tensor(float(hi-lo),device=x.device)) + summaries=torch.stack([alpha_mean-log_band(2,81),alpha_mean-log_band(8,14), + alpha_mean-log_band(30,61),prominence.max(-1).values, + prominence.mean(-1),center,entropy],-1) + return torch.cat([summaries[:,:58].flatten(1),summaries[:,58:].flatten(1), + prominence[:,58:].flatten(1)],1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/config.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/config.json new file mode 100644 index 0000000000000000000000000000000000000000..a37c9d8210b0b2e2a7717f751b56704bd1c28e34 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/config.json @@ -0,0 +1,846 @@ +{ + "schema": "bci-shared-biot-covariance-bf16head-v1", + "architecture": { + "channels": 32, + "width": 128, + "depth": 2, + "dropout": 0.5, + "wave_filters": 32, + "head_width": 64, + "head_dropout": 0.3, + "clinical_asymmetry": true, + "alpha_regions": [ + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.125 + ] + ], + "clinical_envelope": true, + "temporal_pool": true, + "temporal_evidence": true, + "evidence_temperature": 0.25, + "random_fourier": true, + "fourier_features": 256, + "tangent_readout": true, + "shared_context_correction": true, + "wave_coactivation": true, + "ordinal_context": true, + "phase_coherence": true, + "cross_frequency": true, + "cbramod_feature_transfer": true, + "student_architecture": { + "virtual_channels": 32, + "token_width": 64, + "summary_width": 256, + "head_width": 128, + "dropout": 0.3 + } + }, + "initialization": { + "initialization": "continue joint training from a complete shared-model checkpoint", + "parent": "/workspace/research/runs/hybrid_biot_fusionshrink0100/epoch-001/weights.pt", + "parent_initialization": { + "initialization": "jointly trained parent plus audited pretrained BIOT in a single coupled backbone", + "parent": "/workspace/research/runs/hybrid_wide1/epoch-004/weights.pt", + "audited_biot": { + "initialization": "pretrained", + "repo": "braindecode/biot-pretrained-six-datasets-18chs", + "revision": "7e9aabf302870012f73773276803aab97993951c", + "sha256": "a218f4054ae29962c6fd9d23d94c446d354c4f53e805a6771c85749ccc20baaa", + "license": "BSD-3-Clause", + "source_braindecode": "1.3.0", + "loaded_core_tensors": 56, + "skipped_classifier_tensors": 3 + }, + "neural_channel_indices": { + "faced": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "tuev": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15 + ], + "ad65": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "openbmi": [ + 0, + 1, + 3, + 5, + 12, + 14, + 23, + 25, + 28, + 30, + 2, + 6, + 11, + 15, + 22, + 26, + 4, + 13 + ], + "longitudinal": [ + 0, + 2, + 7, + 11, + 23, + 27, + 41, + 45, + 55, + 57, + 5, + 13, + 21, + 29, + 39, + 47, + 9, + 25 + ] + }, + "rebase": "incumbent waveform, fusion and four heads; joint BIOT and TUEV head from readout epoch 9; zero initialized neural interaction", + "jointly_finetuned_neural_parent": "/workspace/research/runs/hybrid_biot_readout1/epoch-009/weights.pt", + "tuev_high_dimensional_spectral_projection_disabled": true, + "frozen_prior_representation": true, + "nonclinical_head_updates": "only the 256 added BIOT columns; original columns and biases fixed", + "faced_openbmi_neural_path": "common nonlinear fusion only; direct head columns masked", + "retention_teacher": "/workspace/research/runs/hybrid_wide1/epoch-004", + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "joint_covariance_parent": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "frozen_prior_representation": true, + "head_updates": "one linear head per track; added 128 shared covariance columns trainable; AD head initialized from the joint covariance parent", + "new_shared_representation": "one common covariance MLP inside the coupled backbone, trained by all five tasks; fixed spatial input adapters from the same jointly trained source", + "head_arithmetic": "one linear head evaluated in fixed feature blocks to preserve original bfloat16 accumulation dimensions", + "retention_teacher": { + "ad65": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "other_tracks": "/workspace/research/runs/hybrid_wide1/epoch-004" + }, + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "loader_scale": 0.01, + "tracks": [ + "faced", + "tuev", + "ad65", + "openbmi", + "longitudinal" + ], + "head_arithmetic": "same linear head in fixed feature blocks, sum in bfloat16 on GPU for non-AD tracks; AD remains float32", + "head_refinement": { + "source": "/workspace/research/runs/residual_heads1/epoch-018", + "source_weights_sha256": "e0b609137391b47f99438ccadaa22fc0bc10d2c10ead0ddf0a3c25be2c907c85", + "shared_backbone_unchanged": true, + "selected_head_epochs": { + "faced": 5, + "tuev": 24, + "ad65": 0, + "openbmi": 0, + "longitudinal": 0 + } + }, + "clinical_spectral_refinement": { + "source": "/workspace/research/runs/head_dropout1/epoch-016", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "head_estimation": { + "method": "class/subject-balanced Gaussian linear discriminant; covariance augmented by class-conditional subject/session mean variation before shrinkage", + "selected_shrinkage": { + "faced": "inherited", + "tuev": "inherited", + "ad65": "inherited", + "openbmi": "inherited", + "longitudinal": { + "shrinkage": 0.9, + "domain_strength": 1.0 + } + }, + "feature_scaling": "fitted on training data and folded into linear coefficients" + }, + "clinical_asymmetry_refinement": { + "source": "/workspace/research/runs/domain_lda_heads1/epoch-001", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "alpha_rhythm_adapter": { + "training_normalization_only": true, + "regions": [ + "occipital", + "parietal", + "central", + "frontal", + "left_posterior", + "right_posterior" + ], + "features": "per-window alpha prominence relative to adjacent frequencies", + "shared_backbone_unchanged": true + }, + "clinical_envelope_refinement": { + "source": "/workspace/research/runs/clinical_asymmetry1/epoch-001", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "independent_adapter_merge": { + "alpha_source": "/workspace/research/runs/alpha_calibrated1/epoch-003", + "clinical_source": "/workspace/research/runs/clinical_envelope1/epoch-002", + "all_shared_and_head_tensors_equal": true + }, + "frequency_montage_refinement": { + "six_frequency_bands": true, + "shared_encoder_unchanged": true, + "selected_track_epochs": { + "faced": 0, + "tuev": 1, + "ad65": 0, + "openbmi": 10, + "longitudinal": 2 + } + }, + "private_track_selection": { + "track": "tuev", + "donor": "/workspace/research/replicates/frequency_head_control1/epoch-001" + }, + "clinical_sampling_refinement": { + "subject_exponent": 0.0, + "class_balanced": true, + "only_clinical_head_updated": true + }, + "temporal_statistics_readout": { + "statistics": [ + "mean", + "standard deviation", + "maximum", + "minimum" + ], + "shared_encoder_and_prior_heads_unchanged": true, + "selected_pool_epochs": { + "faced": 2, + "tuev": 0, + "ad65": 0, + "openbmi": 33, + "longitudinal": 3 + } + }, + "temporal_evidence_readout": { + "pooling": "log mean exp of per-patch class evidence", + "temperature": 0.25, + "shared_encoder_and_prior_heads_unchanged": true, + "selected_evidence_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 6, + "longitudinal": 8 + } + }, + "fourier_basis_readout": { + "basis_functions": 256, + "bandwidths": [ + 0.5, + 1.0, + 2.0 + ], + "shared_encoder_and_prior_heads_unchanged": true, + "selected_fourier_epochs": { + "faced": 21, + "tuev": 0, + "ad65": 0, + "openbmi": 0, + "longitudinal": 2 + } + }, + "shared_tangent_readout": { + "one_shared_tangent_module": true, + "original_and_corrected_shared_features_retained": true, + "private_head_scalar_gains": { + "faced": 0.0, + "tuev": 0.1, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 0.1 + }, + "all_common_weights_fixed_during_gain_refinement": true + }, + "shared_context_correction": { + "source": "/workspace/research/runs/hybrid_codebrain_fusion_control1/epoch-002", + "zero_token_input_preserved": true, + "unused_native_CodeBrain_core_and_input_parameters_removed": true, + "common_patch_and_context_layers_retained": true, + "same_one_shared_backbone_and_five_classifiers": true + }, + "shared_wave_coactivation": { + "channels": 64, + "statistics": 2080, + "diagonal_only_control": false, + "common_encoder_updated_by_all_five_tracks": true, + "gain_selection_within_one_common_checkpoint": { + "faced": 1.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 1.0 + } + }, + "fixed_common_coactivation_readouts": { + "all_common_weights_exactly_unchanged": true, + "selected_private_epochs": { + "faced": 25, + "tuev": 0, + "ad65": 0, + "openbmi": 8, + "longitudinal": 2 + } + }, + "shared_ordinal_context": { + "per_channel_features": 130, + "normalization_fit_on_training_only": true, + "entropy_only_control": false, + "new_common_layers_trained_on_all_five_tracks": true, + "gains_within_one_common_checkpoint": { + "faced": 1.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 0.0 + } + }, + "shared_complex_coherence": { + "features": 5520, + "normalization_fit_on_training_only": true, + "real_only_control": false, + "all_five_tracks_update_common_encoder": true, + "gains_within_one_common_checkpoint": { + "faced": 0.1, + "tuev": 1.0, + "ad65": 0.0, + "openbmi": 0.3, + "longitudinal": 0.0 + } + }, + "shared_cross_frequency": { + "per_channel_features": 30, + "normalization_fit_on_training_only": true, + "amplitude_only_control": false, + "all_five_tracks_update_common_encoder": true, + "gains_within_one_common_checkpoint": { + "faced": 0.3, + "tuev": 0.1, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 0.0 + } + }, + "inherited_private_readout_refresh": { + "child": "/workspace/research/runs/coupling_patient1/epoch-007", + "donor": "/workspace/research/runs/phase_readout1/epoch-016", + "common_ancestor": "/workspace/research/runs/phase_coherence1/epoch-007", + "source_weight_sha256": { + "child": "f8466c6838ff01e54d1619f55668c1a4af26a243b54c67a956a3422d9604632a", + "donor": "ffd219d1480b81720b5aa4014cb2ed2b9cd31b7c92ad4717abc2a9625d30dc1a", + "ancestor": "e53ede409be523d8f4746251f7d46353621049f0378a88d4f7cfe2ba71a57d95" + }, + "changed_private_tensors": [ + "heads.openbmi.prior.projection.weight", + "heads.openbmi.prior.projection.bias" + ], + "all_ancestor_common_and_input_tensors_equal": true, + "all_child_common_and_input_tensors_unchanged": true, + "new_branch_gain_for_refreshed_track": 0.0, + "donor_changes_only_requested_private_projection": true, + "prediction_sources": { + "faced": { + "source": "/workspace/research/runs/coupling_patient1/faced-e007.npy", + "sha256": "68b617c8ecf347c79b23c20b70f6b4981c2f26b7b8c71dc7cd5fa0d7f4285ea6" + }, + "tuev": { + "source": "/workspace/research/runs/coupling_patient1/tuev-e007.npy", + "sha256": "9f0743450f1104d395e9daac0600aaf20755b5590b9f5c3e3137732c479dd647" + }, + "ad65": { + "source": "/workspace/research/runs/coupling_patient1/ad65-e007.npy", + "sha256": "7a3b74c58580b7ba952322bf6d527ebc9a40a6e04c7cdbbaea14e84a7a298d54" + }, + "openbmi": { + "source": "/workspace/research/runs/phase_readout1/openbmi-e016.npy", + "sha256": "14f630543e1df88c88d8f3e0effb4506ba33f533b3484de3c7aaf6554507341c" + }, + "longitudinal": { + "source": "/workspace/research/runs/coupling_patient1/longitudinal-e007.npy", + "sha256": "e93b0a319eaa3ddca9d71b0e786b808ba1630c1d3ce125f8e08036e517741b74" + } + } + }, + "shared_student_residual": { + "dimension": 8448, + "summary_dimension": 256, + "ordered_time_bins": 4, + "student_weights_sha256": "19dfe912cceed997699b5b526c8c2ece55945c5f9bd111c4c13704d0fc460e8b", + "summary_only_control": false, + "normalization_fit_on_training_only": true, + "new_common_readout_jointly_trained_on_all_five": true, + "class_projection_initialized_zero": true, + "student_classifiers_discarded": true, + "gains_within_one_common_checkpoint": { + "faced": 1.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 1.0 + }, + "zero_gain_preserves_complete_parent": true + }, + "private_head_refresh": { + "reference": "/workspace/research/runs/student_private_retention_control1/epoch-030", + "donor": "/workspace/research/runs/student_private_unanchored1/epoch-030", + "track": "faced", + "source_sha256": { + "reference": "de55cf5362cb45ecd7f7cb8ac3ade4d7634fcd2e99f23283abc6e663a261df50", + "donor": "d4e0c43d16cd7d287da31fc2fce57926fd28a04389d8dae421d3d718d097abff" + }, + "changed_private_tensors": [ + "heads.faced.projection.weight", + "heads.faced.projection.bias" + ], + "all_common_input_and_prior_head_tensors_exactly_equal": true, + "executable_code_and_architecture_exactly_equal": true, + "one_common_checkpoint": true, + "prediction_sources": { + "faced": "/workspace/research/runs/student_private_unanchored1/faced-e030.npy", + "tuev": "/workspace/research/runs/student_private_retention_control1/tuev-e030.npy", + "ad65": "/workspace/research/runs/student_private_retention_control1/ad65-e030.npy", + "openbmi": "/workspace/research/runs/student_private_retention_control1/openbmi-e030.npy", + "longitudinal": "/workspace/research/runs/student_private_retention_control1/longitudinal-e030.npy" + } + } +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/coupling_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/coupling_features.py new file mode 100644 index 0000000000000000000000000000000000000000..3a4e51bd7ce07bcec1f0f5b80054d6ff387ac87f --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/coupling_features.py @@ -0,0 +1,34 @@ +"""Per-window cross-frequency envelope and phase-amplitude relationships.""" +import torch +BANDS=((1,4),(4,8),(8,13),(13,30),(30,48)) +PAIRS=tuple((i,j) for i in range(5) for j in range(i+1,5)) +PER_CHANNEL=30 + +@torch.no_grad() +def coupling_features(track,x): + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + n=x.shape[-1];spectrum=torch.fft.fft(x,dim=-1);frequency=torch.fft.fftfreq(n,1/200,device=x.device) + masks=torch.stack([2*((frequency>=lo)&(frequency=lo)&(frequency2).float().mean(-1),(relative>4).float().mean(-1), + ((relative[...,1:]>2)&(relative[...,:-1]<=2)).float().mean(-1), + acf_peak,(acf_index.float()+4)/40, + acf[...,0],acf[...,6],acf[...,16],acf[...,36]] + left=torch.tensor([0,1,2,3,8,9,10,11],device=x.device);right=left+4 + synchrony=(normalized[:,left]*normalized[:,right]).mean(-1).clamp(-1,1) + imbalance=(std[:,left].squeeze(-1).log()-std[:,right].squeeze(-1).log()).abs() + return torch.cat([torch.stack(summaries,-1).flatten(1),synchrony.flatten(1),imbalance.flatten(1)],1) + +def mirrored_features(features): + channels=torch.tensor([4,5,6,7,0,1,2,3,12,13,14,15,8,9,10,11],device=features.device) + return torch.cat([features[:,:16*5*12].reshape(-1,16,5,12)[:,channels].flatten(1),features[:,16*5*12:]],1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/features.py new file mode 100644 index 0000000000000000000000000000000000000000..88f7e8b14c9fab44733d5224ede6d6b5c7f76a45 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/features.py @@ -0,0 +1,63 @@ +"""One shared residual backbone, five linear input adapters and output heads.""" +import torch +from torch import nn + +SPECS = {'faced': (32, 10, 9), 'tuev': (16, 5, 6), 'ad65': (19, 10, 3), + 'openbmi': (62, 4, 2), 'longitudinal': (58, 2, 2)} +TRACKS = tuple(SPECS) +EDGES = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,18,20,22,25,28,32,36,40,45,50,60,70,80,95] +COV_BANDS = [(1,4),(4,8),(8,12),(12,16),(16,20),(20,28),(28,40)] + +def feature_dim(channels): + return channels * (4*(len(EDGES)-1)+4) + len(COV_BANDS)*channels*(channels-1)//2 + +@torch.no_grad() +def extract_features(track, x): + """Fixed features; no batch statistics or fitted inference transformations.""" + x = x.float().flatten(2) + x = torch.nan_to_num(x, nan=0., posinf=1e5, neginf=-1e5).clamp(-1e5,1e5) + x = x - x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'): + x = x - x.mean(1,keepdim=True) + rms = x.square().mean(-1).clamp_min(1e-12).sqrt() + norm = x / rms.unsqueeze(-1) + moments = torch.stack([rms.log(), norm.abs().amax(-1).clamp_min(1).log(), + norm.pow(4).mean(-1).clamp_min(1).log(), + (norm[...,1:]-norm[...,:-1]).square().mean(-1).clamp_min(1e-10).log()],-1) + frames = x.unfold(-1,400,200) + frames = frames - frames.mean(-1,keepdim=True) + window = torch.hann_window(400,device=x.device) + z = torch.fft.rfft(frames*window,dim=-1)/200 + power = z.abs().square() + bands = torch.stack([power[...,2*lo:2*hi].mean(-1) for lo,hi in zip(EDGES[:-1],EDGES[1:])],-1) + lp = bands.mean(-2).clamp_min(1e-12).log() + variation = bands.clamp_min(1e-12).log().std(-2,correction=0) + relative_frequency = lp - lp.mean(-1,keepdim=True) + relative_channel = lp - lp.mean(1,keepdim=True) + parts = [torch.cat([lp, relative_frequency, relative_channel, variation, moments],-1).flatten(1)] + ii,jj = torch.triu_indices(x.shape[1],x.shape[1],offset=1,device=x.device) + for lo,hi in COV_BANDS: + v = z[...,2*lo:2*hi].flatten(2) + cov = v.real @ v.real.transpose(-1,-2) + v.imag @ v.imag.transpose(-1,-2) + d = cov.diagonal(dim1=-2,dim2=-1).clamp_min(1e-12).sqrt() + cor = cov / (d.unsqueeze(1)*d.unsqueeze(2)).clamp_min(1e-12) + parts.append(cor[:,ii,jj].clamp(-1,1)) + result = torch.cat(parts,-1) + return torch.nan_to_num(result).clamp(-40,40) + +class Standardize(nn.Module): + def __init__(self, dim): + super().__init__() + self.register_buffer('mean',torch.zeros(dim)) + self.register_buffer('scale',torch.ones(dim)) + def forward(self,x): + return ((x-self.mean)/self.scale).clamp(-8,8) + +class Residual(nn.Module): + def __init__(self,width,dropout): + super().__init__() + self.net=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(), + nn.Dropout(dropout),nn.Linear(width*2,width),nn.Dropout(dropout)) + def forward(self,x): + return x+self.net(x) + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/frequency_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/frequency_features.py new file mode 100644 index 0000000000000000000000000000000000000000..9194c9e81f801b3833e551e4967991774fa9e398 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/frequency_features.py @@ -0,0 +1,11 @@ +"""Fixed per-window frequency decomposition for a linear montage adapter.""" +import torch + +FREQUENCY_BANDS=((1,4),(4,8),(8,13),(13,20),(20,30),(30,45)) + +def frequency_components(signal): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();spectrum=torch.fft.rfft(x,dim=-1) + frequency=torch.fft.rfftfreq(x.shape[-1],d=1/200,device=x.device) + masks=torch.stack([((frequency>=lo)&(frequencynbf',w,covariances.float(),w).clamp_min(1e-8).log() + return torch.cat([power,power-power.mean(1,keepdim=True)],1).flatten(1) + def wave_signal(self,x,components=None): + if components is None:components=frequency_components(x) + correction=torch.einsum('blc,nbct->nlt',self.frequency_weight,components.to(self.frequency_weight.dtype)) + return (self.signal(x)+correction.to(x.dtype)).unsqueeze(1) + def forward(self,x,features,covariance_features): + return self.wave_signal(x),self.spectral_features(features,signal=x),self.neural(x),covariance_features + +class SharedBackbone(nn.Module): + def __init__(self,channels,width,depth,dropout,wave_filters): + super().__init__() + self.waveform=nn.Sequential( + nn.Conv2d(1,wave_filters,(1,64),padding=(0,32),bias=False),nn.GroupNorm(1,wave_filters), + nn.Conv2d(wave_filters,2*wave_filters,(channels,1),groups=wave_filters,bias=False),nn.GroupNorm(1,2*wave_filters),nn.ELU(), + nn.AvgPool2d((1,4)),nn.Dropout(.35), + nn.Conv2d(2*wave_filters,2*wave_filters,(1,16),padding=(0,8),groups=2*wave_filters,bias=False),nn.Conv2d(2*wave_filters,2*wave_filters,1,bias=False), + nn.GroupNorm(1,2*wave_filters),nn.ELU(),nn.AvgPool2d((1,8)),nn.Dropout(.35)) + self.wave_summary=nn.Sequential(nn.AdaptiveAvgPool2d((1,8)),nn.Flatten(),nn.Linear(2*wave_filters*8,width)) + self.fusion=nn.Sequential(nn.LayerNorm(width),nn.GELU(),nn.Dropout(dropout), + *[Residual(width,dropout) for _ in range(depth)],nn.LayerNorm(width)) + # Both representations interact before the shared residual stack. + self.phase_encoder=nn.Sequential(nn.LayerNorm(PHASE_DIM),nn.Linear(PHASE_DIM,width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width)) + self.register_buffer('phase_imaginary_enabled',torch.ones(())) + self.coupling_encoder=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width),nn.LayerNorm(width)) + self.wave_gain=nn.Parameter(torch.tensor(.1)) + self.biot=BIOT(n_chans=18,n_outputs=2,n_times=400,sfreq=200) + self.biot.final_layer=nn.Identity() + self.biot_projection=nn.Sequential(nn.LayerNorm(256),nn.Linear(256,width),nn.Dropout(.2)) + nn.init.normal_(self.biot_projection[1].weight,std=.001);nn.init.zeros_(self.biot_projection[1].bias) + self.covariance_encoder=nn.Sequential(nn.LayerNorm(len(BANDS)*24*2),nn.Linear(len(BANDS)*24*2,width),nn.GELU(),nn.Dropout(.4), + *[Residual(width,.4) for _ in range(2)],nn.LayerNorm(width)) + self.covariance_projection=nn.Linear(width,width) + nn.init.zeros_(self.covariance_projection.weight);nn.init.zeros_(self.covariance_projection.bias) + self.tangent_encoder=nn.Sequential(nn.LayerNorm(TANGENT_DIM),nn.Linear(TANGENT_DIM,width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width),nn.Linear(width,width)) + self.ordinal_context=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width)) + nn.init.zeros_(self.ordinal_context[-1].weight);nn.init.zeros_(self.ordinal_context[-1].bias) + self.register_buffer('codebrain_enabled',torch.ones(())) + self.codebrain_patch_encoder=nn.Sequential(nn.LayerNorm(24*64),nn.Linear(24*64,width),nn.GELU(),nn.Dropout(.3)) + self.codebrain_context=nn.Sequential(nn.LayerNorm(width*4),nn.Linear(width*4,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width)) + nn.init.zeros_(self.codebrain_context[-1].weight);nn.init.zeros_(self.codebrain_context[-1].bias) + def codebrain_correction(self,tokens,representation,fusion_input): + with torch.autocast(tokens.device.type,enabled=False): + encoded=self.codebrain_patch_encoder(self.codebrain_enabled*tokens.float()) + pooled=torch.cat([encoded.mean(1),encoded.std(1,correction=0),representation[:,-512:-384].float(),representation[:,-128:].float()],-1) + delta=self.codebrain_context(pooled) + added=.001*nn.functional.linear(delta,self.covariance_projection.weight,None) + corrected=self.fusion(fusion_input+added.to(fusion_input.dtype)) + return corrected-representation[:,-512:-384],delta + def forward(self,signal,spectral,neural_signal,covariance_features,tangent_features): + wave=self.waveform(signal) + neural=self.biot(neural_signal.float()) + neural=self.biot_projection[0](neural) + projected=self.biot_projection[2](self.biot_projection[1](neural)) + with torch.autocast(signal.device.type,enabled=False): + covariance_embedding=self.covariance_encoder(covariance_features.float()) + original=spectral+self.wave_gain*self.wave_summary(wave)+.01*projected + coupled=.001*self.covariance_projection(covariance_embedding).to(original.dtype) + fused=self.fusion(original+coupled) + with torch.autocast(signal.device.type,enabled=False):delta=self.tangent_encoder(tangent_features.float()) + added=.001*nn.functional.linear(delta,self.covariance_projection.weight,None) + corrected=self.fusion((original+coupled)+added.to(original.dtype)) + return torch.cat([wave.flatten(1),fused,neural,covariance_embedding],-1),corrected-fused,delta,original+coupled + +class ResidualHead(nn.Module): + """A small nonlinear classifier correction around an inherited linear readout.""" + def __init__(self,features,classes,width=64,dropout=.3,full_precision=False): + super().__init__();self.full_precision=full_precision + self.base=nn.Linear(features,classes) + self.delta=nn.Sequential(nn.LayerNorm(features),nn.Linear(features,width),nn.GELU(),nn.Dropout(dropout),nn.Linear(width,classes)) + nn.init.zeros_(self.delta[-1].weight);nn.init.zeros_(self.delta[-1].bias) + def forward(self,x): + if self.full_precision: + with torch.autocast(x.device.type,enabled=False):return self.base(x.float())+self.delta(x.float()) + prior=nn.functional.linear(x[:,:-128].contiguous(),self.base.weight[:,:-128].contiguous(),self.base.bias) + added=nn.functional.linear(x[:,-128:].contiguous(),self.base.weight[:,-128:].contiguous()) + value=prior+added + return value+self.delta(x).to(value.dtype) + +class TemporalPoolHead(nn.Module): + def __init__(self,prior,channels=64): + super().__init__();self.prior=prior;self.channels=channels + self.register_buffer('pool_output_scale',torch.ones(()));self.register_buffer('pool_mean',torch.zeros(channels*4));self.register_buffer('pool_scale',torch.ones(channels*4)) + self.pool_projection=nn.Linear(channels*4,prior.base.out_features) + nn.init.zeros_(self.pool_projection.weight);nn.init.zeros_(self.pool_projection.bias) + def statistics(self,x): + with torch.autocast(x.device.type,enabled=False): + wave=x[:,:-512].float().reshape(len(x),self.channels,-1) + return torch.cat([wave.mean(-1),wave.std(-1,correction=0),wave.amax(-1),wave.amin(-1)],-1) + def forward(self,x): + prior=self.prior(x) + with torch.autocast(x.device.type,enabled=False): + values=((self.statistics(x)-self.pool_mean)/self.pool_scale).clamp(-8,8) + added=self.pool_output_scale*self.pool_projection(values) + return prior+added.to(prior.dtype) + +class TemporalEvidenceHead(nn.Module): + """Pool class evidence over the shared waveform time axis.""" + def __init__(self,prior,channels=64,temperature=.25): + super().__init__();self.prior=prior;self.channels=channels;self.temperature=temperature + self.register_buffer('evidence_output_scale',torch.ones(())) + self.register_buffer('evidence_mean',torch.zeros(channels)) + self.register_buffer('evidence_scale',torch.ones(channels)) + self.evidence_projection=nn.Linear(channels,prior.prior.base.out_features,bias=False) + nn.init.zeros_(self.evidence_projection.weight) + def patches(self,x): + with torch.autocast(x.device.type,enabled=False): + wave=x[:,:-512].float().reshape(len(x),self.channels,-1).transpose(1,2) + return ((wave-self.evidence_mean)/self.evidence_scale).clamp(-8,8) + def evidence(self,patches): + with torch.autocast(patches.device.type,enabled=False): + values=self.evidence_projection(patches.float())/self.temperature + maximum=values.amax(1,keepdim=True) + pooled=self.temperature*((values-maximum).exp().mean(1).log()+maximum.squeeze(1)) + return self.evidence_output_scale*pooled + def forward(self,x): + prior=self.prior(x) + return prior+self.evidence(self.patches(x)).to(prior.dtype) + +class FourierResidualHead(nn.Module): + """A fixed random Fourier basis and trainable linear classifier correction.""" + def __init__(self,prior,features,classes,basis=256): + super().__init__();self.prior=prior + self.register_buffer('rff_mean',torch.zeros(features));self.register_buffer('rff_scale',torch.ones(features)) + self.register_buffer('rff_frequency',torch.randn(features,basis)/features**.5) + self.register_buffer('rff_phase',torch.rand(basis)*2*torch.pi) + self.register_buffer('rff_output_scale',torch.ones(())) + self.rff_projection=nn.Linear(3*basis,classes);nn.init.zeros_(self.rff_projection.weight);nn.init.zeros_(self.rff_projection.bias) + def basis(self,x): + with torch.autocast(x.device.type,enabled=False): + values=((x.float()-self.rff_mean)/self.rff_scale).clamp(-8,8)@self.rff_frequency + return 2**.5*torch.cat([(values/sigma+self.rff_phase).cos() for sigma in (.5,1.,2.)],-1) + def forward(self,x): + prior=self.prior(x) + with torch.autocast(x.device.type,enabled=False):added=self.rff_output_scale*self.rff_projection(self.basis(x)) + return prior+added.to(prior.dtype) + +class TangentFeatureHead(nn.Module): + """Select a shared feature correction before the inherited classifier.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.feature_gain=nn.Parameter(torch.zeros(())) + def forward(self,values): + old=values[:,:-256];fusion_delta=values[:,-256:-128];covariance_delta=values[:,-128:] + adjusted=torch.cat([old[:,:-512],old[:,-512:-384]+self.feature_gain*fusion_delta,old[:,-384:-128],old[:,-128:]+self.feature_gain*covariance_delta],-1) + return self.prior(adjusted) + +class CodeBrainFeatureHead(nn.Module): + """Private use of a jointly trained common feature correction.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.codebrain_gain=nn.Parameter(torch.ones(())) + def forward(self,values): + previous=values[:,:-256];native=previous[:,:-256] + fusion_delta=values[:,-256:-128];covariance_delta=values[:,-128:] + adjusted=torch.cat([native[:,:-512],native[:,-512:-384]+self.codebrain_gain*fusion_delta,native[:,-384:-128],native[:,-128:]+self.codebrain_gain*covariance_delta],-1) + return self.prior(torch.cat([adjusted,previous[:,-256:]],-1)) + +class WaveCoactivationContext(nn.Module): + """One common encoder of coactivation among the learned waveform channels.""" + def __init__(self,channels=64,width=128): + super().__init__();self.channels=channels + ii,jj=torch.triu_indices(channels,channels,offset=1) + self.register_buffer('pair_i',ii);self.register_buffer('pair_j',jj) + self.register_buffer('offdiagonal_enabled',torch.ones(())) + self.encoder=nn.Sequential(nn.LayerNorm(channels+len(ii)),nn.Linear(channels+len(ii),width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width)) + def statistics(self,native): + with torch.autocast(native.device.type,enabled=False): + wave=native[:,:-512].float().reshape(len(native),self.channels,-1) + centered=wave-wave.mean(-1,keepdim=True) + previous_tf32=torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32=False + covariance=centered@centered.transpose(-1,-2)/wave.shape[-1] + torch.backends.cuda.matmul.allow_tf32=previous_tf32 + variance=covariance.diagonal(dim1=-2,dim2=-1).clamp_min(1e-8) + correlation=covariance/(variance.sqrt()[:,:,None]*variance.sqrt()[:,None,:]) + return torch.cat([variance.log(),correlation[:,self.pair_i,self.pair_j].clamp(-1,1)],-1) + def encode_statistics(self,values): + with torch.autocast(values.device.type,enabled=False): + value=torch.cat([values[:,:self.channels],self.offdiagonal_enabled*values[:,self.channels:]],-1) + return self.encoder(value.float()) + def forward(self,native):return self.encode_statistics(self.statistics(native)) + +class WaveCoactivationHead(nn.Module): + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=self.correction_gain*self.output_scale*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class OrdinalFeatureHead(nn.Module): + """Private strength of one common ordinal-dynamics feature correction.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.ordinal_gain=nn.Parameter(torch.ones(())) + def forward(self,values): + previous=values[:,:-256];native=previous[:,:-640] + adjusted=torch.cat([native[:,:-512],native[:,-512:-384]+self.ordinal_gain*values[:,-256:-128],native[:,-384:-128],native[:,-128:]+self.ordinal_gain*values[:,-128:],previous[:,-640:]],-1) + return self.prior(adjusted) + +class PhaseReadoutHead(nn.Module): + """Private class evidence from the common complex-coherence encoder.""" + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=(self.correction_gain*self.output_scale)*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class CouplingReadoutHead(nn.Module): + """Private class evidence from the common cross-frequency coupling encoder.""" + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=(self.correction_gain*self.output_scale)*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class HybridModel(nn.Module): + def __init__(self,channels=32,width=128,depth=2,dropout=.5,wave_filters=32,head_width=64,head_dropout=.3,clinical_asymmetry=True,alpha_regions=None,clinical_envelope=False,temporal_pool=True,temporal_evidence=False,evidence_temperature=.25,random_fourier=False,fourier_features=256,tangent_readout=True,shared_context_correction=True,wave_coactivation=True,ordinal_context=True,phase_coherence=True,cross_frequency=True,cbramod_feature_transfer=True,student_architecture=None): + super().__init__() + self.adapters=nn.ModuleDict({t:InputAdapter(c,width,channels,spectral_enabled=t not in ("faced","tuev","openbmi"),asymmetry=clinical_asymmetry and t=="tuev",alpha_regions=alpha_regions if t=="longitudinal" else None,envelope=clinical_envelope and t=="tuev") for t,(c,s,k) in SPECS.items()}) + self.backbone=SharedBackbone(channels,width,depth,dropout,wave_filters) + self.backbone.student_encoder=CBraModFeatures(**(student_architecture or {})) + self.backbone.register_buffer('student_ordered_enabled',torch.ones(())) + self.backbone.student_readout=nn.Sequential(nn.Linear(self.backbone.student_encoder.output_dim,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + for t,(c,s,k) in SPECS.items(): + self.adapters[t].student_input=FrequencyAdapter(c,32) + self.adapters[t].student_normalizer=Standardize(self.backbone.student_encoder.output_dim) + self.backbone.wave_coactivation=WaveCoactivationContext(2*wave_filters,width) + self.heads=nn.ModuleDict({t:ResidualHead(2*wave_filters*(((s*200+1)//4+1)//8)+width+256+width,k,head_width,head_dropout,full_precision=t=='ad65') for t,(c,s,k) in SPECS.items()}) + if temporal_pool:self.heads=nn.ModuleDict({t:TemporalPoolHead(head,wave_filters*2) for t,head in self.heads.items()}) + if temporal_evidence:self.heads=nn.ModuleDict({t:TemporalEvidenceHead(head,wave_filters*2,evidence_temperature) for t,head in self.heads.items()}) + if random_fourier:self.heads=nn.ModuleDict({t:FourierResidualHead(head,2*wave_filters*(((SPECS[t][1]*200+1)//4+1)//8)+width+256+width,SPECS[t][2],fourier_features) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:TangentFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CodeBrainFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:WaveCoactivationHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:OrdinalFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:PhaseReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + def student_features(self,t,x): + outputs=[];old_fastpath=torch.backends.mha.get_fastpath_enabled();torch.backends.mha.set_fastpath_enabled(False) + try: + for raw in x.split(16): + signal=torch.nan_to_num(raw.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + with torch.autocast(signal.device.type,dtype=torch.bfloat16,enabled=signal.device.type=='cuda'): + outputs.append(self.backbone.student_encoder(self.adapters[t].student_input(signal))) + finally:torch.backends.mha.set_fastpath_enabled(old_fastpath) + return torch.cat(outputs).float() + def student_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].student_normalizer(values.float()) + normalized=torch.cat([normalized[:,:256],self.backbone.student_ordered_enabled*normalized[:,256:]],-1) + return self.backbone.student_readout(normalized) + def coupling_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False):return self.backbone.coupling_encoder(self.adapters[t].coupling_embedding(values.float())) + def phase_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].phase_normalizer(values.float()) + normalized=torch.cat([normalized[:,:PHASE_HALF],self.backbone.phase_imaginary_enabled*normalized[:,PHASE_HALF:]],-1) + return self.backbone.phase_encoder(normalized) + def forward(self,t,x,features=None,covariances=None,covariance_features=None): + if features is None:features=extract_features(t,x) + if covariance_features is None: + if covariances is None:covariances=extract_covariances(t,x) + covariance_features=self.adapters[t].spatial_features(covariances) + signal=x.flatten(2);signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + adapted=self.adapters[t](signal,features,covariance_features) + if covariances is None:covariances=extract_covariances(t,x) + tangent=extract_tangent_features(covariances,self.adapters[t].spatial_weight) + representation,fusion_delta,covariance_delta,fusion_input=self.backbone(*adapted,tangent_features=tangent) + if t in ('faced','openbmi'): + representation=torch.cat([representation[:,:-384],torch.zeros_like(representation[:,-384:-128]),representation[:,-128:]],-1) + tokens=torch.zeros(len(signal),signal.shape[-1]//200,24*64,device=signal.device,dtype=torch.bfloat16) + code_fusion,code_covariance=self.backbone.codebrain_correction(tokens,representation,fusion_input) + coactivation=self.backbone.wave_coactivation(representation) + with torch.autocast(signal.device.type,enabled=False): + ordinal=self.adapters[t].ordinal_embedding(ordinal_features(t,x)) + ordinal_covariance=self.backbone.ordinal_context(ordinal.float()) + added=.001*nn.functional.linear(ordinal_covariance,self.backbone.covariance_projection.weight,None) + ordinal_fusion=self.backbone.fusion(fusion_input+added.to(fusion_input.dtype))-representation[:,-512:-384] + phase=self.phase_embedding(t,phase_features(t,x,self.adapters[t].spatial_weight)) + coupling=self.coupling_embedding(t,coupling_features(t,x)) + student=self.student_embedding(t,self.student_features(t,x)) + return self.heads[t](torch.cat([representation,fusion_delta,covariance_delta,code_fusion,code_covariance,coactivation,ordinal_fusion,ordinal_covariance,phase,coupling,student],-1)) + +def widen_state_dict(state,multiplier=2): + """Duplicate temporal features and divide downstream sums to preserve outputs.""" + result={} + for key,value in state.items(): + if key.startswith('backbone.waveform.'): + layer=int(key.split('.')[2]) + if layer in (0,2,7):value=value.repeat(multiplier,1,1,1) + elif layer in (1,3,9):value=value.repeat(multiplier) + elif layer==8:value=value.repeat(multiplier,multiplier,1,1)/multiplier + elif key=='backbone.wave_summary.2.weight':value=value.repeat(1,multiplier)/multiplier + elif key.startswith('heads.') and key.endswith('.weight'): + raw=value[:,:-128]/multiplier + value=torch.cat([raw]*multiplier+[value[:,-128:]],1) + result[key]=value + return result + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/ordinal_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/ordinal_features.py new file mode 100644 index 0000000000000000000000000000000000000000..6e3d5ff8264253f058f71b04d9cc8454196592b1 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/ordinal_features.py @@ -0,0 +1,25 @@ +"""Fixed within-window ordinal dynamics, independent of amplitude scaling.""" +import math +import torch +LAGS=(1,2,4,8,16) +PATTERNS=24 +PER_CHANNEL=len(LAGS)*(PATTERNS+2) + +def ordinal_features(track,x): + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + parts=[];uniform=1/PATTERNS;maximum_entropy=math.log(PATTERNS);m0=(1+uniform)/2;mr=uniform/2;maximum_js=-m0*math.log(m0)-(PATTERNS-1)*mr*math.log(mr)-maximum_entropy/2 + for lag in LAGS: + length=x.shape[-1]-3*lag + if length<=0:raise ValueError('window too short for ordinal dynamics') + samples=torch.stack([x[...,i*lag:i*lag+length] for i in range(4)],-1) + order=samples.argsort(dim=-1,stable=True) + code=6*((order[...,0,None]>order[...,1:]).sum(-1))+2*((order[...,1,None]>order[...,2:]).sum(-1))+(order[...,2]>order[...,3]).long() + histogram=torch.zeros(*x.shape[:2],PATTERNS,device=x.device,dtype=torch.float32) + histogram.scatter_add_(-1,code,torch.ones_like(code,dtype=torch.float32));probability=histogram/length + entropy=-(probability*probability.clamp_min(1e-12).log()).sum(-1) + mixture=(probability+uniform)/2;mixture_entropy=-(mixture*mixture.log()).sum(-1) + complexity=((mixture_entropy-.5*entropy-.5*maximum_entropy)/maximum_js).clamp(0,1)*(entropy/maximum_entropy) + parts.append(torch.cat([probability,(entropy/maximum_entropy)[...,None],complexity[...,None]],-1)) + return torch.cat(parts,-1).flatten(1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/phase_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/phase_features.py new file mode 100644 index 0000000000000000000000000000000000000000..8d98822995bf37b499795dfd7e2e401040a01969 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/phase_features.py @@ -0,0 +1,37 @@ +"""Complex spectral coherence of the existing 24 spatial filters in ten bands.""" +import torch +from covariances import BANDS +CHANNELS=24 +PHASE_HALF=len(BANDS)*CHANNELS*(CHANNELS-1)//2 +PHASE_DIM=2*PHASE_HALF + +@torch.no_grad() +def phase_features(track,x,spatial_weight): + previous_tf32=torch.backends.cuda.matmul.allow_tf32 + try: + torch.backends.cuda.matmul.allow_tf32=False + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if track in ('faced','tuev'):x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + else:x=x-x.mean(1,keepdim=True) + x=x/x.square().mean((1,2),keepdim=True).clamp_min(1e-12).sqrt() + frames=x.unfold(-1,400,200);frames=frames-frames.mean(-1,keepdim=True) + z=torch.fft.rfft(frames*torch.hann_window(400,device=x.device),dim=-1)/200 + w=spatial_weight.float()/spatial_weight.float().norm(dim=-1,keepdim=True).clamp_min(1e-6) + index=torch.triu_indices(CHANNELS,CHANNELS,1,device=x.device) + real_parts=[];imaginary_parts=[] + for band,(lo,hi) in enumerate(BANDS): + v=z[...,2*lo:2*hi].flatten(2) + vr=w[band][None]@v.real;vi=w[band][None]@v.imag + real=(vr@vr.transpose(-1,-2)+vi@vi.transpose(-1,-2))/v.shape[-1] + imaginary=(vi@vr.transpose(-1,-2)-vr@vi.transpose(-1,-2))/v.shape[-1] + # Signals have unit global RMS; this floor suppresses phase of numerical silence. + power=real.diagonal(dim1=-2,dim2=-1).clamp_min(1e-6) + denominator=(power[:,:,None]*power[:,None,:]).sqrt().clamp_min(1e-12) + real=(real/denominator).clamp(-.999,.999) + imaginary=(imaginary/denominator).clamp(-.999,.999) + real_parts.append(torch.atanh(real[:,index[0],index[1]])) + imaginary_parts.append(torch.atanh(imaginary[:,index[0],index[1]])) + return torch.cat(real_parts+imaginary_parts,-1) + finally:torch.backends.cuda.matmul.allow_tf32=previous_tf32 diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/private-head-refresh-audit.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/private-head-refresh-audit.json new file mode 100644 index 0000000000000000000000000000000000000000..cc234801dfb95ec73315ed265265e6d4a4ef6959 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/private-head-refresh-audit.json @@ -0,0 +1,23 @@ +{ + "reference": "/workspace/research/runs/student_private_retention_control1/epoch-030", + "donor": "/workspace/research/runs/student_private_unanchored1/epoch-030", + "track": "faced", + "source_sha256": { + "reference": "de55cf5362cb45ecd7f7cb8ac3ade4d7634fcd2e99f23283abc6e663a261df50", + "donor": "d4e0c43d16cd7d287da31fc2fce57926fd28a04389d8dae421d3d718d097abff" + }, + "changed_private_tensors": [ + "heads.faced.projection.weight", + "heads.faced.projection.bias" + ], + "all_common_input_and_prior_head_tensors_exactly_equal": true, + "executable_code_and_architecture_exactly_equal": true, + "one_common_checkpoint": true, + "prediction_sources": { + "faced": "/workspace/research/runs/student_private_unanchored1/faced-e030.npy", + "tuev": "/workspace/research/runs/student_private_retention_control1/tuev-e030.npy", + "ad65": "/workspace/research/runs/student_private_retention_control1/ad65-e030.npy", + "openbmi": "/workspace/research/runs/student_private_retention_control1/openbmi-e030.npy", + "longitudinal": "/workspace/research/runs/student_private_retention_control1/longitudinal-e030.npy" + } +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/private-readout-refresh-audit.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/private-readout-refresh-audit.json new file mode 100644 index 0000000000000000000000000000000000000000..1d02ef9e4aa8d0782c67157b160ef5667bfa1193 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/private-readout-refresh-audit.json @@ -0,0 +1,40 @@ +{ + "child": "/workspace/research/runs/coupling_patient1/epoch-007", + "donor": "/workspace/research/runs/phase_readout1/epoch-016", + "common_ancestor": "/workspace/research/runs/phase_coherence1/epoch-007", + "source_weight_sha256": { + "child": "f8466c6838ff01e54d1619f55668c1a4af26a243b54c67a956a3422d9604632a", + "donor": "ffd219d1480b81720b5aa4014cb2ed2b9cd31b7c92ad4717abc2a9625d30dc1a", + "ancestor": "e53ede409be523d8f4746251f7d46353621049f0378a88d4f7cfe2ba71a57d95" + }, + "changed_private_tensors": [ + "heads.openbmi.prior.projection.weight", + "heads.openbmi.prior.projection.bias" + ], + "all_ancestor_common_and_input_tensors_equal": true, + "all_child_common_and_input_tensors_unchanged": true, + "new_branch_gain_for_refreshed_track": 0.0, + "donor_changes_only_requested_private_projection": true, + "prediction_sources": { + "faced": { + "source": "/workspace/research/runs/coupling_patient1/faced-e007.npy", + "sha256": "68b617c8ecf347c79b23c20b70f6b4981c2f26b7b8c71dc7cd5fa0d7f4285ea6" + }, + "tuev": { + "source": "/workspace/research/runs/coupling_patient1/tuev-e007.npy", + "sha256": "9f0743450f1104d395e9daac0600aaf20755b5590b9f5c3e3137732c479dd647" + }, + "ad65": { + "source": "/workspace/research/runs/coupling_patient1/ad65-e007.npy", + "sha256": "7a3b74c58580b7ba952322bf6d527ebc9a40a6e04c7cdbbaea14e84a7a298d54" + }, + "openbmi": { + "source": "/workspace/research/runs/phase_readout1/openbmi-e016.npy", + "sha256": "14f630543e1df88c88d8f3e0effb4506ba33f533b3484de3c7aaf6554507341c" + }, + "longitudinal": { + "source": "/workspace/research/runs/coupling_patient1/longitudinal-e007.npy", + "sha256": "e93b0a319eaa3ddca9d71b0e786b808ba1630c1d3ce125f8e08036e517741b74" + } + } +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/student_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/student_features.py new file mode 100644 index 0000000000000000000000000000000000000000..57401f6d2ab760cb1a58af564aef2e62290e8907 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/student_features.py @@ -0,0 +1,34 @@ +"""One audited CBraMod core with full-window shared and ordered representations.""" +import torch +from torch import nn +from braindecode.models import CBraMod +from frequency_features import frequency_components,FREQUENCY_BANDS +SPECS={'faced':(32,10,9),'tuev':(16,5,6),'ad65':(19,10,3),'openbmi':(62,4,2),'longitudinal':(58,2,2)} +TRACKS=tuple(SPECS) + +class FrequencyAdapter(nn.Module): + def __init__(self,channels,virtual_channels=32): + super().__init__();self.signal=nn.Conv1d(channels,virtual_channels,1,bias=False) + self.frequency_weight=nn.Parameter(torch.zeros(len(FREQUENCY_BANDS),virtual_channels,channels)) + def forward(self,x): + components=frequency_components(x) + correction=torch.einsum('blc,nbct->nlt',self.frequency_weight,components.to(self.frequency_weight.dtype)) + return self.signal(x)+correction.to(x.dtype) + +class CBraModFeatures(nn.Module): + def __init__(self,virtual_channels=32,token_width=64,summary_width=256,head_width=128,dropout=.3): + super().__init__();self.virtual_channels=virtual_channels;self.output_dim=summary_width+virtual_channels*token_width*4 + self.backbone=CBraMod(n_chans=virtual_channels,n_outputs=2,n_times=400,sfreq=200) + self.backbone.final_layer=nn.Identity() + self.token_projection=nn.Sequential(nn.LayerNorm(200),nn.Linear(200,token_width),nn.GELU()) + self.summary_projection=nn.Sequential(nn.LayerNorm(virtual_channels*token_width*2),nn.Linear(virtual_channels*token_width*2,summary_width),nn.GELU(),nn.Dropout(dropout)) + def forward(self,signal): + tokens=self.token_projection(self.backbone(signal)) + moments=torch.cat([tokens.mean(2),tokens.float().std(2,correction=0).to(tokens.dtype)],-1).flatten(1) + summary=self.summary_projection(moments) + ordered=torch.nn.functional.adaptive_avg_pool1d(tokens.permute(0,1,3,2).flatten(1,2),4).flatten(1) + return torch.cat([summary,ordered],-1) + + def named_shared_parameters(self): + for prefix,module in [('backbone',self.backbone),('token_projection',self.token_projection),('summary_projection',self.summary_projection)]: + for name,p in module.named_parameters():yield f'{prefix}.{name}',p diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/tangent_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/tangent_features.py new file mode 100644 index 0000000000000000000000000000000000000000..314f0cf2f58e4b4a1c1d808edbd4acc3b7b6f85b --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S067/tangent_features.py @@ -0,0 +1,25 @@ +"""Window-local log-correlation geometry in the existing spatial-filter basis.""" +import torch + +TANGENT_DIM=10*24*25//2 + +@torch.no_grad() +def extract_tangent_features(covariances,spatial_weight): + old_tf32=torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(covariances.device.type,enabled=False): + w=spatial_weight.float() + w=w/w.norm(dim=-1,keepdim=True).clamp_min(1e-6) + projected=torch.einsum('bfc,nbcd,bgd->nbfg',w,covariances.float(),w) + d=projected.diagonal(dim1=-2,dim2=-1).clamp_min(1e-10).sqrt() + correlation=(projected/(d.unsqueeze(-1)*d.unsqueeze(-2))).clamp(-1,1) + correlation=(correlation+correlation.transpose(-1,-2))/2 + correlation=.95*correlation+.05*torch.eye(24,device=correlation.device) + values,vectors=torch.linalg.eigh(correlation) + logarithm=(vectors*values.clamp_min(1e-6).log().unsqueeze(-2))@vectors.transpose(-1,-2) + i,j=torch.triu_indices(24,24,device=correlation.device) + scale=torch.where(i==j,1.,2.**.5) + return (logarithm[...,i,j]*scale).flatten(1) + finally: + torch.backends.cuda.matmul.allow_tf32=old_tf32 diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/MODEL_CARD.md b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/MODEL_CARD.md new file mode 100644 index 0000000000000000000000000000000000000000..fc1f7a9dda9ae0cc9730669e5ca4248ca831168f --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/MODEL_CARD.md @@ -0,0 +1,33 @@ +# Shared EEG decoder + +This package contains one coupled backbone used by all five tracks, with private input adapters and classifiers. Every trainable common component was trained with all five training splits. It is a single model; inference performs no parameter updates or dataset-level fitting. + +The common backbone combines waveform convolutions, an audited pretrained BIOT feature path, covariance and log-correlation encoders, and shared feature corrections. The waveform coactivation extension encodes 64 within-window log variances and 2,016 correlations between common waveform channels. A matched experimental control removes the correlation inputs. `config.json` identifies the packaged variant and its five fixed correction gains. All original backbone parameters are fixed during this extension's joint training. + +Weights originate only from the supplied training data and audited initialization checkpoints. Training details, parent provenance, raw/cache checks, shared-gradient checks and the five separate validation metrics are recorded in `training.json`. Validation selects checkpoints and fixed gains; it does not fit normalization or update parameters. Reported validation results belong to selected checkpoints, not to private test evaluation or five-seed means. + +Run `bash infer.sh INPUT_DIR OUTPUT_DIR`. The input manifest specifies a track and opaque sample IDs, shard paths and indices. Signals are in microvolts and are scaled by 1/100. The package writes one probability vector per input ID to `OUTPUT_DIR/predictions.jsonl`. It needs only the packaged files and the contract's installed Python dependencies, works after relocation, and does not need labels, subject IDs, training caches or network access. + +FACED and TUEV use window balanced accuracy. AD65 uses mean window probabilities per patient before balanced accuracy. OpenBMI averages within-subject balanced accuracy. Longitudinal averages within-session balanced accuracy within each subject, then over subjects. These five metrics remain separate. + +This checkpoint adds fixed within-window ordinal pattern probabilities, permutation entropy and statistical complexity at five delays. Training-only normalization and five input projections feed one common correction MLP trained by all five tracks. The common correction enters the existing covariance and fusion representations; fixed per-track gains select its strength. All earlier model tensors remain unchanged. + +Fixed real and imaginary spectral coherence between the inherited 24 spatial filters is normalized using training windows only and encoded by one new common network. Five private linear heads add class evidence. All five training splits update the new common encoder; all earlier model tensors remain unchanged. + +Fixed per-window relative band powers, envelope variability, envelope correlations and phase-amplitude coupling feed training-normalized private input projections and one new shared encoder. Five linear heads add class evidence. All five training splits update the new common encoder; all prior model tensors remain unchanged. AD65 updates use all windows from six class-balanced training patients; objective: mean-probability. + +The inherited OpenBMI phase-classifier projection was refreshed from a separately validated private-readout fit. Every common tensor and input adapter of this jointly trained model is unchanged. Exact ancestor checks confirm that all common tensors used by this inherited readout are identical; the new cross-frequency correction remains disabled for OpenBMI. No shared checkpoints or predictions are ensembled. + +A common CBraMod feature encoder, itself jointly trained on all five training splits, supplies its shared summary and tokens pooled into four ordered time bins. Its classifiers are discarded. A new common feature MLP and five zero-initialized private linear projections learn residual class evidence jointly on all five training splits. The same new class projection also receives an auxiliary standalone classification loss when configured, with the same patient-pooled AD objective; this adds no inference module. The complete earlier decoder and feature extractor remain tensor-identical; selecting zero residual gain preserves its predictions exactly. The summary-only control masks the 8192 ordered features after training-fitted per-feature normalization. One feature backbone and one classifier per track run at inference, with no prediction ensemble or external runtime cache. + +The five outer private student-feature class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. + +The five outer private student-feature class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. + +The faced private outer projection is selected from another training-only readout fit using exactly the same common/input/prior-head tensors. All other private heads are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +The five outer private student-feature class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. + +During training, parent logits may be suppressed independently per window or per AD patient; original teacher probabilities and labels remain unchanged. Validation and inference retain the complete parent. A new common encoder fuses fixed spectral and coupling descriptors from either the central two seconds or the complete window, through five private input projections. It is trained jointly on all five training splits with exact patient-mean AD classification. Every earlier model tensor remains unchanged. Five zero-initialized residual class projections select gains within one common checkpoint. All normalization statistics use training data only. Inference computes descriptors from the current window and requires no labels, subjects, external caches or adaptation. + +The inherited faced classifier projection was refreshed from a validated private-readout fit with exactly matching common ancestry. Every common tensor and input adapter of this child model is unchanged. The added short-window correction is disabled for the refreshed track, so its probabilities equal the donor. Only the specified private projection is copied; there is no shared-weight or prediction averaging. diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/alpha_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/alpha_features.py new file mode 100644 index 0000000000000000000000000000000000000000..455154d715e86d45e4e17113bed69adbcd946b29 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/alpha_features.py @@ -0,0 +1,45 @@ +"""Fixed alpha prominence features from each individual two-second window.""" +import torch + +REGION_NAMES=('occipital','parietal','central','frontal','left_posterior','right_posterior') +REGIONS=(('PO7','PO5','PO3','POZ','PO4','PO6','PO8','O1','OZ','O2'), + ('P7','P5','P3','P1','PZ','P2','P4','P6','P8'), + ('FC5','FC3','FC1','FCZ','FC2','FC4','FC6','C5','C3','C1','CZ','C2','C4','C6'), + ('FP1','FPZ','FP2','AF3','AF4','F7','F5','F3','F1','FZ','F2','F4','F6','F8'), + ('P7','P5','P3','P1','PO7','PO5','PO3','O1'), + ('P2','P4','P6','P8','PO4','PO6','PO8','O2')) +ALPHA_DIM=58*7+6*22 + +def region_matrix(channels): + result=torch.zeros(len(REGIONS),len(channels)) + for i,names in enumerate(REGIONS): + for name in names:result[i,channels.index(name)]=1/len(names) + return result.tolist() + +@torch.no_grad() +def extract_alpha_features(signal,regions): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();x=x-x.mean(-1,keepdim=True) + spectrum=torch.fft.rfft(x*torch.hann_window(400,device=x.device),dim=-1)/200 + power=spectrum.abs().square().clamp_min(1e-12) + lp=power.log() + # Geometric regional means resist domination by one high-amplitude channel. + regional=torch.einsum('rc,ncf->nrf',regions.float(),lp) + lp=torch.cat([lp,regional],1) + low=lp[...,8:13].mean(-1,keepdim=True) + high=lp[...,36:49].mean(-1,keepdim=True) + freq=torch.arange(7.,14.5,.5,device=x.device) + alpha=lp[...,14:29] + baseline=low+(high-low)*((freq-5)/16) + prominence=alpha-baseline + normalized=alpha.softmax(-1) + center=(normalized*freq).sum(-1) + entropy=-(normalized*normalized.clamp_min(1e-12).log()).sum(-1) + alpha_mean=torch.logsumexp(alpha,-1)-torch.log(torch.tensor(15.,device=x.device)) + def log_band(lo,hi): + return torch.logsumexp(lp[...,lo:hi],-1)-torch.log(torch.tensor(float(hi-lo),device=x.device)) + summaries=torch.stack([alpha_mean-log_band(2,81),alpha_mean-log_band(8,14), + alpha_mean-log_band(30,61),prominence.max(-1).values, + prominence.mean(-1),center,entropy],-1) + return torch.cat([summaries[:,:58].flatten(1),summaries[:,58:].flatten(1), + prominence[:,58:].flatten(1)],1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/config.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/config.json new file mode 100644 index 0000000000000000000000000000000000000000..f790ffe3863780f3a2ca9943c6a37744187f48dd --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/config.json @@ -0,0 +1,872 @@ +{ + "schema": "bci-shared-biot-covariance-bf16head-v1", + "architecture": { + "channels": 32, + "width": 128, + "depth": 2, + "dropout": 0.5, + "wave_filters": 32, + "head_width": 64, + "head_dropout": 0.3, + "clinical_asymmetry": true, + "alpha_regions": [ + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.125 + ] + ], + "clinical_envelope": true, + "temporal_pool": true, + "temporal_evidence": true, + "evidence_temperature": 0.25, + "random_fourier": true, + "fourier_features": 256, + "tangent_readout": true, + "shared_context_correction": true, + "wave_coactivation": true, + "ordinal_context": true, + "phase_coherence": true, + "cross_frequency": true, + "cbramod_feature_transfer": true, + "student_architecture": { + "virtual_channels": 32, + "token_width": 64, + "summary_width": 256, + "head_width": 128, + "dropout": 0.3 + }, + "short_window_view": "full" + }, + "initialization": { + "initialization": "continue joint training from a complete shared-model checkpoint", + "parent": "/workspace/research/runs/hybrid_biot_fusionshrink0100/epoch-001/weights.pt", + "parent_initialization": { + "initialization": "jointly trained parent plus audited pretrained BIOT in a single coupled backbone", + "parent": "/workspace/research/runs/hybrid_wide1/epoch-004/weights.pt", + "audited_biot": { + "initialization": "pretrained", + "repo": "braindecode/biot-pretrained-six-datasets-18chs", + "revision": "7e9aabf302870012f73773276803aab97993951c", + "sha256": "a218f4054ae29962c6fd9d23d94c446d354c4f53e805a6771c85749ccc20baaa", + "license": "BSD-3-Clause", + "source_braindecode": "1.3.0", + "loaded_core_tensors": 56, + "skipped_classifier_tensors": 3 + }, + "neural_channel_indices": { + "faced": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "tuev": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15 + ], + "ad65": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "openbmi": [ + 0, + 1, + 3, + 5, + 12, + 14, + 23, + 25, + 28, + 30, + 2, + 6, + 11, + 15, + 22, + 26, + 4, + 13 + ], + "longitudinal": [ + 0, + 2, + 7, + 11, + 23, + 27, + 41, + 45, + 55, + 57, + 5, + 13, + 21, + 29, + 39, + 47, + 9, + 25 + ] + }, + "rebase": "incumbent waveform, fusion and four heads; joint BIOT and TUEV head from readout epoch 9; zero initialized neural interaction", + "jointly_finetuned_neural_parent": "/workspace/research/runs/hybrid_biot_readout1/epoch-009/weights.pt", + "tuev_high_dimensional_spectral_projection_disabled": true, + "frozen_prior_representation": true, + "nonclinical_head_updates": "only the 256 added BIOT columns; original columns and biases fixed", + "faced_openbmi_neural_path": "common nonlinear fusion only; direct head columns masked", + "retention_teacher": "/workspace/research/runs/hybrid_wide1/epoch-004", + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "joint_covariance_parent": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "frozen_prior_representation": true, + "head_updates": "one linear head per track; added 128 shared covariance columns trainable; AD head initialized from the joint covariance parent", + "new_shared_representation": "one common covariance MLP inside the coupled backbone, trained by all five tasks; fixed spatial input adapters from the same jointly trained source", + "head_arithmetic": "one linear head evaluated in fixed feature blocks to preserve original bfloat16 accumulation dimensions", + "retention_teacher": { + "ad65": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "other_tracks": "/workspace/research/runs/hybrid_wide1/epoch-004" + }, + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "loader_scale": 0.01, + "tracks": [ + "faced", + "tuev", + "ad65", + "openbmi", + "longitudinal" + ], + "head_arithmetic": "same linear head in fixed feature blocks, sum in bfloat16 on GPU for non-AD tracks; AD remains float32", + "head_refinement": { + "source": "/workspace/research/runs/residual_heads1/epoch-018", + "source_weights_sha256": "e0b609137391b47f99438ccadaa22fc0bc10d2c10ead0ddf0a3c25be2c907c85", + "shared_backbone_unchanged": true, + "selected_head_epochs": { + "faced": 5, + "tuev": 24, + "ad65": 0, + "openbmi": 0, + "longitudinal": 0 + } + }, + "clinical_spectral_refinement": { + "source": "/workspace/research/runs/head_dropout1/epoch-016", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "head_estimation": { + "method": "class/subject-balanced Gaussian linear discriminant; covariance augmented by class-conditional subject/session mean variation before shrinkage", + "selected_shrinkage": { + "faced": "inherited", + "tuev": "inherited", + "ad65": "inherited", + "openbmi": "inherited", + "longitudinal": { + "shrinkage": 0.9, + "domain_strength": 1.0 + } + }, + "feature_scaling": "fitted on training data and folded into linear coefficients" + }, + "clinical_asymmetry_refinement": { + "source": "/workspace/research/runs/domain_lda_heads1/epoch-001", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "alpha_rhythm_adapter": { + "training_normalization_only": true, + "regions": [ + "occipital", + "parietal", + "central", + "frontal", + "left_posterior", + "right_posterior" + ], + "features": "per-window alpha prominence relative to adjacent frequencies", + "shared_backbone_unchanged": true + }, + "clinical_envelope_refinement": { + "source": "/workspace/research/runs/clinical_asymmetry1/epoch-001", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "independent_adapter_merge": { + "alpha_source": "/workspace/research/runs/alpha_calibrated1/epoch-003", + "clinical_source": "/workspace/research/runs/clinical_envelope1/epoch-002", + "all_shared_and_head_tensors_equal": true + }, + "frequency_montage_refinement": { + "six_frequency_bands": true, + "shared_encoder_unchanged": true, + "selected_track_epochs": { + "faced": 0, + "tuev": 1, + "ad65": 0, + "openbmi": 10, + "longitudinal": 2 + } + }, + "private_track_selection": { + "track": "tuev", + "donor": "/workspace/research/replicates/frequency_head_control1/epoch-001" + }, + "clinical_sampling_refinement": { + "subject_exponent": 0.0, + "class_balanced": true, + "only_clinical_head_updated": true + }, + "temporal_statistics_readout": { + "statistics": [ + "mean", + "standard deviation", + "maximum", + "minimum" + ], + "shared_encoder_and_prior_heads_unchanged": true, + "selected_pool_epochs": { + "faced": 2, + "tuev": 0, + "ad65": 0, + "openbmi": 33, + "longitudinal": 3 + } + }, + "temporal_evidence_readout": { + "pooling": "log mean exp of per-patch class evidence", + "temperature": 0.25, + "shared_encoder_and_prior_heads_unchanged": true, + "selected_evidence_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 6, + "longitudinal": 8 + } + }, + "fourier_basis_readout": { + "basis_functions": 256, + "bandwidths": [ + 0.5, + 1.0, + 2.0 + ], + "shared_encoder_and_prior_heads_unchanged": true, + "selected_fourier_epochs": { + "faced": 21, + "tuev": 0, + "ad65": 0, + "openbmi": 0, + "longitudinal": 2 + } + }, + "shared_tangent_readout": { + "one_shared_tangent_module": true, + "original_and_corrected_shared_features_retained": true, + "private_head_scalar_gains": { + "faced": 0.0, + "tuev": 0.1, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 0.1 + }, + "all_common_weights_fixed_during_gain_refinement": true + }, + "shared_context_correction": { + "source": "/workspace/research/runs/hybrid_codebrain_fusion_control1/epoch-002", + "zero_token_input_preserved": true, + "unused_native_CodeBrain_core_and_input_parameters_removed": true, + "common_patch_and_context_layers_retained": true, + "same_one_shared_backbone_and_five_classifiers": true + }, + "shared_wave_coactivation": { + "channels": 64, + "statistics": 2080, + "diagonal_only_control": false, + "common_encoder_updated_by_all_five_tracks": true, + "gain_selection_within_one_common_checkpoint": { + "faced": 1.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 1.0 + } + }, + "fixed_common_coactivation_readouts": { + "all_common_weights_exactly_unchanged": true, + "selected_private_epochs": { + "faced": 25, + "tuev": 0, + "ad65": 0, + "openbmi": 8, + "longitudinal": 2 + } + }, + "shared_ordinal_context": { + "per_channel_features": 130, + "normalization_fit_on_training_only": true, + "entropy_only_control": false, + "new_common_layers_trained_on_all_five_tracks": true, + "gains_within_one_common_checkpoint": { + "faced": 1.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 0.0 + } + }, + "shared_complex_coherence": { + "features": 5520, + "normalization_fit_on_training_only": true, + "real_only_control": false, + "all_five_tracks_update_common_encoder": true, + "gains_within_one_common_checkpoint": { + "faced": 0.1, + "tuev": 1.0, + "ad65": 0.0, + "openbmi": 0.3, + "longitudinal": 0.0 + } + }, + "shared_cross_frequency": { + "per_channel_features": 30, + "normalization_fit_on_training_only": true, + "amplitude_only_control": false, + "all_five_tracks_update_common_encoder": true, + "gains_within_one_common_checkpoint": { + "faced": 0.3, + "tuev": 0.1, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 0.0 + } + }, + "inherited_private_readout_refresh": { + "child": "/workspace/research/pilots/short_window_parent_dropout_pilot1/epoch-001", + "donor": "/workspace/research/candidates/student_private_retention_selected_faced", + "common_ancestor": "/workspace/research/runs/student_private_retention_control1/epoch-001", + "source_weight_sha256": { + "child": "67c28768783a1a890f92c1bac734a191bdf28851bfba3e572f05c948da7c484e", + "donor": "0d433d0c6bdf259d65e2ca28e1036cba8e3117567687e7bf2e7966fb01fe879f", + "ancestor": "de55cf5362cb45ecd7f7cb8ac3ade4d7634fcd2e99f23283abc6e663a261df50" + }, + "changed_private_tensors": [ + "heads.faced.prior.projection.weight", + "heads.faced.prior.projection.bias" + ], + "all_ancestor_common_and_input_tensors_equal": true, + "all_child_common_and_input_tensors_unchanged": true, + "new_branch_gain_for_refreshed_track": 0.0, + "donor_changes_only_requested_private_projection": true, + "prediction_sources": { + "faced": { + "source": "/workspace/research/derived_predictions/student_private_retention_selected_faced/faced-e000.npy", + "sha256": "f873fd8d0328350c654396bb431c55cf51380d4a96665de0e3ab8bd62eff0c71" + }, + "tuev": { + "source": "/workspace/research/pilots/short_window_parent_dropout_pilot1/tuev-e001.npy", + "sha256": "9f0743450f1104d395e9daac0600aaf20755b5590b9f5c3e3137732c479dd647" + }, + "ad65": { + "source": "/workspace/research/pilots/short_window_parent_dropout_pilot1/ad65-e001.npy", + "sha256": "7a3b74c58580b7ba952322bf6d527ebc9a40a6e04c7cdbbaea14e84a7a298d54" + }, + "openbmi": { + "source": "/workspace/research/pilots/short_window_parent_dropout_pilot1/openbmi-e001.npy", + "sha256": "14f630543e1df88c88d8f3e0effb4506ba33f533b3484de3c7aaf6554507341c" + }, + "longitudinal": { + "source": "/workspace/research/pilots/short_window_parent_dropout_pilot1/longitudinal-e001.npy", + "sha256": "92dd8348510a643b24cb67a81fbcb6709ef22fcd44b6ec85fccfc2e5bf7aa3f1" + } + } + }, + "shared_student_residual": { + "dimension": 8448, + "summary_dimension": 256, + "ordered_time_bins": 4, + "student_weights_sha256": "19dfe912cceed997699b5b526c8c2ece55945c5f9bd111c4c13704d0fc460e8b", + "summary_only_control": false, + "normalization_fit_on_training_only": true, + "new_common_readout_jointly_trained_on_all_five": true, + "class_projection_initialized_zero": true, + "student_classifiers_discarded": true, + "gains_within_one_common_checkpoint": { + "faced": 1.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 1.0 + }, + "zero_gain_preserves_complete_parent": true + }, + "private_head_refresh": { + "reference": "/workspace/research/runs/student_private_readout1/epoch-030", + "donor": "/workspace/research/pilots/student_common_frozen_pilot1/epoch-001", + "track": "faced", + "source_sha256": { + "reference": "3709c349fae529d53cfe155976f4911c8850077b0283067f1e3ba6029bcc358a", + "donor": "6ebebd9a90057afdaf4720a9d3bbd29fdc5606c9ef826aaebcf7316d31b15a06" + }, + "changed_private_tensors": [ + "heads.faced.projection.weight", + "heads.faced.projection.bias" + ], + "all_common_input_and_prior_head_tensors_exactly_equal": true, + "executable_code_and_architecture_exactly_equal": true, + "one_common_checkpoint": true, + "prediction_sources": { + "faced": "/workspace/research/pilots/student_common_frozen_pilot1/faced-e001.npy", + "tuev": "/workspace/research/runs/student_private_readout1/tuev-e030.npy", + "ad65": "/workspace/research/runs/student_private_readout1/ad65-e030.npy", + "openbmi": "/workspace/research/runs/student_private_readout1/openbmi-e030.npy", + "longitudinal": "/workspace/research/runs/student_private_readout1/longitudinal-e030.npy" + } + }, + "fixed_common_student_readouts": { + "all_common_weights_exactly_unchanged": true, + "selected_private_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 0, + "longitudinal": 1 + } + }, + "short_window_fusion": { + "view": "full", + "center_samples": 400, + "new_common_encoder_trained_on_all_five": true, + "fixed_parent": "/workspace/research/runs/student_private_retention_control1/epoch-001", + "parent_weights_sha256": "de55cf5362cb45ecd7f7cb8ac3ade4d7634fcd2e99f23283abc6e663a261df50", + "gains_within_one_common_checkpoint": { + "faced": 0.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 0.1 + }, + "normalization_fit_on_training_only": true + } +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/coupling_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/coupling_features.py new file mode 100644 index 0000000000000000000000000000000000000000..3a4e51bd7ce07bcec1f0f5b80054d6ff387ac87f --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/coupling_features.py @@ -0,0 +1,34 @@ +"""Per-window cross-frequency envelope and phase-amplitude relationships.""" +import torch +BANDS=((1,4),(4,8),(8,13),(13,30),(30,48)) +PAIRS=tuple((i,j) for i in range(5) for j in range(i+1,5)) +PER_CHANNEL=30 + +@torch.no_grad() +def coupling_features(track,x): + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + n=x.shape[-1];spectrum=torch.fft.fft(x,dim=-1);frequency=torch.fft.fftfreq(n,1/200,device=x.device) + masks=torch.stack([2*((frequency>=lo)&(frequency=lo)&(frequency2).float().mean(-1),(relative>4).float().mean(-1), + ((relative[...,1:]>2)&(relative[...,:-1]<=2)).float().mean(-1), + acf_peak,(acf_index.float()+4)/40, + acf[...,0],acf[...,6],acf[...,16],acf[...,36]] + left=torch.tensor([0,1,2,3,8,9,10,11],device=x.device);right=left+4 + synchrony=(normalized[:,left]*normalized[:,right]).mean(-1).clamp(-1,1) + imbalance=(std[:,left].squeeze(-1).log()-std[:,right].squeeze(-1).log()).abs() + return torch.cat([torch.stack(summaries,-1).flatten(1),synchrony.flatten(1),imbalance.flatten(1)],1) + +def mirrored_features(features): + channels=torch.tensor([4,5,6,7,0,1,2,3,12,13,14,15,8,9,10,11],device=features.device) + return torch.cat([features[:,:16*5*12].reshape(-1,16,5,12)[:,channels].flatten(1),features[:,16*5*12:]],1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/features.py new file mode 100644 index 0000000000000000000000000000000000000000..88f7e8b14c9fab44733d5224ede6d6b5c7f76a45 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/features.py @@ -0,0 +1,63 @@ +"""One shared residual backbone, five linear input adapters and output heads.""" +import torch +from torch import nn + +SPECS = {'faced': (32, 10, 9), 'tuev': (16, 5, 6), 'ad65': (19, 10, 3), + 'openbmi': (62, 4, 2), 'longitudinal': (58, 2, 2)} +TRACKS = tuple(SPECS) +EDGES = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,18,20,22,25,28,32,36,40,45,50,60,70,80,95] +COV_BANDS = [(1,4),(4,8),(8,12),(12,16),(16,20),(20,28),(28,40)] + +def feature_dim(channels): + return channels * (4*(len(EDGES)-1)+4) + len(COV_BANDS)*channels*(channels-1)//2 + +@torch.no_grad() +def extract_features(track, x): + """Fixed features; no batch statistics or fitted inference transformations.""" + x = x.float().flatten(2) + x = torch.nan_to_num(x, nan=0., posinf=1e5, neginf=-1e5).clamp(-1e5,1e5) + x = x - x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'): + x = x - x.mean(1,keepdim=True) + rms = x.square().mean(-1).clamp_min(1e-12).sqrt() + norm = x / rms.unsqueeze(-1) + moments = torch.stack([rms.log(), norm.abs().amax(-1).clamp_min(1).log(), + norm.pow(4).mean(-1).clamp_min(1).log(), + (norm[...,1:]-norm[...,:-1]).square().mean(-1).clamp_min(1e-10).log()],-1) + frames = x.unfold(-1,400,200) + frames = frames - frames.mean(-1,keepdim=True) + window = torch.hann_window(400,device=x.device) + z = torch.fft.rfft(frames*window,dim=-1)/200 + power = z.abs().square() + bands = torch.stack([power[...,2*lo:2*hi].mean(-1) for lo,hi in zip(EDGES[:-1],EDGES[1:])],-1) + lp = bands.mean(-2).clamp_min(1e-12).log() + variation = bands.clamp_min(1e-12).log().std(-2,correction=0) + relative_frequency = lp - lp.mean(-1,keepdim=True) + relative_channel = lp - lp.mean(1,keepdim=True) + parts = [torch.cat([lp, relative_frequency, relative_channel, variation, moments],-1).flatten(1)] + ii,jj = torch.triu_indices(x.shape[1],x.shape[1],offset=1,device=x.device) + for lo,hi in COV_BANDS: + v = z[...,2*lo:2*hi].flatten(2) + cov = v.real @ v.real.transpose(-1,-2) + v.imag @ v.imag.transpose(-1,-2) + d = cov.diagonal(dim1=-2,dim2=-1).clamp_min(1e-12).sqrt() + cor = cov / (d.unsqueeze(1)*d.unsqueeze(2)).clamp_min(1e-12) + parts.append(cor[:,ii,jj].clamp(-1,1)) + result = torch.cat(parts,-1) + return torch.nan_to_num(result).clamp(-40,40) + +class Standardize(nn.Module): + def __init__(self, dim): + super().__init__() + self.register_buffer('mean',torch.zeros(dim)) + self.register_buffer('scale',torch.ones(dim)) + def forward(self,x): + return ((x-self.mean)/self.scale).clamp(-8,8) + +class Residual(nn.Module): + def __init__(self,width,dropout): + super().__init__() + self.net=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(), + nn.Dropout(dropout),nn.Linear(width*2,width),nn.Dropout(dropout)) + def forward(self,x): + return x+self.net(x) + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/frequency_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/frequency_features.py new file mode 100644 index 0000000000000000000000000000000000000000..9194c9e81f801b3833e551e4967991774fa9e398 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/frequency_features.py @@ -0,0 +1,11 @@ +"""Fixed per-window frequency decomposition for a linear montage adapter.""" +import torch + +FREQUENCY_BANDS=((1,4),(4,8),(8,13),(13,20),(20,30),(30,45)) + +def frequency_components(signal): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();spectrum=torch.fft.rfft(x,dim=-1) + frequency=torch.fft.rfftfreq(x.shape[-1],d=1/200,device=x.device) + masks=torch.stack([((frequency>=lo)&(frequencynbf',w,covariances.float(),w).clamp_min(1e-8).log() + return torch.cat([power,power-power.mean(1,keepdim=True)],1).flatten(1) + def wave_signal(self,x,components=None): + if components is None:components=frequency_components(x) + correction=torch.einsum('blc,nbct->nlt',self.frequency_weight,components.to(self.frequency_weight.dtype)) + return (self.signal(x)+correction.to(x.dtype)).unsqueeze(1) + def forward(self,x,features,covariance_features): + return self.wave_signal(x),self.spectral_features(features,signal=x),self.neural(x),covariance_features + +class SharedBackbone(nn.Module): + def __init__(self,channels,width,depth,dropout,wave_filters): + super().__init__() + self.waveform=nn.Sequential( + nn.Conv2d(1,wave_filters,(1,64),padding=(0,32),bias=False),nn.GroupNorm(1,wave_filters), + nn.Conv2d(wave_filters,2*wave_filters,(channels,1),groups=wave_filters,bias=False),nn.GroupNorm(1,2*wave_filters),nn.ELU(), + nn.AvgPool2d((1,4)),nn.Dropout(.35), + nn.Conv2d(2*wave_filters,2*wave_filters,(1,16),padding=(0,8),groups=2*wave_filters,bias=False),nn.Conv2d(2*wave_filters,2*wave_filters,1,bias=False), + nn.GroupNorm(1,2*wave_filters),nn.ELU(),nn.AvgPool2d((1,8)),nn.Dropout(.35)) + self.wave_summary=nn.Sequential(nn.AdaptiveAvgPool2d((1,8)),nn.Flatten(),nn.Linear(2*wave_filters*8,width)) + self.fusion=nn.Sequential(nn.LayerNorm(width),nn.GELU(),nn.Dropout(dropout), + *[Residual(width,dropout) for _ in range(depth)],nn.LayerNorm(width)) + # Both representations interact before the shared residual stack. + self.phase_encoder=nn.Sequential(nn.LayerNorm(PHASE_DIM),nn.Linear(PHASE_DIM,width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width)) + self.register_buffer('phase_imaginary_enabled',torch.ones(())) + self.coupling_encoder=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width),nn.LayerNorm(width)) + self.wave_gain=nn.Parameter(torch.tensor(.1)) + self.biot=BIOT(n_chans=18,n_outputs=2,n_times=400,sfreq=200) + self.biot.final_layer=nn.Identity() + self.biot_projection=nn.Sequential(nn.LayerNorm(256),nn.Linear(256,width),nn.Dropout(.2)) + nn.init.normal_(self.biot_projection[1].weight,std=.001);nn.init.zeros_(self.biot_projection[1].bias) + self.covariance_encoder=nn.Sequential(nn.LayerNorm(len(BANDS)*24*2),nn.Linear(len(BANDS)*24*2,width),nn.GELU(),nn.Dropout(.4), + *[Residual(width,.4) for _ in range(2)],nn.LayerNorm(width)) + self.covariance_projection=nn.Linear(width,width) + nn.init.zeros_(self.covariance_projection.weight);nn.init.zeros_(self.covariance_projection.bias) + self.tangent_encoder=nn.Sequential(nn.LayerNorm(TANGENT_DIM),nn.Linear(TANGENT_DIM,width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width),nn.Linear(width,width)) + self.ordinal_context=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width)) + nn.init.zeros_(self.ordinal_context[-1].weight);nn.init.zeros_(self.ordinal_context[-1].bias) + self.register_buffer('codebrain_enabled',torch.ones(())) + self.codebrain_patch_encoder=nn.Sequential(nn.LayerNorm(24*64),nn.Linear(24*64,width),nn.GELU(),nn.Dropout(.3)) + self.codebrain_context=nn.Sequential(nn.LayerNorm(width*4),nn.Linear(width*4,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width)) + nn.init.zeros_(self.codebrain_context[-1].weight);nn.init.zeros_(self.codebrain_context[-1].bias) + def codebrain_correction(self,tokens,representation,fusion_input): + with torch.autocast(tokens.device.type,enabled=False): + encoded=self.codebrain_patch_encoder(self.codebrain_enabled*tokens.float()) + pooled=torch.cat([encoded.mean(1),encoded.std(1,correction=0),representation[:,-512:-384].float(),representation[:,-128:].float()],-1) + delta=self.codebrain_context(pooled) + added=.001*nn.functional.linear(delta,self.covariance_projection.weight,None) + corrected=self.fusion(fusion_input+added.to(fusion_input.dtype)) + return corrected-representation[:,-512:-384],delta + def forward(self,signal,spectral,neural_signal,covariance_features,tangent_features): + wave=self.waveform(signal) + neural=self.biot(neural_signal.float()) + neural=self.biot_projection[0](neural) + projected=self.biot_projection[2](self.biot_projection[1](neural)) + with torch.autocast(signal.device.type,enabled=False): + covariance_embedding=self.covariance_encoder(covariance_features.float()) + original=spectral+self.wave_gain*self.wave_summary(wave)+.01*projected + coupled=.001*self.covariance_projection(covariance_embedding).to(original.dtype) + fused=self.fusion(original+coupled) + with torch.autocast(signal.device.type,enabled=False):delta=self.tangent_encoder(tangent_features.float()) + added=.001*nn.functional.linear(delta,self.covariance_projection.weight,None) + corrected=self.fusion((original+coupled)+added.to(original.dtype)) + return torch.cat([wave.flatten(1),fused,neural,covariance_embedding],-1),corrected-fused,delta,original+coupled + +class ResidualHead(nn.Module): + """A small nonlinear classifier correction around an inherited linear readout.""" + def __init__(self,features,classes,width=64,dropout=.3,full_precision=False): + super().__init__();self.full_precision=full_precision + self.base=nn.Linear(features,classes) + self.delta=nn.Sequential(nn.LayerNorm(features),nn.Linear(features,width),nn.GELU(),nn.Dropout(dropout),nn.Linear(width,classes)) + nn.init.zeros_(self.delta[-1].weight);nn.init.zeros_(self.delta[-1].bias) + def forward(self,x): + if self.full_precision: + with torch.autocast(x.device.type,enabled=False):return self.base(x.float())+self.delta(x.float()) + prior=nn.functional.linear(x[:,:-128].contiguous(),self.base.weight[:,:-128].contiguous(),self.base.bias) + added=nn.functional.linear(x[:,-128:].contiguous(),self.base.weight[:,-128:].contiguous()) + value=prior+added + return value+self.delta(x).to(value.dtype) + +class TemporalPoolHead(nn.Module): + def __init__(self,prior,channels=64): + super().__init__();self.prior=prior;self.channels=channels + self.register_buffer('pool_output_scale',torch.ones(()));self.register_buffer('pool_mean',torch.zeros(channels*4));self.register_buffer('pool_scale',torch.ones(channels*4)) + self.pool_projection=nn.Linear(channels*4,prior.base.out_features) + nn.init.zeros_(self.pool_projection.weight);nn.init.zeros_(self.pool_projection.bias) + def statistics(self,x): + with torch.autocast(x.device.type,enabled=False): + wave=x[:,:-512].float().reshape(len(x),self.channels,-1) + return torch.cat([wave.mean(-1),wave.std(-1,correction=0),wave.amax(-1),wave.amin(-1)],-1) + def forward(self,x): + prior=self.prior(x) + with torch.autocast(x.device.type,enabled=False): + values=((self.statistics(x)-self.pool_mean)/self.pool_scale).clamp(-8,8) + added=self.pool_output_scale*self.pool_projection(values) + return prior+added.to(prior.dtype) + +class TemporalEvidenceHead(nn.Module): + """Pool class evidence over the shared waveform time axis.""" + def __init__(self,prior,channels=64,temperature=.25): + super().__init__();self.prior=prior;self.channels=channels;self.temperature=temperature + self.register_buffer('evidence_output_scale',torch.ones(())) + self.register_buffer('evidence_mean',torch.zeros(channels)) + self.register_buffer('evidence_scale',torch.ones(channels)) + self.evidence_projection=nn.Linear(channels,prior.prior.base.out_features,bias=False) + nn.init.zeros_(self.evidence_projection.weight) + def patches(self,x): + with torch.autocast(x.device.type,enabled=False): + wave=x[:,:-512].float().reshape(len(x),self.channels,-1).transpose(1,2) + return ((wave-self.evidence_mean)/self.evidence_scale).clamp(-8,8) + def evidence(self,patches): + with torch.autocast(patches.device.type,enabled=False): + values=self.evidence_projection(patches.float())/self.temperature + maximum=values.amax(1,keepdim=True) + pooled=self.temperature*((values-maximum).exp().mean(1).log()+maximum.squeeze(1)) + return self.evidence_output_scale*pooled + def forward(self,x): + prior=self.prior(x) + return prior+self.evidence(self.patches(x)).to(prior.dtype) + +class FourierResidualHead(nn.Module): + """A fixed random Fourier basis and trainable linear classifier correction.""" + def __init__(self,prior,features,classes,basis=256): + super().__init__();self.prior=prior + self.register_buffer('rff_mean',torch.zeros(features));self.register_buffer('rff_scale',torch.ones(features)) + self.register_buffer('rff_frequency',torch.randn(features,basis)/features**.5) + self.register_buffer('rff_phase',torch.rand(basis)*2*torch.pi) + self.register_buffer('rff_output_scale',torch.ones(())) + self.rff_projection=nn.Linear(3*basis,classes);nn.init.zeros_(self.rff_projection.weight);nn.init.zeros_(self.rff_projection.bias) + def basis(self,x): + with torch.autocast(x.device.type,enabled=False): + values=((x.float()-self.rff_mean)/self.rff_scale).clamp(-8,8)@self.rff_frequency + return 2**.5*torch.cat([(values/sigma+self.rff_phase).cos() for sigma in (.5,1.,2.)],-1) + def forward(self,x): + prior=self.prior(x) + with torch.autocast(x.device.type,enabled=False):added=self.rff_output_scale*self.rff_projection(self.basis(x)) + return prior+added.to(prior.dtype) + +class TangentFeatureHead(nn.Module): + """Select a shared feature correction before the inherited classifier.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.feature_gain=nn.Parameter(torch.zeros(())) + def forward(self,values): + old=values[:,:-256];fusion_delta=values[:,-256:-128];covariance_delta=values[:,-128:] + adjusted=torch.cat([old[:,:-512],old[:,-512:-384]+self.feature_gain*fusion_delta,old[:,-384:-128],old[:,-128:]+self.feature_gain*covariance_delta],-1) + return self.prior(adjusted) + +class CodeBrainFeatureHead(nn.Module): + """Private use of a jointly trained common feature correction.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.codebrain_gain=nn.Parameter(torch.ones(())) + def forward(self,values): + previous=values[:,:-256];native=previous[:,:-256] + fusion_delta=values[:,-256:-128];covariance_delta=values[:,-128:] + adjusted=torch.cat([native[:,:-512],native[:,-512:-384]+self.codebrain_gain*fusion_delta,native[:,-384:-128],native[:,-128:]+self.codebrain_gain*covariance_delta],-1) + return self.prior(torch.cat([adjusted,previous[:,-256:]],-1)) + +class WaveCoactivationContext(nn.Module): + """One common encoder of coactivation among the learned waveform channels.""" + def __init__(self,channels=64,width=128): + super().__init__();self.channels=channels + ii,jj=torch.triu_indices(channels,channels,offset=1) + self.register_buffer('pair_i',ii);self.register_buffer('pair_j',jj) + self.register_buffer('offdiagonal_enabled',torch.ones(())) + self.encoder=nn.Sequential(nn.LayerNorm(channels+len(ii)),nn.Linear(channels+len(ii),width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width)) + def statistics(self,native): + with torch.autocast(native.device.type,enabled=False): + wave=native[:,:-512].float().reshape(len(native),self.channels,-1) + centered=wave-wave.mean(-1,keepdim=True) + previous_tf32=torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32=False + covariance=centered@centered.transpose(-1,-2)/wave.shape[-1] + torch.backends.cuda.matmul.allow_tf32=previous_tf32 + variance=covariance.diagonal(dim1=-2,dim2=-1).clamp_min(1e-8) + correlation=covariance/(variance.sqrt()[:,:,None]*variance.sqrt()[:,None,:]) + return torch.cat([variance.log(),correlation[:,self.pair_i,self.pair_j].clamp(-1,1)],-1) + def encode_statistics(self,values): + with torch.autocast(values.device.type,enabled=False): + value=torch.cat([values[:,:self.channels],self.offdiagonal_enabled*values[:,self.channels:]],-1) + return self.encoder(value.float()) + def forward(self,native):return self.encode_statistics(self.statistics(native)) + +class WaveCoactivationHead(nn.Module): + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=self.correction_gain*self.output_scale*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class OrdinalFeatureHead(nn.Module): + """Private strength of one common ordinal-dynamics feature correction.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.ordinal_gain=nn.Parameter(torch.ones(())) + def forward(self,values): + previous=values[:,:-256];native=previous[:,:-640] + adjusted=torch.cat([native[:,:-512],native[:,-512:-384]+self.ordinal_gain*values[:,-256:-128],native[:,-384:-128],native[:,-128:]+self.ordinal_gain*values[:,-128:],previous[:,-640:]],-1) + return self.prior(adjusted) + +class PhaseReadoutHead(nn.Module): + """Private class evidence from the common complex-coherence encoder.""" + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=(self.correction_gain*self.output_scale)*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class CouplingReadoutHead(nn.Module): + """Private class evidence from the common cross-frequency coupling encoder.""" + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=(self.correction_gain*self.output_scale)*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class HybridModel(nn.Module): + def __init__(self,channels=32,width=128,depth=2,dropout=.5,wave_filters=32,head_width=64,head_dropout=.3,clinical_asymmetry=True,alpha_regions=None,clinical_envelope=False,temporal_pool=True,temporal_evidence=False,evidence_temperature=.25,random_fourier=False,fourier_features=256,tangent_readout=True,shared_context_correction=True,wave_coactivation=True,ordinal_context=True,phase_coherence=True,cross_frequency=True,cbramod_feature_transfer=True,student_architecture=None,short_window_view="center"): + super().__init__() + self.adapters=nn.ModuleDict({t:InputAdapter(c,width,channels,spectral_enabled=t not in ("faced","tuev","openbmi"),asymmetry=clinical_asymmetry and t=="tuev",alpha_regions=alpha_regions if t=="longitudinal" else None,envelope=clinical_envelope and t=="tuev") for t,(c,s,k) in SPECS.items()}) + self.backbone=SharedBackbone(channels,width,depth,dropout,wave_filters) + self.backbone.student_encoder=CBraModFeatures(**(student_architecture or {})) + self.backbone.register_buffer('student_ordered_enabled',torch.ones(())) + self.backbone.student_readout=nn.Sequential(nn.Linear(self.backbone.student_encoder.output_dim,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + for t,(c,s,k) in SPECS.items(): + self.adapters[t].student_input=FrequencyAdapter(c,32) + self.adapters[t].student_normalizer=Standardize(self.backbone.student_encoder.output_dim) + self.backbone.wave_coactivation=WaveCoactivationContext(2*wave_filters,width) + self.heads=nn.ModuleDict({t:ResidualHead(2*wave_filters*(((s*200+1)//4+1)//8)+width+256+width,k,head_width,head_dropout,full_precision=t=='ad65') for t,(c,s,k) in SPECS.items()}) + if temporal_pool:self.heads=nn.ModuleDict({t:TemporalPoolHead(head,wave_filters*2) for t,head in self.heads.items()}) + if temporal_evidence:self.heads=nn.ModuleDict({t:TemporalEvidenceHead(head,wave_filters*2,evidence_temperature) for t,head in self.heads.items()}) + if random_fourier:self.heads=nn.ModuleDict({t:FourierResidualHead(head,2*wave_filters*(((SPECS[t][1]*200+1)//4+1)//8)+width+256+width,SPECS[t][2],fourier_features) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:TangentFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CodeBrainFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:WaveCoactivationHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:OrdinalFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:PhaseReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert short_window_view in ('center','full') + self.short_window_view=short_window_view + self.backbone.short_window_encoder=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,2*width),nn.GELU(),nn.Dropout(.3),nn.Linear(2*width,width),nn.LayerNorm(width)) + for t,(c,s,k) in SPECS.items(): + self.adapters[t].short_window_normalizer=Standardize(short_window_dimension(c)) + self.adapters[t].short_window_projection=nn.Linear(short_window_dimension(c),width) + self.adapters[t].short_window_dropout=nn.Dropout(.3) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + def short_window_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + adapter=self.adapters[t] + projected=adapter.short_window_projection(adapter.short_window_dropout(adapter.short_window_normalizer(values.float()))) + return self.backbone.short_window_encoder(projected) + def student_features(self,t,x): + outputs=[];old_fastpath=torch.backends.mha.get_fastpath_enabled();torch.backends.mha.set_fastpath_enabled(False) + try: + for raw in x.split(16): + signal=torch.nan_to_num(raw.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + with torch.autocast(signal.device.type,dtype=torch.bfloat16,enabled=signal.device.type=='cuda'): + outputs.append(self.backbone.student_encoder(self.adapters[t].student_input(signal))) + finally:torch.backends.mha.set_fastpath_enabled(old_fastpath) + return torch.cat(outputs).float() + def student_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].student_normalizer(values.float()) + normalized=torch.cat([normalized[:,:256],self.backbone.student_ordered_enabled*normalized[:,256:]],-1) + return self.backbone.student_readout(normalized) + def coupling_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False):return self.backbone.coupling_encoder(self.adapters[t].coupling_embedding(values.float())) + def phase_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].phase_normalizer(values.float()) + normalized=torch.cat([normalized[:,:PHASE_HALF],self.backbone.phase_imaginary_enabled*normalized[:,PHASE_HALF:]],-1) + return self.backbone.phase_encoder(normalized) + def forward(self,t,x,features=None,covariances=None,covariance_features=None): + if features is None:features=extract_features(t,x) + if covariance_features is None: + if covariances is None:covariances=extract_covariances(t,x) + covariance_features=self.adapters[t].spatial_features(covariances) + signal=x.flatten(2);signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + adapted=self.adapters[t](signal,features,covariance_features) + if covariances is None:covariances=extract_covariances(t,x) + tangent=extract_tangent_features(covariances,self.adapters[t].spatial_weight) + representation,fusion_delta,covariance_delta,fusion_input=self.backbone(*adapted,tangent_features=tangent) + if t in ('faced','openbmi'): + representation=torch.cat([representation[:,:-384],torch.zeros_like(representation[:,-384:-128]),representation[:,-128:]],-1) + tokens=torch.zeros(len(signal),signal.shape[-1]//200,24*64,device=signal.device,dtype=torch.bfloat16) + code_fusion,code_covariance=self.backbone.codebrain_correction(tokens,representation,fusion_input) + coactivation=self.backbone.wave_coactivation(representation) + with torch.autocast(signal.device.type,enabled=False): + ordinal=self.adapters[t].ordinal_embedding(ordinal_features(t,x)) + ordinal_covariance=self.backbone.ordinal_context(ordinal.float()) + added=.001*nn.functional.linear(ordinal_covariance,self.backbone.covariance_projection.weight,None) + ordinal_fusion=self.backbone.fusion(fusion_input+added.to(fusion_input.dtype))-representation[:,-512:-384] + phase=self.phase_embedding(t,phase_features(t,x,self.adapters[t].spatial_weight)) + coupling=self.coupling_embedding(t,coupling_features(t,x)) + student=self.student_embedding(t,self.student_features(t,x)) + short=self.short_window_embedding(t,short_window_features(t,x,self.short_window_view)) + return self.heads[t](torch.cat([representation,fusion_delta,covariance_delta,code_fusion,code_covariance,coactivation,ordinal_fusion,ordinal_covariance,phase,coupling,student,short],-1)) + +def widen_state_dict(state,multiplier=2): + """Duplicate temporal features and divide downstream sums to preserve outputs.""" + result={} + for key,value in state.items(): + if key.startswith('backbone.waveform.'): + layer=int(key.split('.')[2]) + if layer in (0,2,7):value=value.repeat(multiplier,1,1,1) + elif layer in (1,3,9):value=value.repeat(multiplier) + elif layer==8:value=value.repeat(multiplier,multiplier,1,1)/multiplier + elif key=='backbone.wave_summary.2.weight':value=value.repeat(1,multiplier)/multiplier + elif key.startswith('heads.') and key.endswith('.weight'): + raw=value[:,:-128]/multiplier + value=torch.cat([raw]*multiplier+[value[:,-128:]],1) + result[key]=value + return result + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/ordinal_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/ordinal_features.py new file mode 100644 index 0000000000000000000000000000000000000000..6e3d5ff8264253f058f71b04d9cc8454196592b1 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/ordinal_features.py @@ -0,0 +1,25 @@ +"""Fixed within-window ordinal dynamics, independent of amplitude scaling.""" +import math +import torch +LAGS=(1,2,4,8,16) +PATTERNS=24 +PER_CHANNEL=len(LAGS)*(PATTERNS+2) + +def ordinal_features(track,x): + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + parts=[];uniform=1/PATTERNS;maximum_entropy=math.log(PATTERNS);m0=(1+uniform)/2;mr=uniform/2;maximum_js=-m0*math.log(m0)-(PATTERNS-1)*mr*math.log(mr)-maximum_entropy/2 + for lag in LAGS: + length=x.shape[-1]-3*lag + if length<=0:raise ValueError('window too short for ordinal dynamics') + samples=torch.stack([x[...,i*lag:i*lag+length] for i in range(4)],-1) + order=samples.argsort(dim=-1,stable=True) + code=6*((order[...,0,None]>order[...,1:]).sum(-1))+2*((order[...,1,None]>order[...,2:]).sum(-1))+(order[...,2]>order[...,3]).long() + histogram=torch.zeros(*x.shape[:2],PATTERNS,device=x.device,dtype=torch.float32) + histogram.scatter_add_(-1,code,torch.ones_like(code,dtype=torch.float32));probability=histogram/length + entropy=-(probability*probability.clamp_min(1e-12).log()).sum(-1) + mixture=(probability+uniform)/2;mixture_entropy=-(mixture*mixture.log()).sum(-1) + complexity=((mixture_entropy-.5*entropy-.5*maximum_entropy)/maximum_js).clamp(0,1)*(entropy/maximum_entropy) + parts.append(torch.cat([probability,(entropy/maximum_entropy)[...,None],complexity[...,None]],-1)) + return torch.cat(parts,-1).flatten(1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/phase_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/phase_features.py new file mode 100644 index 0000000000000000000000000000000000000000..8d98822995bf37b499795dfd7e2e401040a01969 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/phase_features.py @@ -0,0 +1,37 @@ +"""Complex spectral coherence of the existing 24 spatial filters in ten bands.""" +import torch +from covariances import BANDS +CHANNELS=24 +PHASE_HALF=len(BANDS)*CHANNELS*(CHANNELS-1)//2 +PHASE_DIM=2*PHASE_HALF + +@torch.no_grad() +def phase_features(track,x,spatial_weight): + previous_tf32=torch.backends.cuda.matmul.allow_tf32 + try: + torch.backends.cuda.matmul.allow_tf32=False + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if track in ('faced','tuev'):x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + else:x=x-x.mean(1,keepdim=True) + x=x/x.square().mean((1,2),keepdim=True).clamp_min(1e-12).sqrt() + frames=x.unfold(-1,400,200);frames=frames-frames.mean(-1,keepdim=True) + z=torch.fft.rfft(frames*torch.hann_window(400,device=x.device),dim=-1)/200 + w=spatial_weight.float()/spatial_weight.float().norm(dim=-1,keepdim=True).clamp_min(1e-6) + index=torch.triu_indices(CHANNELS,CHANNELS,1,device=x.device) + real_parts=[];imaginary_parts=[] + for band,(lo,hi) in enumerate(BANDS): + v=z[...,2*lo:2*hi].flatten(2) + vr=w[band][None]@v.real;vi=w[band][None]@v.imag + real=(vr@vr.transpose(-1,-2)+vi@vi.transpose(-1,-2))/v.shape[-1] + imaginary=(vi@vr.transpose(-1,-2)-vr@vi.transpose(-1,-2))/v.shape[-1] + # Signals have unit global RMS; this floor suppresses phase of numerical silence. + power=real.diagonal(dim1=-2,dim2=-1).clamp_min(1e-6) + denominator=(power[:,:,None]*power[:,None,:]).sqrt().clamp_min(1e-12) + real=(real/denominator).clamp(-.999,.999) + imaginary=(imaginary/denominator).clamp(-.999,.999) + real_parts.append(torch.atanh(real[:,index[0],index[1]])) + imaginary_parts.append(torch.atanh(imaginary[:,index[0],index[1]])) + return torch.cat(real_parts+imaginary_parts,-1) + finally:torch.backends.cuda.matmul.allow_tf32=previous_tf32 diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/private-head-refresh-audit.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/private-head-refresh-audit.json new file mode 100644 index 0000000000000000000000000000000000000000..4ee2ad13d0488eb4b14aff114ec3b9780a1305fd --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/private-head-refresh-audit.json @@ -0,0 +1,23 @@ +{ + "reference": "/workspace/research/runs/student_private_readout1/epoch-030", + "donor": "/workspace/research/pilots/student_common_frozen_pilot1/epoch-001", + "track": "faced", + "source_sha256": { + "reference": "3709c349fae529d53cfe155976f4911c8850077b0283067f1e3ba6029bcc358a", + "donor": "6ebebd9a90057afdaf4720a9d3bbd29fdc5606c9ef826aaebcf7316d31b15a06" + }, + "changed_private_tensors": [ + "heads.faced.projection.weight", + "heads.faced.projection.bias" + ], + "all_common_input_and_prior_head_tensors_exactly_equal": true, + "executable_code_and_architecture_exactly_equal": true, + "one_common_checkpoint": true, + "prediction_sources": { + "faced": "/workspace/research/pilots/student_common_frozen_pilot1/faced-e001.npy", + "tuev": "/workspace/research/runs/student_private_readout1/tuev-e030.npy", + "ad65": "/workspace/research/runs/student_private_readout1/ad65-e030.npy", + "openbmi": "/workspace/research/runs/student_private_readout1/openbmi-e030.npy", + "longitudinal": "/workspace/research/runs/student_private_readout1/longitudinal-e030.npy" + } +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/private-readout-refresh-audit.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/private-readout-refresh-audit.json new file mode 100644 index 0000000000000000000000000000000000000000..247370db3d54c36215cee0a3daf7bc2438d458a0 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/private-readout-refresh-audit.json @@ -0,0 +1,40 @@ +{ + "child": "/workspace/research/pilots/short_window_parent_dropout_pilot1/epoch-001", + "donor": "/workspace/research/candidates/student_private_retention_selected_faced", + "common_ancestor": "/workspace/research/runs/student_private_retention_control1/epoch-001", + "source_weight_sha256": { + "child": "67c28768783a1a890f92c1bac734a191bdf28851bfba3e572f05c948da7c484e", + "donor": "0d433d0c6bdf259d65e2ca28e1036cba8e3117567687e7bf2e7966fb01fe879f", + "ancestor": "de55cf5362cb45ecd7f7cb8ac3ade4d7634fcd2e99f23283abc6e663a261df50" + }, + "changed_private_tensors": [ + "heads.faced.prior.projection.weight", + "heads.faced.prior.projection.bias" + ], + "all_ancestor_common_and_input_tensors_equal": true, + "all_child_common_and_input_tensors_unchanged": true, + "new_branch_gain_for_refreshed_track": 0.0, + "donor_changes_only_requested_private_projection": true, + "prediction_sources": { + "faced": { + "source": "/workspace/research/derived_predictions/student_private_retention_selected_faced/faced-e000.npy", + "sha256": "f873fd8d0328350c654396bb431c55cf51380d4a96665de0e3ab8bd62eff0c71" + }, + "tuev": { + "source": "/workspace/research/pilots/short_window_parent_dropout_pilot1/tuev-e001.npy", + "sha256": "9f0743450f1104d395e9daac0600aaf20755b5590b9f5c3e3137732c479dd647" + }, + "ad65": { + "source": "/workspace/research/pilots/short_window_parent_dropout_pilot1/ad65-e001.npy", + "sha256": "7a3b74c58580b7ba952322bf6d527ebc9a40a6e04c7cdbbaea14e84a7a298d54" + }, + "openbmi": { + "source": "/workspace/research/pilots/short_window_parent_dropout_pilot1/openbmi-e001.npy", + "sha256": "14f630543e1df88c88d8f3e0effb4506ba33f533b3484de3c7aaf6554507341c" + }, + "longitudinal": { + "source": "/workspace/research/pilots/short_window_parent_dropout_pilot1/longitudinal-e001.npy", + "sha256": "92dd8348510a643b24cb67a81fbcb6709ef22fcd44b6ec85fccfc2e5bf7aa3f1" + } + } +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/short_window_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/short_window_features.py new file mode 100644 index 0000000000000000000000000000000000000000..cf0e79cb97290f06c4dc5a96651de2247e2dd180 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/short_window_features.py @@ -0,0 +1,21 @@ +"""Fixed full or central-two-second spectral and coupling descriptors.""" +import torch +from features import extract_features,feature_dim +from coupling_features import coupling_features,PER_CHANNEL + +def short_window_dimension(channels): + return feature_dim(channels)+channels*PER_CHANNEL + +@torch.no_grad() +def short_window_features(track,x,view='center'): + assert view in ('center','full') + previous=torch.backends.cuda.matmul.allow_tf32 + try: + torch.backends.cuda.matmul.allow_tf32=False + with torch.autocast(x.device.type,enabled=False): + values=x.float().flatten(2) + if view=='center': + left=(values.shape[-1]-400)//2 + values=values[...,left:left+400] + return torch.cat([extract_features(track,values),coupling_features(track,values)],-1) + finally:torch.backends.cuda.matmul.allow_tf32=previous diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/student_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/student_features.py new file mode 100644 index 0000000000000000000000000000000000000000..57401f6d2ab760cb1a58af564aef2e62290e8907 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/student_features.py @@ -0,0 +1,34 @@ +"""One audited CBraMod core with full-window shared and ordered representations.""" +import torch +from torch import nn +from braindecode.models import CBraMod +from frequency_features import frequency_components,FREQUENCY_BANDS +SPECS={'faced':(32,10,9),'tuev':(16,5,6),'ad65':(19,10,3),'openbmi':(62,4,2),'longitudinal':(58,2,2)} +TRACKS=tuple(SPECS) + +class FrequencyAdapter(nn.Module): + def __init__(self,channels,virtual_channels=32): + super().__init__();self.signal=nn.Conv1d(channels,virtual_channels,1,bias=False) + self.frequency_weight=nn.Parameter(torch.zeros(len(FREQUENCY_BANDS),virtual_channels,channels)) + def forward(self,x): + components=frequency_components(x) + correction=torch.einsum('blc,nbct->nlt',self.frequency_weight,components.to(self.frequency_weight.dtype)) + return self.signal(x)+correction.to(x.dtype) + +class CBraModFeatures(nn.Module): + def __init__(self,virtual_channels=32,token_width=64,summary_width=256,head_width=128,dropout=.3): + super().__init__();self.virtual_channels=virtual_channels;self.output_dim=summary_width+virtual_channels*token_width*4 + self.backbone=CBraMod(n_chans=virtual_channels,n_outputs=2,n_times=400,sfreq=200) + self.backbone.final_layer=nn.Identity() + self.token_projection=nn.Sequential(nn.LayerNorm(200),nn.Linear(200,token_width),nn.GELU()) + self.summary_projection=nn.Sequential(nn.LayerNorm(virtual_channels*token_width*2),nn.Linear(virtual_channels*token_width*2,summary_width),nn.GELU(),nn.Dropout(dropout)) + def forward(self,signal): + tokens=self.token_projection(self.backbone(signal)) + moments=torch.cat([tokens.mean(2),tokens.float().std(2,correction=0).to(tokens.dtype)],-1).flatten(1) + summary=self.summary_projection(moments) + ordered=torch.nn.functional.adaptive_avg_pool1d(tokens.permute(0,1,3,2).flatten(1,2),4).flatten(1) + return torch.cat([summary,ordered],-1) + + def named_shared_parameters(self): + for prefix,module in [('backbone',self.backbone),('token_projection',self.token_projection),('summary_projection',self.summary_projection)]: + for name,p in module.named_parameters():yield f'{prefix}.{name}',p diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/tangent_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/tangent_features.py new file mode 100644 index 0000000000000000000000000000000000000000..314f0cf2f58e4b4a1c1d808edbd4acc3b7b6f85b --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S069/tangent_features.py @@ -0,0 +1,25 @@ +"""Window-local log-correlation geometry in the existing spatial-filter basis.""" +import torch + +TANGENT_DIM=10*24*25//2 + +@torch.no_grad() +def extract_tangent_features(covariances,spatial_weight): + old_tf32=torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(covariances.device.type,enabled=False): + w=spatial_weight.float() + w=w/w.norm(dim=-1,keepdim=True).clamp_min(1e-6) + projected=torch.einsum('bfc,nbcd,bgd->nbfg',w,covariances.float(),w) + d=projected.diagonal(dim1=-2,dim2=-1).clamp_min(1e-10).sqrt() + correlation=(projected/(d.unsqueeze(-1)*d.unsqueeze(-2))).clamp(-1,1) + correlation=(correlation+correlation.transpose(-1,-2))/2 + correlation=.95*correlation+.05*torch.eye(24,device=correlation.device) + values,vectors=torch.linalg.eigh(correlation) + logarithm=(vectors*values.clamp_min(1e-6).log().unsqueeze(-2))@vectors.transpose(-1,-2) + i,j=torch.triu_indices(24,24,device=correlation.device) + scale=torch.where(i==j,1.,2.**.5) + return (logarithm[...,i,j]*scale).flatten(1) + finally: + torch.backends.cuda.matmul.allow_tf32=old_tf32 diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S072/data.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S072/data.py new file mode 100644 index 0000000000000000000000000000000000000000..e3cf61f3b1ac4d22858c6e6f387024abd27d953d --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S072/data.py @@ -0,0 +1,33 @@ +import json +from functools import lru_cache +from pathlib import Path +import numpy as np +import torch +@lru_cache(maxsize=8) +def array(path):return np.load(path,mmap_mode='r',allow_pickle=False) +class Dataset(torch.utils.data.Dataset): + def __init__(self,root,limit=None,cache=False): + self.root=Path(root) + self.rows=json.loads((self.root/'manifest.json').read_text())['samples'] + if limit:self.rows=self.rows[:limit] + self.cached=None + if cache and self.rows: + from collections import defaultdict + groups=defaultdict(list) + for i,r in enumerate(self.rows):groups[r['path']].append((i,r['index'])) + for name,indices in groups.items(): + path=(self.root/name).resolve() + if not path.is_relative_to(self.root.resolve()):raise ValueError('input outside root') + source=np.load(path,mmap_mode='r',allow_pickle=False) + if self.cached is None:self.cached=torch.empty((len(self.rows),*source.shape[1:]),dtype=torch.float32) + dst,src=zip(*indices) + self.cached[list(dst)]=torch.as_tensor(source[list(src)]/100,dtype=torch.float32) + def __len__(self):return len(self.rows) + def __getitem__(self,i): + r=self.rows[i] + if self.cached is not None:return self.cached[i],r.get('label',-1),r['id'] + p=(self.root/r['path']).resolve() + if not p.is_relative_to(self.root.resolve()):raise ValueError('input outside root') + # Division precedes float32 conversion, matching official FACED/TUEV collate. + x=np.asarray(array(str(p))[r['index']])/100 + return torch.as_tensor(x,dtype=torch.float32),r.get('label',-1),r['id'] diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S072/model.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S072/model.py new file mode 100644 index 0000000000000000000000000000000000000000..dbf330c374a0189521e061b974138a148f6415e2 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S072/model.py @@ -0,0 +1,402 @@ +from student_features import CBraModFeatures,FrequencyAdapter +"""One fused waveform/spectral backbone used identically by all five tasks.""" +import torch +from torch import nn +from braindecode.models import BIOT +from features import SPECS,TRACKS,feature_dim,extract_features,Standardize,Residual,EDGES,COV_BANDS +from covariances import BANDS,extract_covariances +from alpha_features import extract_alpha_features,ALPHA_DIM +from envelope_features import extract_envelope_features,ENVELOPE_DIM +from frequency_features import frequency_components,FREQUENCY_BANDS +from tangent_features import extract_tangent_features,TANGENT_DIM +from phase_features import phase_features,PHASE_DIM,PHASE_HALF +from coupling_features import coupling_features,PER_CHANNEL as COUPLING_PER_CHANNEL +from ordinal_features import ordinal_features,PER_CHANNEL as ORDINAL_PER_CHANNEL + +def clinical_asymmetry_features(features): + """Bipolar homologous-channel amplitude and coherence, invariant to mirroring.""" + bands=len(EDGES)-1;per_channel=4*bands+4 + block=features[:,:16*per_channel].reshape(-1,16,per_channel) + left=torch.tensor([0,1,2,3,8,9,10,11],device=features.device);right=left+4 + pair_power=(block[:,left,:bands]-block[:,right,:bands]).abs().flatten(1) + pair_rms=(block[:,left,4*bands]-block[:,right,4*bands]).abs() + hemisphere=(block[:,left,:bands].mean(1)-block[:,right,:bands].mean(1)).abs() + index=left*(32-left-1)//2+(right-left-1) + correlations=features[:,16*per_channel:].reshape(-1,len(COV_BANDS),120)[:,:,index].flatten(1) + return torch.cat([pair_power,pair_rms,hemisphere,correlations],1) + +class InputAdapter(nn.Module): + def __init__(self,c,width,channels,spectral_enabled=True,asymmetry=False,alpha_regions=None,envelope=False): + super().__init__() + self.ordinal_normalizer=Standardize(c*ORDINAL_PER_CHANNEL) + self.ordinal_projection=nn.Linear(c*ORDINAL_PER_CHANNEL,width) + self.ordinal_dropout=nn.Dropout(.3) + self.register_buffer('ordinal_probabilities_enabled',torch.ones(())) + self.coupling_normalizer=Standardize(c*COUPLING_PER_CHANNEL) + self.coupling_projection=nn.Linear(c*COUPLING_PER_CHANNEL,width) + self.coupling_dropout=nn.Dropout(.3) + self.register_buffer('coupling_dependence_enabled',torch.ones(())) + self.phase_normalizer=Standardize(PHASE_DIM) + self.signal=nn.Conv1d(c,channels,1,bias=False) + self.frequency_weight=nn.Parameter(torch.zeros(len(FREQUENCY_BANDS),channels,c)) + self.neural=nn.Conv1d(c,18,1,bias=False) + self.normalizer=Standardize(feature_dim(c)) + self.spectral=nn.Linear(feature_dim(c),width) + self.dropout=nn.Dropout(.1) + self.register_buffer("spectral_enabled",torch.tensor(float(spectral_enabled))) + self.spatial_weight=nn.Parameter(torch.randn(len(BANDS),24,c)/c**.5) + self.asymmetry_projection=nn.Linear(316,width,bias=False) if asymmetry else None + if asymmetry: + nn.init.zeros_(self.asymmetry_projection.weight) + self.asymmetry_normalizer=Standardize(316) + self.asymmetry_dropout=nn.Dropout(.1) + self.alpha_projection=None + if alpha_regions is not None: + self.register_buffer('alpha_regions',torch.tensor(alpha_regions,dtype=torch.float32)) + self.alpha_normalizer=Standardize(ALPHA_DIM) + self.alpha_projection=nn.Linear(ALPHA_DIM,width,bias=False) + nn.init.zeros_(self.alpha_projection.weight) + self.alpha_dropout=nn.Dropout(.3) + self.envelope_projection=None + if envelope: + self.envelope_normalizer=Standardize(ENVELOPE_DIM) + self.envelope_projection=nn.Linear(ENVELOPE_DIM,width,bias=False) + nn.init.zeros_(self.envelope_projection.weight) + self.envelope_dropout=nn.Dropout(.3) + def coupling_embedding(self,features): + values=self.coupling_normalizer(features).reshape(len(features),-1,COUPLING_PER_CHANNEL) + values=torch.cat([values[...,:10],self.coupling_dependence_enabled*values[...,10:]],-1).flatten(1) + return self.coupling_projection(self.coupling_dropout(values)) + def ordinal_embedding(self,features): + values=self.ordinal_normalizer(features).reshape(len(features),-1,5,26) + values=torch.cat([self.ordinal_probabilities_enabled*values[...,:24],values[...,24:]],-1).flatten(1) + return self.ordinal_projection(self.ordinal_dropout(values)) + def spectral_features(self,features,signal=None,alpha_features=None,envelope_features=None): + value=self.spectral_enabled*self.spectral(self.dropout(self.normalizer(features))) + if self.asymmetry_projection is not None: + extra=self.asymmetry_dropout(self.asymmetry_normalizer(clinical_asymmetry_features(features))) + value=value+self.asymmetry_projection(extra) + if self.alpha_projection is not None: + if alpha_features is None:alpha_features=extract_alpha_features(signal,self.alpha_regions) + value=value+self.alpha_projection(self.alpha_dropout(self.alpha_normalizer(alpha_features))) + if self.envelope_projection is not None: + if envelope_features is None:envelope_features=extract_envelope_features(signal) + value=value+self.envelope_projection(self.envelope_dropout(self.envelope_normalizer(envelope_features))) + return value + def spatial_features(self,covariances): + with torch.autocast(covariances.device.type,enabled=False): + w=self.spatial_weight.float()/self.spatial_weight.float().norm(dim=-1,keepdim=True).clamp_min(1e-6) + power=torch.einsum('bfc,nbcd,bfd->nbf',w,covariances.float(),w).clamp_min(1e-8).log() + return torch.cat([power,power-power.mean(1,keepdim=True)],1).flatten(1) + def wave_signal(self,x,components=None): + if components is None:components=frequency_components(x) + correction=torch.einsum('blc,nbct->nlt',self.frequency_weight,components.to(self.frequency_weight.dtype)) + return (self.signal(x)+correction.to(x.dtype)).unsqueeze(1) + def forward(self,x,features,covariance_features): + return self.wave_signal(x),self.spectral_features(features,signal=x),self.neural(x),covariance_features + +class SharedBackbone(nn.Module): + def __init__(self,channels,width,depth,dropout,wave_filters): + super().__init__() + self.waveform=nn.Sequential( + nn.Conv2d(1,wave_filters,(1,64),padding=(0,32),bias=False),nn.GroupNorm(1,wave_filters), + nn.Conv2d(wave_filters,2*wave_filters,(channels,1),groups=wave_filters,bias=False),nn.GroupNorm(1,2*wave_filters),nn.ELU(), + nn.AvgPool2d((1,4)),nn.Dropout(.35), + nn.Conv2d(2*wave_filters,2*wave_filters,(1,16),padding=(0,8),groups=2*wave_filters,bias=False),nn.Conv2d(2*wave_filters,2*wave_filters,1,bias=False), + nn.GroupNorm(1,2*wave_filters),nn.ELU(),nn.AvgPool2d((1,8)),nn.Dropout(.35)) + self.wave_summary=nn.Sequential(nn.AdaptiveAvgPool2d((1,8)),nn.Flatten(),nn.Linear(2*wave_filters*8,width)) + self.fusion=nn.Sequential(nn.LayerNorm(width),nn.GELU(),nn.Dropout(dropout), + *[Residual(width,dropout) for _ in range(depth)],nn.LayerNorm(width)) + # Both representations interact before the shared residual stack. + self.phase_encoder=nn.Sequential(nn.LayerNorm(PHASE_DIM),nn.Linear(PHASE_DIM,width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width)) + self.register_buffer('phase_imaginary_enabled',torch.ones(())) + self.coupling_encoder=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width),nn.LayerNorm(width)) + self.wave_gain=nn.Parameter(torch.tensor(.1)) + self.biot=BIOT(n_chans=18,n_outputs=2,n_times=400,sfreq=200) + self.biot.final_layer=nn.Identity() + self.biot_projection=nn.Sequential(nn.LayerNorm(256),nn.Linear(256,width),nn.Dropout(.2)) + nn.init.normal_(self.biot_projection[1].weight,std=.001);nn.init.zeros_(self.biot_projection[1].bias) + self.covariance_encoder=nn.Sequential(nn.LayerNorm(len(BANDS)*24*2),nn.Linear(len(BANDS)*24*2,width),nn.GELU(),nn.Dropout(.4), + *[Residual(width,.4) for _ in range(2)],nn.LayerNorm(width)) + self.covariance_projection=nn.Linear(width,width) + nn.init.zeros_(self.covariance_projection.weight);nn.init.zeros_(self.covariance_projection.bias) + self.tangent_encoder=nn.Sequential(nn.LayerNorm(TANGENT_DIM),nn.Linear(TANGENT_DIM,width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width),nn.Linear(width,width)) + self.ordinal_context=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width)) + nn.init.zeros_(self.ordinal_context[-1].weight);nn.init.zeros_(self.ordinal_context[-1].bias) + self.register_buffer('codebrain_enabled',torch.ones(())) + self.codebrain_patch_encoder=nn.Sequential(nn.LayerNorm(24*64),nn.Linear(24*64,width),nn.GELU(),nn.Dropout(.3)) + self.codebrain_context=nn.Sequential(nn.LayerNorm(width*4),nn.Linear(width*4,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width)) + nn.init.zeros_(self.codebrain_context[-1].weight);nn.init.zeros_(self.codebrain_context[-1].bias) + def codebrain_correction(self,tokens,representation,fusion_input): + with torch.autocast(tokens.device.type,enabled=False): + encoded=self.codebrain_patch_encoder(self.codebrain_enabled*tokens.float()) + pooled=torch.cat([encoded.mean(1),encoded.std(1,correction=0),representation[:,-512:-384].float(),representation[:,-128:].float()],-1) + delta=self.codebrain_context(pooled) + added=.001*nn.functional.linear(delta,self.covariance_projection.weight,None) + corrected=self.fusion(fusion_input+added.to(fusion_input.dtype)) + return corrected-representation[:,-512:-384],delta + def forward(self,signal,spectral,neural_signal,covariance_features,tangent_features): + wave=self.waveform(signal) + neural=self.biot(neural_signal.float()) + neural=self.biot_projection[0](neural) + projected=self.biot_projection[2](self.biot_projection[1](neural)) + with torch.autocast(signal.device.type,enabled=False): + covariance_embedding=self.covariance_encoder(covariance_features.float()) + original=spectral+self.wave_gain*self.wave_summary(wave)+.01*projected + coupled=.001*self.covariance_projection(covariance_embedding).to(original.dtype) + fused=self.fusion(original+coupled) + with torch.autocast(signal.device.type,enabled=False):delta=self.tangent_encoder(tangent_features.float()) + added=.001*nn.functional.linear(delta,self.covariance_projection.weight,None) + corrected=self.fusion((original+coupled)+added.to(original.dtype)) + return torch.cat([wave.flatten(1),fused,neural,covariance_embedding],-1),corrected-fused,delta,original+coupled + +class ResidualHead(nn.Module): + """A small nonlinear classifier correction around an inherited linear readout.""" + def __init__(self,features,classes,width=64,dropout=.3,full_precision=False): + super().__init__();self.full_precision=full_precision + self.base=nn.Linear(features,classes) + self.delta=nn.Sequential(nn.LayerNorm(features),nn.Linear(features,width),nn.GELU(),nn.Dropout(dropout),nn.Linear(width,classes)) + nn.init.zeros_(self.delta[-1].weight);nn.init.zeros_(self.delta[-1].bias) + def forward(self,x): + if self.full_precision: + with torch.autocast(x.device.type,enabled=False):return self.base(x.float())+self.delta(x.float()) + prior=nn.functional.linear(x[:,:-128].contiguous(),self.base.weight[:,:-128].contiguous(),self.base.bias) + added=nn.functional.linear(x[:,-128:].contiguous(),self.base.weight[:,-128:].contiguous()) + value=prior+added + return value+self.delta(x).to(value.dtype) + +class TemporalPoolHead(nn.Module): + def __init__(self,prior,channels=64): + super().__init__();self.prior=prior;self.channels=channels + self.register_buffer('pool_output_scale',torch.ones(()));self.register_buffer('pool_mean',torch.zeros(channels*4));self.register_buffer('pool_scale',torch.ones(channels*4)) + self.pool_projection=nn.Linear(channels*4,prior.base.out_features) + nn.init.zeros_(self.pool_projection.weight);nn.init.zeros_(self.pool_projection.bias) + def statistics(self,x): + with torch.autocast(x.device.type,enabled=False): + wave=x[:,:-512].float().reshape(len(x),self.channels,-1) + return torch.cat([wave.mean(-1),wave.std(-1,correction=0),wave.amax(-1),wave.amin(-1)],-1) + def forward(self,x): + prior=self.prior(x) + with torch.autocast(x.device.type,enabled=False): + values=((self.statistics(x)-self.pool_mean)/self.pool_scale).clamp(-8,8) + added=self.pool_output_scale*self.pool_projection(values) + return prior+added.to(prior.dtype) + +class TemporalEvidenceHead(nn.Module): + """Pool class evidence over the shared waveform time axis.""" + def __init__(self,prior,channels=64,temperature=.25): + super().__init__();self.prior=prior;self.channels=channels;self.temperature=temperature + self.register_buffer('evidence_output_scale',torch.ones(())) + self.register_buffer('evidence_mean',torch.zeros(channels)) + self.register_buffer('evidence_scale',torch.ones(channels)) + self.evidence_projection=nn.Linear(channels,prior.prior.base.out_features,bias=False) + nn.init.zeros_(self.evidence_projection.weight) + def patches(self,x): + with torch.autocast(x.device.type,enabled=False): + wave=x[:,:-512].float().reshape(len(x),self.channels,-1).transpose(1,2) + return ((wave-self.evidence_mean)/self.evidence_scale).clamp(-8,8) + def evidence(self,patches): + with torch.autocast(patches.device.type,enabled=False): + values=self.evidence_projection(patches.float())/self.temperature + maximum=values.amax(1,keepdim=True) + pooled=self.temperature*((values-maximum).exp().mean(1).log()+maximum.squeeze(1)) + return self.evidence_output_scale*pooled + def forward(self,x): + prior=self.prior(x) + return prior+self.evidence(self.patches(x)).to(prior.dtype) + +class FourierResidualHead(nn.Module): + """A fixed random Fourier basis and trainable linear classifier correction.""" + def __init__(self,prior,features,classes,basis=256): + super().__init__();self.prior=prior + self.register_buffer('rff_mean',torch.zeros(features));self.register_buffer('rff_scale',torch.ones(features)) + self.register_buffer('rff_frequency',torch.randn(features,basis)/features**.5) + self.register_buffer('rff_phase',torch.rand(basis)*2*torch.pi) + self.register_buffer('rff_output_scale',torch.ones(())) + self.rff_projection=nn.Linear(3*basis,classes);nn.init.zeros_(self.rff_projection.weight);nn.init.zeros_(self.rff_projection.bias) + def basis(self,x): + with torch.autocast(x.device.type,enabled=False): + values=((x.float()-self.rff_mean)/self.rff_scale).clamp(-8,8)@self.rff_frequency + return 2**.5*torch.cat([(values/sigma+self.rff_phase).cos() for sigma in (.5,1.,2.)],-1) + def forward(self,x): + prior=self.prior(x) + with torch.autocast(x.device.type,enabled=False):added=self.rff_output_scale*self.rff_projection(self.basis(x)) + return prior+added.to(prior.dtype) + +class TangentFeatureHead(nn.Module): + """Select a shared feature correction before the inherited classifier.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.feature_gain=nn.Parameter(torch.zeros(())) + def forward(self,values): + old=values[:,:-256];fusion_delta=values[:,-256:-128];covariance_delta=values[:,-128:] + adjusted=torch.cat([old[:,:-512],old[:,-512:-384]+self.feature_gain*fusion_delta,old[:,-384:-128],old[:,-128:]+self.feature_gain*covariance_delta],-1) + return self.prior(adjusted) + +class CodeBrainFeatureHead(nn.Module): + """Private use of a jointly trained common feature correction.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.codebrain_gain=nn.Parameter(torch.ones(())) + def forward(self,values): + previous=values[:,:-256];native=previous[:,:-256] + fusion_delta=values[:,-256:-128];covariance_delta=values[:,-128:] + adjusted=torch.cat([native[:,:-512],native[:,-512:-384]+self.codebrain_gain*fusion_delta,native[:,-384:-128],native[:,-128:]+self.codebrain_gain*covariance_delta],-1) + return self.prior(torch.cat([adjusted,previous[:,-256:]],-1)) + +class WaveCoactivationContext(nn.Module): + """One common encoder of coactivation among the learned waveform channels.""" + def __init__(self,channels=64,width=128): + super().__init__();self.channels=channels + ii,jj=torch.triu_indices(channels,channels,offset=1) + self.register_buffer('pair_i',ii);self.register_buffer('pair_j',jj) + self.register_buffer('offdiagonal_enabled',torch.ones(())) + self.encoder=nn.Sequential(nn.LayerNorm(channels+len(ii)),nn.Linear(channels+len(ii),width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width)) + def statistics(self,native): + with torch.autocast(native.device.type,enabled=False): + wave=native[:,:-512].float().reshape(len(native),self.channels,-1) + centered=wave-wave.mean(-1,keepdim=True) + previous_tf32=torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32=False + covariance=centered@centered.transpose(-1,-2)/wave.shape[-1] + torch.backends.cuda.matmul.allow_tf32=previous_tf32 + variance=covariance.diagonal(dim1=-2,dim2=-1).clamp_min(1e-8) + correlation=covariance/(variance.sqrt()[:,:,None]*variance.sqrt()[:,None,:]) + return torch.cat([variance.log(),correlation[:,self.pair_i,self.pair_j].clamp(-1,1)],-1) + def encode_statistics(self,values): + with torch.autocast(values.device.type,enabled=False): + value=torch.cat([values[:,:self.channels],self.offdiagonal_enabled*values[:,self.channels:]],-1) + return self.encoder(value.float()) + def forward(self,native):return self.encode_statistics(self.statistics(native)) + +class WaveCoactivationHead(nn.Module): + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=self.correction_gain*self.output_scale*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class OrdinalFeatureHead(nn.Module): + """Private strength of one common ordinal-dynamics feature correction.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.ordinal_gain=nn.Parameter(torch.ones(())) + def forward(self,values): + previous=values[:,:-256];native=previous[:,:-640] + adjusted=torch.cat([native[:,:-512],native[:,-512:-384]+self.ordinal_gain*values[:,-256:-128],native[:,-384:-128],native[:,-128:]+self.ordinal_gain*values[:,-128:],previous[:,-640:]],-1) + return self.prior(adjusted) + +class PhaseReadoutHead(nn.Module): + """Private class evidence from the common complex-coherence encoder.""" + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=(self.correction_gain*self.output_scale)*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class CouplingReadoutHead(nn.Module): + """Private class evidence from the common cross-frequency coupling encoder.""" + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=(self.correction_gain*self.output_scale)*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class HybridModel(nn.Module): + def __init__(self,channels=32,width=128,depth=2,dropout=.5,wave_filters=32,head_width=64,head_dropout=.3,clinical_asymmetry=True,alpha_regions=None,clinical_envelope=False,temporal_pool=True,temporal_evidence=False,evidence_temperature=.25,random_fourier=False,fourier_features=256,tangent_readout=True,shared_context_correction=True,wave_coactivation=True,ordinal_context=True,phase_coherence=True,cross_frequency=True,cbramod_feature_transfer=True,student_architecture=None): + super().__init__() + self.adapters=nn.ModuleDict({t:InputAdapter(c,width,channels,spectral_enabled=t not in ("faced","tuev","openbmi"),asymmetry=clinical_asymmetry and t=="tuev",alpha_regions=alpha_regions if t=="longitudinal" else None,envelope=clinical_envelope and t=="tuev") for t,(c,s,k) in SPECS.items()}) + self.backbone=SharedBackbone(channels,width,depth,dropout,wave_filters) + self.backbone.student_encoder=CBraModFeatures(**(student_architecture or {})) + self.backbone.register_buffer('student_ordered_enabled',torch.ones(())) + self.backbone.student_readout=nn.Sequential(nn.Linear(self.backbone.student_encoder.output_dim,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + for t,(c,s,k) in SPECS.items(): + self.adapters[t].student_input=FrequencyAdapter(c,32) + self.adapters[t].student_normalizer=Standardize(self.backbone.student_encoder.output_dim) + self.backbone.wave_coactivation=WaveCoactivationContext(2*wave_filters,width) + self.heads=nn.ModuleDict({t:ResidualHead(2*wave_filters*(((s*200+1)//4+1)//8)+width+256+width,k,head_width,head_dropout,full_precision=t=='ad65') for t,(c,s,k) in SPECS.items()}) + if temporal_pool:self.heads=nn.ModuleDict({t:TemporalPoolHead(head,wave_filters*2) for t,head in self.heads.items()}) + if temporal_evidence:self.heads=nn.ModuleDict({t:TemporalEvidenceHead(head,wave_filters*2,evidence_temperature) for t,head in self.heads.items()}) + if random_fourier:self.heads=nn.ModuleDict({t:FourierResidualHead(head,2*wave_filters*(((SPECS[t][1]*200+1)//4+1)//8)+width+256+width,SPECS[t][2],fourier_features) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:TangentFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CodeBrainFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:WaveCoactivationHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:OrdinalFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:PhaseReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + def student_features(self,t,x): + outputs=[];old_fastpath=torch.backends.mha.get_fastpath_enabled();torch.backends.mha.set_fastpath_enabled(False) + try: + for raw in x.split(16): + signal=torch.nan_to_num(raw.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + with torch.autocast(signal.device.type,dtype=torch.bfloat16,enabled=signal.device.type=='cuda'): + outputs.append(self.backbone.student_encoder(self.adapters[t].student_input(signal))) + finally:torch.backends.mha.set_fastpath_enabled(old_fastpath) + return torch.cat(outputs).float() + def student_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].student_normalizer(values.float()) + normalized=torch.cat([normalized[:,:256],self.backbone.student_ordered_enabled*normalized[:,256:]],-1) + return self.backbone.student_readout(normalized) + def coupling_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False):return self.backbone.coupling_encoder(self.adapters[t].coupling_embedding(values.float())) + def phase_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].phase_normalizer(values.float()) + normalized=torch.cat([normalized[:,:PHASE_HALF],self.backbone.phase_imaginary_enabled*normalized[:,PHASE_HALF:]],-1) + return self.backbone.phase_encoder(normalized) + def forward(self,t,x,features=None,covariances=None,covariance_features=None): + if features is None:features=extract_features(t,x) + if covariance_features is None: + if covariances is None:covariances=extract_covariances(t,x) + covariance_features=self.adapters[t].spatial_features(covariances) + signal=x.flatten(2);signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + adapted=self.adapters[t](signal,features,covariance_features) + if covariances is None:covariances=extract_covariances(t,x) + tangent=extract_tangent_features(covariances,self.adapters[t].spatial_weight) + representation,fusion_delta,covariance_delta,fusion_input=self.backbone(*adapted,tangent_features=tangent) + if t in ('faced','openbmi'): + representation=torch.cat([representation[:,:-384],torch.zeros_like(representation[:,-384:-128]),representation[:,-128:]],-1) + tokens=torch.zeros(len(signal),signal.shape[-1]//200,24*64,device=signal.device,dtype=torch.bfloat16) + code_fusion,code_covariance=self.backbone.codebrain_correction(tokens,representation,fusion_input) + coactivation=self.backbone.wave_coactivation(representation) + with torch.autocast(signal.device.type,enabled=False): + ordinal=self.adapters[t].ordinal_embedding(ordinal_features(t,x)) + ordinal_covariance=self.backbone.ordinal_context(ordinal.float()) + added=.001*nn.functional.linear(ordinal_covariance,self.backbone.covariance_projection.weight,None) + ordinal_fusion=self.backbone.fusion(fusion_input+added.to(fusion_input.dtype))-representation[:,-512:-384] + phase=self.phase_embedding(t,phase_features(t,x,self.adapters[t].spatial_weight)) + coupling=self.coupling_embedding(t,coupling_features(t,x)) + student=self.student_embedding(t,self.student_features(t,x)) + return self.heads[t](torch.cat([representation,fusion_delta,covariance_delta,code_fusion,code_covariance,coactivation,ordinal_fusion,ordinal_covariance,phase,coupling,student],-1)) + +def widen_state_dict(state,multiplier=2): + """Duplicate temporal features and divide downstream sums to preserve outputs.""" + result={} + for key,value in state.items(): + if key.startswith('backbone.waveform.'): + layer=int(key.split('.')[2]) + if layer in (0,2,7):value=value.repeat(multiplier,1,1,1) + elif layer in (1,3,9):value=value.repeat(multiplier) + elif layer==8:value=value.repeat(multiplier,multiplier,1,1)/multiplier + elif key=='backbone.wave_summary.2.weight':value=value.repeat(1,multiplier)/multiplier + elif key.startswith('heads.') and key.endswith('.weight'): + raw=value[:,:-128]/multiplier + value=torch.cat([raw]*multiplier+[value[:,-128:]],1) + result[key]=value + return result + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/MODEL_CARD.md b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/MODEL_CARD.md new file mode 100644 index 0000000000000000000000000000000000000000..78b94952c8c4a2ed3aa93577dfb38c629d6e52fe --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/MODEL_CARD.md @@ -0,0 +1,23 @@ +# Shared EEG decoder + +This package contains one coupled backbone used by all five tracks, with private input adapters and classifiers. Every trainable common component was trained with all five training splits. It is a single model; inference performs no parameter updates or dataset-level fitting. + +The common backbone combines waveform convolutions, an audited pretrained BIOT feature path, covariance and log-correlation encoders, and shared feature corrections. The waveform coactivation extension encodes 64 within-window log variances and 2,016 correlations between common waveform channels. A matched experimental control removes the correlation inputs. `config.json` identifies the packaged variant and its five fixed correction gains. All original backbone parameters are fixed during this extension's joint training. + +Weights originate only from the supplied training data and audited initialization checkpoints. Training details, parent provenance, raw/cache checks, shared-gradient checks and the five separate validation metrics are recorded in `training.json`. Validation selects checkpoints and fixed gains; it does not fit normalization or update parameters. Reported validation results belong to selected checkpoints, not to private test evaluation or five-seed means. + +Run `bash infer.sh INPUT_DIR OUTPUT_DIR`. The input manifest specifies a track and opaque sample IDs, shard paths and indices. Signals are in microvolts and are scaled by 1/100. The package writes one probability vector per input ID to `OUTPUT_DIR/predictions.jsonl`. It needs only the packaged files and the contract's installed Python dependencies, works after relocation, and does not need labels, subject IDs, training caches or network access. + +FACED and TUEV use window balanced accuracy. AD65 uses mean window probabilities per patient before balanced accuracy. OpenBMI averages within-subject balanced accuracy. Longitudinal averages within-session balanced accuracy within each subject, then over subjects. These five metrics remain separate. + +This checkpoint adds fixed within-window ordinal pattern probabilities, permutation entropy and statistical complexity at five delays. Training-only normalization and five input projections feed one common correction MLP trained by all five tracks. The common correction enters the existing covariance and fusion representations; fixed per-track gains select its strength. All earlier model tensors remain unchanged. + +Fixed real and imaginary spectral coherence between the inherited 24 spatial filters is normalized using training windows only and encoded by one new common network. Five private linear heads add class evidence. All five training splits update the new common encoder; all earlier model tensors remain unchanged. + +Fixed per-window relative band powers, envelope variability, envelope correlations and phase-amplitude coupling feed training-normalized private input projections and one new shared encoder. Five linear heads add class evidence. All five training splits update the new common encoder; all prior model tensors remain unchanged. AD65 updates use all windows from six class-balanced training patients; objective: mean-probability. + +The inherited OpenBMI phase-classifier projection was refreshed from a separately validated private-readout fit. Every common tensor and input adapter of this jointly trained model is unchanged. Exact ancestor checks confirm that all common tensors used by this inherited readout are identical; the new cross-frequency correction remains disabled for OpenBMI. No shared checkpoints or predictions are ensembled. + +A common CBraMod feature encoder, itself jointly trained on all five training splits, supplies its shared summary and tokens pooled into four ordered time bins. Its classifiers are discarded. A new common feature MLP and five zero-initialized private linear projections learn residual class evidence jointly on all five training splits. Training may randomly remove the earlier decoder logits for half of training groups, using one mask per AD patient and one per other window; labels and teacher targets remain unchanged. Validation and inference always retain the complete earlier decoder. The same new class projection also receives an auxiliary standalone classification loss when configured, with the same patient-pooled AD objective; this adds no inference module. The complete earlier decoder and feature extractor remain tensor-identical; selecting zero residual gain preserves its predictions exactly. The summary-only control masks the 8192 ordered features after training-fitted per-feature normalization. One feature backbone and one classifier per track run at inference, with no prediction ensemble or external runtime cache. + +One private residual-strength scalar per track is selected from eight bounded values on validation, with the previous value preferred on ties. All learned tensors and the complete shared backbone are unchanged. This is additional model selection, not new independent performance evidence. diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/alpha_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/alpha_features.py new file mode 100644 index 0000000000000000000000000000000000000000..455154d715e86d45e4e17113bed69adbcd946b29 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/alpha_features.py @@ -0,0 +1,45 @@ +"""Fixed alpha prominence features from each individual two-second window.""" +import torch + +REGION_NAMES=('occipital','parietal','central','frontal','left_posterior','right_posterior') +REGIONS=(('PO7','PO5','PO3','POZ','PO4','PO6','PO8','O1','OZ','O2'), + ('P7','P5','P3','P1','PZ','P2','P4','P6','P8'), + ('FC5','FC3','FC1','FCZ','FC2','FC4','FC6','C5','C3','C1','CZ','C2','C4','C6'), + ('FP1','FPZ','FP2','AF3','AF4','F7','F5','F3','F1','FZ','F2','F4','F6','F8'), + ('P7','P5','P3','P1','PO7','PO5','PO3','O1'), + ('P2','P4','P6','P8','PO4','PO6','PO8','O2')) +ALPHA_DIM=58*7+6*22 + +def region_matrix(channels): + result=torch.zeros(len(REGIONS),len(channels)) + for i,names in enumerate(REGIONS): + for name in names:result[i,channels.index(name)]=1/len(names) + return result.tolist() + +@torch.no_grad() +def extract_alpha_features(signal,regions): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();x=x-x.mean(-1,keepdim=True) + spectrum=torch.fft.rfft(x*torch.hann_window(400,device=x.device),dim=-1)/200 + power=spectrum.abs().square().clamp_min(1e-12) + lp=power.log() + # Geometric regional means resist domination by one high-amplitude channel. + regional=torch.einsum('rc,ncf->nrf',regions.float(),lp) + lp=torch.cat([lp,regional],1) + low=lp[...,8:13].mean(-1,keepdim=True) + high=lp[...,36:49].mean(-1,keepdim=True) + freq=torch.arange(7.,14.5,.5,device=x.device) + alpha=lp[...,14:29] + baseline=low+(high-low)*((freq-5)/16) + prominence=alpha-baseline + normalized=alpha.softmax(-1) + center=(normalized*freq).sum(-1) + entropy=-(normalized*normalized.clamp_min(1e-12).log()).sum(-1) + alpha_mean=torch.logsumexp(alpha,-1)-torch.log(torch.tensor(15.,device=x.device)) + def log_band(lo,hi): + return torch.logsumexp(lp[...,lo:hi],-1)-torch.log(torch.tensor(float(hi-lo),device=x.device)) + summaries=torch.stack([alpha_mean-log_band(2,81),alpha_mean-log_band(8,14), + alpha_mean-log_band(30,61),prominence.max(-1).values, + prominence.mean(-1),center,entropy],-1) + return torch.cat([summaries[:,:58].flatten(1),summaries[:,58:].flatten(1), + prominence[:,58:].flatten(1)],1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/config.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/config.json new file mode 100644 index 0000000000000000000000000000000000000000..6994fad0a1bbbb32279f69b50e1334ead6229ceb --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/config.json @@ -0,0 +1,842 @@ +{ + "schema": "bci-shared-biot-covariance-bf16head-v1", + "architecture": { + "channels": 32, + "width": 128, + "depth": 2, + "dropout": 0.5, + "wave_filters": 32, + "head_width": 64, + "head_dropout": 0.3, + "clinical_asymmetry": true, + "alpha_regions": [ + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.125 + ] + ], + "clinical_envelope": true, + "temporal_pool": true, + "temporal_evidence": true, + "evidence_temperature": 0.25, + "random_fourier": true, + "fourier_features": 256, + "tangent_readout": true, + "shared_context_correction": true, + "wave_coactivation": true, + "ordinal_context": true, + "phase_coherence": true, + "cross_frequency": true, + "cbramod_feature_transfer": true, + "student_architecture": { + "virtual_channels": 32, + "token_width": 64, + "summary_width": 256, + "head_width": 128, + "dropout": 0.3 + } + }, + "initialization": { + "initialization": "continue joint training from a complete shared-model checkpoint", + "parent": "/workspace/research/runs/hybrid_biot_fusionshrink0100/epoch-001/weights.pt", + "parent_initialization": { + "initialization": "jointly trained parent plus audited pretrained BIOT in a single coupled backbone", + "parent": "/workspace/research/runs/hybrid_wide1/epoch-004/weights.pt", + "audited_biot": { + "initialization": "pretrained", + "repo": "braindecode/biot-pretrained-six-datasets-18chs", + "revision": "7e9aabf302870012f73773276803aab97993951c", + "sha256": "a218f4054ae29962c6fd9d23d94c446d354c4f53e805a6771c85749ccc20baaa", + "license": "BSD-3-Clause", + "source_braindecode": "1.3.0", + "loaded_core_tensors": 56, + "skipped_classifier_tensors": 3 + }, + "neural_channel_indices": { + "faced": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "tuev": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15 + ], + "ad65": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "openbmi": [ + 0, + 1, + 3, + 5, + 12, + 14, + 23, + 25, + 28, + 30, + 2, + 6, + 11, + 15, + 22, + 26, + 4, + 13 + ], + "longitudinal": [ + 0, + 2, + 7, + 11, + 23, + 27, + 41, + 45, + 55, + 57, + 5, + 13, + 21, + 29, + 39, + 47, + 9, + 25 + ] + }, + "rebase": "incumbent waveform, fusion and four heads; joint BIOT and TUEV head from readout epoch 9; zero initialized neural interaction", + "jointly_finetuned_neural_parent": "/workspace/research/runs/hybrid_biot_readout1/epoch-009/weights.pt", + "tuev_high_dimensional_spectral_projection_disabled": true, + "frozen_prior_representation": true, + "nonclinical_head_updates": "only the 256 added BIOT columns; original columns and biases fixed", + "faced_openbmi_neural_path": "common nonlinear fusion only; direct head columns masked", + "retention_teacher": "/workspace/research/runs/hybrid_wide1/epoch-004", + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "joint_covariance_parent": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "frozen_prior_representation": true, + "head_updates": "one linear head per track; added 128 shared covariance columns trainable; AD head initialized from the joint covariance parent", + "new_shared_representation": "one common covariance MLP inside the coupled backbone, trained by all five tasks; fixed spatial input adapters from the same jointly trained source", + "head_arithmetic": "one linear head evaluated in fixed feature blocks to preserve original bfloat16 accumulation dimensions", + "retention_teacher": { + "ad65": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "other_tracks": "/workspace/research/runs/hybrid_wide1/epoch-004" + }, + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "loader_scale": 0.01, + "tracks": [ + "faced", + "tuev", + "ad65", + "openbmi", + "longitudinal" + ], + "head_arithmetic": "same linear head in fixed feature blocks, sum in bfloat16 on GPU for non-AD tracks; AD remains float32", + "head_refinement": { + "source": "/workspace/research/runs/residual_heads1/epoch-018", + "source_weights_sha256": "e0b609137391b47f99438ccadaa22fc0bc10d2c10ead0ddf0a3c25be2c907c85", + "shared_backbone_unchanged": true, + "selected_head_epochs": { + "faced": 5, + "tuev": 24, + "ad65": 0, + "openbmi": 0, + "longitudinal": 0 + } + }, + "clinical_spectral_refinement": { + "source": "/workspace/research/runs/head_dropout1/epoch-016", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "head_estimation": { + "method": "class/subject-balanced Gaussian linear discriminant; covariance augmented by class-conditional subject/session mean variation before shrinkage", + "selected_shrinkage": { + "faced": "inherited", + "tuev": "inherited", + "ad65": "inherited", + "openbmi": "inherited", + "longitudinal": { + "shrinkage": 0.9, + "domain_strength": 1.0 + } + }, + "feature_scaling": "fitted on training data and folded into linear coefficients" + }, + "clinical_asymmetry_refinement": { + "source": "/workspace/research/runs/domain_lda_heads1/epoch-001", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "alpha_rhythm_adapter": { + "training_normalization_only": true, + "regions": [ + "occipital", + "parietal", + "central", + "frontal", + "left_posterior", + "right_posterior" + ], + "features": "per-window alpha prominence relative to adjacent frequencies", + "shared_backbone_unchanged": true + }, + "clinical_envelope_refinement": { + "source": "/workspace/research/runs/clinical_asymmetry1/epoch-001", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "independent_adapter_merge": { + "alpha_source": "/workspace/research/runs/alpha_calibrated1/epoch-003", + "clinical_source": "/workspace/research/runs/clinical_envelope1/epoch-002", + "all_shared_and_head_tensors_equal": true + }, + "frequency_montage_refinement": { + "six_frequency_bands": true, + "shared_encoder_unchanged": true, + "selected_track_epochs": { + "faced": 0, + "tuev": 1, + "ad65": 0, + "openbmi": 10, + "longitudinal": 2 + } + }, + "private_track_selection": { + "track": "tuev", + "donor": "/workspace/research/replicates/frequency_head_control1/epoch-001" + }, + "clinical_sampling_refinement": { + "subject_exponent": 0.0, + "class_balanced": true, + "only_clinical_head_updated": true + }, + "temporal_statistics_readout": { + "statistics": [ + "mean", + "standard deviation", + "maximum", + "minimum" + ], + "shared_encoder_and_prior_heads_unchanged": true, + "selected_pool_epochs": { + "faced": 2, + "tuev": 0, + "ad65": 0, + "openbmi": 33, + "longitudinal": 3 + } + }, + "temporal_evidence_readout": { + "pooling": "log mean exp of per-patch class evidence", + "temperature": 0.25, + "shared_encoder_and_prior_heads_unchanged": true, + "selected_evidence_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 6, + "longitudinal": 8 + } + }, + "fourier_basis_readout": { + "basis_functions": 256, + "bandwidths": [ + 0.5, + 1.0, + 2.0 + ], + "shared_encoder_and_prior_heads_unchanged": true, + "selected_fourier_epochs": { + "faced": 21, + "tuev": 0, + "ad65": 0, + "openbmi": 0, + "longitudinal": 2 + } + }, + "shared_tangent_readout": { + "one_shared_tangent_module": true, + "original_and_corrected_shared_features_retained": true, + "private_head_scalar_gains": { + "faced": 0.0, + "tuev": 0.1, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 0.1 + }, + "all_common_weights_fixed_during_gain_refinement": true + }, + "shared_context_correction": { + "source": "/workspace/research/runs/hybrid_codebrain_fusion_control1/epoch-002", + "zero_token_input_preserved": true, + "unused_native_CodeBrain_core_and_input_parameters_removed": true, + "common_patch_and_context_layers_retained": true, + "same_one_shared_backbone_and_five_classifiers": true + }, + "shared_wave_coactivation": { + "channels": 64, + "statistics": 2080, + "diagonal_only_control": false, + "common_encoder_updated_by_all_five_tracks": true, + "gain_selection_within_one_common_checkpoint": { + "faced": 1.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 1.0 + } + }, + "fixed_common_coactivation_readouts": { + "all_common_weights_exactly_unchanged": true, + "selected_private_epochs": { + "faced": 25, + "tuev": 0, + "ad65": 0, + "openbmi": 8, + "longitudinal": 2 + } + }, + "shared_ordinal_context": { + "per_channel_features": 130, + "normalization_fit_on_training_only": true, + "entropy_only_control": false, + "new_common_layers_trained_on_all_five_tracks": true, + "gains_within_one_common_checkpoint": { + "faced": 1.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 0.0 + } + }, + "shared_complex_coherence": { + "features": 5520, + "normalization_fit_on_training_only": true, + "real_only_control": false, + "all_five_tracks_update_common_encoder": true, + "gains_within_one_common_checkpoint": { + "faced": 0.1, + "tuev": 1.0, + "ad65": 0.0, + "openbmi": 0.3, + "longitudinal": 0.0 + } + }, + "shared_cross_frequency": { + "per_channel_features": 30, + "normalization_fit_on_training_only": true, + "amplitude_only_control": false, + "all_five_tracks_update_common_encoder": true, + "gains_within_one_common_checkpoint": { + "faced": 0.3, + "tuev": 0.1, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 0.0 + } + }, + "inherited_private_readout_refresh": { + "child": "/workspace/research/runs/coupling_patient1/epoch-007", + "donor": "/workspace/research/runs/phase_readout1/epoch-016", + "common_ancestor": "/workspace/research/runs/phase_coherence1/epoch-007", + "source_weight_sha256": { + "child": "f8466c6838ff01e54d1619f55668c1a4af26a243b54c67a956a3422d9604632a", + "donor": "ffd219d1480b81720b5aa4014cb2ed2b9cd31b7c92ad4717abc2a9625d30dc1a", + "ancestor": "e53ede409be523d8f4746251f7d46353621049f0378a88d4f7cfe2ba71a57d95" + }, + "changed_private_tensors": [ + "heads.openbmi.prior.projection.weight", + "heads.openbmi.prior.projection.bias" + ], + "all_ancestor_common_and_input_tensors_equal": true, + "all_child_common_and_input_tensors_unchanged": true, + "new_branch_gain_for_refreshed_track": 0.0, + "donor_changes_only_requested_private_projection": true, + "prediction_sources": { + "faced": { + "source": "/workspace/research/runs/coupling_patient1/faced-e007.npy", + "sha256": "68b617c8ecf347c79b23c20b70f6b4981c2f26b7b8c71dc7cd5fa0d7f4285ea6" + }, + "tuev": { + "source": "/workspace/research/runs/coupling_patient1/tuev-e007.npy", + "sha256": "9f0743450f1104d395e9daac0600aaf20755b5590b9f5c3e3137732c479dd647" + }, + "ad65": { + "source": "/workspace/research/runs/coupling_patient1/ad65-e007.npy", + "sha256": "7a3b74c58580b7ba952322bf6d527ebc9a40a6e04c7cdbbaea14e84a7a298d54" + }, + "openbmi": { + "source": "/workspace/research/runs/phase_readout1/openbmi-e016.npy", + "sha256": "14f630543e1df88c88d8f3e0effb4506ba33f533b3484de3c7aaf6554507341c" + }, + "longitudinal": { + "source": "/workspace/research/runs/coupling_patient1/longitudinal-e007.npy", + "sha256": "e93b0a319eaa3ddca9d71b0e786b808ba1630c1d3ce125f8e08036e517741b74" + } + } + }, + "shared_student_residual": { + "dimension": 8448, + "summary_dimension": 256, + "ordered_time_bins": 4, + "student_weights_sha256": "19dfe912cceed997699b5b526c8c2ece55945c5f9bd111c4c13704d0fc460e8b", + "summary_only_control": false, + "normalization_fit_on_training_only": true, + "new_common_readout_jointly_trained_on_all_five": true, + "class_projection_initialized_zero": true, + "student_classifiers_discarded": true, + "gains_within_one_common_checkpoint": { + "faced": 0.7, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 0.3, + "longitudinal": 1.0 + }, + "zero_gain_preserves_complete_parent": true + }, + "residual_gain_resolution_selection": { + "choices": [ + 0.0, + 0.03, + 0.1, + 0.2, + 0.3, + 0.5, + 0.7, + 1.0 + ], + "selected": { + "faced": 0.7, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 0.3, + "longitudinal": 1.0 + } + } +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/coupling_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/coupling_features.py new file mode 100644 index 0000000000000000000000000000000000000000..3a4e51bd7ce07bcec1f0f5b80054d6ff387ac87f --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/coupling_features.py @@ -0,0 +1,34 @@ +"""Per-window cross-frequency envelope and phase-amplitude relationships.""" +import torch +BANDS=((1,4),(4,8),(8,13),(13,30),(30,48)) +PAIRS=tuple((i,j) for i in range(5) for j in range(i+1,5)) +PER_CHANNEL=30 + +@torch.no_grad() +def coupling_features(track,x): + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + n=x.shape[-1];spectrum=torch.fft.fft(x,dim=-1);frequency=torch.fft.fftfreq(n,1/200,device=x.device) + masks=torch.stack([2*((frequency>=lo)&(frequency=lo)&(frequency2).float().mean(-1),(relative>4).float().mean(-1), + ((relative[...,1:]>2)&(relative[...,:-1]<=2)).float().mean(-1), + acf_peak,(acf_index.float()+4)/40, + acf[...,0],acf[...,6],acf[...,16],acf[...,36]] + left=torch.tensor([0,1,2,3,8,9,10,11],device=x.device);right=left+4 + synchrony=(normalized[:,left]*normalized[:,right]).mean(-1).clamp(-1,1) + imbalance=(std[:,left].squeeze(-1).log()-std[:,right].squeeze(-1).log()).abs() + return torch.cat([torch.stack(summaries,-1).flatten(1),synchrony.flatten(1),imbalance.flatten(1)],1) + +def mirrored_features(features): + channels=torch.tensor([4,5,6,7,0,1,2,3,12,13,14,15,8,9,10,11],device=features.device) + return torch.cat([features[:,:16*5*12].reshape(-1,16,5,12)[:,channels].flatten(1),features[:,16*5*12:]],1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/features.py new file mode 100644 index 0000000000000000000000000000000000000000..88f7e8b14c9fab44733d5224ede6d6b5c7f76a45 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/features.py @@ -0,0 +1,63 @@ +"""One shared residual backbone, five linear input adapters and output heads.""" +import torch +from torch import nn + +SPECS = {'faced': (32, 10, 9), 'tuev': (16, 5, 6), 'ad65': (19, 10, 3), + 'openbmi': (62, 4, 2), 'longitudinal': (58, 2, 2)} +TRACKS = tuple(SPECS) +EDGES = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,18,20,22,25,28,32,36,40,45,50,60,70,80,95] +COV_BANDS = [(1,4),(4,8),(8,12),(12,16),(16,20),(20,28),(28,40)] + +def feature_dim(channels): + return channels * (4*(len(EDGES)-1)+4) + len(COV_BANDS)*channels*(channels-1)//2 + +@torch.no_grad() +def extract_features(track, x): + """Fixed features; no batch statistics or fitted inference transformations.""" + x = x.float().flatten(2) + x = torch.nan_to_num(x, nan=0., posinf=1e5, neginf=-1e5).clamp(-1e5,1e5) + x = x - x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'): + x = x - x.mean(1,keepdim=True) + rms = x.square().mean(-1).clamp_min(1e-12).sqrt() + norm = x / rms.unsqueeze(-1) + moments = torch.stack([rms.log(), norm.abs().amax(-1).clamp_min(1).log(), + norm.pow(4).mean(-1).clamp_min(1).log(), + (norm[...,1:]-norm[...,:-1]).square().mean(-1).clamp_min(1e-10).log()],-1) + frames = x.unfold(-1,400,200) + frames = frames - frames.mean(-1,keepdim=True) + window = torch.hann_window(400,device=x.device) + z = torch.fft.rfft(frames*window,dim=-1)/200 + power = z.abs().square() + bands = torch.stack([power[...,2*lo:2*hi].mean(-1) for lo,hi in zip(EDGES[:-1],EDGES[1:])],-1) + lp = bands.mean(-2).clamp_min(1e-12).log() + variation = bands.clamp_min(1e-12).log().std(-2,correction=0) + relative_frequency = lp - lp.mean(-1,keepdim=True) + relative_channel = lp - lp.mean(1,keepdim=True) + parts = [torch.cat([lp, relative_frequency, relative_channel, variation, moments],-1).flatten(1)] + ii,jj = torch.triu_indices(x.shape[1],x.shape[1],offset=1,device=x.device) + for lo,hi in COV_BANDS: + v = z[...,2*lo:2*hi].flatten(2) + cov = v.real @ v.real.transpose(-1,-2) + v.imag @ v.imag.transpose(-1,-2) + d = cov.diagonal(dim1=-2,dim2=-1).clamp_min(1e-12).sqrt() + cor = cov / (d.unsqueeze(1)*d.unsqueeze(2)).clamp_min(1e-12) + parts.append(cor[:,ii,jj].clamp(-1,1)) + result = torch.cat(parts,-1) + return torch.nan_to_num(result).clamp(-40,40) + +class Standardize(nn.Module): + def __init__(self, dim): + super().__init__() + self.register_buffer('mean',torch.zeros(dim)) + self.register_buffer('scale',torch.ones(dim)) + def forward(self,x): + return ((x-self.mean)/self.scale).clamp(-8,8) + +class Residual(nn.Module): + def __init__(self,width,dropout): + super().__init__() + self.net=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(), + nn.Dropout(dropout),nn.Linear(width*2,width),nn.Dropout(dropout)) + def forward(self,x): + return x+self.net(x) + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/frequency_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/frequency_features.py new file mode 100644 index 0000000000000000000000000000000000000000..9194c9e81f801b3833e551e4967991774fa9e398 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/frequency_features.py @@ -0,0 +1,11 @@ +"""Fixed per-window frequency decomposition for a linear montage adapter.""" +import torch + +FREQUENCY_BANDS=((1,4),(4,8),(8,13),(13,20),(20,30),(30,45)) + +def frequency_components(signal): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();spectrum=torch.fft.rfft(x,dim=-1) + frequency=torch.fft.rfftfreq(x.shape[-1],d=1/200,device=x.device) + masks=torch.stack([((frequency>=lo)&(frequencynbf',w,covariances.float(),w).clamp_min(1e-8).log() + return torch.cat([power,power-power.mean(1,keepdim=True)],1).flatten(1) + def wave_signal(self,x,components=None): + if components is None:components=frequency_components(x) + correction=torch.einsum('blc,nbct->nlt',self.frequency_weight,components.to(self.frequency_weight.dtype)) + return (self.signal(x)+correction.to(x.dtype)).unsqueeze(1) + def forward(self,x,features,covariance_features): + return self.wave_signal(x),self.spectral_features(features,signal=x),self.neural(x),covariance_features + +class SharedBackbone(nn.Module): + def __init__(self,channels,width,depth,dropout,wave_filters): + super().__init__() + self.waveform=nn.Sequential( + nn.Conv2d(1,wave_filters,(1,64),padding=(0,32),bias=False),nn.GroupNorm(1,wave_filters), + nn.Conv2d(wave_filters,2*wave_filters,(channels,1),groups=wave_filters,bias=False),nn.GroupNorm(1,2*wave_filters),nn.ELU(), + nn.AvgPool2d((1,4)),nn.Dropout(.35), + nn.Conv2d(2*wave_filters,2*wave_filters,(1,16),padding=(0,8),groups=2*wave_filters,bias=False),nn.Conv2d(2*wave_filters,2*wave_filters,1,bias=False), + nn.GroupNorm(1,2*wave_filters),nn.ELU(),nn.AvgPool2d((1,8)),nn.Dropout(.35)) + self.wave_summary=nn.Sequential(nn.AdaptiveAvgPool2d((1,8)),nn.Flatten(),nn.Linear(2*wave_filters*8,width)) + self.fusion=nn.Sequential(nn.LayerNorm(width),nn.GELU(),nn.Dropout(dropout), + *[Residual(width,dropout) for _ in range(depth)],nn.LayerNorm(width)) + # Both representations interact before the shared residual stack. + self.phase_encoder=nn.Sequential(nn.LayerNorm(PHASE_DIM),nn.Linear(PHASE_DIM,width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width)) + self.register_buffer('phase_imaginary_enabled',torch.ones(())) + self.coupling_encoder=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width),nn.LayerNorm(width)) + self.wave_gain=nn.Parameter(torch.tensor(.1)) + self.biot=BIOT(n_chans=18,n_outputs=2,n_times=400,sfreq=200) + self.biot.final_layer=nn.Identity() + self.biot_projection=nn.Sequential(nn.LayerNorm(256),nn.Linear(256,width),nn.Dropout(.2)) + nn.init.normal_(self.biot_projection[1].weight,std=.001);nn.init.zeros_(self.biot_projection[1].bias) + self.covariance_encoder=nn.Sequential(nn.LayerNorm(len(BANDS)*24*2),nn.Linear(len(BANDS)*24*2,width),nn.GELU(),nn.Dropout(.4), + *[Residual(width,.4) for _ in range(2)],nn.LayerNorm(width)) + self.covariance_projection=nn.Linear(width,width) + nn.init.zeros_(self.covariance_projection.weight);nn.init.zeros_(self.covariance_projection.bias) + self.tangent_encoder=nn.Sequential(nn.LayerNorm(TANGENT_DIM),nn.Linear(TANGENT_DIM,width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width),nn.Linear(width,width)) + self.ordinal_context=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width)) + nn.init.zeros_(self.ordinal_context[-1].weight);nn.init.zeros_(self.ordinal_context[-1].bias) + self.register_buffer('codebrain_enabled',torch.ones(())) + self.codebrain_patch_encoder=nn.Sequential(nn.LayerNorm(24*64),nn.Linear(24*64,width),nn.GELU(),nn.Dropout(.3)) + self.codebrain_context=nn.Sequential(nn.LayerNorm(width*4),nn.Linear(width*4,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width)) + nn.init.zeros_(self.codebrain_context[-1].weight);nn.init.zeros_(self.codebrain_context[-1].bias) + def codebrain_correction(self,tokens,representation,fusion_input): + with torch.autocast(tokens.device.type,enabled=False): + encoded=self.codebrain_patch_encoder(self.codebrain_enabled*tokens.float()) + pooled=torch.cat([encoded.mean(1),encoded.std(1,correction=0),representation[:,-512:-384].float(),representation[:,-128:].float()],-1) + delta=self.codebrain_context(pooled) + added=.001*nn.functional.linear(delta,self.covariance_projection.weight,None) + corrected=self.fusion(fusion_input+added.to(fusion_input.dtype)) + return corrected-representation[:,-512:-384],delta + def forward(self,signal,spectral,neural_signal,covariance_features,tangent_features): + wave=self.waveform(signal) + neural=self.biot(neural_signal.float()) + neural=self.biot_projection[0](neural) + projected=self.biot_projection[2](self.biot_projection[1](neural)) + with torch.autocast(signal.device.type,enabled=False): + covariance_embedding=self.covariance_encoder(covariance_features.float()) + original=spectral+self.wave_gain*self.wave_summary(wave)+.01*projected + coupled=.001*self.covariance_projection(covariance_embedding).to(original.dtype) + fused=self.fusion(original+coupled) + with torch.autocast(signal.device.type,enabled=False):delta=self.tangent_encoder(tangent_features.float()) + added=.001*nn.functional.linear(delta,self.covariance_projection.weight,None) + corrected=self.fusion((original+coupled)+added.to(original.dtype)) + return torch.cat([wave.flatten(1),fused,neural,covariance_embedding],-1),corrected-fused,delta,original+coupled + +class ResidualHead(nn.Module): + """A small nonlinear classifier correction around an inherited linear readout.""" + def __init__(self,features,classes,width=64,dropout=.3,full_precision=False): + super().__init__();self.full_precision=full_precision + self.base=nn.Linear(features,classes) + self.delta=nn.Sequential(nn.LayerNorm(features),nn.Linear(features,width),nn.GELU(),nn.Dropout(dropout),nn.Linear(width,classes)) + nn.init.zeros_(self.delta[-1].weight);nn.init.zeros_(self.delta[-1].bias) + def forward(self,x): + if self.full_precision: + with torch.autocast(x.device.type,enabled=False):return self.base(x.float())+self.delta(x.float()) + prior=nn.functional.linear(x[:,:-128].contiguous(),self.base.weight[:,:-128].contiguous(),self.base.bias) + added=nn.functional.linear(x[:,-128:].contiguous(),self.base.weight[:,-128:].contiguous()) + value=prior+added + return value+self.delta(x).to(value.dtype) + +class TemporalPoolHead(nn.Module): + def __init__(self,prior,channels=64): + super().__init__();self.prior=prior;self.channels=channels + self.register_buffer('pool_output_scale',torch.ones(()));self.register_buffer('pool_mean',torch.zeros(channels*4));self.register_buffer('pool_scale',torch.ones(channels*4)) + self.pool_projection=nn.Linear(channels*4,prior.base.out_features) + nn.init.zeros_(self.pool_projection.weight);nn.init.zeros_(self.pool_projection.bias) + def statistics(self,x): + with torch.autocast(x.device.type,enabled=False): + wave=x[:,:-512].float().reshape(len(x),self.channels,-1) + return torch.cat([wave.mean(-1),wave.std(-1,correction=0),wave.amax(-1),wave.amin(-1)],-1) + def forward(self,x): + prior=self.prior(x) + with torch.autocast(x.device.type,enabled=False): + values=((self.statistics(x)-self.pool_mean)/self.pool_scale).clamp(-8,8) + added=self.pool_output_scale*self.pool_projection(values) + return prior+added.to(prior.dtype) + +class TemporalEvidenceHead(nn.Module): + """Pool class evidence over the shared waveform time axis.""" + def __init__(self,prior,channels=64,temperature=.25): + super().__init__();self.prior=prior;self.channels=channels;self.temperature=temperature + self.register_buffer('evidence_output_scale',torch.ones(())) + self.register_buffer('evidence_mean',torch.zeros(channels)) + self.register_buffer('evidence_scale',torch.ones(channels)) + self.evidence_projection=nn.Linear(channels,prior.prior.base.out_features,bias=False) + nn.init.zeros_(self.evidence_projection.weight) + def patches(self,x): + with torch.autocast(x.device.type,enabled=False): + wave=x[:,:-512].float().reshape(len(x),self.channels,-1).transpose(1,2) + return ((wave-self.evidence_mean)/self.evidence_scale).clamp(-8,8) + def evidence(self,patches): + with torch.autocast(patches.device.type,enabled=False): + values=self.evidence_projection(patches.float())/self.temperature + maximum=values.amax(1,keepdim=True) + pooled=self.temperature*((values-maximum).exp().mean(1).log()+maximum.squeeze(1)) + return self.evidence_output_scale*pooled + def forward(self,x): + prior=self.prior(x) + return prior+self.evidence(self.patches(x)).to(prior.dtype) + +class FourierResidualHead(nn.Module): + """A fixed random Fourier basis and trainable linear classifier correction.""" + def __init__(self,prior,features,classes,basis=256): + super().__init__();self.prior=prior + self.register_buffer('rff_mean',torch.zeros(features));self.register_buffer('rff_scale',torch.ones(features)) + self.register_buffer('rff_frequency',torch.randn(features,basis)/features**.5) + self.register_buffer('rff_phase',torch.rand(basis)*2*torch.pi) + self.register_buffer('rff_output_scale',torch.ones(())) + self.rff_projection=nn.Linear(3*basis,classes);nn.init.zeros_(self.rff_projection.weight);nn.init.zeros_(self.rff_projection.bias) + def basis(self,x): + with torch.autocast(x.device.type,enabled=False): + values=((x.float()-self.rff_mean)/self.rff_scale).clamp(-8,8)@self.rff_frequency + return 2**.5*torch.cat([(values/sigma+self.rff_phase).cos() for sigma in (.5,1.,2.)],-1) + def forward(self,x): + prior=self.prior(x) + with torch.autocast(x.device.type,enabled=False):added=self.rff_output_scale*self.rff_projection(self.basis(x)) + return prior+added.to(prior.dtype) + +class TangentFeatureHead(nn.Module): + """Select a shared feature correction before the inherited classifier.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.feature_gain=nn.Parameter(torch.zeros(())) + def forward(self,values): + old=values[:,:-256];fusion_delta=values[:,-256:-128];covariance_delta=values[:,-128:] + adjusted=torch.cat([old[:,:-512],old[:,-512:-384]+self.feature_gain*fusion_delta,old[:,-384:-128],old[:,-128:]+self.feature_gain*covariance_delta],-1) + return self.prior(adjusted) + +class CodeBrainFeatureHead(nn.Module): + """Private use of a jointly trained common feature correction.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.codebrain_gain=nn.Parameter(torch.ones(())) + def forward(self,values): + previous=values[:,:-256];native=previous[:,:-256] + fusion_delta=values[:,-256:-128];covariance_delta=values[:,-128:] + adjusted=torch.cat([native[:,:-512],native[:,-512:-384]+self.codebrain_gain*fusion_delta,native[:,-384:-128],native[:,-128:]+self.codebrain_gain*covariance_delta],-1) + return self.prior(torch.cat([adjusted,previous[:,-256:]],-1)) + +class WaveCoactivationContext(nn.Module): + """One common encoder of coactivation among the learned waveform channels.""" + def __init__(self,channels=64,width=128): + super().__init__();self.channels=channels + ii,jj=torch.triu_indices(channels,channels,offset=1) + self.register_buffer('pair_i',ii);self.register_buffer('pair_j',jj) + self.register_buffer('offdiagonal_enabled',torch.ones(())) + self.encoder=nn.Sequential(nn.LayerNorm(channels+len(ii)),nn.Linear(channels+len(ii),width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width)) + def statistics(self,native): + with torch.autocast(native.device.type,enabled=False): + wave=native[:,:-512].float().reshape(len(native),self.channels,-1) + centered=wave-wave.mean(-1,keepdim=True) + previous_tf32=torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32=False + covariance=centered@centered.transpose(-1,-2)/wave.shape[-1] + torch.backends.cuda.matmul.allow_tf32=previous_tf32 + variance=covariance.diagonal(dim1=-2,dim2=-1).clamp_min(1e-8) + correlation=covariance/(variance.sqrt()[:,:,None]*variance.sqrt()[:,None,:]) + return torch.cat([variance.log(),correlation[:,self.pair_i,self.pair_j].clamp(-1,1)],-1) + def encode_statistics(self,values): + with torch.autocast(values.device.type,enabled=False): + value=torch.cat([values[:,:self.channels],self.offdiagonal_enabled*values[:,self.channels:]],-1) + return self.encoder(value.float()) + def forward(self,native):return self.encode_statistics(self.statistics(native)) + +class WaveCoactivationHead(nn.Module): + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=self.correction_gain*self.output_scale*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class OrdinalFeatureHead(nn.Module): + """Private strength of one common ordinal-dynamics feature correction.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.ordinal_gain=nn.Parameter(torch.ones(())) + def forward(self,values): + previous=values[:,:-256];native=previous[:,:-640] + adjusted=torch.cat([native[:,:-512],native[:,-512:-384]+self.ordinal_gain*values[:,-256:-128],native[:,-384:-128],native[:,-128:]+self.ordinal_gain*values[:,-128:],previous[:,-640:]],-1) + return self.prior(adjusted) + +class PhaseReadoutHead(nn.Module): + """Private class evidence from the common complex-coherence encoder.""" + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=(self.correction_gain*self.output_scale)*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class CouplingReadoutHead(nn.Module): + """Private class evidence from the common cross-frequency coupling encoder.""" + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=(self.correction_gain*self.output_scale)*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class HybridModel(nn.Module): + def __init__(self,channels=32,width=128,depth=2,dropout=.5,wave_filters=32,head_width=64,head_dropout=.3,clinical_asymmetry=True,alpha_regions=None,clinical_envelope=False,temporal_pool=True,temporal_evidence=False,evidence_temperature=.25,random_fourier=False,fourier_features=256,tangent_readout=True,shared_context_correction=True,wave_coactivation=True,ordinal_context=True,phase_coherence=True,cross_frequency=True,cbramod_feature_transfer=True,student_architecture=None): + super().__init__() + self.adapters=nn.ModuleDict({t:InputAdapter(c,width,channels,spectral_enabled=t not in ("faced","tuev","openbmi"),asymmetry=clinical_asymmetry and t=="tuev",alpha_regions=alpha_regions if t=="longitudinal" else None,envelope=clinical_envelope and t=="tuev") for t,(c,s,k) in SPECS.items()}) + self.backbone=SharedBackbone(channels,width,depth,dropout,wave_filters) + self.backbone.student_encoder=CBraModFeatures(**(student_architecture or {})) + self.backbone.register_buffer('student_ordered_enabled',torch.ones(())) + self.backbone.student_readout=nn.Sequential(nn.Linear(self.backbone.student_encoder.output_dim,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + for t,(c,s,k) in SPECS.items(): + self.adapters[t].student_input=FrequencyAdapter(c,32) + self.adapters[t].student_normalizer=Standardize(self.backbone.student_encoder.output_dim) + self.backbone.wave_coactivation=WaveCoactivationContext(2*wave_filters,width) + self.heads=nn.ModuleDict({t:ResidualHead(2*wave_filters*(((s*200+1)//4+1)//8)+width+256+width,k,head_width,head_dropout,full_precision=t=='ad65') for t,(c,s,k) in SPECS.items()}) + if temporal_pool:self.heads=nn.ModuleDict({t:TemporalPoolHead(head,wave_filters*2) for t,head in self.heads.items()}) + if temporal_evidence:self.heads=nn.ModuleDict({t:TemporalEvidenceHead(head,wave_filters*2,evidence_temperature) for t,head in self.heads.items()}) + if random_fourier:self.heads=nn.ModuleDict({t:FourierResidualHead(head,2*wave_filters*(((SPECS[t][1]*200+1)//4+1)//8)+width+256+width,SPECS[t][2],fourier_features) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:TangentFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CodeBrainFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:WaveCoactivationHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:OrdinalFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:PhaseReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + def student_features(self,t,x): + outputs=[];old_fastpath=torch.backends.mha.get_fastpath_enabled();torch.backends.mha.set_fastpath_enabled(False) + try: + for raw in x.split(16): + signal=torch.nan_to_num(raw.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + with torch.autocast(signal.device.type,dtype=torch.bfloat16,enabled=signal.device.type=='cuda'): + outputs.append(self.backbone.student_encoder(self.adapters[t].student_input(signal))) + finally:torch.backends.mha.set_fastpath_enabled(old_fastpath) + return torch.cat(outputs).float() + def student_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].student_normalizer(values.float()) + normalized=torch.cat([normalized[:,:256],self.backbone.student_ordered_enabled*normalized[:,256:]],-1) + return self.backbone.student_readout(normalized) + def coupling_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False):return self.backbone.coupling_encoder(self.adapters[t].coupling_embedding(values.float())) + def phase_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].phase_normalizer(values.float()) + normalized=torch.cat([normalized[:,:PHASE_HALF],self.backbone.phase_imaginary_enabled*normalized[:,PHASE_HALF:]],-1) + return self.backbone.phase_encoder(normalized) + def forward(self,t,x,features=None,covariances=None,covariance_features=None): + if features is None:features=extract_features(t,x) + if covariance_features is None: + if covariances is None:covariances=extract_covariances(t,x) + covariance_features=self.adapters[t].spatial_features(covariances) + signal=x.flatten(2);signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + adapted=self.adapters[t](signal,features,covariance_features) + if covariances is None:covariances=extract_covariances(t,x) + tangent=extract_tangent_features(covariances,self.adapters[t].spatial_weight) + representation,fusion_delta,covariance_delta,fusion_input=self.backbone(*adapted,tangent_features=tangent) + if t in ('faced','openbmi'): + representation=torch.cat([representation[:,:-384],torch.zeros_like(representation[:,-384:-128]),representation[:,-128:]],-1) + tokens=torch.zeros(len(signal),signal.shape[-1]//200,24*64,device=signal.device,dtype=torch.bfloat16) + code_fusion,code_covariance=self.backbone.codebrain_correction(tokens,representation,fusion_input) + coactivation=self.backbone.wave_coactivation(representation) + with torch.autocast(signal.device.type,enabled=False): + ordinal=self.adapters[t].ordinal_embedding(ordinal_features(t,x)) + ordinal_covariance=self.backbone.ordinal_context(ordinal.float()) + added=.001*nn.functional.linear(ordinal_covariance,self.backbone.covariance_projection.weight,None) + ordinal_fusion=self.backbone.fusion(fusion_input+added.to(fusion_input.dtype))-representation[:,-512:-384] + phase=self.phase_embedding(t,phase_features(t,x,self.adapters[t].spatial_weight)) + coupling=self.coupling_embedding(t,coupling_features(t,x)) + student=self.student_embedding(t,self.student_features(t,x)) + return self.heads[t](torch.cat([representation,fusion_delta,covariance_delta,code_fusion,code_covariance,coactivation,ordinal_fusion,ordinal_covariance,phase,coupling,student],-1)) + +def widen_state_dict(state,multiplier=2): + """Duplicate temporal features and divide downstream sums to preserve outputs.""" + result={} + for key,value in state.items(): + if key.startswith('backbone.waveform.'): + layer=int(key.split('.')[2]) + if layer in (0,2,7):value=value.repeat(multiplier,1,1,1) + elif layer in (1,3,9):value=value.repeat(multiplier) + elif layer==8:value=value.repeat(multiplier,multiplier,1,1)/multiplier + elif key=='backbone.wave_summary.2.weight':value=value.repeat(1,multiplier)/multiplier + elif key.startswith('heads.') and key.endswith('.weight'): + raw=value[:,:-128]/multiplier + value=torch.cat([raw]*multiplier+[value[:,-128:]],1) + result[key]=value + return result + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/ordinal_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/ordinal_features.py new file mode 100644 index 0000000000000000000000000000000000000000..6e3d5ff8264253f058f71b04d9cc8454196592b1 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/ordinal_features.py @@ -0,0 +1,25 @@ +"""Fixed within-window ordinal dynamics, independent of amplitude scaling.""" +import math +import torch +LAGS=(1,2,4,8,16) +PATTERNS=24 +PER_CHANNEL=len(LAGS)*(PATTERNS+2) + +def ordinal_features(track,x): + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + parts=[];uniform=1/PATTERNS;maximum_entropy=math.log(PATTERNS);m0=(1+uniform)/2;mr=uniform/2;maximum_js=-m0*math.log(m0)-(PATTERNS-1)*mr*math.log(mr)-maximum_entropy/2 + for lag in LAGS: + length=x.shape[-1]-3*lag + if length<=0:raise ValueError('window too short for ordinal dynamics') + samples=torch.stack([x[...,i*lag:i*lag+length] for i in range(4)],-1) + order=samples.argsort(dim=-1,stable=True) + code=6*((order[...,0,None]>order[...,1:]).sum(-1))+2*((order[...,1,None]>order[...,2:]).sum(-1))+(order[...,2]>order[...,3]).long() + histogram=torch.zeros(*x.shape[:2],PATTERNS,device=x.device,dtype=torch.float32) + histogram.scatter_add_(-1,code,torch.ones_like(code,dtype=torch.float32));probability=histogram/length + entropy=-(probability*probability.clamp_min(1e-12).log()).sum(-1) + mixture=(probability+uniform)/2;mixture_entropy=-(mixture*mixture.log()).sum(-1) + complexity=((mixture_entropy-.5*entropy-.5*maximum_entropy)/maximum_js).clamp(0,1)*(entropy/maximum_entropy) + parts.append(torch.cat([probability,(entropy/maximum_entropy)[...,None],complexity[...,None]],-1)) + return torch.cat(parts,-1).flatten(1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/phase_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/phase_features.py new file mode 100644 index 0000000000000000000000000000000000000000..8d98822995bf37b499795dfd7e2e401040a01969 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/phase_features.py @@ -0,0 +1,37 @@ +"""Complex spectral coherence of the existing 24 spatial filters in ten bands.""" +import torch +from covariances import BANDS +CHANNELS=24 +PHASE_HALF=len(BANDS)*CHANNELS*(CHANNELS-1)//2 +PHASE_DIM=2*PHASE_HALF + +@torch.no_grad() +def phase_features(track,x,spatial_weight): + previous_tf32=torch.backends.cuda.matmul.allow_tf32 + try: + torch.backends.cuda.matmul.allow_tf32=False + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if track in ('faced','tuev'):x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + else:x=x-x.mean(1,keepdim=True) + x=x/x.square().mean((1,2),keepdim=True).clamp_min(1e-12).sqrt() + frames=x.unfold(-1,400,200);frames=frames-frames.mean(-1,keepdim=True) + z=torch.fft.rfft(frames*torch.hann_window(400,device=x.device),dim=-1)/200 + w=spatial_weight.float()/spatial_weight.float().norm(dim=-1,keepdim=True).clamp_min(1e-6) + index=torch.triu_indices(CHANNELS,CHANNELS,1,device=x.device) + real_parts=[];imaginary_parts=[] + for band,(lo,hi) in enumerate(BANDS): + v=z[...,2*lo:2*hi].flatten(2) + vr=w[band][None]@v.real;vi=w[band][None]@v.imag + real=(vr@vr.transpose(-1,-2)+vi@vi.transpose(-1,-2))/v.shape[-1] + imaginary=(vi@vr.transpose(-1,-2)-vr@vi.transpose(-1,-2))/v.shape[-1] + # Signals have unit global RMS; this floor suppresses phase of numerical silence. + power=real.diagonal(dim1=-2,dim2=-1).clamp_min(1e-6) + denominator=(power[:,:,None]*power[:,None,:]).sqrt().clamp_min(1e-12) + real=(real/denominator).clamp(-.999,.999) + imaginary=(imaginary/denominator).clamp(-.999,.999) + real_parts.append(torch.atanh(real[:,index[0],index[1]])) + imaginary_parts.append(torch.atanh(imaginary[:,index[0],index[1]])) + return torch.cat(real_parts+imaginary_parts,-1) + finally:torch.backends.cuda.matmul.allow_tf32=previous_tf32 diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/private-readout-refresh-audit.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/private-readout-refresh-audit.json new file mode 100644 index 0000000000000000000000000000000000000000..1d02ef9e4aa8d0782c67157b160ef5667bfa1193 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/private-readout-refresh-audit.json @@ -0,0 +1,40 @@ +{ + "child": "/workspace/research/runs/coupling_patient1/epoch-007", + "donor": "/workspace/research/runs/phase_readout1/epoch-016", + "common_ancestor": "/workspace/research/runs/phase_coherence1/epoch-007", + "source_weight_sha256": { + "child": "f8466c6838ff01e54d1619f55668c1a4af26a243b54c67a956a3422d9604632a", + "donor": "ffd219d1480b81720b5aa4014cb2ed2b9cd31b7c92ad4717abc2a9625d30dc1a", + "ancestor": "e53ede409be523d8f4746251f7d46353621049f0378a88d4f7cfe2ba71a57d95" + }, + "changed_private_tensors": [ + "heads.openbmi.prior.projection.weight", + "heads.openbmi.prior.projection.bias" + ], + "all_ancestor_common_and_input_tensors_equal": true, + "all_child_common_and_input_tensors_unchanged": true, + "new_branch_gain_for_refreshed_track": 0.0, + "donor_changes_only_requested_private_projection": true, + "prediction_sources": { + "faced": { + "source": "/workspace/research/runs/coupling_patient1/faced-e007.npy", + "sha256": "68b617c8ecf347c79b23c20b70f6b4981c2f26b7b8c71dc7cd5fa0d7f4285ea6" + }, + "tuev": { + "source": "/workspace/research/runs/coupling_patient1/tuev-e007.npy", + "sha256": "9f0743450f1104d395e9daac0600aaf20755b5590b9f5c3e3137732c479dd647" + }, + "ad65": { + "source": "/workspace/research/runs/coupling_patient1/ad65-e007.npy", + "sha256": "7a3b74c58580b7ba952322bf6d527ebc9a40a6e04c7cdbbaea14e84a7a298d54" + }, + "openbmi": { + "source": "/workspace/research/runs/phase_readout1/openbmi-e016.npy", + "sha256": "14f630543e1df88c88d8f3e0effb4506ba33f533b3484de3c7aaf6554507341c" + }, + "longitudinal": { + "source": "/workspace/research/runs/coupling_patient1/longitudinal-e007.npy", + "sha256": "e93b0a319eaa3ddca9d71b0e786b808ba1630c1d3ce125f8e08036e517741b74" + } + } +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/student_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/student_features.py new file mode 100644 index 0000000000000000000000000000000000000000..57401f6d2ab760cb1a58af564aef2e62290e8907 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/student_features.py @@ -0,0 +1,34 @@ +"""One audited CBraMod core with full-window shared and ordered representations.""" +import torch +from torch import nn +from braindecode.models import CBraMod +from frequency_features import frequency_components,FREQUENCY_BANDS +SPECS={'faced':(32,10,9),'tuev':(16,5,6),'ad65':(19,10,3),'openbmi':(62,4,2),'longitudinal':(58,2,2)} +TRACKS=tuple(SPECS) + +class FrequencyAdapter(nn.Module): + def __init__(self,channels,virtual_channels=32): + super().__init__();self.signal=nn.Conv1d(channels,virtual_channels,1,bias=False) + self.frequency_weight=nn.Parameter(torch.zeros(len(FREQUENCY_BANDS),virtual_channels,channels)) + def forward(self,x): + components=frequency_components(x) + correction=torch.einsum('blc,nbct->nlt',self.frequency_weight,components.to(self.frequency_weight.dtype)) + return self.signal(x)+correction.to(x.dtype) + +class CBraModFeatures(nn.Module): + def __init__(self,virtual_channels=32,token_width=64,summary_width=256,head_width=128,dropout=.3): + super().__init__();self.virtual_channels=virtual_channels;self.output_dim=summary_width+virtual_channels*token_width*4 + self.backbone=CBraMod(n_chans=virtual_channels,n_outputs=2,n_times=400,sfreq=200) + self.backbone.final_layer=nn.Identity() + self.token_projection=nn.Sequential(nn.LayerNorm(200),nn.Linear(200,token_width),nn.GELU()) + self.summary_projection=nn.Sequential(nn.LayerNorm(virtual_channels*token_width*2),nn.Linear(virtual_channels*token_width*2,summary_width),nn.GELU(),nn.Dropout(dropout)) + def forward(self,signal): + tokens=self.token_projection(self.backbone(signal)) + moments=torch.cat([tokens.mean(2),tokens.float().std(2,correction=0).to(tokens.dtype)],-1).flatten(1) + summary=self.summary_projection(moments) + ordered=torch.nn.functional.adaptive_avg_pool1d(tokens.permute(0,1,3,2).flatten(1,2),4).flatten(1) + return torch.cat([summary,ordered],-1) + + def named_shared_parameters(self): + for prefix,module in [('backbone',self.backbone),('token_projection',self.token_projection),('summary_projection',self.summary_projection)]: + for name,p in module.named_parameters():yield f'{prefix}.{name}',p diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/tangent_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/tangent_features.py new file mode 100644 index 0000000000000000000000000000000000000000..314f0cf2f58e4b4a1c1d808edbd4acc3b7b6f85b --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S073/tangent_features.py @@ -0,0 +1,25 @@ +"""Window-local log-correlation geometry in the existing spatial-filter basis.""" +import torch + +TANGENT_DIM=10*24*25//2 + +@torch.no_grad() +def extract_tangent_features(covariances,spatial_weight): + old_tf32=torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(covariances.device.type,enabled=False): + w=spatial_weight.float() + w=w/w.norm(dim=-1,keepdim=True).clamp_min(1e-6) + projected=torch.einsum('bfc,nbcd,bgd->nbfg',w,covariances.float(),w) + d=projected.diagonal(dim1=-2,dim2=-1).clamp_min(1e-10).sqrt() + correlation=(projected/(d.unsqueeze(-1)*d.unsqueeze(-2))).clamp(-1,1) + correlation=(correlation+correlation.transpose(-1,-2))/2 + correlation=.95*correlation+.05*torch.eye(24,device=correlation.device) + values,vectors=torch.linalg.eigh(correlation) + logarithm=(vectors*values.clamp_min(1e-6).log().unsqueeze(-2))@vectors.transpose(-1,-2) + i,j=torch.triu_indices(24,24,device=correlation.device) + scale=torch.where(i==j,1.,2.**.5) + return (logarithm[...,i,j]*scale).flatten(1) + finally: + torch.backends.cuda.matmul.allow_tf32=old_tf32 diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/MODEL_CARD.md b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/MODEL_CARD.md new file mode 100644 index 0000000000000000000000000000000000000000..b5cb126e4f5338a8f5357cc148f210a81f695403 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/MODEL_CARD.md @@ -0,0 +1,35 @@ +# Shared EEG decoder + +This package contains one coupled backbone used by all five tracks, with private input adapters and classifiers. Every trainable common component was trained with all five training splits. It is a single model; inference performs no parameter updates or dataset-level fitting. + +The common backbone combines waveform convolutions, an audited pretrained BIOT feature path, covariance and log-correlation encoders, and shared feature corrections. The waveform coactivation extension encodes 64 within-window log variances and 2,016 correlations between common waveform channels. A matched experimental control removes the correlation inputs. `config.json` identifies the packaged variant and its five fixed correction gains. All original backbone parameters are fixed during this extension's joint training. + +Weights originate only from the supplied training data and audited initialization checkpoints. Training details, parent provenance, raw/cache checks, shared-gradient checks and the five separate validation metrics are recorded in `training.json`. Validation selects checkpoints and fixed gains; it does not fit normalization or update parameters. Reported validation results belong to selected checkpoints, not to private test evaluation or five-seed means. + +Run `bash infer.sh INPUT_DIR OUTPUT_DIR`. The input manifest specifies a track and opaque sample IDs, shard paths and indices. Signals are in microvolts and are scaled by 1/100. The package writes one probability vector per input ID to `OUTPUT_DIR/predictions.jsonl`. It needs only the packaged files and the contract's installed Python dependencies, works after relocation, and does not need labels, subject IDs, training caches or network access. + +FACED and TUEV use window balanced accuracy. AD65 uses mean window probabilities per patient before balanced accuracy. OpenBMI averages within-subject balanced accuracy. Longitudinal averages within-session balanced accuracy within each subject, then over subjects. These five metrics remain separate. + +This checkpoint adds fixed within-window ordinal pattern probabilities, permutation entropy and statistical complexity at five delays. Training-only normalization and five input projections feed one common correction MLP trained by all five tracks. The common correction enters the existing covariance and fusion representations; fixed per-track gains select its strength. All earlier model tensors remain unchanged. + +Fixed real and imaginary spectral coherence between the inherited 24 spatial filters is normalized using training windows only and encoded by one new common network. Five private linear heads add class evidence. All five training splits update the new common encoder; all earlier model tensors remain unchanged. + +Fixed per-window relative band powers, envelope variability, envelope correlations and phase-amplitude coupling feed training-normalized private input projections and one new shared encoder. Five linear heads add class evidence. All five training splits update the new common encoder; all prior model tensors remain unchanged. AD65 updates use all windows from six class-balanced training patients; objective: mean-probability. + +The inherited OpenBMI phase-classifier projection was refreshed from a separately validated private-readout fit. Every common tensor and input adapter of this jointly trained model is unchanged. Exact ancestor checks confirm that all common tensors used by this inherited readout are identical; the new cross-frequency correction remains disabled for OpenBMI. No shared checkpoints or predictions are ensembled. + +A common CBraMod feature encoder, itself jointly trained on all five training splits, supplies its shared summary and tokens pooled into four ordered time bins. Its classifiers are discarded. A new common feature MLP and five zero-initialized private linear projections learn residual class evidence jointly on all five training splits. Training may randomly remove the earlier decoder logits for half of training groups, using one mask per AD patient and one per other window; labels and teacher targets remain unchanged. Validation and inference always retain the complete earlier decoder. The same new class projection also receives an auxiliary standalone classification loss when configured, with the same patient-pooled AD objective; this adds no inference module. The complete earlier decoder and feature extractor remain tensor-identical; selecting zero residual gain preserves its predictions exactly. The summary-only control masks the 8192 ordered features after training-fitted per-feature normalization. One feature backbone and one classifier per track run at inference, with no prediction ensemble or external runtime cache. + +The five outer private student-feature class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. + +The longitudinal private outer projection is selected from another training-only readout fit using exactly the same common/input/prior-head tensors. All other private heads are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +The complete stronger parent is retained, including its common CBraMod feature encoder, common readout and all private classifiers. The CBraMod features and existing common128-dimensional embedding are computed once and reused. An additional common128-to256-to128 MLP with the configured GELU or identity activation and five zero-initialized private linear projections learn residual class evidence jointly on all five training splits. Training may randomly remove the earlier decoder logits for half of training groups, using one mask per AD patient and one per other window; labels and teacher targets remain unchanged. Validation and inference always retain the complete earlier decoder. The same new class projection also receives an auxiliary standalone classification loss when configured, with the same patient-pooled AD objective; this adds no inference module. The complete earlier decoder and feature extractor remain tensor-identical; selecting zero residual gain preserves its predictions exactly. One feature backbone and one classifier per track run at inference, with no prediction ensemble or external runtime cache. + +The five outer private student-feature class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. + +The openbmi private outer projection is selected from another training-only readout fit using exactly the same common/input/prior-head tensors. All other private heads are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +A fixed two-second crop supplies spectral and cross-frequency coupling features, with no short-window envelope autocorrelation. The crop is configured as center or first. Each track has a training-fitted normalizer and linear input adapter to128 dimensions; one common128-to256-to128 GELU/LayerNorm block and five zero-initialized class projections are jointly trained on all five training splits. All complete-parent tensors are preserved exactly. Normalization statistics use training windows only. The parent is randomly removed from the training loss at the configured probability; it is always present at inference. AD uses mean patient probabilities over all sampled patient windows. Auxiliary classification uses the same class projection. There is one composed feature backbone and head per track; no prediction ensemble, external runtime cache, test adaptation, or evaluation-metadata features. Zero residual gain exactly retains the complete parent. + +The five outer private center-context class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/alpha_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/alpha_features.py new file mode 100644 index 0000000000000000000000000000000000000000..455154d715e86d45e4e17113bed69adbcd946b29 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/alpha_features.py @@ -0,0 +1,45 @@ +"""Fixed alpha prominence features from each individual two-second window.""" +import torch + +REGION_NAMES=('occipital','parietal','central','frontal','left_posterior','right_posterior') +REGIONS=(('PO7','PO5','PO3','POZ','PO4','PO6','PO8','O1','OZ','O2'), + ('P7','P5','P3','P1','PZ','P2','P4','P6','P8'), + ('FC5','FC3','FC1','FCZ','FC2','FC4','FC6','C5','C3','C1','CZ','C2','C4','C6'), + ('FP1','FPZ','FP2','AF3','AF4','F7','F5','F3','F1','FZ','F2','F4','F6','F8'), + ('P7','P5','P3','P1','PO7','PO5','PO3','O1'), + ('P2','P4','P6','P8','PO4','PO6','PO8','O2')) +ALPHA_DIM=58*7+6*22 + +def region_matrix(channels): + result=torch.zeros(len(REGIONS),len(channels)) + for i,names in enumerate(REGIONS): + for name in names:result[i,channels.index(name)]=1/len(names) + return result.tolist() + +@torch.no_grad() +def extract_alpha_features(signal,regions): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();x=x-x.mean(-1,keepdim=True) + spectrum=torch.fft.rfft(x*torch.hann_window(400,device=x.device),dim=-1)/200 + power=spectrum.abs().square().clamp_min(1e-12) + lp=power.log() + # Geometric regional means resist domination by one high-amplitude channel. + regional=torch.einsum('rc,ncf->nrf',regions.float(),lp) + lp=torch.cat([lp,regional],1) + low=lp[...,8:13].mean(-1,keepdim=True) + high=lp[...,36:49].mean(-1,keepdim=True) + freq=torch.arange(7.,14.5,.5,device=x.device) + alpha=lp[...,14:29] + baseline=low+(high-low)*((freq-5)/16) + prominence=alpha-baseline + normalized=alpha.softmax(-1) + center=(normalized*freq).sum(-1) + entropy=-(normalized*normalized.clamp_min(1e-12).log()).sum(-1) + alpha_mean=torch.logsumexp(alpha,-1)-torch.log(torch.tensor(15.,device=x.device)) + def log_band(lo,hi): + return torch.logsumexp(lp[...,lo:hi],-1)-torch.log(torch.tensor(float(hi-lo),device=x.device)) + summaries=torch.stack([alpha_mean-log_band(2,81),alpha_mean-log_band(8,14), + alpha_mean-log_band(30,61),prominence.max(-1).values, + prominence.mean(-1),center,entropy],-1) + return torch.cat([summaries[:,:58].flatten(1),summaries[:,58:].flatten(1), + prominence[:,58:].flatten(1)],1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/config.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/config.json new file mode 100644 index 0000000000000000000000000000000000000000..262ad75ec7e510696a61a0d2aa9f03836c2b85bc --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/config.json @@ -0,0 +1,912 @@ +{ + "schema": "bci-shared-biot-covariance-bf16head-v1", + "architecture": { + "channels": 32, + "width": 128, + "depth": 2, + "dropout": 0.5, + "wave_filters": 32, + "head_width": 64, + "head_dropout": 0.3, + "clinical_asymmetry": true, + "alpha_regions": [ + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.125 + ] + ], + "clinical_envelope": true, + "temporal_pool": true, + "temporal_evidence": true, + "evidence_temperature": 0.25, + "random_fourier": true, + "fourier_features": 256, + "tangent_readout": true, + "shared_context_correction": true, + "wave_coactivation": true, + "ordinal_context": true, + "phase_coherence": true, + "cross_frequency": true, + "cbramod_feature_transfer": true, + "student_architecture": { + "virtual_channels": 32, + "token_width": 64, + "summary_width": 256, + "head_width": 128, + "dropout": 0.3 + }, + "student_extension": true, + "post_embedding_extension": true, + "extension_activation": "identity", + "center_context_extension": true, + "context_crop": "center" + }, + "initialization": { + "initialization": "continue joint training from a complete shared-model checkpoint", + "parent": "/workspace/research/runs/hybrid_biot_fusionshrink0100/epoch-001/weights.pt", + "parent_initialization": { + "initialization": "jointly trained parent plus audited pretrained BIOT in a single coupled backbone", + "parent": "/workspace/research/runs/hybrid_wide1/epoch-004/weights.pt", + "audited_biot": { + "initialization": "pretrained", + "repo": "braindecode/biot-pretrained-six-datasets-18chs", + "revision": "7e9aabf302870012f73773276803aab97993951c", + "sha256": "a218f4054ae29962c6fd9d23d94c446d354c4f53e805a6771c85749ccc20baaa", + "license": "BSD-3-Clause", + "source_braindecode": "1.3.0", + "loaded_core_tensors": 56, + "skipped_classifier_tensors": 3 + }, + "neural_channel_indices": { + "faced": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "tuev": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15 + ], + "ad65": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "openbmi": [ + 0, + 1, + 3, + 5, + 12, + 14, + 23, + 25, + 28, + 30, + 2, + 6, + 11, + 15, + 22, + 26, + 4, + 13 + ], + "longitudinal": [ + 0, + 2, + 7, + 11, + 23, + 27, + 41, + 45, + 55, + 57, + 5, + 13, + 21, + 29, + 39, + 47, + 9, + 25 + ] + }, + "rebase": "incumbent waveform, fusion and four heads; joint BIOT and TUEV head from readout epoch 9; zero initialized neural interaction", + "jointly_finetuned_neural_parent": "/workspace/research/runs/hybrid_biot_readout1/epoch-009/weights.pt", + "tuev_high_dimensional_spectral_projection_disabled": true, + "frozen_prior_representation": true, + "nonclinical_head_updates": "only the 256 added BIOT columns; original columns and biases fixed", + "faced_openbmi_neural_path": "common nonlinear fusion only; direct head columns masked", + "retention_teacher": "/workspace/research/runs/hybrid_wide1/epoch-004", + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "joint_covariance_parent": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "frozen_prior_representation": true, + "head_updates": "one linear head per track; added 128 shared covariance columns trainable; AD head initialized from the joint covariance parent", + "new_shared_representation": "one common covariance MLP inside the coupled backbone, trained by all five tasks; fixed spatial input adapters from the same jointly trained source", + "head_arithmetic": "one linear head evaluated in fixed feature blocks to preserve original bfloat16 accumulation dimensions", + "retention_teacher": { + "ad65": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "other_tracks": "/workspace/research/runs/hybrid_wide1/epoch-004" + }, + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "loader_scale": 0.01, + "tracks": [ + "faced", + "tuev", + "ad65", + "openbmi", + "longitudinal" + ], + "head_arithmetic": "same linear head in fixed feature blocks, sum in bfloat16 on GPU for non-AD tracks; AD remains float32", + "head_refinement": { + "source": "/workspace/research/runs/residual_heads1/epoch-018", + "source_weights_sha256": "e0b609137391b47f99438ccadaa22fc0bc10d2c10ead0ddf0a3c25be2c907c85", + "shared_backbone_unchanged": true, + "selected_head_epochs": { + "faced": 5, + "tuev": 24, + "ad65": 0, + "openbmi": 0, + "longitudinal": 0 + } + }, + "clinical_spectral_refinement": { + "source": "/workspace/research/runs/head_dropout1/epoch-016", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "head_estimation": { + "method": "class/subject-balanced Gaussian linear discriminant; covariance augmented by class-conditional subject/session mean variation before shrinkage", + "selected_shrinkage": { + "faced": "inherited", + "tuev": "inherited", + "ad65": "inherited", + "openbmi": "inherited", + "longitudinal": { + "shrinkage": 0.9, + "domain_strength": 1.0 + } + }, + "feature_scaling": "fitted on training data and folded into linear coefficients" + }, + "clinical_asymmetry_refinement": { + "source": "/workspace/research/runs/domain_lda_heads1/epoch-001", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "alpha_rhythm_adapter": { + "training_normalization_only": true, + "regions": [ + "occipital", + "parietal", + "central", + "frontal", + "left_posterior", + "right_posterior" + ], + "features": "per-window alpha prominence relative to adjacent frequencies", + "shared_backbone_unchanged": true + }, + "clinical_envelope_refinement": { + "source": "/workspace/research/runs/clinical_asymmetry1/epoch-001", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "independent_adapter_merge": { + "alpha_source": "/workspace/research/runs/alpha_calibrated1/epoch-003", + "clinical_source": "/workspace/research/runs/clinical_envelope1/epoch-002", + "all_shared_and_head_tensors_equal": true + }, + "frequency_montage_refinement": { + "six_frequency_bands": true, + "shared_encoder_unchanged": true, + "selected_track_epochs": { + "faced": 0, + "tuev": 1, + "ad65": 0, + "openbmi": 10, + "longitudinal": 2 + } + }, + "private_track_selection": { + "track": "tuev", + "donor": "/workspace/research/replicates/frequency_head_control1/epoch-001" + }, + "clinical_sampling_refinement": { + "subject_exponent": 0.0, + "class_balanced": true, + "only_clinical_head_updated": true + }, + "temporal_statistics_readout": { + "statistics": [ + "mean", + "standard deviation", + "maximum", + "minimum" + ], + "shared_encoder_and_prior_heads_unchanged": true, + "selected_pool_epochs": { + "faced": 2, + "tuev": 0, + "ad65": 0, + "openbmi": 33, + "longitudinal": 3 + } + }, + "temporal_evidence_readout": { + "pooling": "log mean exp of per-patch class evidence", + "temperature": 0.25, + "shared_encoder_and_prior_heads_unchanged": true, + "selected_evidence_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 6, + "longitudinal": 8 + } + }, + "fourier_basis_readout": { + "basis_functions": 256, + "bandwidths": [ + 0.5, + 1.0, + 2.0 + ], + "shared_encoder_and_prior_heads_unchanged": true, + "selected_fourier_epochs": { + "faced": 21, + "tuev": 0, + "ad65": 0, + "openbmi": 0, + "longitudinal": 2 + } + }, + "shared_tangent_readout": { + "one_shared_tangent_module": true, + "original_and_corrected_shared_features_retained": true, + "private_head_scalar_gains": { + "faced": 0.0, + "tuev": 0.1, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 0.1 + }, + "all_common_weights_fixed_during_gain_refinement": true + }, + "shared_context_correction": { + "source": "/workspace/research/runs/hybrid_codebrain_fusion_control1/epoch-002", + "zero_token_input_preserved": true, + "unused_native_CodeBrain_core_and_input_parameters_removed": true, + "common_patch_and_context_layers_retained": true, + "same_one_shared_backbone_and_five_classifiers": true + }, + "shared_wave_coactivation": { + "channels": 64, + "statistics": 2080, + "diagonal_only_control": false, + "common_encoder_updated_by_all_five_tracks": true, + "gain_selection_within_one_common_checkpoint": { + "faced": 1.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 1.0 + } + }, + "fixed_common_coactivation_readouts": { + "all_common_weights_exactly_unchanged": true, + "selected_private_epochs": { + "faced": 25, + "tuev": 0, + "ad65": 0, + "openbmi": 8, + "longitudinal": 2 + } + }, + "shared_ordinal_context": { + "per_channel_features": 130, + "normalization_fit_on_training_only": true, + "entropy_only_control": false, + "new_common_layers_trained_on_all_five_tracks": true, + "gains_within_one_common_checkpoint": { + "faced": 1.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 0.0 + } + }, + "shared_complex_coherence": { + "features": 5520, + "normalization_fit_on_training_only": true, + "real_only_control": false, + "all_five_tracks_update_common_encoder": true, + "gains_within_one_common_checkpoint": { + "faced": 0.1, + "tuev": 1.0, + "ad65": 0.0, + "openbmi": 0.3, + "longitudinal": 0.0 + } + }, + "shared_cross_frequency": { + "per_channel_features": 30, + "normalization_fit_on_training_only": true, + "amplitude_only_control": false, + "all_five_tracks_update_common_encoder": true, + "gains_within_one_common_checkpoint": { + "faced": 0.3, + "tuev": 0.1, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 0.0 + } + }, + "inherited_private_readout_refresh": { + "child": "/workspace/research/runs/coupling_patient1/epoch-007", + "donor": "/workspace/research/runs/phase_readout1/epoch-016", + "common_ancestor": "/workspace/research/runs/phase_coherence1/epoch-007", + "source_weight_sha256": { + "child": "f8466c6838ff01e54d1619f55668c1a4af26a243b54c67a956a3422d9604632a", + "donor": "ffd219d1480b81720b5aa4014cb2ed2b9cd31b7c92ad4717abc2a9625d30dc1a", + "ancestor": "e53ede409be523d8f4746251f7d46353621049f0378a88d4f7cfe2ba71a57d95" + }, + "changed_private_tensors": [ + "heads.openbmi.prior.projection.weight", + "heads.openbmi.prior.projection.bias" + ], + "all_ancestor_common_and_input_tensors_equal": true, + "all_child_common_and_input_tensors_unchanged": true, + "new_branch_gain_for_refreshed_track": 0.0, + "donor_changes_only_requested_private_projection": true, + "prediction_sources": { + "faced": { + "source": "/workspace/research/runs/coupling_patient1/faced-e007.npy", + "sha256": "68b617c8ecf347c79b23c20b70f6b4981c2f26b7b8c71dc7cd5fa0d7f4285ea6" + }, + "tuev": { + "source": "/workspace/research/runs/coupling_patient1/tuev-e007.npy", + "sha256": "9f0743450f1104d395e9daac0600aaf20755b5590b9f5c3e3137732c479dd647" + }, + "ad65": { + "source": "/workspace/research/runs/coupling_patient1/ad65-e007.npy", + "sha256": "7a3b74c58580b7ba952322bf6d527ebc9a40a6e04c7cdbbaea14e84a7a298d54" + }, + "openbmi": { + "source": "/workspace/research/runs/phase_readout1/openbmi-e016.npy", + "sha256": "14f630543e1df88c88d8f3e0effb4506ba33f533b3484de3c7aaf6554507341c" + }, + "longitudinal": { + "source": "/workspace/research/runs/coupling_patient1/longitudinal-e007.npy", + "sha256": "e93b0a319eaa3ddca9d71b0e786b808ba1630c1d3ce125f8e08036e517741b74" + } + } + }, + "shared_student_residual": { + "dimension": 8448, + "summary_dimension": 256, + "ordered_time_bins": 4, + "student_weights_sha256": "19dfe912cceed997699b5b526c8c2ece55945c5f9bd111c4c13704d0fc460e8b", + "summary_only_control": false, + "normalization_fit_on_training_only": true, + "new_common_readout_jointly_trained_on_all_five": true, + "class_projection_initialized_zero": true, + "student_classifiers_discarded": true, + "gains_within_one_common_checkpoint": { + "faced": 1.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 1.0 + }, + "zero_gain_preserves_complete_parent": true + }, + "private_head_refresh": { + "reference": "/workspace/research/pilots/embedding_private_pilot1/epoch-001", + "donor": "/workspace/research/runs/embedding_private1/epoch-006", + "track": "openbmi", + "source_sha256": { + "reference": "154faf7d58401ce99cd004b7867cda31e93dc3aedbd21bb3fc457cc4b5a66197", + "donor": "1f6dcb1e8b78741dccd32bbb53ceb1cc9bd6295ba6797aae900079575e79ded0" + }, + "changed_private_tensors": [ + "heads.openbmi.correction_gain", + "heads.openbmi.projection.weight", + "heads.openbmi.projection.bias" + ], + "all_common_input_and_prior_head_tensors_exactly_equal": true, + "executable_code_and_architecture_exactly_equal": true, + "one_common_checkpoint": true, + "prediction_sources": { + "faced": "/workspace/research/pilots/embedding_private_pilot1/faced-e001.npy", + "tuev": "/workspace/research/pilots/embedding_private_pilot1/tuev-e001.npy", + "ad65": "/workspace/research/pilots/embedding_private_pilot1/ad65-e001.npy", + "openbmi": "/workspace/research/runs/embedding_private1/openbmi-e006.npy", + "longitudinal": "/workspace/research/pilots/embedding_private_pilot1/longitudinal-e001.npy" + } + }, + "shared_student_extension_residual": { + "dimension": 128, + "input_representation": "fixed jointly trained common student embedding", + "activation": "identity", + "student_weights_sha256": "19dfe912cceed997699b5b526c8c2ece55945c5f9bd111c4c13704d0fc460e8b", + "summary_only_control": false, + "normalization_fit_on_training_only": true, + "new_common_readout_jointly_trained_on_all_five": true, + "class_projection_initialized_zero": true, + "student_classifiers_discarded": true, + "gains_within_one_common_checkpoint": { + "faced": 0.30000001192092896, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 0.30000001192092896, + "longitudinal": 0.30000001192092896 + }, + "zero_gain_preserves_complete_parent": true + }, + "fixed_common_embedding_readouts": { + "all_common_weights_exactly_unchanged": true, + "selected_private_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 0, + "longitudinal": 1 + } + }, + "shared_center_context_residual": { + "dimension": 128, + "crop": "center", + "samples": 400, + "sample_rate": 200, + "feature_types": [ + "spectral", + "cross_frequency_coupling" + ], + "normalization_fit_on_training_only": true, + "new_common_block_jointly_trained_on_all_five": true, + "class_projection_initialized_zero": true, + "gains_within_one_common_checkpoint": { + "faced": 1.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 1.0 + }, + "zero_gain_preserves_complete_parent": true + }, + "fixed_common_center_context_readouts": { + "all_common_weights_exactly_unchanged": true, + "selected_private_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 0, + "longitudinal": 1 + } + } +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/coupling_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/coupling_features.py new file mode 100644 index 0000000000000000000000000000000000000000..3a4e51bd7ce07bcec1f0f5b80054d6ff387ac87f --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/coupling_features.py @@ -0,0 +1,34 @@ +"""Per-window cross-frequency envelope and phase-amplitude relationships.""" +import torch +BANDS=((1,4),(4,8),(8,13),(13,30),(30,48)) +PAIRS=tuple((i,j) for i in range(5) for j in range(i+1,5)) +PER_CHANNEL=30 + +@torch.no_grad() +def coupling_features(track,x): + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + n=x.shape[-1];spectrum=torch.fft.fft(x,dim=-1);frequency=torch.fft.fftfreq(n,1/200,device=x.device) + masks=torch.stack([2*((frequency>=lo)&(frequency=lo)&(frequency2).float().mean(-1),(relative>4).float().mean(-1), + ((relative[...,1:]>2)&(relative[...,:-1]<=2)).float().mean(-1), + acf_peak,(acf_index.float()+4)/40, + acf[...,0],acf[...,6],acf[...,16],acf[...,36]] + left=torch.tensor([0,1,2,3,8,9,10,11],device=x.device);right=left+4 + synchrony=(normalized[:,left]*normalized[:,right]).mean(-1).clamp(-1,1) + imbalance=(std[:,left].squeeze(-1).log()-std[:,right].squeeze(-1).log()).abs() + return torch.cat([torch.stack(summaries,-1).flatten(1),synchrony.flatten(1),imbalance.flatten(1)],1) + +def mirrored_features(features): + channels=torch.tensor([4,5,6,7,0,1,2,3,12,13,14,15,8,9,10,11],device=features.device) + return torch.cat([features[:,:16*5*12].reshape(-1,16,5,12)[:,channels].flatten(1),features[:,16*5*12:]],1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/features.py new file mode 100644 index 0000000000000000000000000000000000000000..88f7e8b14c9fab44733d5224ede6d6b5c7f76a45 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/features.py @@ -0,0 +1,63 @@ +"""One shared residual backbone, five linear input adapters and output heads.""" +import torch +from torch import nn + +SPECS = {'faced': (32, 10, 9), 'tuev': (16, 5, 6), 'ad65': (19, 10, 3), + 'openbmi': (62, 4, 2), 'longitudinal': (58, 2, 2)} +TRACKS = tuple(SPECS) +EDGES = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,18,20,22,25,28,32,36,40,45,50,60,70,80,95] +COV_BANDS = [(1,4),(4,8),(8,12),(12,16),(16,20),(20,28),(28,40)] + +def feature_dim(channels): + return channels * (4*(len(EDGES)-1)+4) + len(COV_BANDS)*channels*(channels-1)//2 + +@torch.no_grad() +def extract_features(track, x): + """Fixed features; no batch statistics or fitted inference transformations.""" + x = x.float().flatten(2) + x = torch.nan_to_num(x, nan=0., posinf=1e5, neginf=-1e5).clamp(-1e5,1e5) + x = x - x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'): + x = x - x.mean(1,keepdim=True) + rms = x.square().mean(-1).clamp_min(1e-12).sqrt() + norm = x / rms.unsqueeze(-1) + moments = torch.stack([rms.log(), norm.abs().amax(-1).clamp_min(1).log(), + norm.pow(4).mean(-1).clamp_min(1).log(), + (norm[...,1:]-norm[...,:-1]).square().mean(-1).clamp_min(1e-10).log()],-1) + frames = x.unfold(-1,400,200) + frames = frames - frames.mean(-1,keepdim=True) + window = torch.hann_window(400,device=x.device) + z = torch.fft.rfft(frames*window,dim=-1)/200 + power = z.abs().square() + bands = torch.stack([power[...,2*lo:2*hi].mean(-1) for lo,hi in zip(EDGES[:-1],EDGES[1:])],-1) + lp = bands.mean(-2).clamp_min(1e-12).log() + variation = bands.clamp_min(1e-12).log().std(-2,correction=0) + relative_frequency = lp - lp.mean(-1,keepdim=True) + relative_channel = lp - lp.mean(1,keepdim=True) + parts = [torch.cat([lp, relative_frequency, relative_channel, variation, moments],-1).flatten(1)] + ii,jj = torch.triu_indices(x.shape[1],x.shape[1],offset=1,device=x.device) + for lo,hi in COV_BANDS: + v = z[...,2*lo:2*hi].flatten(2) + cov = v.real @ v.real.transpose(-1,-2) + v.imag @ v.imag.transpose(-1,-2) + d = cov.diagonal(dim1=-2,dim2=-1).clamp_min(1e-12).sqrt() + cor = cov / (d.unsqueeze(1)*d.unsqueeze(2)).clamp_min(1e-12) + parts.append(cor[:,ii,jj].clamp(-1,1)) + result = torch.cat(parts,-1) + return torch.nan_to_num(result).clamp(-40,40) + +class Standardize(nn.Module): + def __init__(self, dim): + super().__init__() + self.register_buffer('mean',torch.zeros(dim)) + self.register_buffer('scale',torch.ones(dim)) + def forward(self,x): + return ((x-self.mean)/self.scale).clamp(-8,8) + +class Residual(nn.Module): + def __init__(self,width,dropout): + super().__init__() + self.net=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(), + nn.Dropout(dropout),nn.Linear(width*2,width),nn.Dropout(dropout)) + def forward(self,x): + return x+self.net(x) + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/frequency_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/frequency_features.py new file mode 100644 index 0000000000000000000000000000000000000000..9194c9e81f801b3833e551e4967991774fa9e398 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/frequency_features.py @@ -0,0 +1,11 @@ +"""Fixed per-window frequency decomposition for a linear montage adapter.""" +import torch + +FREQUENCY_BANDS=((1,4),(4,8),(8,13),(13,20),(20,30),(30,45)) + +def frequency_components(signal): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();spectrum=torch.fft.rfft(x,dim=-1) + frequency=torch.fft.rfftfreq(x.shape[-1],d=1/200,device=x.device) + masks=torch.stack([((frequency>=lo)&(frequencynbf',w,covariances.float(),w).clamp_min(1e-8).log() + return torch.cat([power,power-power.mean(1,keepdim=True)],1).flatten(1) + def wave_signal(self,x,components=None): + if components is None:components=frequency_components(x) + correction=torch.einsum('blc,nbct->nlt',self.frequency_weight,components.to(self.frequency_weight.dtype)) + return (self.signal(x)+correction.to(x.dtype)).unsqueeze(1) + def forward(self,x,features,covariance_features): + return self.wave_signal(x),self.spectral_features(features,signal=x),self.neural(x),covariance_features + +class SharedBackbone(nn.Module): + def __init__(self,channels,width,depth,dropout,wave_filters): + super().__init__() + self.waveform=nn.Sequential( + nn.Conv2d(1,wave_filters,(1,64),padding=(0,32),bias=False),nn.GroupNorm(1,wave_filters), + nn.Conv2d(wave_filters,2*wave_filters,(channels,1),groups=wave_filters,bias=False),nn.GroupNorm(1,2*wave_filters),nn.ELU(), + nn.AvgPool2d((1,4)),nn.Dropout(.35), + nn.Conv2d(2*wave_filters,2*wave_filters,(1,16),padding=(0,8),groups=2*wave_filters,bias=False),nn.Conv2d(2*wave_filters,2*wave_filters,1,bias=False), + nn.GroupNorm(1,2*wave_filters),nn.ELU(),nn.AvgPool2d((1,8)),nn.Dropout(.35)) + self.wave_summary=nn.Sequential(nn.AdaptiveAvgPool2d((1,8)),nn.Flatten(),nn.Linear(2*wave_filters*8,width)) + self.fusion=nn.Sequential(nn.LayerNorm(width),nn.GELU(),nn.Dropout(dropout), + *[Residual(width,dropout) for _ in range(depth)],nn.LayerNorm(width)) + # Both representations interact before the shared residual stack. + self.phase_encoder=nn.Sequential(nn.LayerNorm(PHASE_DIM),nn.Linear(PHASE_DIM,width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width)) + self.register_buffer('phase_imaginary_enabled',torch.ones(())) + self.coupling_encoder=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width),nn.LayerNorm(width)) + self.wave_gain=nn.Parameter(torch.tensor(.1)) + self.biot=BIOT(n_chans=18,n_outputs=2,n_times=400,sfreq=200) + self.biot.final_layer=nn.Identity() + self.biot_projection=nn.Sequential(nn.LayerNorm(256),nn.Linear(256,width),nn.Dropout(.2)) + nn.init.normal_(self.biot_projection[1].weight,std=.001);nn.init.zeros_(self.biot_projection[1].bias) + self.covariance_encoder=nn.Sequential(nn.LayerNorm(len(BANDS)*24*2),nn.Linear(len(BANDS)*24*2,width),nn.GELU(),nn.Dropout(.4), + *[Residual(width,.4) for _ in range(2)],nn.LayerNorm(width)) + self.covariance_projection=nn.Linear(width,width) + nn.init.zeros_(self.covariance_projection.weight);nn.init.zeros_(self.covariance_projection.bias) + self.tangent_encoder=nn.Sequential(nn.LayerNorm(TANGENT_DIM),nn.Linear(TANGENT_DIM,width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width),nn.Linear(width,width)) + self.ordinal_context=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width)) + nn.init.zeros_(self.ordinal_context[-1].weight);nn.init.zeros_(self.ordinal_context[-1].bias) + self.register_buffer('codebrain_enabled',torch.ones(())) + self.codebrain_patch_encoder=nn.Sequential(nn.LayerNorm(24*64),nn.Linear(24*64,width),nn.GELU(),nn.Dropout(.3)) + self.codebrain_context=nn.Sequential(nn.LayerNorm(width*4),nn.Linear(width*4,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width)) + nn.init.zeros_(self.codebrain_context[-1].weight);nn.init.zeros_(self.codebrain_context[-1].bias) + def codebrain_correction(self,tokens,representation,fusion_input): + with torch.autocast(tokens.device.type,enabled=False): + encoded=self.codebrain_patch_encoder(self.codebrain_enabled*tokens.float()) + pooled=torch.cat([encoded.mean(1),encoded.std(1,correction=0),representation[:,-512:-384].float(),representation[:,-128:].float()],-1) + delta=self.codebrain_context(pooled) + added=.001*nn.functional.linear(delta,self.covariance_projection.weight,None) + corrected=self.fusion(fusion_input+added.to(fusion_input.dtype)) + return corrected-representation[:,-512:-384],delta + def forward(self,signal,spectral,neural_signal,covariance_features,tangent_features): + wave=self.waveform(signal) + neural=self.biot(neural_signal.float()) + neural=self.biot_projection[0](neural) + projected=self.biot_projection[2](self.biot_projection[1](neural)) + with torch.autocast(signal.device.type,enabled=False): + covariance_embedding=self.covariance_encoder(covariance_features.float()) + original=spectral+self.wave_gain*self.wave_summary(wave)+.01*projected + coupled=.001*self.covariance_projection(covariance_embedding).to(original.dtype) + fused=self.fusion(original+coupled) + with torch.autocast(signal.device.type,enabled=False):delta=self.tangent_encoder(tangent_features.float()) + added=.001*nn.functional.linear(delta,self.covariance_projection.weight,None) + corrected=self.fusion((original+coupled)+added.to(original.dtype)) + return torch.cat([wave.flatten(1),fused,neural,covariance_embedding],-1),corrected-fused,delta,original+coupled + +class ResidualHead(nn.Module): + """A small nonlinear classifier correction around an inherited linear readout.""" + def __init__(self,features,classes,width=64,dropout=.3,full_precision=False): + super().__init__();self.full_precision=full_precision + self.base=nn.Linear(features,classes) + self.delta=nn.Sequential(nn.LayerNorm(features),nn.Linear(features,width),nn.GELU(),nn.Dropout(dropout),nn.Linear(width,classes)) + nn.init.zeros_(self.delta[-1].weight);nn.init.zeros_(self.delta[-1].bias) + def forward(self,x): + if self.full_precision: + with torch.autocast(x.device.type,enabled=False):return self.base(x.float())+self.delta(x.float()) + prior=nn.functional.linear(x[:,:-128].contiguous(),self.base.weight[:,:-128].contiguous(),self.base.bias) + added=nn.functional.linear(x[:,-128:].contiguous(),self.base.weight[:,-128:].contiguous()) + value=prior+added + return value+self.delta(x).to(value.dtype) + +class TemporalPoolHead(nn.Module): + def __init__(self,prior,channels=64): + super().__init__();self.prior=prior;self.channels=channels + self.register_buffer('pool_output_scale',torch.ones(()));self.register_buffer('pool_mean',torch.zeros(channels*4));self.register_buffer('pool_scale',torch.ones(channels*4)) + self.pool_projection=nn.Linear(channels*4,prior.base.out_features) + nn.init.zeros_(self.pool_projection.weight);nn.init.zeros_(self.pool_projection.bias) + def statistics(self,x): + with torch.autocast(x.device.type,enabled=False): + wave=x[:,:-512].float().reshape(len(x),self.channels,-1) + return torch.cat([wave.mean(-1),wave.std(-1,correction=0),wave.amax(-1),wave.amin(-1)],-1) + def forward(self,x): + prior=self.prior(x) + with torch.autocast(x.device.type,enabled=False): + values=((self.statistics(x)-self.pool_mean)/self.pool_scale).clamp(-8,8) + added=self.pool_output_scale*self.pool_projection(values) + return prior+added.to(prior.dtype) + +class TemporalEvidenceHead(nn.Module): + """Pool class evidence over the shared waveform time axis.""" + def __init__(self,prior,channels=64,temperature=.25): + super().__init__();self.prior=prior;self.channels=channels;self.temperature=temperature + self.register_buffer('evidence_output_scale',torch.ones(())) + self.register_buffer('evidence_mean',torch.zeros(channels)) + self.register_buffer('evidence_scale',torch.ones(channels)) + self.evidence_projection=nn.Linear(channels,prior.prior.base.out_features,bias=False) + nn.init.zeros_(self.evidence_projection.weight) + def patches(self,x): + with torch.autocast(x.device.type,enabled=False): + wave=x[:,:-512].float().reshape(len(x),self.channels,-1).transpose(1,2) + return ((wave-self.evidence_mean)/self.evidence_scale).clamp(-8,8) + def evidence(self,patches): + with torch.autocast(patches.device.type,enabled=False): + values=self.evidence_projection(patches.float())/self.temperature + maximum=values.amax(1,keepdim=True) + pooled=self.temperature*((values-maximum).exp().mean(1).log()+maximum.squeeze(1)) + return self.evidence_output_scale*pooled + def forward(self,x): + prior=self.prior(x) + return prior+self.evidence(self.patches(x)).to(prior.dtype) + +class FourierResidualHead(nn.Module): + """A fixed random Fourier basis and trainable linear classifier correction.""" + def __init__(self,prior,features,classes,basis=256): + super().__init__();self.prior=prior + self.register_buffer('rff_mean',torch.zeros(features));self.register_buffer('rff_scale',torch.ones(features)) + self.register_buffer('rff_frequency',torch.randn(features,basis)/features**.5) + self.register_buffer('rff_phase',torch.rand(basis)*2*torch.pi) + self.register_buffer('rff_output_scale',torch.ones(())) + self.rff_projection=nn.Linear(3*basis,classes);nn.init.zeros_(self.rff_projection.weight);nn.init.zeros_(self.rff_projection.bias) + def basis(self,x): + with torch.autocast(x.device.type,enabled=False): + values=((x.float()-self.rff_mean)/self.rff_scale).clamp(-8,8)@self.rff_frequency + return 2**.5*torch.cat([(values/sigma+self.rff_phase).cos() for sigma in (.5,1.,2.)],-1) + def forward(self,x): + prior=self.prior(x) + with torch.autocast(x.device.type,enabled=False):added=self.rff_output_scale*self.rff_projection(self.basis(x)) + return prior+added.to(prior.dtype) + +class TangentFeatureHead(nn.Module): + """Select a shared feature correction before the inherited classifier.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.feature_gain=nn.Parameter(torch.zeros(())) + def forward(self,values): + old=values[:,:-256];fusion_delta=values[:,-256:-128];covariance_delta=values[:,-128:] + adjusted=torch.cat([old[:,:-512],old[:,-512:-384]+self.feature_gain*fusion_delta,old[:,-384:-128],old[:,-128:]+self.feature_gain*covariance_delta],-1) + return self.prior(adjusted) + +class CodeBrainFeatureHead(nn.Module): + """Private use of a jointly trained common feature correction.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.codebrain_gain=nn.Parameter(torch.ones(())) + def forward(self,values): + previous=values[:,:-256];native=previous[:,:-256] + fusion_delta=values[:,-256:-128];covariance_delta=values[:,-128:] + adjusted=torch.cat([native[:,:-512],native[:,-512:-384]+self.codebrain_gain*fusion_delta,native[:,-384:-128],native[:,-128:]+self.codebrain_gain*covariance_delta],-1) + return self.prior(torch.cat([adjusted,previous[:,-256:]],-1)) + +class WaveCoactivationContext(nn.Module): + """One common encoder of coactivation among the learned waveform channels.""" + def __init__(self,channels=64,width=128): + super().__init__();self.channels=channels + ii,jj=torch.triu_indices(channels,channels,offset=1) + self.register_buffer('pair_i',ii);self.register_buffer('pair_j',jj) + self.register_buffer('offdiagonal_enabled',torch.ones(())) + self.encoder=nn.Sequential(nn.LayerNorm(channels+len(ii)),nn.Linear(channels+len(ii),width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width)) + def statistics(self,native): + with torch.autocast(native.device.type,enabled=False): + wave=native[:,:-512].float().reshape(len(native),self.channels,-1) + centered=wave-wave.mean(-1,keepdim=True) + previous_tf32=torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32=False + covariance=centered@centered.transpose(-1,-2)/wave.shape[-1] + torch.backends.cuda.matmul.allow_tf32=previous_tf32 + variance=covariance.diagonal(dim1=-2,dim2=-1).clamp_min(1e-8) + correlation=covariance/(variance.sqrt()[:,:,None]*variance.sqrt()[:,None,:]) + return torch.cat([variance.log(),correlation[:,self.pair_i,self.pair_j].clamp(-1,1)],-1) + def encode_statistics(self,values): + with torch.autocast(values.device.type,enabled=False): + value=torch.cat([values[:,:self.channels],self.offdiagonal_enabled*values[:,self.channels:]],-1) + return self.encoder(value.float()) + def forward(self,native):return self.encode_statistics(self.statistics(native)) + +class WaveCoactivationHead(nn.Module): + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=self.correction_gain*self.output_scale*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class OrdinalFeatureHead(nn.Module): + """Private strength of one common ordinal-dynamics feature correction.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.ordinal_gain=nn.Parameter(torch.ones(())) + def forward(self,values): + previous=values[:,:-256];native=previous[:,:-640] + adjusted=torch.cat([native[:,:-512],native[:,-512:-384]+self.ordinal_gain*values[:,-256:-128],native[:,-384:-128],native[:,-128:]+self.ordinal_gain*values[:,-128:],previous[:,-640:]],-1) + return self.prior(adjusted) + +class PhaseReadoutHead(nn.Module): + """Private class evidence from the common complex-coherence encoder.""" + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=(self.correction_gain*self.output_scale)*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class CouplingReadoutHead(nn.Module): + """Private class evidence from the common cross-frequency coupling encoder.""" + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=(self.correction_gain*self.output_scale)*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class HybridModel(nn.Module): + def __init__(self,channels=32,width=128,depth=2,dropout=.5,wave_filters=32,head_width=64,head_dropout=.3,clinical_asymmetry=True,alpha_regions=None,clinical_envelope=False,temporal_pool=True,temporal_evidence=False,evidence_temperature=.25,random_fourier=False,fourier_features=256,tangent_readout=True,shared_context_correction=True,wave_coactivation=True,ordinal_context=True,phase_coherence=True,cross_frequency=True,cbramod_feature_transfer=True,student_architecture=None,student_extension=True,post_embedding_extension=True,extension_activation='gelu',center_context_extension=True,context_crop='center'): + super().__init__() + self.adapters=nn.ModuleDict({t:InputAdapter(c,width,channels,spectral_enabled=t not in ("faced","tuev","openbmi"),asymmetry=clinical_asymmetry and t=="tuev",alpha_regions=alpha_regions if t=="longitudinal" else None,envelope=clinical_envelope and t=="tuev") for t,(c,s,k) in SPECS.items()}) + self.backbone=SharedBackbone(channels,width,depth,dropout,wave_filters) + self.backbone.student_encoder=CBraModFeatures(**(student_architecture or {})) + self.backbone.register_buffer('student_ordered_enabled',torch.ones(())) + self.backbone.student_readout=nn.Sequential(nn.Linear(self.backbone.student_encoder.output_dim,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + for t,(c,s,k) in SPECS.items(): + self.adapters[t].student_input=FrequencyAdapter(c,32) + self.adapters[t].student_normalizer=Standardize(self.backbone.student_encoder.output_dim) + self.backbone.wave_coactivation=WaveCoactivationContext(2*wave_filters,width) + self.heads=nn.ModuleDict({t:ResidualHead(2*wave_filters*(((s*200+1)//4+1)//8)+width+256+width,k,head_width,head_dropout,full_precision=t=='ad65') for t,(c,s,k) in SPECS.items()}) + if temporal_pool:self.heads=nn.ModuleDict({t:TemporalPoolHead(head,wave_filters*2) for t,head in self.heads.items()}) + if temporal_evidence:self.heads=nn.ModuleDict({t:TemporalEvidenceHead(head,wave_filters*2,evidence_temperature) for t,head in self.heads.items()}) + if random_fourier:self.heads=nn.ModuleDict({t:FourierResidualHead(head,2*wave_filters*(((SPECS[t][1]*200+1)//4+1)//8)+width+256+width,SPECS[t][2],fourier_features) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:TangentFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CodeBrainFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:WaveCoactivationHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:OrdinalFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:PhaseReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert student_extension and post_embedding_extension + assert extension_activation in ('gelu','identity') + self.backbone.student_extension=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU() if extension_activation=='gelu' else nn.Identity(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert center_context_extension and context_crop in ('center','first') + self.context_crop=context_crop + for t,(c,s,k) in SPECS.items(): + self.adapters[t].center_normalizer=Standardize(feature_dim(c)+30*c) + self.adapters[t].center_projection=nn.Linear(feature_dim(c)+30*c,width) + self.backbone.center_encoder=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + def center_features(self,t,x): + raw=x.flatten(2);start=(raw.shape[-1]-400)//2 if self.context_crop=='center' else 0 + cropped=raw[...,start:start+400];assert cropped.shape[-1]==400 + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(raw.device.type,enabled=False):return torch.cat([extract_features(t,cropped),coupling_features(t,cropped)],-1) + finally:torch.backends.cuda.matmul.allow_tf32=old + def center_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].center_normalizer(values.float()) + return self.backbone.center_encoder(self.adapters[t].center_projection(normalized)) + def student_extension_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + assert values.shape[-1]==128 + return self.backbone.student_extension(values.float()) + + def student_features(self,t,x): + outputs=[];old_fastpath=torch.backends.mha.get_fastpath_enabled();torch.backends.mha.set_fastpath_enabled(False) + try: + for raw in x.split(16): + signal=torch.nan_to_num(raw.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + with torch.autocast(signal.device.type,dtype=torch.bfloat16,enabled=signal.device.type=='cuda'): + outputs.append(self.backbone.student_encoder(self.adapters[t].student_input(signal))) + finally:torch.backends.mha.set_fastpath_enabled(old_fastpath) + return torch.cat(outputs).float() + def student_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].student_normalizer(values.float()) + normalized=torch.cat([normalized[:,:256],self.backbone.student_ordered_enabled*normalized[:,256:]],-1) + return self.backbone.student_readout(normalized) + def coupling_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False):return self.backbone.coupling_encoder(self.adapters[t].coupling_embedding(values.float())) + def phase_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].phase_normalizer(values.float()) + normalized=torch.cat([normalized[:,:PHASE_HALF],self.backbone.phase_imaginary_enabled*normalized[:,PHASE_HALF:]],-1) + return self.backbone.phase_encoder(normalized) + def forward(self,t,x,features=None,covariances=None,covariance_features=None): + if features is None:features=extract_features(t,x) + if covariance_features is None: + if covariances is None:covariances=extract_covariances(t,x) + covariance_features=self.adapters[t].spatial_features(covariances) + signal=x.flatten(2);signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + adapted=self.adapters[t](signal,features,covariance_features) + if covariances is None:covariances=extract_covariances(t,x) + tangent=extract_tangent_features(covariances,self.adapters[t].spatial_weight) + representation,fusion_delta,covariance_delta,fusion_input=self.backbone(*adapted,tangent_features=tangent) + if t in ('faced','openbmi'): + representation=torch.cat([representation[:,:-384],torch.zeros_like(representation[:,-384:-128]),representation[:,-128:]],-1) + tokens=torch.zeros(len(signal),signal.shape[-1]//200,24*64,device=signal.device,dtype=torch.bfloat16) + code_fusion,code_covariance=self.backbone.codebrain_correction(tokens,representation,fusion_input) + coactivation=self.backbone.wave_coactivation(representation) + with torch.autocast(signal.device.type,enabled=False): + ordinal=self.adapters[t].ordinal_embedding(ordinal_features(t,x)) + ordinal_covariance=self.backbone.ordinal_context(ordinal.float()) + added=.001*nn.functional.linear(ordinal_covariance,self.backbone.covariance_projection.weight,None) + ordinal_fusion=self.backbone.fusion(fusion_input+added.to(fusion_input.dtype))-representation[:,-512:-384] + phase=self.phase_embedding(t,phase_features(t,x,self.adapters[t].spatial_weight)) + coupling=self.coupling_embedding(t,coupling_features(t,x)) + student_values=self.student_features(t,x) + student=self.student_embedding(t,student_values) + extension=self.student_extension_embedding(t,student) + return self.heads[t](torch.cat([representation,fusion_delta,covariance_delta,code_fusion,code_covariance,coactivation,ordinal_fusion,ordinal_covariance,phase,coupling,student,extension,self.center_embedding(t,self.center_features(t,x))],-1)) + +def widen_state_dict(state,multiplier=2): + """Duplicate temporal features and divide downstream sums to preserve outputs.""" + result={} + for key,value in state.items(): + if key.startswith('backbone.waveform.'): + layer=int(key.split('.')[2]) + if layer in (0,2,7):value=value.repeat(multiplier,1,1,1) + elif layer in (1,3,9):value=value.repeat(multiplier) + elif layer==8:value=value.repeat(multiplier,multiplier,1,1)/multiplier + elif key=='backbone.wave_summary.2.weight':value=value.repeat(1,multiplier)/multiplier + elif key.startswith('heads.') and key.endswith('.weight'): + raw=value[:,:-128]/multiplier + value=torch.cat([raw]*multiplier+[value[:,-128:]],1) + result[key]=value + return result + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/ordinal_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/ordinal_features.py new file mode 100644 index 0000000000000000000000000000000000000000..6e3d5ff8264253f058f71b04d9cc8454196592b1 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/ordinal_features.py @@ -0,0 +1,25 @@ +"""Fixed within-window ordinal dynamics, independent of amplitude scaling.""" +import math +import torch +LAGS=(1,2,4,8,16) +PATTERNS=24 +PER_CHANNEL=len(LAGS)*(PATTERNS+2) + +def ordinal_features(track,x): + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + parts=[];uniform=1/PATTERNS;maximum_entropy=math.log(PATTERNS);m0=(1+uniform)/2;mr=uniform/2;maximum_js=-m0*math.log(m0)-(PATTERNS-1)*mr*math.log(mr)-maximum_entropy/2 + for lag in LAGS: + length=x.shape[-1]-3*lag + if length<=0:raise ValueError('window too short for ordinal dynamics') + samples=torch.stack([x[...,i*lag:i*lag+length] for i in range(4)],-1) + order=samples.argsort(dim=-1,stable=True) + code=6*((order[...,0,None]>order[...,1:]).sum(-1))+2*((order[...,1,None]>order[...,2:]).sum(-1))+(order[...,2]>order[...,3]).long() + histogram=torch.zeros(*x.shape[:2],PATTERNS,device=x.device,dtype=torch.float32) + histogram.scatter_add_(-1,code,torch.ones_like(code,dtype=torch.float32));probability=histogram/length + entropy=-(probability*probability.clamp_min(1e-12).log()).sum(-1) + mixture=(probability+uniform)/2;mixture_entropy=-(mixture*mixture.log()).sum(-1) + complexity=((mixture_entropy-.5*entropy-.5*maximum_entropy)/maximum_js).clamp(0,1)*(entropy/maximum_entropy) + parts.append(torch.cat([probability,(entropy/maximum_entropy)[...,None],complexity[...,None]],-1)) + return torch.cat(parts,-1).flatten(1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/phase_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/phase_features.py new file mode 100644 index 0000000000000000000000000000000000000000..8d98822995bf37b499795dfd7e2e401040a01969 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/phase_features.py @@ -0,0 +1,37 @@ +"""Complex spectral coherence of the existing 24 spatial filters in ten bands.""" +import torch +from covariances import BANDS +CHANNELS=24 +PHASE_HALF=len(BANDS)*CHANNELS*(CHANNELS-1)//2 +PHASE_DIM=2*PHASE_HALF + +@torch.no_grad() +def phase_features(track,x,spatial_weight): + previous_tf32=torch.backends.cuda.matmul.allow_tf32 + try: + torch.backends.cuda.matmul.allow_tf32=False + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if track in ('faced','tuev'):x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + else:x=x-x.mean(1,keepdim=True) + x=x/x.square().mean((1,2),keepdim=True).clamp_min(1e-12).sqrt() + frames=x.unfold(-1,400,200);frames=frames-frames.mean(-1,keepdim=True) + z=torch.fft.rfft(frames*torch.hann_window(400,device=x.device),dim=-1)/200 + w=spatial_weight.float()/spatial_weight.float().norm(dim=-1,keepdim=True).clamp_min(1e-6) + index=torch.triu_indices(CHANNELS,CHANNELS,1,device=x.device) + real_parts=[];imaginary_parts=[] + for band,(lo,hi) in enumerate(BANDS): + v=z[...,2*lo:2*hi].flatten(2) + vr=w[band][None]@v.real;vi=w[band][None]@v.imag + real=(vr@vr.transpose(-1,-2)+vi@vi.transpose(-1,-2))/v.shape[-1] + imaginary=(vi@vr.transpose(-1,-2)-vr@vi.transpose(-1,-2))/v.shape[-1] + # Signals have unit global RMS; this floor suppresses phase of numerical silence. + power=real.diagonal(dim1=-2,dim2=-1).clamp_min(1e-6) + denominator=(power[:,:,None]*power[:,None,:]).sqrt().clamp_min(1e-12) + real=(real/denominator).clamp(-.999,.999) + imaginary=(imaginary/denominator).clamp(-.999,.999) + real_parts.append(torch.atanh(real[:,index[0],index[1]])) + imaginary_parts.append(torch.atanh(imaginary[:,index[0],index[1]])) + return torch.cat(real_parts+imaginary_parts,-1) + finally:torch.backends.cuda.matmul.allow_tf32=previous_tf32 diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/student_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/student_features.py new file mode 100644 index 0000000000000000000000000000000000000000..57401f6d2ab760cb1a58af564aef2e62290e8907 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/student_features.py @@ -0,0 +1,34 @@ +"""One audited CBraMod core with full-window shared and ordered representations.""" +import torch +from torch import nn +from braindecode.models import CBraMod +from frequency_features import frequency_components,FREQUENCY_BANDS +SPECS={'faced':(32,10,9),'tuev':(16,5,6),'ad65':(19,10,3),'openbmi':(62,4,2),'longitudinal':(58,2,2)} +TRACKS=tuple(SPECS) + +class FrequencyAdapter(nn.Module): + def __init__(self,channels,virtual_channels=32): + super().__init__();self.signal=nn.Conv1d(channels,virtual_channels,1,bias=False) + self.frequency_weight=nn.Parameter(torch.zeros(len(FREQUENCY_BANDS),virtual_channels,channels)) + def forward(self,x): + components=frequency_components(x) + correction=torch.einsum('blc,nbct->nlt',self.frequency_weight,components.to(self.frequency_weight.dtype)) + return self.signal(x)+correction.to(x.dtype) + +class CBraModFeatures(nn.Module): + def __init__(self,virtual_channels=32,token_width=64,summary_width=256,head_width=128,dropout=.3): + super().__init__();self.virtual_channels=virtual_channels;self.output_dim=summary_width+virtual_channels*token_width*4 + self.backbone=CBraMod(n_chans=virtual_channels,n_outputs=2,n_times=400,sfreq=200) + self.backbone.final_layer=nn.Identity() + self.token_projection=nn.Sequential(nn.LayerNorm(200),nn.Linear(200,token_width),nn.GELU()) + self.summary_projection=nn.Sequential(nn.LayerNorm(virtual_channels*token_width*2),nn.Linear(virtual_channels*token_width*2,summary_width),nn.GELU(),nn.Dropout(dropout)) + def forward(self,signal): + tokens=self.token_projection(self.backbone(signal)) + moments=torch.cat([tokens.mean(2),tokens.float().std(2,correction=0).to(tokens.dtype)],-1).flatten(1) + summary=self.summary_projection(moments) + ordered=torch.nn.functional.adaptive_avg_pool1d(tokens.permute(0,1,3,2).flatten(1,2),4).flatten(1) + return torch.cat([summary,ordered],-1) + + def named_shared_parameters(self): + for prefix,module in [('backbone',self.backbone),('token_projection',self.token_projection),('summary_projection',self.summary_projection)]: + for name,p in module.named_parameters():yield f'{prefix}.{name}',p diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/tangent_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/tangent_features.py new file mode 100644 index 0000000000000000000000000000000000000000..314f0cf2f58e4b4a1c1d808edbd4acc3b7b6f85b --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S080/tangent_features.py @@ -0,0 +1,25 @@ +"""Window-local log-correlation geometry in the existing spatial-filter basis.""" +import torch + +TANGENT_DIM=10*24*25//2 + +@torch.no_grad() +def extract_tangent_features(covariances,spatial_weight): + old_tf32=torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(covariances.device.type,enabled=False): + w=spatial_weight.float() + w=w/w.norm(dim=-1,keepdim=True).clamp_min(1e-6) + projected=torch.einsum('bfc,nbcd,bgd->nbfg',w,covariances.float(),w) + d=projected.diagonal(dim1=-2,dim2=-1).clamp_min(1e-10).sqrt() + correlation=(projected/(d.unsqueeze(-1)*d.unsqueeze(-2))).clamp(-1,1) + correlation=(correlation+correlation.transpose(-1,-2))/2 + correlation=.95*correlation+.05*torch.eye(24,device=correlation.device) + values,vectors=torch.linalg.eigh(correlation) + logarithm=(vectors*values.clamp_min(1e-6).log().unsqueeze(-2))@vectors.transpose(-1,-2) + i,j=torch.triu_indices(24,24,device=correlation.device) + scale=torch.where(i==j,1.,2.**.5) + return (logarithm[...,i,j]*scale).flatten(1) + finally: + torch.backends.cuda.matmul.allow_tf32=old_tf32 diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S085/MODEL_CARD.md b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S085/MODEL_CARD.md new file mode 100644 index 0000000000000000000000000000000000000000..d975dba7f7cdb2eec1995b91a8eecd6658f9c053 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S085/MODEL_CARD.md @@ -0,0 +1,43 @@ +# Shared EEG decoder + +This package contains one coupled backbone used by all five tracks, with private input adapters and classifiers. Every trainable common component was trained with all five training splits. It is a single model; inference performs no parameter updates or dataset-level fitting. + +The common backbone combines waveform convolutions, an audited pretrained BIOT feature path, covariance and log-correlation encoders, and shared feature corrections. The waveform coactivation extension encodes 64 within-window log variances and 2,016 correlations between common waveform channels. A matched experimental control removes the correlation inputs. `config.json` identifies the packaged variant and its five fixed correction gains. All original backbone parameters are fixed during this extension's joint training. + +Weights originate only from the supplied training data and audited initialization checkpoints. Training details, parent provenance, raw/cache checks, shared-gradient checks and the five separate validation metrics are recorded in `training.json`. Validation selects checkpoints and fixed gains; it does not fit normalization or update parameters. Reported validation results belong to selected checkpoints, not to private test evaluation or five-seed means. + +Run `bash infer.sh INPUT_DIR OUTPUT_DIR`. The input manifest specifies a track and opaque sample IDs, shard paths and indices. Signals are in microvolts and are scaled by 1/100. The package writes one probability vector per input ID to `OUTPUT_DIR/predictions.jsonl`. It needs only the packaged files and the contract's installed Python dependencies, works after relocation, and does not need labels, subject IDs, training caches or network access. + +FACED and TUEV use window balanced accuracy. AD65 uses mean window probabilities per patient before balanced accuracy. OpenBMI averages within-subject balanced accuracy. Longitudinal averages within-session balanced accuracy within each subject, then over subjects. These five metrics remain separate. + +This checkpoint adds fixed within-window ordinal pattern probabilities, permutation entropy and statistical complexity at five delays. Training-only normalization and five input projections feed one common correction MLP trained by all five tracks. The common correction enters the existing covariance and fusion representations; fixed per-track gains select its strength. All earlier model tensors remain unchanged. + +Fixed real and imaginary spectral coherence between the inherited 24 spatial filters is normalized using training windows only and encoded by one new common network. Five private linear heads add class evidence. All five training splits update the new common encoder; all earlier model tensors remain unchanged. + +Fixed per-window relative band powers, envelope variability, envelope correlations and phase-amplitude coupling feed training-normalized private input projections and one new shared encoder. Five linear heads add class evidence. All five training splits update the new common encoder; all prior model tensors remain unchanged. AD65 updates use all windows from six class-balanced training patients; objective: mean-probability. + +The inherited OpenBMI phase-classifier projection was refreshed from a separately validated private-readout fit. Every common tensor and input adapter of this jointly trained model is unchanged. Exact ancestor checks confirm that all common tensors used by this inherited readout are identical; the new cross-frequency correction remains disabled for OpenBMI. No shared checkpoints or predictions are ensembled. + +A common CBraMod feature encoder, itself jointly trained on all five training splits, supplies its shared summary and tokens pooled into four ordered time bins. Its classifiers are discarded. A new common feature MLP and five zero-initialized private linear projections learn residual class evidence jointly on all five training splits. Training may randomly remove the earlier decoder logits for half of training groups, using one mask per AD patient and one per other window; labels and teacher targets remain unchanged. Validation and inference always retain the complete earlier decoder. The same new class projection also receives an auxiliary standalone classification loss when configured, with the same patient-pooled AD objective; this adds no inference module. The complete earlier decoder and feature extractor remain tensor-identical; selecting zero residual gain preserves its predictions exactly. The summary-only control masks the 8192 ordered features after training-fitted per-feature normalization. One feature backbone and one classifier per track run at inference, with no prediction ensemble or external runtime cache. + +The five outer private student-feature class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. + +The longitudinal private outer projection is selected from another training-only readout fit using exactly the same common/input/prior-head tensors. All other private heads are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +The complete stronger parent is retained, including its common CBraMod feature encoder, common readout and all private classifiers. The CBraMod features and existing common128-dimensional embedding are computed once and reused. An additional common128-to256-to128 MLP with the configured GELU or identity activation and five zero-initialized private linear projections learn residual class evidence jointly on all five training splits. Training may randomly remove the earlier decoder logits for half of training groups, using one mask per AD patient and one per other window; labels and teacher targets remain unchanged. Validation and inference always retain the complete earlier decoder. The same new class projection also receives an auxiliary standalone classification loss when configured, with the same patient-pooled AD objective; this adds no inference module. The complete earlier decoder and feature extractor remain tensor-identical; selecting zero residual gain preserves its predictions exactly. One feature backbone and one classifier per track run at inference, with no prediction ensemble or external runtime cache. + +The five outer private student-feature class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. + +The openbmi private outer projection is selected from another training-only readout fit using exactly the same common/input/prior-head tensors. All other private heads are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +A fixed two-second crop supplies spectral and cross-frequency coupling features, with no short-window envelope autocorrelation. The crop is configured as center or first. Each track has a training-fitted normalizer and linear input adapter to128 dimensions; one common128-to256-to128 GELU/LayerNorm block and five zero-initialized class projections are jointly trained on all five training splits. All complete-parent tensors are preserved exactly. Normalization statistics use training windows only. The parent is randomly removed from the training loss at the configured probability; it is always present at inference. AD uses mean patient probabilities over all sampled patient windows. Auxiliary classification uses the same class projection. There is one composed feature backbone and head per track; no prediction ensemble, external runtime cache, test adaptation, or evaluation-metadata features. Zero residual gain exactly retains the complete parent. + +The five outer private center-context class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. + +The tuev private outer projection is selected from another training-only readout fit using exactly the same common/input/prior-head tensors. All other private heads are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +The faced private context input and outer class projections are selected from another training-only readout fit using exactly the same common/oldinput/normalizer/prior-head tensors. All other private input/head pairs are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +A fixed one-second crop supplies spectral and cross-frequency coupling features, with no short-window envelope autocorrelation. The crop is configured as center or first. Each track has a training-fitted normalizer and linear input adapter to128 dimensions; one common128-to256-to128 GELU/LayerNorm block and five zero-initialized class projections are jointly trained on all five training splits. All complete-parent tensors are preserved exactly. Normalization statistics use training windows only. The parent is randomly removed from the training loss at the configured probability; it is always present at inference. AD uses mean patient probabilities over all sampled patient windows. Auxiliary classification uses the same class projection. There is one composed feature backbone and head per track; no prediction ensemble, external runtime cache, test adaptation, or evaluation-metadata features. Zero residual gain exactly retains the complete parent. + +The five outer private short-context class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S085/alpha_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S085/alpha_features.py new file mode 100644 index 0000000000000000000000000000000000000000..455154d715e86d45e4e17113bed69adbcd946b29 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S085/alpha_features.py @@ -0,0 +1,45 @@ +"""Fixed alpha prominence features from each individual two-second window.""" +import torch + +REGION_NAMES=('occipital','parietal','central','frontal','left_posterior','right_posterior') +REGIONS=(('PO7','PO5','PO3','POZ','PO4','PO6','PO8','O1','OZ','O2'), + ('P7','P5','P3','P1','PZ','P2','P4','P6','P8'), + ('FC5','FC3','FC1','FCZ','FC2','FC4','FC6','C5','C3','C1','CZ','C2','C4','C6'), + ('FP1','FPZ','FP2','AF3','AF4','F7','F5','F3','F1','FZ','F2','F4','F6','F8'), + ('P7','P5','P3','P1','PO7','PO5','PO3','O1'), + ('P2','P4','P6','P8','PO4','PO6','PO8','O2')) +ALPHA_DIM=58*7+6*22 + +def region_matrix(channels): + result=torch.zeros(len(REGIONS),len(channels)) + for i,names in enumerate(REGIONS): + for name in names:result[i,channels.index(name)]=1/len(names) + return result.tolist() + +@torch.no_grad() +def extract_alpha_features(signal,regions): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();x=x-x.mean(-1,keepdim=True) + spectrum=torch.fft.rfft(x*torch.hann_window(400,device=x.device),dim=-1)/200 + power=spectrum.abs().square().clamp_min(1e-12) + lp=power.log() + # Geometric regional means resist domination by one high-amplitude channel. + regional=torch.einsum('rc,ncf->nrf',regions.float(),lp) + lp=torch.cat([lp,regional],1) + low=lp[...,8:13].mean(-1,keepdim=True) + high=lp[...,36:49].mean(-1,keepdim=True) + freq=torch.arange(7.,14.5,.5,device=x.device) + alpha=lp[...,14:29] + baseline=low+(high-low)*((freq-5)/16) + prominence=alpha-baseline + normalized=alpha.softmax(-1) + center=(normalized*freq).sum(-1) + entropy=-(normalized*normalized.clamp_min(1e-12).log()).sum(-1) + alpha_mean=torch.logsumexp(alpha,-1)-torch.log(torch.tensor(15.,device=x.device)) + def log_band(lo,hi): + return torch.logsumexp(lp[...,lo:hi],-1)-torch.log(torch.tensor(float(hi-lo),device=x.device)) + summaries=torch.stack([alpha_mean-log_band(2,81),alpha_mean-log_band(8,14), + alpha_mean-log_band(30,61),prominence.max(-1).values, + prominence.mean(-1),center,entropy],-1) + return torch.cat([summaries[:,:58].flatten(1),summaries[:,58:].flatten(1), + prominence[:,58:].flatten(1)],1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S085/config.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S085/config.json new file mode 100644 index 0000000000000000000000000000000000000000..a80738d34f012ebf0ece18b776a98eb1e234c518 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S085/config.json @@ -0,0 +1,961 @@ +{ + "schema": "bci-shared-biot-covariance-bf16head-v1", + "architecture": { + "channels": 32, + "width": 128, + "depth": 2, + "dropout": 0.5, + "wave_filters": 32, + "head_width": 64, + "head_dropout": 0.3, + "clinical_asymmetry": true, + "alpha_regions": [ + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.125 + ] + ], + "clinical_envelope": true, + "temporal_pool": true, + "temporal_evidence": true, + "evidence_temperature": 0.25, + "random_fourier": true, + "fourier_features": 256, + "tangent_readout": true, + "shared_context_correction": true, + "wave_coactivation": true, + "ordinal_context": true, + "phase_coherence": true, + "cross_frequency": true, + "cbramod_feature_transfer": true, + "student_architecture": { + "virtual_channels": 32, + "token_width": 64, + "summary_width": 256, + "head_width": 128, + "dropout": 0.3 + }, + "student_extension": true, + "post_embedding_extension": true, + "extension_activation": "identity", + "center_context_extension": true, + "context_crop": "center", + "short_context_extension": true, + "short_crop": "first" + }, + "initialization": { + "initialization": "continue joint training from a complete shared-model checkpoint", + "parent": "/workspace/research/runs/hybrid_biot_fusionshrink0100/epoch-001/weights.pt", + "parent_initialization": { + "initialization": "jointly trained parent plus audited pretrained BIOT in a single coupled backbone", + "parent": "/workspace/research/runs/hybrid_wide1/epoch-004/weights.pt", + "audited_biot": { + "initialization": "pretrained", + "repo": "braindecode/biot-pretrained-six-datasets-18chs", + "revision": "7e9aabf302870012f73773276803aab97993951c", + "sha256": "a218f4054ae29962c6fd9d23d94c446d354c4f53e805a6771c85749ccc20baaa", + "license": "BSD-3-Clause", + "source_braindecode": "1.3.0", + "loaded_core_tensors": 56, + "skipped_classifier_tensors": 3 + }, + "neural_channel_indices": { + "faced": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "tuev": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15 + ], + "ad65": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "openbmi": [ + 0, + 1, + 3, + 5, + 12, + 14, + 23, + 25, + 28, + 30, + 2, + 6, + 11, + 15, + 22, + 26, + 4, + 13 + ], + "longitudinal": [ + 0, + 2, + 7, + 11, + 23, + 27, + 41, + 45, + 55, + 57, + 5, + 13, + 21, + 29, + 39, + 47, + 9, + 25 + ] + }, + "rebase": "incumbent waveform, fusion and four heads; joint BIOT and TUEV head from readout epoch 9; zero initialized neural interaction", + "jointly_finetuned_neural_parent": "/workspace/research/runs/hybrid_biot_readout1/epoch-009/weights.pt", + "tuev_high_dimensional_spectral_projection_disabled": true, + "frozen_prior_representation": true, + "nonclinical_head_updates": "only the 256 added BIOT columns; original columns and biases fixed", + "faced_openbmi_neural_path": "common nonlinear fusion only; direct head columns masked", + "retention_teacher": "/workspace/research/runs/hybrid_wide1/epoch-004", + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "joint_covariance_parent": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "frozen_prior_representation": true, + "head_updates": "one linear head per track; added 128 shared covariance columns trainable; AD head initialized from the joint covariance parent", + "new_shared_representation": "one common covariance MLP inside the coupled backbone, trained by all five tasks; fixed spatial input adapters from the same jointly trained source", + "head_arithmetic": "one linear head evaluated in fixed feature blocks to preserve original bfloat16 accumulation dimensions", + "retention_teacher": { + "ad65": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "other_tracks": "/workspace/research/runs/hybrid_wide1/epoch-004" + }, + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "loader_scale": 0.01, + "tracks": [ + "faced", + "tuev", + "ad65", + "openbmi", + "longitudinal" + ], + "head_arithmetic": "same linear head in fixed feature blocks, sum in bfloat16 on GPU for non-AD tracks; AD remains float32", + "head_refinement": { + "source": "/workspace/research/runs/residual_heads1/epoch-018", + "source_weights_sha256": "e0b609137391b47f99438ccadaa22fc0bc10d2c10ead0ddf0a3c25be2c907c85", + "shared_backbone_unchanged": true, + "selected_head_epochs": { + "faced": 5, + "tuev": 24, + "ad65": 0, + "openbmi": 0, + "longitudinal": 0 + } + }, + "clinical_spectral_refinement": { + "source": "/workspace/research/runs/head_dropout1/epoch-016", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "head_estimation": { + "method": "class/subject-balanced Gaussian linear discriminant; covariance augmented by class-conditional subject/session mean variation before shrinkage", + "selected_shrinkage": { + "faced": "inherited", + "tuev": "inherited", + "ad65": "inherited", + "openbmi": "inherited", + "longitudinal": { + "shrinkage": 0.9, + "domain_strength": 1.0 + } + }, + "feature_scaling": "fitted on training data and folded into linear coefficients" + }, + "clinical_asymmetry_refinement": { + "source": "/workspace/research/runs/domain_lda_heads1/epoch-001", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "alpha_rhythm_adapter": { + "training_normalization_only": true, + "regions": [ + "occipital", + "parietal", + "central", + "frontal", + "left_posterior", + "right_posterior" + ], + "features": "per-window alpha prominence relative to adjacent frequencies", + "shared_backbone_unchanged": true + }, + "clinical_envelope_refinement": { + "source": "/workspace/research/runs/clinical_asymmetry1/epoch-001", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "independent_adapter_merge": { + "alpha_source": "/workspace/research/runs/alpha_calibrated1/epoch-003", + "clinical_source": "/workspace/research/runs/clinical_envelope1/epoch-002", + "all_shared_and_head_tensors_equal": true + }, + "frequency_montage_refinement": { + "six_frequency_bands": true, + "shared_encoder_unchanged": true, + "selected_track_epochs": { + "faced": 0, + "tuev": 1, + "ad65": 0, + "openbmi": 10, + "longitudinal": 2 + } + }, + "private_track_selection": { + "track": "tuev", + "donor": "/workspace/research/replicates/frequency_head_control1/epoch-001" + }, + "clinical_sampling_refinement": { + "subject_exponent": 0.0, + "class_balanced": true, + "only_clinical_head_updated": true + }, + "temporal_statistics_readout": { + "statistics": [ + "mean", + "standard deviation", + "maximum", + "minimum" + ], + "shared_encoder_and_prior_heads_unchanged": true, + "selected_pool_epochs": { + "faced": 2, + "tuev": 0, + "ad65": 0, + "openbmi": 33, + "longitudinal": 3 + } + }, + "temporal_evidence_readout": { + "pooling": "log mean exp of per-patch class evidence", + "temperature": 0.25, + "shared_encoder_and_prior_heads_unchanged": true, + "selected_evidence_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 6, + "longitudinal": 8 + } + }, + "fourier_basis_readout": { + "basis_functions": 256, + "bandwidths": [ + 0.5, + 1.0, + 2.0 + ], + "shared_encoder_and_prior_heads_unchanged": true, + "selected_fourier_epochs": { + "faced": 21, + "tuev": 0, + "ad65": 0, + "openbmi": 0, + "longitudinal": 2 + } + }, + "shared_tangent_readout": { + "one_shared_tangent_module": true, + "original_and_corrected_shared_features_retained": true, + "private_head_scalar_gains": { + "faced": 0.0, + "tuev": 0.1, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 0.1 + }, + "all_common_weights_fixed_during_gain_refinement": true + }, + "shared_context_correction": { + "source": "/workspace/research/runs/hybrid_codebrain_fusion_control1/epoch-002", + "zero_token_input_preserved": true, + "unused_native_CodeBrain_core_and_input_parameters_removed": true, + "common_patch_and_context_layers_retained": true, + "same_one_shared_backbone_and_five_classifiers": true + }, + "shared_wave_coactivation": { + "channels": 64, + "statistics": 2080, + "diagonal_only_control": false, + "common_encoder_updated_by_all_five_tracks": true, + "gain_selection_within_one_common_checkpoint": { + "faced": 1.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 1.0 + } + }, + "fixed_common_coactivation_readouts": { + "all_common_weights_exactly_unchanged": true, + "selected_private_epochs": { + "faced": 25, + "tuev": 0, + "ad65": 0, + "openbmi": 8, + "longitudinal": 2 + } + }, + "shared_ordinal_context": { + "per_channel_features": 130, + "normalization_fit_on_training_only": true, + "entropy_only_control": false, + "new_common_layers_trained_on_all_five_tracks": true, + "gains_within_one_common_checkpoint": { + "faced": 1.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 0.0 + } + }, + "shared_complex_coherence": { + "features": 5520, + "normalization_fit_on_training_only": true, + "real_only_control": false, + "all_five_tracks_update_common_encoder": true, + "gains_within_one_common_checkpoint": { + "faced": 0.1, + "tuev": 1.0, + "ad65": 0.0, + "openbmi": 0.3, + "longitudinal": 0.0 + } + }, + "shared_cross_frequency": { + "per_channel_features": 30, + "normalization_fit_on_training_only": true, + "amplitude_only_control": false, + "all_five_tracks_update_common_encoder": true, + "gains_within_one_common_checkpoint": { + "faced": 0.3, + "tuev": 0.1, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 0.0 + } + }, + "inherited_private_readout_refresh": { + "child": "/workspace/research/runs/coupling_patient1/epoch-007", + "donor": "/workspace/research/runs/phase_readout1/epoch-016", + "common_ancestor": "/workspace/research/runs/phase_coherence1/epoch-007", + "source_weight_sha256": { + "child": "f8466c6838ff01e54d1619f55668c1a4af26a243b54c67a956a3422d9604632a", + "donor": "ffd219d1480b81720b5aa4014cb2ed2b9cd31b7c92ad4717abc2a9625d30dc1a", + "ancestor": "e53ede409be523d8f4746251f7d46353621049f0378a88d4f7cfe2ba71a57d95" + }, + "changed_private_tensors": [ + "heads.openbmi.prior.projection.weight", + "heads.openbmi.prior.projection.bias" + ], + "all_ancestor_common_and_input_tensors_equal": true, + "all_child_common_and_input_tensors_unchanged": true, + "new_branch_gain_for_refreshed_track": 0.0, + "donor_changes_only_requested_private_projection": true, + "prediction_sources": { + "faced": { + "source": "/workspace/research/runs/coupling_patient1/faced-e007.npy", + "sha256": "68b617c8ecf347c79b23c20b70f6b4981c2f26b7b8c71dc7cd5fa0d7f4285ea6" + }, + "tuev": { + "source": "/workspace/research/runs/coupling_patient1/tuev-e007.npy", + "sha256": "9f0743450f1104d395e9daac0600aaf20755b5590b9f5c3e3137732c479dd647" + }, + "ad65": { + "source": "/workspace/research/runs/coupling_patient1/ad65-e007.npy", + "sha256": "7a3b74c58580b7ba952322bf6d527ebc9a40a6e04c7cdbbaea14e84a7a298d54" + }, + "openbmi": { + "source": "/workspace/research/runs/phase_readout1/openbmi-e016.npy", + "sha256": "14f630543e1df88c88d8f3e0effb4506ba33f533b3484de3c7aaf6554507341c" + }, + "longitudinal": { + "source": "/workspace/research/runs/coupling_patient1/longitudinal-e007.npy", + "sha256": "e93b0a319eaa3ddca9d71b0e786b808ba1630c1d3ce125f8e08036e517741b74" + } + } + }, + "shared_student_residual": { + "dimension": 8448, + "summary_dimension": 256, + "ordered_time_bins": 4, + "student_weights_sha256": "19dfe912cceed997699b5b526c8c2ece55945c5f9bd111c4c13704d0fc460e8b", + "summary_only_control": false, + "normalization_fit_on_training_only": true, + "new_common_readout_jointly_trained_on_all_five": true, + "class_projection_initialized_zero": true, + "student_classifiers_discarded": true, + "gains_within_one_common_checkpoint": { + "faced": 1.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 1.0 + }, + "zero_gain_preserves_complete_parent": true + }, + "private_head_refresh": { + "reference": "/workspace/research/pilots/center_private_pilot1/epoch-001", + "donor": "/workspace/research/runs/center_private1/epoch-030", + "track": "tuev", + "source_sha256": { + "reference": "9b00b654824d7e91fb20836278720ad7f719d087f06442c4279494e2b2cacc7b", + "donor": "0ab89e645a67ba9950509c8fd9c450566d92105259a8ff0552e54182c37f2078" + }, + "changed_private_tensors": [ + "heads.tuev.correction_gain", + "heads.tuev.projection.weight", + "heads.tuev.projection.bias" + ], + "all_common_input_and_prior_head_tensors_exactly_equal": true, + "executable_code_and_architecture_exactly_equal": true, + "one_common_checkpoint": true, + "prediction_sources": { + "faced": "/workspace/research/pilots/center_private_pilot1/faced-e001.npy", + "tuev": "/workspace/research/runs/center_private1/tuev-e030.npy", + "ad65": "/workspace/research/pilots/center_private_pilot1/ad65-e001.npy", + "openbmi": "/workspace/research/pilots/center_private_pilot1/openbmi-e001.npy", + "longitudinal": "/workspace/research/pilots/center_private_pilot1/longitudinal-e001.npy" + } + }, + "shared_student_extension_residual": { + "dimension": 128, + "input_representation": "fixed jointly trained common student embedding", + "activation": "identity", + "student_weights_sha256": "19dfe912cceed997699b5b526c8c2ece55945c5f9bd111c4c13704d0fc460e8b", + "summary_only_control": false, + "normalization_fit_on_training_only": true, + "new_common_readout_jointly_trained_on_all_five": true, + "class_projection_initialized_zero": true, + "student_classifiers_discarded": true, + "gains_within_one_common_checkpoint": { + "faced": 0.30000001192092896, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 0.30000001192092896, + "longitudinal": 0.30000001192092896 + }, + "zero_gain_preserves_complete_parent": true + }, + "fixed_common_embedding_readouts": { + "all_common_weights_exactly_unchanged": true, + "selected_private_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 0, + "longitudinal": 1 + } + }, + "shared_center_context_residual": { + "dimension": 128, + "crop": "center", + "samples": 400, + "sample_rate": 200, + "feature_types": [ + "spectral", + "cross_frequency_coupling" + ], + "normalization_fit_on_training_only": true, + "new_common_block_jointly_trained_on_all_five": true, + "class_projection_initialized_zero": true, + "gains_within_one_common_checkpoint": { + "faced": 0.10000000149011612, + "tuev": 0.30000001192092896, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 1.0 + }, + "zero_gain_preserves_complete_parent": true + }, + "private_input_head_refresh": { + "reference": "/workspace/research/candidates/center_private_selected", + "donor": "/workspace/research/runs/center_input_adapt_full1/epoch-030", + "track": "faced", + "source_sha256": { + "reference": "d4fc27932a82970d6e309dec4f915ec2a325b17e833684d23ce66667af06f15a", + "donor": "1b57adb8eb277735bbb114023f1ab2b2e10b18a75fd6932453ac2d9de27a6a6c" + }, + "changed_private_tensors": [ + "adapters.faced.center_projection.weight", + "adapters.faced.center_projection.bias", + "heads.faced.correction_gain", + "heads.faced.projection.weight", + "heads.faced.projection.bias" + ], + "all_common_old_input_normalizer_and_prior_head_tensors_exactly_equal": true, + "executable_code_and_architecture_exactly_equal": true, + "one_common_checkpoint": true, + "prediction_sources": { + "faced": "/workspace/research/runs/center_input_adapt_full1/faced-e030.npy", + "tuev": "/workspace/research/selection_predictions/center_private_selected_tuev/tuev-e000.npy", + "ad65": "/workspace/research/selection_predictions/center_private_selected_tuev/ad65-e000.npy", + "openbmi": "/workspace/research/selection_predictions/center_private_selected_tuev/openbmi-e000.npy", + "longitudinal": "/workspace/research/selection_predictions/center_private_selected_tuev/longitudinal-e000.npy" + } + }, + "shared_short_context_residual": { + "dimension": 128, + "crop": "first", + "samples": 200, + "sample_rate": 200, + "feature_types": [ + "spectral", + "cross_frequency_coupling" + ], + "normalization_fit_on_training_only": true, + "new_common_block_jointly_trained_on_all_five": true, + "class_projection_initialized_zero": true, + "gains_within_one_common_checkpoint": { + "faced": 0.30000001192092896, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 0.30000001192092896 + }, + "zero_gain_preserves_complete_parent": true + }, + "fixed_common_short_context_readouts": { + "all_common_weights_exactly_unchanged": true, + "selected_private_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 0, + "longitudinal": 1 + } + } +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S085/coupling_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S085/coupling_features.py new file mode 100644 index 0000000000000000000000000000000000000000..3a4e51bd7ce07bcec1f0f5b80054d6ff387ac87f --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S085/coupling_features.py @@ -0,0 +1,34 @@ +"""Per-window cross-frequency envelope and phase-amplitude relationships.""" +import torch +BANDS=((1,4),(4,8),(8,13),(13,30),(30,48)) +PAIRS=tuple((i,j) for i in range(5) for j in range(i+1,5)) +PER_CHANNEL=30 + +@torch.no_grad() +def coupling_features(track,x): + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + n=x.shape[-1];spectrum=torch.fft.fft(x,dim=-1);frequency=torch.fft.fftfreq(n,1/200,device=x.device) + masks=torch.stack([2*((frequency>=lo)&(frequencynbf',w,covariances.float(),w).clamp_min(1e-8).log() + return torch.cat([power,power-power.mean(1,keepdim=True)],1).flatten(1) + def wave_signal(self,x,components=None): + if components is None:components=frequency_components(x) + correction=torch.einsum('blc,nbct->nlt',self.frequency_weight,components.to(self.frequency_weight.dtype)) + return (self.signal(x)+correction.to(x.dtype)).unsqueeze(1) + def forward(self,x,features,covariance_features): + return self.wave_signal(x),self.spectral_features(features,signal=x),self.neural(x),covariance_features + +class SharedBackbone(nn.Module): + def __init__(self,channels,width,depth,dropout,wave_filters): + super().__init__() + self.waveform=nn.Sequential( + nn.Conv2d(1,wave_filters,(1,64),padding=(0,32),bias=False),nn.GroupNorm(1,wave_filters), + nn.Conv2d(wave_filters,2*wave_filters,(channels,1),groups=wave_filters,bias=False),nn.GroupNorm(1,2*wave_filters),nn.ELU(), + nn.AvgPool2d((1,4)),nn.Dropout(.35), + nn.Conv2d(2*wave_filters,2*wave_filters,(1,16),padding=(0,8),groups=2*wave_filters,bias=False),nn.Conv2d(2*wave_filters,2*wave_filters,1,bias=False), + nn.GroupNorm(1,2*wave_filters),nn.ELU(),nn.AvgPool2d((1,8)),nn.Dropout(.35)) + self.wave_summary=nn.Sequential(nn.AdaptiveAvgPool2d((1,8)),nn.Flatten(),nn.Linear(2*wave_filters*8,width)) + self.fusion=nn.Sequential(nn.LayerNorm(width),nn.GELU(),nn.Dropout(dropout), + *[Residual(width,dropout) for _ in range(depth)],nn.LayerNorm(width)) + # Both representations interact before the shared residual stack. + self.phase_encoder=nn.Sequential(nn.LayerNorm(PHASE_DIM),nn.Linear(PHASE_DIM,width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width)) + self.register_buffer('phase_imaginary_enabled',torch.ones(())) + self.coupling_encoder=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width),nn.LayerNorm(width)) + self.wave_gain=nn.Parameter(torch.tensor(.1)) + self.biot=BIOT(n_chans=18,n_outputs=2,n_times=400,sfreq=200) + self.biot.final_layer=nn.Identity() + self.biot_projection=nn.Sequential(nn.LayerNorm(256),nn.Linear(256,width),nn.Dropout(.2)) + nn.init.normal_(self.biot_projection[1].weight,std=.001);nn.init.zeros_(self.biot_projection[1].bias) + self.covariance_encoder=nn.Sequential(nn.LayerNorm(len(BANDS)*24*2),nn.Linear(len(BANDS)*24*2,width),nn.GELU(),nn.Dropout(.4), + *[Residual(width,.4) for _ in range(2)],nn.LayerNorm(width)) + self.covariance_projection=nn.Linear(width,width) + nn.init.zeros_(self.covariance_projection.weight);nn.init.zeros_(self.covariance_projection.bias) + self.tangent_encoder=nn.Sequential(nn.LayerNorm(TANGENT_DIM),nn.Linear(TANGENT_DIM,width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width),nn.Linear(width,width)) + self.ordinal_context=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width)) + nn.init.zeros_(self.ordinal_context[-1].weight);nn.init.zeros_(self.ordinal_context[-1].bias) + self.register_buffer('codebrain_enabled',torch.ones(())) + self.codebrain_patch_encoder=nn.Sequential(nn.LayerNorm(24*64),nn.Linear(24*64,width),nn.GELU(),nn.Dropout(.3)) + self.codebrain_context=nn.Sequential(nn.LayerNorm(width*4),nn.Linear(width*4,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width)) + nn.init.zeros_(self.codebrain_context[-1].weight);nn.init.zeros_(self.codebrain_context[-1].bias) + def codebrain_correction(self,tokens,representation,fusion_input): + with torch.autocast(tokens.device.type,enabled=False): + encoded=self.codebrain_patch_encoder(self.codebrain_enabled*tokens.float()) + pooled=torch.cat([encoded.mean(1),encoded.std(1,correction=0),representation[:,-512:-384].float(),representation[:,-128:].float()],-1) + delta=self.codebrain_context(pooled) + added=.001*nn.functional.linear(delta,self.covariance_projection.weight,None) + corrected=self.fusion(fusion_input+added.to(fusion_input.dtype)) + return corrected-representation[:,-512:-384],delta + def forward(self,signal,spectral,neural_signal,covariance_features,tangent_features): + wave=self.waveform(signal) + neural=self.biot(neural_signal.float()) + neural=self.biot_projection[0](neural) + projected=self.biot_projection[2](self.biot_projection[1](neural)) + with torch.autocast(signal.device.type,enabled=False): + covariance_embedding=self.covariance_encoder(covariance_features.float()) + original=spectral+self.wave_gain*self.wave_summary(wave)+.01*projected + coupled=.001*self.covariance_projection(covariance_embedding).to(original.dtype) + fused=self.fusion(original+coupled) + with torch.autocast(signal.device.type,enabled=False):delta=self.tangent_encoder(tangent_features.float()) + added=.001*nn.functional.linear(delta,self.covariance_projection.weight,None) + corrected=self.fusion((original+coupled)+added.to(original.dtype)) + return torch.cat([wave.flatten(1),fused,neural,covariance_embedding],-1),corrected-fused,delta,original+coupled + +class ResidualHead(nn.Module): + """A small nonlinear classifier correction around an inherited linear readout.""" + def __init__(self,features,classes,width=64,dropout=.3,full_precision=False): + super().__init__();self.full_precision=full_precision + self.base=nn.Linear(features,classes) + self.delta=nn.Sequential(nn.LayerNorm(features),nn.Linear(features,width),nn.GELU(),nn.Dropout(dropout),nn.Linear(width,classes)) + nn.init.zeros_(self.delta[-1].weight);nn.init.zeros_(self.delta[-1].bias) + def forward(self,x): + if self.full_precision: + with torch.autocast(x.device.type,enabled=False):return self.base(x.float())+self.delta(x.float()) + prior=nn.functional.linear(x[:,:-128].contiguous(),self.base.weight[:,:-128].contiguous(),self.base.bias) + added=nn.functional.linear(x[:,-128:].contiguous(),self.base.weight[:,-128:].contiguous()) + value=prior+added + return value+self.delta(x).to(value.dtype) + +class TemporalPoolHead(nn.Module): + def __init__(self,prior,channels=64): + super().__init__();self.prior=prior;self.channels=channels + self.register_buffer('pool_output_scale',torch.ones(()));self.register_buffer('pool_mean',torch.zeros(channels*4));self.register_buffer('pool_scale',torch.ones(channels*4)) + self.pool_projection=nn.Linear(channels*4,prior.base.out_features) + nn.init.zeros_(self.pool_projection.weight);nn.init.zeros_(self.pool_projection.bias) + def statistics(self,x): + with torch.autocast(x.device.type,enabled=False): + wave=x[:,:-512].float().reshape(len(x),self.channels,-1) + return torch.cat([wave.mean(-1),wave.std(-1,correction=0),wave.amax(-1),wave.amin(-1)],-1) + def forward(self,x): + prior=self.prior(x) + with torch.autocast(x.device.type,enabled=False): + values=((self.statistics(x)-self.pool_mean)/self.pool_scale).clamp(-8,8) + added=self.pool_output_scale*self.pool_projection(values) + return prior+added.to(prior.dtype) + +class TemporalEvidenceHead(nn.Module): + """Pool class evidence over the shared waveform time axis.""" + def __init__(self,prior,channels=64,temperature=.25): + super().__init__();self.prior=prior;self.channels=channels;self.temperature=temperature + self.register_buffer('evidence_output_scale',torch.ones(())) + self.register_buffer('evidence_mean',torch.zeros(channels)) + self.register_buffer('evidence_scale',torch.ones(channels)) + self.evidence_projection=nn.Linear(channels,prior.prior.base.out_features,bias=False) + nn.init.zeros_(self.evidence_projection.weight) + def patches(self,x): + with torch.autocast(x.device.type,enabled=False): + wave=x[:,:-512].float().reshape(len(x),self.channels,-1).transpose(1,2) + return ((wave-self.evidence_mean)/self.evidence_scale).clamp(-8,8) + def evidence(self,patches): + with torch.autocast(patches.device.type,enabled=False): + values=self.evidence_projection(patches.float())/self.temperature + maximum=values.amax(1,keepdim=True) + pooled=self.temperature*((values-maximum).exp().mean(1).log()+maximum.squeeze(1)) + return self.evidence_output_scale*pooled + def forward(self,x): + prior=self.prior(x) + return prior+self.evidence(self.patches(x)).to(prior.dtype) + +class FourierResidualHead(nn.Module): + """A fixed random Fourier basis and trainable linear classifier correction.""" + def __init__(self,prior,features,classes,basis=256): + super().__init__();self.prior=prior + self.register_buffer('rff_mean',torch.zeros(features));self.register_buffer('rff_scale',torch.ones(features)) + self.register_buffer('rff_frequency',torch.randn(features,basis)/features**.5) + self.register_buffer('rff_phase',torch.rand(basis)*2*torch.pi) + self.register_buffer('rff_output_scale',torch.ones(())) + self.rff_projection=nn.Linear(3*basis,classes);nn.init.zeros_(self.rff_projection.weight);nn.init.zeros_(self.rff_projection.bias) + def basis(self,x): + with torch.autocast(x.device.type,enabled=False): + values=((x.float()-self.rff_mean)/self.rff_scale).clamp(-8,8)@self.rff_frequency + return 2**.5*torch.cat([(values/sigma+self.rff_phase).cos() for sigma in (.5,1.,2.)],-1) + def forward(self,x): + prior=self.prior(x) + with torch.autocast(x.device.type,enabled=False):added=self.rff_output_scale*self.rff_projection(self.basis(x)) + return prior+added.to(prior.dtype) + +class TangentFeatureHead(nn.Module): + """Select a shared feature correction before the inherited classifier.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.feature_gain=nn.Parameter(torch.zeros(())) + def forward(self,values): + old=values[:,:-256];fusion_delta=values[:,-256:-128];covariance_delta=values[:,-128:] + adjusted=torch.cat([old[:,:-512],old[:,-512:-384]+self.feature_gain*fusion_delta,old[:,-384:-128],old[:,-128:]+self.feature_gain*covariance_delta],-1) + return self.prior(adjusted) + +class CodeBrainFeatureHead(nn.Module): + """Private use of a jointly trained common feature correction.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.codebrain_gain=nn.Parameter(torch.ones(())) + def forward(self,values): + previous=values[:,:-256];native=previous[:,:-256] + fusion_delta=values[:,-256:-128];covariance_delta=values[:,-128:] + adjusted=torch.cat([native[:,:-512],native[:,-512:-384]+self.codebrain_gain*fusion_delta,native[:,-384:-128],native[:,-128:]+self.codebrain_gain*covariance_delta],-1) + return self.prior(torch.cat([adjusted,previous[:,-256:]],-1)) + +class WaveCoactivationContext(nn.Module): + """One common encoder of coactivation among the learned waveform channels.""" + def __init__(self,channels=64,width=128): + super().__init__();self.channels=channels + ii,jj=torch.triu_indices(channels,channels,offset=1) + self.register_buffer('pair_i',ii);self.register_buffer('pair_j',jj) + self.register_buffer('offdiagonal_enabled',torch.ones(())) + self.encoder=nn.Sequential(nn.LayerNorm(channels+len(ii)),nn.Linear(channels+len(ii),width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width)) + def statistics(self,native): + with torch.autocast(native.device.type,enabled=False): + wave=native[:,:-512].float().reshape(len(native),self.channels,-1) + centered=wave-wave.mean(-1,keepdim=True) + previous_tf32=torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32=False + covariance=centered@centered.transpose(-1,-2)/wave.shape[-1] + torch.backends.cuda.matmul.allow_tf32=previous_tf32 + variance=covariance.diagonal(dim1=-2,dim2=-1).clamp_min(1e-8) + correlation=covariance/(variance.sqrt()[:,:,None]*variance.sqrt()[:,None,:]) + return torch.cat([variance.log(),correlation[:,self.pair_i,self.pair_j].clamp(-1,1)],-1) + def encode_statistics(self,values): + with torch.autocast(values.device.type,enabled=False): + value=torch.cat([values[:,:self.channels],self.offdiagonal_enabled*values[:,self.channels:]],-1) + return self.encoder(value.float()) + def forward(self,native):return self.encode_statistics(self.statistics(native)) + +class WaveCoactivationHead(nn.Module): + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=self.correction_gain*self.output_scale*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class OrdinalFeatureHead(nn.Module): + """Private strength of one common ordinal-dynamics feature correction.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.ordinal_gain=nn.Parameter(torch.ones(())) + def forward(self,values): + previous=values[:,:-256];native=previous[:,:-640] + adjusted=torch.cat([native[:,:-512],native[:,-512:-384]+self.ordinal_gain*values[:,-256:-128],native[:,-384:-128],native[:,-128:]+self.ordinal_gain*values[:,-128:],previous[:,-640:]],-1) + return self.prior(adjusted) + +class PhaseReadoutHead(nn.Module): + """Private class evidence from the common complex-coherence encoder.""" + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=(self.correction_gain*self.output_scale)*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class CouplingReadoutHead(nn.Module): + """Private class evidence from the common cross-frequency coupling encoder.""" + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=(self.correction_gain*self.output_scale)*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class HybridModel(nn.Module): + def __init__(self,channels=32,width=128,depth=2,dropout=.5,wave_filters=32,head_width=64,head_dropout=.3,clinical_asymmetry=True,alpha_regions=None,clinical_envelope=False,temporal_pool=True,temporal_evidence=False,evidence_temperature=.25,random_fourier=False,fourier_features=256,tangent_readout=True,shared_context_correction=True,wave_coactivation=True,ordinal_context=True,phase_coherence=True,cross_frequency=True,cbramod_feature_transfer=True,student_architecture=None,student_extension=True,post_embedding_extension=True,extension_activation='gelu',center_context_extension=True,context_crop='center',short_context_extension=True,short_crop='center'): + super().__init__() + self.adapters=nn.ModuleDict({t:InputAdapter(c,width,channels,spectral_enabled=t not in ("faced","tuev","openbmi"),asymmetry=clinical_asymmetry and t=="tuev",alpha_regions=alpha_regions if t=="longitudinal" else None,envelope=clinical_envelope and t=="tuev") for t,(c,s,k) in SPECS.items()}) + self.backbone=SharedBackbone(channels,width,depth,dropout,wave_filters) + self.backbone.student_encoder=CBraModFeatures(**(student_architecture or {})) + self.backbone.register_buffer('student_ordered_enabled',torch.ones(())) + self.backbone.student_readout=nn.Sequential(nn.Linear(self.backbone.student_encoder.output_dim,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + for t,(c,s,k) in SPECS.items(): + self.adapters[t].student_input=FrequencyAdapter(c,32) + self.adapters[t].student_normalizer=Standardize(self.backbone.student_encoder.output_dim) + self.backbone.wave_coactivation=WaveCoactivationContext(2*wave_filters,width) + self.heads=nn.ModuleDict({t:ResidualHead(2*wave_filters*(((s*200+1)//4+1)//8)+width+256+width,k,head_width,head_dropout,full_precision=t=='ad65') for t,(c,s,k) in SPECS.items()}) + if temporal_pool:self.heads=nn.ModuleDict({t:TemporalPoolHead(head,wave_filters*2) for t,head in self.heads.items()}) + if temporal_evidence:self.heads=nn.ModuleDict({t:TemporalEvidenceHead(head,wave_filters*2,evidence_temperature) for t,head in self.heads.items()}) + if random_fourier:self.heads=nn.ModuleDict({t:FourierResidualHead(head,2*wave_filters*(((SPECS[t][1]*200+1)//4+1)//8)+width+256+width,SPECS[t][2],fourier_features) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:TangentFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CodeBrainFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:WaveCoactivationHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:OrdinalFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:PhaseReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert student_extension and post_embedding_extension + assert extension_activation in ('gelu','identity') + self.backbone.student_extension=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU() if extension_activation=='gelu' else nn.Identity(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert center_context_extension and context_crop in ('center','first') + self.context_crop=context_crop + for t,(c,s,k) in SPECS.items(): + self.adapters[t].center_normalizer=Standardize(feature_dim(c)+30*c) + self.adapters[t].center_projection=nn.Linear(feature_dim(c)+30*c,width) + self.backbone.center_encoder=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert short_context_extension and short_crop in ('center','first') + self.short_crop=short_crop + for t,(c,s,k) in SPECS.items(): + self.adapters[t].short_normalizer=Standardize(feature_dim(c)+30*c) + self.adapters[t].short_projection=nn.Linear(feature_dim(c)+30*c,width) + self.backbone.short_encoder=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + def short_features(self,t,x): + from short_context_features import short_spectral_features + raw=x.flatten(2);start=(raw.shape[-1]-200)//2 if self.short_crop=='center' else 0 + cropped=raw[...,start:start+200];assert cropped.shape[-1]==200 + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(raw.device.type,enabled=False):return torch.cat([short_spectral_features(t,cropped),coupling_features(t,cropped)],-1) + finally:torch.backends.cuda.matmul.allow_tf32=old + def short_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].short_normalizer(values.float()) + return self.backbone.short_encoder(self.adapters[t].short_projection(normalized)) + def center_features(self,t,x): + raw=x.flatten(2);start=(raw.shape[-1]-400)//2 if self.context_crop=='center' else 0 + cropped=raw[...,start:start+400];assert cropped.shape[-1]==400 + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(raw.device.type,enabled=False):return torch.cat([extract_features(t,cropped),coupling_features(t,cropped)],-1) + finally:torch.backends.cuda.matmul.allow_tf32=old + def center_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].center_normalizer(values.float()) + return self.backbone.center_encoder(self.adapters[t].center_projection(normalized)) + def student_extension_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + assert values.shape[-1]==128 + return self.backbone.student_extension(values.float()) + + def student_features(self,t,x): + outputs=[];old_fastpath=torch.backends.mha.get_fastpath_enabled();torch.backends.mha.set_fastpath_enabled(False) + try: + for raw in x.split(16): + signal=torch.nan_to_num(raw.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + with torch.autocast(signal.device.type,dtype=torch.bfloat16,enabled=signal.device.type=='cuda'): + outputs.append(self.backbone.student_encoder(self.adapters[t].student_input(signal))) + finally:torch.backends.mha.set_fastpath_enabled(old_fastpath) + return torch.cat(outputs).float() + def student_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].student_normalizer(values.float()) + normalized=torch.cat([normalized[:,:256],self.backbone.student_ordered_enabled*normalized[:,256:]],-1) + return self.backbone.student_readout(normalized) + def coupling_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False):return self.backbone.coupling_encoder(self.adapters[t].coupling_embedding(values.float())) + def phase_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].phase_normalizer(values.float()) + normalized=torch.cat([normalized[:,:PHASE_HALF],self.backbone.phase_imaginary_enabled*normalized[:,PHASE_HALF:]],-1) + return self.backbone.phase_encoder(normalized) + def forward(self,t,x,features=None,covariances=None,covariance_features=None): + if features is None:features=extract_features(t,x) + if covariance_features is None: + if covariances is None:covariances=extract_covariances(t,x) + covariance_features=self.adapters[t].spatial_features(covariances) + signal=x.flatten(2);signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + adapted=self.adapters[t](signal,features,covariance_features) + if covariances is None:covariances=extract_covariances(t,x) + tangent=extract_tangent_features(covariances,self.adapters[t].spatial_weight) + representation,fusion_delta,covariance_delta,fusion_input=self.backbone(*adapted,tangent_features=tangent) + if t in ('faced','openbmi'): + representation=torch.cat([representation[:,:-384],torch.zeros_like(representation[:,-384:-128]),representation[:,-128:]],-1) + tokens=torch.zeros(len(signal),signal.shape[-1]//200,24*64,device=signal.device,dtype=torch.bfloat16) + code_fusion,code_covariance=self.backbone.codebrain_correction(tokens,representation,fusion_input) + coactivation=self.backbone.wave_coactivation(representation) + with torch.autocast(signal.device.type,enabled=False): + ordinal=self.adapters[t].ordinal_embedding(ordinal_features(t,x)) + ordinal_covariance=self.backbone.ordinal_context(ordinal.float()) + added=.001*nn.functional.linear(ordinal_covariance,self.backbone.covariance_projection.weight,None) + ordinal_fusion=self.backbone.fusion(fusion_input+added.to(fusion_input.dtype))-representation[:,-512:-384] + phase=self.phase_embedding(t,phase_features(t,x,self.adapters[t].spatial_weight)) + coupling=self.coupling_embedding(t,coupling_features(t,x)) + student_values=self.student_features(t,x) + student=self.student_embedding(t,student_values) + extension=self.student_extension_embedding(t,student) + return self.heads[t](torch.cat([representation,fusion_delta,covariance_delta,code_fusion,code_covariance,coactivation,ordinal_fusion,ordinal_covariance,phase,coupling,student,extension,self.center_embedding(t,self.center_features(t,x)),self.short_embedding(t,self.short_features(t,x))],-1)) + +def widen_state_dict(state,multiplier=2): + """Duplicate temporal features and divide downstream sums to preserve outputs.""" + result={} + for key,value in state.items(): + if key.startswith('backbone.waveform.'): + layer=int(key.split('.')[2]) + if layer in (0,2,7):value=value.repeat(multiplier,1,1,1) + elif layer in (1,3,9):value=value.repeat(multiplier) + elif layer==8:value=value.repeat(multiplier,multiplier,1,1)/multiplier + elif key=='backbone.wave_summary.2.weight':value=value.repeat(1,multiplier)/multiplier + elif key.startswith('heads.') and key.endswith('.weight'): + raw=value[:,:-128]/multiplier + value=torch.cat([raw]*multiplier+[value[:,-128:]],1) + result[key]=value + return result + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S085/phase_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S085/phase_features.py new file mode 100644 index 0000000000000000000000000000000000000000..8d98822995bf37b499795dfd7e2e401040a01969 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S085/phase_features.py @@ -0,0 +1,37 @@ +"""Complex spectral coherence of the existing 24 spatial filters in ten bands.""" +import torch +from covariances import BANDS +CHANNELS=24 +PHASE_HALF=len(BANDS)*CHANNELS*(CHANNELS-1)//2 +PHASE_DIM=2*PHASE_HALF + +@torch.no_grad() +def phase_features(track,x,spatial_weight): + previous_tf32=torch.backends.cuda.matmul.allow_tf32 + try: + torch.backends.cuda.matmul.allow_tf32=False + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if track in ('faced','tuev'):x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + else:x=x-x.mean(1,keepdim=True) + x=x/x.square().mean((1,2),keepdim=True).clamp_min(1e-12).sqrt() + frames=x.unfold(-1,400,200);frames=frames-frames.mean(-1,keepdim=True) + z=torch.fft.rfft(frames*torch.hann_window(400,device=x.device),dim=-1)/200 + w=spatial_weight.float()/spatial_weight.float().norm(dim=-1,keepdim=True).clamp_min(1e-6) + index=torch.triu_indices(CHANNELS,CHANNELS,1,device=x.device) + real_parts=[];imaginary_parts=[] + for band,(lo,hi) in enumerate(BANDS): + v=z[...,2*lo:2*hi].flatten(2) + vr=w[band][None]@v.real;vi=w[band][None]@v.imag + real=(vr@vr.transpose(-1,-2)+vi@vi.transpose(-1,-2))/v.shape[-1] + imaginary=(vi@vr.transpose(-1,-2)-vr@vi.transpose(-1,-2))/v.shape[-1] + # Signals have unit global RMS; this floor suppresses phase of numerical silence. + power=real.diagonal(dim1=-2,dim2=-1).clamp_min(1e-6) + denominator=(power[:,:,None]*power[:,None,:]).sqrt().clamp_min(1e-12) + real=(real/denominator).clamp(-.999,.999) + imaginary=(imaginary/denominator).clamp(-.999,.999) + real_parts.append(torch.atanh(real[:,index[0],index[1]])) + imaginary_parts.append(torch.atanh(imaginary[:,index[0],index[1]])) + return torch.cat(real_parts+imaginary_parts,-1) + finally:torch.backends.cuda.matmul.allow_tf32=previous_tf32 diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S085/private-readout-refresh-audit.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S085/private-readout-refresh-audit.json new file mode 100644 index 0000000000000000000000000000000000000000..1d02ef9e4aa8d0782c67157b160ef5667bfa1193 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S085/private-readout-refresh-audit.json @@ -0,0 +1,40 @@ +{ + "child": "/workspace/research/runs/coupling_patient1/epoch-007", + "donor": "/workspace/research/runs/phase_readout1/epoch-016", + "common_ancestor": "/workspace/research/runs/phase_coherence1/epoch-007", + "source_weight_sha256": { + "child": "f8466c6838ff01e54d1619f55668c1a4af26a243b54c67a956a3422d9604632a", + "donor": "ffd219d1480b81720b5aa4014cb2ed2b9cd31b7c92ad4717abc2a9625d30dc1a", + "ancestor": "e53ede409be523d8f4746251f7d46353621049f0378a88d4f7cfe2ba71a57d95" + }, + "changed_private_tensors": [ + "heads.openbmi.prior.projection.weight", + "heads.openbmi.prior.projection.bias" + ], + "all_ancestor_common_and_input_tensors_equal": true, + "all_child_common_and_input_tensors_unchanged": true, + "new_branch_gain_for_refreshed_track": 0.0, + "donor_changes_only_requested_private_projection": true, + "prediction_sources": { + "faced": { + "source": "/workspace/research/runs/coupling_patient1/faced-e007.npy", + "sha256": "68b617c8ecf347c79b23c20b70f6b4981c2f26b7b8c71dc7cd5fa0d7f4285ea6" + }, + "tuev": { + "source": "/workspace/research/runs/coupling_patient1/tuev-e007.npy", + "sha256": "9f0743450f1104d395e9daac0600aaf20755b5590b9f5c3e3137732c479dd647" + }, + "ad65": { + "source": "/workspace/research/runs/coupling_patient1/ad65-e007.npy", + "sha256": "7a3b74c58580b7ba952322bf6d527ebc9a40a6e04c7cdbbaea14e84a7a298d54" + }, + "openbmi": { + "source": "/workspace/research/runs/phase_readout1/openbmi-e016.npy", + "sha256": "14f630543e1df88c88d8f3e0effb4506ba33f533b3484de3c7aaf6554507341c" + }, + "longitudinal": { + "source": "/workspace/research/runs/coupling_patient1/longitudinal-e007.npy", + "sha256": "e93b0a319eaa3ddca9d71b0e786b808ba1630c1d3ce125f8e08036e517741b74" + } + } +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S085/short_context_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S085/short_context_features.py new file mode 100644 index 0000000000000000000000000000000000000000..f677f7a4319f4afb9071665bf7804558bfdd69d8 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S085/short_context_features.py @@ -0,0 +1,22 @@ +"""One/two-second fixed spectral descriptors with physical-frequency bands.""" +import torch +from features import EDGES,COV_BANDS +@torch.no_grad() +def short_spectral_features(track,x): + x=x.float().flatten(2) + x=torch.nan_to_num(x,nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + assert x.shape[-1] in (200,400) + x=x-x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + rms=x.square().mean(-1).clamp_min(1e-12).sqrt();norm=x/rms.unsqueeze(-1) + moments=torch.stack([rms.log(),norm.abs().amax(-1).clamp_min(1).log(),norm.pow(4).mean(-1).clamp_min(1).log(),(norm[...,1:]-norm[...,:-1]).square().mean(-1).clamp_min(1e-10).log()],-1) + n=x.shape[-1];frames=x.unfold(-1,n,n//2);frames=frames-frames.mean(-1,keepdim=True) + z=torch.fft.rfft(frames*torch.hann_window(n,device=x.device),dim=-1)/(n//2) + power=z.abs().square() + bands=torch.stack([power[...,n*lo//200:n*hi//200].mean(-1) for lo,hi in zip(EDGES[:-1],EDGES[1:])],-1) + lp=bands.mean(-2).clamp_min(1e-12).log();variation=bands.clamp_min(1e-12).log().std(-2,correction=0) + parts=[torch.cat([lp,lp-lp.mean(-1,keepdim=True),lp-lp.mean(1,keepdim=True),variation,moments],-1).flatten(1)] + ii,jj=torch.triu_indices(x.shape[1],x.shape[1],offset=1,device=x.device) + for lo,hi in COV_BANDS: + v=z[...,n*lo//200:n*hi//200].flatten(2);cov=v.real@v.real.transpose(-1,-2)+v.imag@v.imag.transpose(-1,-2);d=cov.diagonal(dim1=-2,dim2=-1).clamp_min(1e-12).sqrt();cor=cov/(d.unsqueeze(1)*d.unsqueeze(2)).clamp_min(1e-12);parts.append(cor[:,ii,jj].clamp(-1,1)) + return torch.nan_to_num(torch.cat(parts,-1)).clamp(-40,40) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S085/student_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S085/student_features.py new file mode 100644 index 0000000000000000000000000000000000000000..57401f6d2ab760cb1a58af564aef2e62290e8907 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S085/student_features.py @@ -0,0 +1,34 @@ +"""One audited CBraMod core with full-window shared and ordered representations.""" +import torch +from torch import nn +from braindecode.models import CBraMod +from frequency_features import frequency_components,FREQUENCY_BANDS +SPECS={'faced':(32,10,9),'tuev':(16,5,6),'ad65':(19,10,3),'openbmi':(62,4,2),'longitudinal':(58,2,2)} +TRACKS=tuple(SPECS) + +class FrequencyAdapter(nn.Module): + def __init__(self,channels,virtual_channels=32): + super().__init__();self.signal=nn.Conv1d(channels,virtual_channels,1,bias=False) + self.frequency_weight=nn.Parameter(torch.zeros(len(FREQUENCY_BANDS),virtual_channels,channels)) + def forward(self,x): + components=frequency_components(x) + correction=torch.einsum('blc,nbct->nlt',self.frequency_weight,components.to(self.frequency_weight.dtype)) + return self.signal(x)+correction.to(x.dtype) + +class CBraModFeatures(nn.Module): + def __init__(self,virtual_channels=32,token_width=64,summary_width=256,head_width=128,dropout=.3): + super().__init__();self.virtual_channels=virtual_channels;self.output_dim=summary_width+virtual_channels*token_width*4 + self.backbone=CBraMod(n_chans=virtual_channels,n_outputs=2,n_times=400,sfreq=200) + self.backbone.final_layer=nn.Identity() + self.token_projection=nn.Sequential(nn.LayerNorm(200),nn.Linear(200,token_width),nn.GELU()) + self.summary_projection=nn.Sequential(nn.LayerNorm(virtual_channels*token_width*2),nn.Linear(virtual_channels*token_width*2,summary_width),nn.GELU(),nn.Dropout(dropout)) + def forward(self,signal): + tokens=self.token_projection(self.backbone(signal)) + moments=torch.cat([tokens.mean(2),tokens.float().std(2,correction=0).to(tokens.dtype)],-1).flatten(1) + summary=self.summary_projection(moments) + ordered=torch.nn.functional.adaptive_avg_pool1d(tokens.permute(0,1,3,2).flatten(1,2),4).flatten(1) + return torch.cat([summary,ordered],-1) + + def named_shared_parameters(self): + for prefix,module in [('backbone',self.backbone),('token_projection',self.token_projection),('summary_projection',self.summary_projection)]: + for name,p in module.named_parameters():yield f'{prefix}.{name}',p diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/MODEL_CARD.md b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/MODEL_CARD.md new file mode 100644 index 0000000000000000000000000000000000000000..1cdca9c151ff13d9ac9e1b6279a07848ae7864b9 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/MODEL_CARD.md @@ -0,0 +1,49 @@ +# Shared EEG decoder + +This package contains one coupled backbone used by all five tracks, with private input adapters and classifiers. Every trainable common component was trained with all five training splits. It is a single model; inference performs no parameter updates or dataset-level fitting. + +The common backbone combines waveform convolutions, an audited pretrained BIOT feature path, covariance and log-correlation encoders, and shared feature corrections. The waveform coactivation extension encodes 64 within-window log variances and 2,016 correlations between common waveform channels. A matched experimental control removes the correlation inputs. `config.json` identifies the packaged variant and its five fixed correction gains. All original backbone parameters are fixed during this extension's joint training. + +Weights originate only from the supplied training data and audited initialization checkpoints. Training details, parent provenance, raw/cache checks, shared-gradient checks and the five separate validation metrics are recorded in `training.json`. Validation selects checkpoints and fixed gains; it does not fit normalization or update parameters. Reported validation results belong to selected checkpoints, not to private test evaluation or five-seed means. + +Run `bash infer.sh INPUT_DIR OUTPUT_DIR`. The input manifest specifies a track and opaque sample IDs, shard paths and indices. Signals are in microvolts and are scaled by 1/100. The package writes one probability vector per input ID to `OUTPUT_DIR/predictions.jsonl`. It needs only the packaged files and the contract's installed Python dependencies, works after relocation, and does not need labels, subject IDs, training caches or network access. + +FACED and TUEV use window balanced accuracy. AD65 uses mean window probabilities per patient before balanced accuracy. OpenBMI averages within-subject balanced accuracy. Longitudinal averages within-session balanced accuracy within each subject, then over subjects. These five metrics remain separate. + +This checkpoint adds fixed within-window ordinal pattern probabilities, permutation entropy and statistical complexity at five delays. Training-only normalization and five input projections feed one common correction MLP trained by all five tracks. The common correction enters the existing covariance and fusion representations; fixed per-track gains select its strength. All earlier model tensors remain unchanged. + +Fixed real and imaginary spectral coherence between the inherited 24 spatial filters is normalized using training windows only and encoded by one new common network. Five private linear heads add class evidence. All five training splits update the new common encoder; all earlier model tensors remain unchanged. + +Fixed per-window relative band powers, envelope variability, envelope correlations and phase-amplitude coupling feed training-normalized private input projections and one new shared encoder. Five linear heads add class evidence. All five training splits update the new common encoder; all prior model tensors remain unchanged. AD65 updates use all windows from six class-balanced training patients; objective: mean-probability. + +The inherited OpenBMI phase-classifier projection was refreshed from a separately validated private-readout fit. Every common tensor and input adapter of this jointly trained model is unchanged. Exact ancestor checks confirm that all common tensors used by this inherited readout are identical; the new cross-frequency correction remains disabled for OpenBMI. No shared checkpoints or predictions are ensembled. + +A common CBraMod feature encoder, itself jointly trained on all five training splits, supplies its shared summary and tokens pooled into four ordered time bins. Its classifiers are discarded. A new common feature MLP and five zero-initialized private linear projections learn residual class evidence jointly on all five training splits. Training may randomly remove the earlier decoder logits for half of training groups, using one mask per AD patient and one per other window; labels and teacher targets remain unchanged. Validation and inference always retain the complete earlier decoder. The same new class projection also receives an auxiliary standalone classification loss when configured, with the same patient-pooled AD objective; this adds no inference module. The complete earlier decoder and feature extractor remain tensor-identical; selecting zero residual gain preserves its predictions exactly. The summary-only control masks the 8192 ordered features after training-fitted per-feature normalization. One feature backbone and one classifier per track run at inference, with no prediction ensemble or external runtime cache. + +The five outer private student-feature class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. + +The longitudinal private outer projection is selected from another training-only readout fit using exactly the same common/input/prior-head tensors. All other private heads are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +The complete stronger parent is retained, including its common CBraMod feature encoder, common readout and all private classifiers. The CBraMod features and existing common128-dimensional embedding are computed once and reused. An additional common128-to256-to128 MLP with the configured GELU or identity activation and five zero-initialized private linear projections learn residual class evidence jointly on all five training splits. Training may randomly remove the earlier decoder logits for half of training groups, using one mask per AD patient and one per other window; labels and teacher targets remain unchanged. Validation and inference always retain the complete earlier decoder. The same new class projection also receives an auxiliary standalone classification loss when configured, with the same patient-pooled AD objective; this adds no inference module. The complete earlier decoder and feature extractor remain tensor-identical; selecting zero residual gain preserves its predictions exactly. One feature backbone and one classifier per track run at inference, with no prediction ensemble or external runtime cache. + +The five outer private student-feature class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. + +The openbmi private outer projection is selected from another training-only readout fit using exactly the same common/input/prior-head tensors. All other private heads are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +A fixed two-second crop supplies spectral and cross-frequency coupling features, with no short-window envelope autocorrelation. The crop is configured as center or first. Each track has a training-fitted normalizer and linear input adapter to128 dimensions; one common128-to256-to128 GELU/LayerNorm block and five zero-initialized class projections are jointly trained on all five training splits. All complete-parent tensors are preserved exactly. Normalization statistics use training windows only. The parent is randomly removed from the training loss at the configured probability; it is always present at inference. AD uses mean patient probabilities over all sampled patient windows. Auxiliary classification uses the same class projection. There is one composed feature backbone and head per track; no prediction ensemble, external runtime cache, test adaptation, or evaluation-metadata features. Zero residual gain exactly retains the complete parent. + +The five outer private center-context class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. + +The tuev private outer projection is selected from another training-only readout fit using exactly the same common/input/prior-head tensors. All other private heads are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +The faced private context input and outer class projections are selected from another training-only readout fit using exactly the same common/oldinput/normalizer/prior-head tensors. All other private input/head pairs are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +A fixed one-second crop supplies spectral and cross-frequency coupling features, with no short-window envelope autocorrelation. The crop is configured as center or first. Each track has a training-fitted normalizer and linear input adapter to128 dimensions; one common128-to256-to128 GELU/LayerNorm block and five zero-initialized class projections are jointly trained on all five training splits. All complete-parent tensors are preserved exactly. Normalization statistics use training windows only. The parent is randomly removed from the training loss at the configured probability; it is always present at inference. AD uses mean patient probabilities over all sampled patient windows. Auxiliary classification uses the same class projection. There is one composed feature backbone and head per track; no prediction ensemble, external runtime cache, test adaptation, or evaluation-metadata features. Zero residual gain exactly retains the complete parent. + +The five outer private short-context class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. + +The tuev private outer projection is selected from another training-only readout fit using exactly the same common/input/prior-head tensors. All other private heads are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +An additional common context block preserves every existing short-context parent tensor and correction. A fixed one-second crop supplies spectral and cross-frequency coupling features, with no short-window envelope autocorrelation. TUEV concatenates first and center one-second descriptors; the parameter-matched control repeats first descriptors. Other tracks use first one-second descriptors. Each track has a training-fitted normalizer and linear input adapter to128 dimensions; one common128-to256-to128 GELU/LayerNorm block and five zero-initialized class projections are jointly trained on all five training splits. All complete-parent tensors are preserved exactly. Normalization statistics use training windows only. The parent is randomly removed from the training loss at the configured probability; it is always present at inference. AD uses mean patient probabilities over all sampled patient windows. Auxiliary classification uses the same class projection. There is one composed feature backbone and head per track; no prediction ensemble, external runtime cache, test adaptation, or evaluation-metadata features. Zero residual gain exactly retains the complete parent. + +An additional shared128-to256-to128 GELU/LayerNorm block is jointly trained by all five tracks. OpenBMI uses seven native-channel trace-normalized covariance matrices with fixed5percent identity shrinkage: matrix-log upper triangles in the main arm, covariance-minus-identity in the matched control. Other four new inputs are first-one-second spectral/coupling descriptors. Every complete-parent tensor is preserved exactly. Input normalization uses training windows only; zero outer gain retains the parent. Five private adapters and class projections, one composed shared backbone, no evaluation adaptation or external runtime cache. diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/alpha_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/alpha_features.py new file mode 100644 index 0000000000000000000000000000000000000000..455154d715e86d45e4e17113bed69adbcd946b29 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/alpha_features.py @@ -0,0 +1,45 @@ +"""Fixed alpha prominence features from each individual two-second window.""" +import torch + +REGION_NAMES=('occipital','parietal','central','frontal','left_posterior','right_posterior') +REGIONS=(('PO7','PO5','PO3','POZ','PO4','PO6','PO8','O1','OZ','O2'), + ('P7','P5','P3','P1','PZ','P2','P4','P6','P8'), + ('FC5','FC3','FC1','FCZ','FC2','FC4','FC6','C5','C3','C1','CZ','C2','C4','C6'), + ('FP1','FPZ','FP2','AF3','AF4','F7','F5','F3','F1','FZ','F2','F4','F6','F8'), + ('P7','P5','P3','P1','PO7','PO5','PO3','O1'), + ('P2','P4','P6','P8','PO4','PO6','PO8','O2')) +ALPHA_DIM=58*7+6*22 + +def region_matrix(channels): + result=torch.zeros(len(REGIONS),len(channels)) + for i,names in enumerate(REGIONS): + for name in names:result[i,channels.index(name)]=1/len(names) + return result.tolist() + +@torch.no_grad() +def extract_alpha_features(signal,regions): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();x=x-x.mean(-1,keepdim=True) + spectrum=torch.fft.rfft(x*torch.hann_window(400,device=x.device),dim=-1)/200 + power=spectrum.abs().square().clamp_min(1e-12) + lp=power.log() + # Geometric regional means resist domination by one high-amplitude channel. + regional=torch.einsum('rc,ncf->nrf',regions.float(),lp) + lp=torch.cat([lp,regional],1) + low=lp[...,8:13].mean(-1,keepdim=True) + high=lp[...,36:49].mean(-1,keepdim=True) + freq=torch.arange(7.,14.5,.5,device=x.device) + alpha=lp[...,14:29] + baseline=low+(high-low)*((freq-5)/16) + prominence=alpha-baseline + normalized=alpha.softmax(-1) + center=(normalized*freq).sum(-1) + entropy=-(normalized*normalized.clamp_min(1e-12).log()).sum(-1) + alpha_mean=torch.logsumexp(alpha,-1)-torch.log(torch.tensor(15.,device=x.device)) + def log_band(lo,hi): + return torch.logsumexp(lp[...,lo:hi],-1)-torch.log(torch.tensor(float(hi-lo),device=x.device)) + summaries=torch.stack([alpha_mean-log_band(2,81),alpha_mean-log_band(8,14), + alpha_mean-log_band(30,61),prominence.max(-1).values, + prominence.mean(-1),center,entropy],-1) + return torch.cat([summaries[:,:58].flatten(1),summaries[:,58:].flatten(1), + prominence[:,58:].flatten(1)],1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/coupling_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/coupling_features.py new file mode 100644 index 0000000000000000000000000000000000000000..3a4e51bd7ce07bcec1f0f5b80054d6ff387ac87f --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/coupling_features.py @@ -0,0 +1,34 @@ +"""Per-window cross-frequency envelope and phase-amplitude relationships.""" +import torch +BANDS=((1,4),(4,8),(8,13),(13,30),(30,48)) +PAIRS=tuple((i,j) for i in range(5) for j in range(i+1,5)) +PER_CHANNEL=30 + +@torch.no_grad() +def coupling_features(track,x): + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + n=x.shape[-1];spectrum=torch.fft.fft(x,dim=-1);frequency=torch.fft.fftfreq(n,1/200,device=x.device) + masks=torch.stack([2*((frequency>=lo)&(frequency=lo)&(frequency=low)&(f(1e-10*reference).clamp_min(1e-20) + normalized=covariance/power.clamp_min(1e-20) + normalized=torch.where(active,normalized,eye) + matrix=.95*normalized+.05*eye + parts.append((matrix+matrix.transpose(-1,-2))*.5) + return torch.stack(parts,1) + +@torch.no_grad() +def connectivity(track,x,logarithmic=True): + matrix=band_matrices(track,x);c=matrix.shape[-1] + if logarithmic: + # CUDA eigh can perturb exactly degenerate identity eigenvalues. + # Preserve the mathematical log(I)=0 for exactly silent/isotropic bands. + nonidentity=(matrix-torch.eye(c,device=matrix.device)).abs().amax((-1,-2))>0 + values,vectors=torch.linalg.eigh(matrix) + matrix=(vectors*values.clamp_min(1e-6).log().unsqueeze(-2))@vectors.transpose(-1,-2) + matrix=torch.where(nonidentity[...,None,None],matrix,torch.zeros_like(matrix)) + else:matrix=matrix-torch.eye(c,device=matrix.device) + i,j=torch.triu_indices(c,c,device=matrix.device);scale=torch.where(i==j,1.,2.**.5) + return (matrix[...,i,j]*scale).flatten(1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/ordinal_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/ordinal_features.py new file mode 100644 index 0000000000000000000000000000000000000000..6e3d5ff8264253f058f71b04d9cc8454196592b1 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/ordinal_features.py @@ -0,0 +1,25 @@ +"""Fixed within-window ordinal dynamics, independent of amplitude scaling.""" +import math +import torch +LAGS=(1,2,4,8,16) +PATTERNS=24 +PER_CHANNEL=len(LAGS)*(PATTERNS+2) + +def ordinal_features(track,x): + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + parts=[];uniform=1/PATTERNS;maximum_entropy=math.log(PATTERNS);m0=(1+uniform)/2;mr=uniform/2;maximum_js=-m0*math.log(m0)-(PATTERNS-1)*mr*math.log(mr)-maximum_entropy/2 + for lag in LAGS: + length=x.shape[-1]-3*lag + if length<=0:raise ValueError('window too short for ordinal dynamics') + samples=torch.stack([x[...,i*lag:i*lag+length] for i in range(4)],-1) + order=samples.argsort(dim=-1,stable=True) + code=6*((order[...,0,None]>order[...,1:]).sum(-1))+2*((order[...,1,None]>order[...,2:]).sum(-1))+(order[...,2]>order[...,3]).long() + histogram=torch.zeros(*x.shape[:2],PATTERNS,device=x.device,dtype=torch.float32) + histogram.scatter_add_(-1,code,torch.ones_like(code,dtype=torch.float32));probability=histogram/length + entropy=-(probability*probability.clamp_min(1e-12).log()).sum(-1) + mixture=(probability+uniform)/2;mixture_entropy=-(mixture*mixture.log()).sum(-1) + complexity=((mixture_entropy-.5*entropy-.5*maximum_entropy)/maximum_js).clamp(0,1)*(entropy/maximum_entropy) + parts.append(torch.cat([probability,(entropy/maximum_entropy)[...,None],complexity[...,None]],-1)) + return torch.cat(parts,-1).flatten(1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/phase_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/phase_features.py new file mode 100644 index 0000000000000000000000000000000000000000..8d98822995bf37b499795dfd7e2e401040a01969 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/phase_features.py @@ -0,0 +1,37 @@ +"""Complex spectral coherence of the existing 24 spatial filters in ten bands.""" +import torch +from covariances import BANDS +CHANNELS=24 +PHASE_HALF=len(BANDS)*CHANNELS*(CHANNELS-1)//2 +PHASE_DIM=2*PHASE_HALF + +@torch.no_grad() +def phase_features(track,x,spatial_weight): + previous_tf32=torch.backends.cuda.matmul.allow_tf32 + try: + torch.backends.cuda.matmul.allow_tf32=False + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if track in ('faced','tuev'):x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + else:x=x-x.mean(1,keepdim=True) + x=x/x.square().mean((1,2),keepdim=True).clamp_min(1e-12).sqrt() + frames=x.unfold(-1,400,200);frames=frames-frames.mean(-1,keepdim=True) + z=torch.fft.rfft(frames*torch.hann_window(400,device=x.device),dim=-1)/200 + w=spatial_weight.float()/spatial_weight.float().norm(dim=-1,keepdim=True).clamp_min(1e-6) + index=torch.triu_indices(CHANNELS,CHANNELS,1,device=x.device) + real_parts=[];imaginary_parts=[] + for band,(lo,hi) in enumerate(BANDS): + v=z[...,2*lo:2*hi].flatten(2) + vr=w[band][None]@v.real;vi=w[band][None]@v.imag + real=(vr@vr.transpose(-1,-2)+vi@vi.transpose(-1,-2))/v.shape[-1] + imaginary=(vi@vr.transpose(-1,-2)-vr@vi.transpose(-1,-2))/v.shape[-1] + # Signals have unit global RMS; this floor suppresses phase of numerical silence. + power=real.diagonal(dim1=-2,dim2=-1).clamp_min(1e-6) + denominator=(power[:,:,None]*power[:,None,:]).sqrt().clamp_min(1e-12) + real=(real/denominator).clamp(-.999,.999) + imaginary=(imaginary/denominator).clamp(-.999,.999) + real_parts.append(torch.atanh(real[:,index[0],index[1]])) + imaginary_parts.append(torch.atanh(imaginary[:,index[0],index[1]])) + return torch.cat(real_parts+imaginary_parts,-1) + finally:torch.backends.cuda.matmul.allow_tf32=previous_tf32 diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/private-readout-refresh-audit.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/private-readout-refresh-audit.json new file mode 100644 index 0000000000000000000000000000000000000000..1d02ef9e4aa8d0782c67157b160ef5667bfa1193 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/private-readout-refresh-audit.json @@ -0,0 +1,40 @@ +{ + "child": "/workspace/research/runs/coupling_patient1/epoch-007", + "donor": "/workspace/research/runs/phase_readout1/epoch-016", + "common_ancestor": "/workspace/research/runs/phase_coherence1/epoch-007", + "source_weight_sha256": { + "child": "f8466c6838ff01e54d1619f55668c1a4af26a243b54c67a956a3422d9604632a", + "donor": "ffd219d1480b81720b5aa4014cb2ed2b9cd31b7c92ad4717abc2a9625d30dc1a", + "ancestor": "e53ede409be523d8f4746251f7d46353621049f0378a88d4f7cfe2ba71a57d95" + }, + "changed_private_tensors": [ + "heads.openbmi.prior.projection.weight", + "heads.openbmi.prior.projection.bias" + ], + "all_ancestor_common_and_input_tensors_equal": true, + "all_child_common_and_input_tensors_unchanged": true, + "new_branch_gain_for_refreshed_track": 0.0, + "donor_changes_only_requested_private_projection": true, + "prediction_sources": { + "faced": { + "source": "/workspace/research/runs/coupling_patient1/faced-e007.npy", + "sha256": "68b617c8ecf347c79b23c20b70f6b4981c2f26b7b8c71dc7cd5fa0d7f4285ea6" + }, + "tuev": { + "source": "/workspace/research/runs/coupling_patient1/tuev-e007.npy", + "sha256": "9f0743450f1104d395e9daac0600aaf20755b5590b9f5c3e3137732c479dd647" + }, + "ad65": { + "source": "/workspace/research/runs/coupling_patient1/ad65-e007.npy", + "sha256": "7a3b74c58580b7ba952322bf6d527ebc9a40a6e04c7cdbbaea14e84a7a298d54" + }, + "openbmi": { + "source": "/workspace/research/runs/phase_readout1/openbmi-e016.npy", + "sha256": "14f630543e1df88c88d8f3e0effb4506ba33f533b3484de3c7aaf6554507341c" + }, + "longitudinal": { + "source": "/workspace/research/runs/coupling_patient1/longitudinal-e007.npy", + "sha256": "e93b0a319eaa3ddca9d71b0e786b808ba1630c1d3ce125f8e08036e517741b74" + } + } +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/short_context_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/short_context_features.py new file mode 100644 index 0000000000000000000000000000000000000000..f677f7a4319f4afb9071665bf7804558bfdd69d8 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/short_context_features.py @@ -0,0 +1,22 @@ +"""One/two-second fixed spectral descriptors with physical-frequency bands.""" +import torch +from features import EDGES,COV_BANDS +@torch.no_grad() +def short_spectral_features(track,x): + x=x.float().flatten(2) + x=torch.nan_to_num(x,nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + assert x.shape[-1] in (200,400) + x=x-x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + rms=x.square().mean(-1).clamp_min(1e-12).sqrt();norm=x/rms.unsqueeze(-1) + moments=torch.stack([rms.log(),norm.abs().amax(-1).clamp_min(1).log(),norm.pow(4).mean(-1).clamp_min(1).log(),(norm[...,1:]-norm[...,:-1]).square().mean(-1).clamp_min(1e-10).log()],-1) + n=x.shape[-1];frames=x.unfold(-1,n,n//2);frames=frames-frames.mean(-1,keepdim=True) + z=torch.fft.rfft(frames*torch.hann_window(n,device=x.device),dim=-1)/(n//2) + power=z.abs().square() + bands=torch.stack([power[...,n*lo//200:n*hi//200].mean(-1) for lo,hi in zip(EDGES[:-1],EDGES[1:])],-1) + lp=bands.mean(-2).clamp_min(1e-12).log();variation=bands.clamp_min(1e-12).log().std(-2,correction=0) + parts=[torch.cat([lp,lp-lp.mean(-1,keepdim=True),lp-lp.mean(1,keepdim=True),variation,moments],-1).flatten(1)] + ii,jj=torch.triu_indices(x.shape[1],x.shape[1],offset=1,device=x.device) + for lo,hi in COV_BANDS: + v=z[...,n*lo//200:n*hi//200].flatten(2);cov=v.real@v.real.transpose(-1,-2)+v.imag@v.imag.transpose(-1,-2);d=cov.diagonal(dim1=-2,dim2=-1).clamp_min(1e-12).sqrt();cor=cov/(d.unsqueeze(1)*d.unsqueeze(2)).clamp_min(1e-12);parts.append(cor[:,ii,jj].clamp(-1,1)) + return torch.nan_to_num(torch.cat(parts,-1)).clamp(-40,40) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/student_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/student_features.py new file mode 100644 index 0000000000000000000000000000000000000000..57401f6d2ab760cb1a58af564aef2e62290e8907 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/student_features.py @@ -0,0 +1,34 @@ +"""One audited CBraMod core with full-window shared and ordered representations.""" +import torch +from torch import nn +from braindecode.models import CBraMod +from frequency_features import frequency_components,FREQUENCY_BANDS +SPECS={'faced':(32,10,9),'tuev':(16,5,6),'ad65':(19,10,3),'openbmi':(62,4,2),'longitudinal':(58,2,2)} +TRACKS=tuple(SPECS) + +class FrequencyAdapter(nn.Module): + def __init__(self,channels,virtual_channels=32): + super().__init__();self.signal=nn.Conv1d(channels,virtual_channels,1,bias=False) + self.frequency_weight=nn.Parameter(torch.zeros(len(FREQUENCY_BANDS),virtual_channels,channels)) + def forward(self,x): + components=frequency_components(x) + correction=torch.einsum('blc,nbct->nlt',self.frequency_weight,components.to(self.frequency_weight.dtype)) + return self.signal(x)+correction.to(x.dtype) + +class CBraModFeatures(nn.Module): + def __init__(self,virtual_channels=32,token_width=64,summary_width=256,head_width=128,dropout=.3): + super().__init__();self.virtual_channels=virtual_channels;self.output_dim=summary_width+virtual_channels*token_width*4 + self.backbone=CBraMod(n_chans=virtual_channels,n_outputs=2,n_times=400,sfreq=200) + self.backbone.final_layer=nn.Identity() + self.token_projection=nn.Sequential(nn.LayerNorm(200),nn.Linear(200,token_width),nn.GELU()) + self.summary_projection=nn.Sequential(nn.LayerNorm(virtual_channels*token_width*2),nn.Linear(virtual_channels*token_width*2,summary_width),nn.GELU(),nn.Dropout(dropout)) + def forward(self,signal): + tokens=self.token_projection(self.backbone(signal)) + moments=torch.cat([tokens.mean(2),tokens.float().std(2,correction=0).to(tokens.dtype)],-1).flatten(1) + summary=self.summary_projection(moments) + ordered=torch.nn.functional.adaptive_avg_pool1d(tokens.permute(0,1,3,2).flatten(1,2),4).flatten(1) + return torch.cat([summary,ordered],-1) + + def named_shared_parameters(self): + for prefix,module in [('backbone',self.backbone),('token_projection',self.token_projection),('summary_projection',self.summary_projection)]: + for name,p in module.named_parameters():yield f'{prefix}.{name}',p diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/tangent_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/tangent_features.py new file mode 100644 index 0000000000000000000000000000000000000000..314f0cf2f58e4b4a1c1d808edbd4acc3b7b6f85b --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S092/tangent_features.py @@ -0,0 +1,25 @@ +"""Window-local log-correlation geometry in the existing spatial-filter basis.""" +import torch + +TANGENT_DIM=10*24*25//2 + +@torch.no_grad() +def extract_tangent_features(covariances,spatial_weight): + old_tf32=torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(covariances.device.type,enabled=False): + w=spatial_weight.float() + w=w/w.norm(dim=-1,keepdim=True).clamp_min(1e-6) + projected=torch.einsum('bfc,nbcd,bgd->nbfg',w,covariances.float(),w) + d=projected.diagonal(dim1=-2,dim2=-1).clamp_min(1e-10).sqrt() + correlation=(projected/(d.unsqueeze(-1)*d.unsqueeze(-2))).clamp(-1,1) + correlation=(correlation+correlation.transpose(-1,-2))/2 + correlation=.95*correlation+.05*torch.eye(24,device=correlation.device) + values,vectors=torch.linalg.eigh(correlation) + logarithm=(vectors*values.clamp_min(1e-6).log().unsqueeze(-2))@vectors.transpose(-1,-2) + i,j=torch.triu_indices(24,24,device=correlation.device) + scale=torch.where(i==j,1.,2.**.5) + return (logarithm[...,i,j]*scale).flatten(1) + finally: + torch.backends.cuda.matmul.allow_tf32=old_tf32 diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/MODEL_CARD.md b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/MODEL_CARD.md new file mode 100644 index 0000000000000000000000000000000000000000..8f794bc25c1ca10577991d64c2252ed95e58a6d4 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/MODEL_CARD.md @@ -0,0 +1,63 @@ +# Shared EEG decoder + +This package contains one coupled backbone used by all five tracks, with private input adapters and classifiers. Every trainable common component was trained with all five training splits. It is a single model; inference performs no parameter updates or dataset-level fitting. + +The common backbone combines waveform convolutions, an audited pretrained BIOT feature path, covariance and log-correlation encoders, and shared feature corrections. The waveform coactivation extension encodes 64 within-window log variances and 2,016 correlations between common waveform channels. A matched experimental control removes the correlation inputs. `config.json` identifies the packaged variant and its five fixed correction gains. All original backbone parameters are fixed during this extension's joint training. + +Weights originate only from the supplied training data and audited initialization checkpoints. Training details, parent provenance, raw/cache checks, shared-gradient checks and the five separate validation metrics are recorded in `training.json`. Validation selects checkpoints and fixed gains; it does not fit normalization or update parameters. Reported validation results belong to selected checkpoints, not to private test evaluation or five-seed means. + +Run `bash infer.sh INPUT_DIR OUTPUT_DIR`. The input manifest specifies a track and opaque sample IDs, shard paths and indices. Signals are in microvolts and are scaled by 1/100. The package writes one probability vector per input ID to `OUTPUT_DIR/predictions.jsonl`. It needs only the packaged files and the contract's installed Python dependencies, works after relocation, and does not need labels, subject IDs, training caches or network access. + +FACED and TUEV use window balanced accuracy. AD65 uses mean window probabilities per patient before balanced accuracy. OpenBMI averages within-subject balanced accuracy. Longitudinal averages within-session balanced accuracy within each subject, then over subjects. These five metrics remain separate. + +This checkpoint adds fixed within-window ordinal pattern probabilities, permutation entropy and statistical complexity at five delays. Training-only normalization and five input projections feed one common correction MLP trained by all five tracks. The common correction enters the existing covariance and fusion representations; fixed per-track gains select its strength. All earlier model tensors remain unchanged. + +Fixed real and imaginary spectral coherence between the inherited 24 spatial filters is normalized using training windows only and encoded by one new common network. Five private linear heads add class evidence. All five training splits update the new common encoder; all earlier model tensors remain unchanged. + +Fixed per-window relative band powers, envelope variability, envelope correlations and phase-amplitude coupling feed training-normalized private input projections and one new shared encoder. Five linear heads add class evidence. All five training splits update the new common encoder; all prior model tensors remain unchanged. AD65 updates use all windows from six class-balanced training patients; objective: mean-probability. + +The inherited OpenBMI phase-classifier projection was refreshed from a separately validated private-readout fit. Every common tensor and input adapter of this jointly trained model is unchanged. Exact ancestor checks confirm that all common tensors used by this inherited readout are identical; the new cross-frequency correction remains disabled for OpenBMI. No shared checkpoints or predictions are ensembled. + +A common CBraMod feature encoder, itself jointly trained on all five training splits, supplies its shared summary and tokens pooled into four ordered time bins. Its classifiers are discarded. A new common feature MLP and five zero-initialized private linear projections learn residual class evidence jointly on all five training splits. Training may randomly remove the earlier decoder logits for half of training groups, using one mask per AD patient and one per other window; labels and teacher targets remain unchanged. Validation and inference always retain the complete earlier decoder. The same new class projection also receives an auxiliary standalone classification loss when configured, with the same patient-pooled AD objective; this adds no inference module. The complete earlier decoder and feature extractor remain tensor-identical; selecting zero residual gain preserves its predictions exactly. The summary-only control masks the 8192 ordered features after training-fitted per-feature normalization. One feature backbone and one classifier per track run at inference, with no prediction ensemble or external runtime cache. + +The five outer private student-feature class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. + +The longitudinal private outer projection is selected from another training-only readout fit using exactly the same common/input/prior-head tensors. All other private heads are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +The complete stronger parent is retained, including its common CBraMod feature encoder, common readout and all private classifiers. The CBraMod features and existing common128-dimensional embedding are computed once and reused. An additional common128-to256-to128 MLP with the configured GELU or identity activation and five zero-initialized private linear projections learn residual class evidence jointly on all five training splits. Training may randomly remove the earlier decoder logits for half of training groups, using one mask per AD patient and one per other window; labels and teacher targets remain unchanged. Validation and inference always retain the complete earlier decoder. The same new class projection also receives an auxiliary standalone classification loss when configured, with the same patient-pooled AD objective; this adds no inference module. The complete earlier decoder and feature extractor remain tensor-identical; selecting zero residual gain preserves its predictions exactly. One feature backbone and one classifier per track run at inference, with no prediction ensemble or external runtime cache. + +The five outer private student-feature class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. + +The openbmi private outer projection is selected from another training-only readout fit using exactly the same common/input/prior-head tensors. All other private heads are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +A fixed two-second crop supplies spectral and cross-frequency coupling features, with no short-window envelope autocorrelation. The crop is configured as center or first. Each track has a training-fitted normalizer and linear input adapter to128 dimensions; one common128-to256-to128 GELU/LayerNorm block and five zero-initialized class projections are jointly trained on all five training splits. All complete-parent tensors are preserved exactly. Normalization statistics use training windows only. The parent is randomly removed from the training loss at the configured probability; it is always present at inference. AD uses mean patient probabilities over all sampled patient windows. Auxiliary classification uses the same class projection. There is one composed feature backbone and head per track; no prediction ensemble, external runtime cache, test adaptation, or evaluation-metadata features. Zero residual gain exactly retains the complete parent. + +The five outer private center-context class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. + +The tuev private outer projection is selected from another training-only readout fit using exactly the same common/input/prior-head tensors. All other private heads are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +The faced private context input and outer class projections are selected from another training-only readout fit using exactly the same common/oldinput/normalizer/prior-head tensors. All other private input/head pairs are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +A fixed one-second crop supplies spectral and cross-frequency coupling features, with no short-window envelope autocorrelation. The crop is configured as center or first. Each track has a training-fitted normalizer and linear input adapter to128 dimensions; one common128-to256-to128 GELU/LayerNorm block and five zero-initialized class projections are jointly trained on all five training splits. All complete-parent tensors are preserved exactly. Normalization statistics use training windows only. The parent is randomly removed from the training loss at the configured probability; it is always present at inference. AD uses mean patient probabilities over all sampled patient windows. Auxiliary classification uses the same class projection. There is one composed feature backbone and head per track; no prediction ensemble, external runtime cache, test adaptation, or evaluation-metadata features. Zero residual gain exactly retains the complete parent. + +The five outer private short-context class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. + +The tuev private outer projection is selected from another training-only readout fit using exactly the same common/input/prior-head tensors. All other private heads are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +An additional common context block preserves every existing short-context parent tensor and correction. A fixed one-second crop supplies spectral and cross-frequency coupling features, with no short-window envelope autocorrelation. TUEV concatenates first and center one-second descriptors; the parameter-matched control repeats first descriptors. Other tracks use first one-second descriptors. Each track has a training-fitted normalizer and linear input adapter to128 dimensions; one common128-to256-to128 GELU/LayerNorm block and five zero-initialized class projections are jointly trained on all five training splits. All complete-parent tensors are preserved exactly. Normalization statistics use training windows only. The parent is randomly removed from the training loss at the configured probability; it is always present at inference. AD uses mean patient probabilities over all sampled patient windows. Auxiliary classification uses the same class projection. There is one composed feature backbone and head per track; no prediction ensemble, external runtime cache, test adaptation, or evaluation-metadata features. Zero residual gain exactly retains the complete parent. + +An additional shared128-to256-to128 GELU/LayerNorm block is jointly trained by all five tracks. OpenBMI uses seven native-channel trace-normalized covariance matrices with fixed5percent identity shrinkage: matrix-log upper triangles in the main arm, covariance-minus-identity in the matched control. Other four new inputs are first-one-second spectral/coupling descriptors. Every complete-parent tensor is preserved exactly. Input normalization uses training windows only; zero outer gain retains the parent. Five private adapters and class projections, one composed shared backbone, no evaluation adaptation or external runtime cache. + +The five outer private geometry-block input adapters and class projections are refined on all five training splits. Every common backbone, fitted normalizer and earlier input/prior-head tensor remains exactly fixed. Common parameters are excluded from optimization; differentiable evaluation of the fixed common block permits gradients to the private input maps. AD uses the exact patient-mean probability objective. Private input/head checkpoints may be selected independently only because the common parameter state is identical and every track uses its own private adapter/head; all five metrics are evaluated for every exported package. + +An additional shared128-to256-to128 GELU/LayerNorm block is jointly trained by all five tracks. FACED uses seven native-channel trace-normalized covariance matrices with fixed5percent identity shrinkage: matrix-log upper triangles in the main arm, covariance-minus-identity in the matched control. Other four new inputs are first-one-second spectral/coupling descriptors. Every complete-parent tensor is preserved exactly. Input normalization uses training windows only; zero outer gain retains the parent. Five private adapters and class projections, one composed shared backbone, no evaluation adaptation or external runtime cache. + +The longitudinal private context input and outer class projections are selected from another training-only readout fit using exactly the same common/oldinput/normalizer/prior-head tensors. All other private input/head pairs are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +An additional shared128-to256-to128 gelu/LayerNorm block is jointly trained by all five tracks. FACED uses seven native-channel trace-normalized covariance matrices with fixed5percent identity shrinkage and matrix-log upper triangles in both activation conditions. Other four new inputs are first-one-second spectral/coupling descriptors. Every complete-parent tensor is preserved exactly. Input normalization uses training windows only; zero outer gain retains the parent. Five private adapters and class projections, one composed shared backbone, no evaluation adaptation or external runtime cache. + +The five outer private refinement-block input adapters and class projections are refined on all five training splits. Every common backbone, fitted normalizer and earlier input/prior-head tensor remains exactly fixed. Common parameters are excluded from optimization; differentiable evaluation of the fixed common block permits gradients to the private input maps. AD uses the exact patient-mean probability objective. Private input/head checkpoints may be selected independently only because the common parameter state is identical and every track uses its own private adapter/head; all five metrics are evaluated for every exported package. + +The five outer private refinement-block input adapters and class projections are refined on all five training splits. Every common backbone, fitted normalizer and earlier input/prior-head tensor remains exactly fixed. Common parameters are excluded from optimization; differentiable evaluation of the fixed common block permits gradients to the private input maps. AD uses the exact patient-mean probability objective. Private input/head checkpoints may be selected independently only because the common parameter state is identical and every track uses its own private adapter/head; all five metrics are evaluated for every exported package. + +An additional shared128-to256-to128 gelu/LayerNorm block is jointly trained by all five tracks. OpenBMI uses full-window spectral and cross-frequency features from six central/parietal local differences or the matched six native channels under common-average reference. FACED retains native log covariance descriptors; TUEV/AD65/Longitudinal retain first1s descriptors. Both conditions have identical parameter dimensions. Every complete-parent tensor is preserved exactly. Input normalization uses training windows only; zero outer gain retains the parent. Five private adapters and class projections, one composed shared backbone, no evaluation adaptation or external runtime cache. diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/alpha_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/alpha_features.py new file mode 100644 index 0000000000000000000000000000000000000000..455154d715e86d45e4e17113bed69adbcd946b29 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/alpha_features.py @@ -0,0 +1,45 @@ +"""Fixed alpha prominence features from each individual two-second window.""" +import torch + +REGION_NAMES=('occipital','parietal','central','frontal','left_posterior','right_posterior') +REGIONS=(('PO7','PO5','PO3','POZ','PO4','PO6','PO8','O1','OZ','O2'), + ('P7','P5','P3','P1','PZ','P2','P4','P6','P8'), + ('FC5','FC3','FC1','FCZ','FC2','FC4','FC6','C5','C3','C1','CZ','C2','C4','C6'), + ('FP1','FPZ','FP2','AF3','AF4','F7','F5','F3','F1','FZ','F2','F4','F6','F8'), + ('P7','P5','P3','P1','PO7','PO5','PO3','O1'), + ('P2','P4','P6','P8','PO4','PO6','PO8','O2')) +ALPHA_DIM=58*7+6*22 + +def region_matrix(channels): + result=torch.zeros(len(REGIONS),len(channels)) + for i,names in enumerate(REGIONS): + for name in names:result[i,channels.index(name)]=1/len(names) + return result.tolist() + +@torch.no_grad() +def extract_alpha_features(signal,regions): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();x=x-x.mean(-1,keepdim=True) + spectrum=torch.fft.rfft(x*torch.hann_window(400,device=x.device),dim=-1)/200 + power=spectrum.abs().square().clamp_min(1e-12) + lp=power.log() + # Geometric regional means resist domination by one high-amplitude channel. + regional=torch.einsum('rc,ncf->nrf',regions.float(),lp) + lp=torch.cat([lp,regional],1) + low=lp[...,8:13].mean(-1,keepdim=True) + high=lp[...,36:49].mean(-1,keepdim=True) + freq=torch.arange(7.,14.5,.5,device=x.device) + alpha=lp[...,14:29] + baseline=low+(high-low)*((freq-5)/16) + prominence=alpha-baseline + normalized=alpha.softmax(-1) + center=(normalized*freq).sum(-1) + entropy=-(normalized*normalized.clamp_min(1e-12).log()).sum(-1) + alpha_mean=torch.logsumexp(alpha,-1)-torch.log(torch.tensor(15.,device=x.device)) + def log_band(lo,hi): + return torch.logsumexp(lp[...,lo:hi],-1)-torch.log(torch.tensor(float(hi-lo),device=x.device)) + summaries=torch.stack([alpha_mean-log_band(2,81),alpha_mean-log_band(8,14), + alpha_mean-log_band(30,61),prominence.max(-1).values, + prominence.mean(-1),center,entropy],-1) + return torch.cat([summaries[:,:58].flatten(1),summaries[:,58:].flatten(1), + prominence[:,58:].flatten(1)],1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/config.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/config.json new file mode 100644 index 0000000000000000000000000000000000000000..42104bed77ae73d0af0b95d85bf2ab829e2f96f2 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/config.json @@ -0,0 +1,1152 @@ +{ + "schema": "bci-shared-biot-covariance-bf16head-v1", + "architecture": { + "channels": 32, + "width": 128, + "depth": 2, + "dropout": 0.5, + "wave_filters": 32, + "head_width": 64, + "head_dropout": 0.3, + "clinical_asymmetry": true, + "alpha_regions": [ + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612, + 0.10000000149011612 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.1111111119389534, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0714285746216774, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.0, + 0.0, + 0.125, + 0.125, + 0.125, + 0.0, + 0.0, + 0.125 + ] + ], + "clinical_envelope": true, + "temporal_pool": true, + "temporal_evidence": true, + "evidence_temperature": 0.25, + "random_fourier": true, + "fourier_features": 256, + "tangent_readout": true, + "shared_context_correction": true, + "wave_coactivation": true, + "ordinal_context": true, + "phase_coherence": true, + "cross_frequency": true, + "cbramod_feature_transfer": true, + "student_architecture": { + "virtual_channels": 32, + "token_width": 64, + "summary_width": 256, + "head_width": 128, + "dropout": 0.3 + }, + "student_extension": true, + "post_embedding_extension": true, + "extension_activation": "identity", + "center_context_extension": true, + "context_crop": "center", + "short_context_extension": true, + "short_crop": "first", + "dual_context_extension": true, + "dual_crop": "clinical-dual", + "geometry_extension": true, + "geometry_mode": "mi-linear", + "emotion_extension": true, + "emotion_mode": "faced-log", + "refinement_extension": true, + "refinement_mode": "faced-log", + "spatial_extension": true, + "spatial_mode": "native" + }, + "initialization": { + "initialization": "continue joint training from a complete shared-model checkpoint", + "parent": "/workspace/research/runs/hybrid_biot_fusionshrink0100/epoch-001/weights.pt", + "parent_initialization": { + "initialization": "jointly trained parent plus audited pretrained BIOT in a single coupled backbone", + "parent": "/workspace/research/runs/hybrid_wide1/epoch-004/weights.pt", + "audited_biot": { + "initialization": "pretrained", + "repo": "braindecode/biot-pretrained-six-datasets-18chs", + "revision": "7e9aabf302870012f73773276803aab97993951c", + "sha256": "a218f4054ae29962c6fd9d23d94c446d354c4f53e805a6771c85749ccc20baaa", + "license": "BSD-3-Clause", + "source_braindecode": "1.3.0", + "loaded_core_tensors": 56, + "skipped_classifier_tensors": 3 + }, + "neural_channel_indices": { + "faced": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "tuev": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15 + ], + "ad65": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ], + "openbmi": [ + 0, + 1, + 3, + 5, + 12, + 14, + 23, + 25, + 28, + 30, + 2, + 6, + 11, + 15, + 22, + 26, + 4, + 13 + ], + "longitudinal": [ + 0, + 2, + 7, + 11, + 23, + 27, + 41, + 45, + 55, + 57, + 5, + 13, + 21, + 29, + 39, + 47, + 9, + 25 + ] + }, + "rebase": "incumbent waveform, fusion and four heads; joint BIOT and TUEV head from readout epoch 9; zero initialized neural interaction", + "jointly_finetuned_neural_parent": "/workspace/research/runs/hybrid_biot_readout1/epoch-009/weights.pt", + "tuev_high_dimensional_spectral_projection_disabled": true, + "frozen_prior_representation": true, + "nonclinical_head_updates": "only the 256 added BIOT columns; original columns and biases fixed", + "faced_openbmi_neural_path": "common nonlinear fusion only; direct head columns masked", + "retention_teacher": "/workspace/research/runs/hybrid_wide1/epoch-004", + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "joint_covariance_parent": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "frozen_prior_representation": true, + "head_updates": "one linear head per track; added 128 shared covariance columns trainable; AD head initialized from the joint covariance parent", + "new_shared_representation": "one common covariance MLP inside the coupled backbone, trained by all five tasks; fixed spatial input adapters from the same jointly trained source", + "head_arithmetic": "one linear head evaluated in fixed feature blocks to preserve original bfloat16 accumulation dimensions", + "retention_teacher": { + "ad65": "/workspace/research/runs/filterbank1/epoch-002/weights.pt", + "other_tracks": "/workspace/research/runs/hybrid_wide1/epoch-004" + }, + "retention_loss": { + "split": "train", + "temperature": 2.0, + "kl_weight": 1.0, + "tracks": [ + "faced", + "ad65", + "openbmi", + "longitudinal" + ] + } + }, + "loader_scale": 0.01, + "tracks": [ + "faced", + "tuev", + "ad65", + "openbmi", + "longitudinal" + ], + "head_arithmetic": "same linear head in fixed feature blocks, sum in bfloat16 on GPU for non-AD tracks; AD remains float32", + "head_refinement": { + "source": "/workspace/research/runs/residual_heads1/epoch-018", + "source_weights_sha256": "e0b609137391b47f99438ccadaa22fc0bc10d2c10ead0ddf0a3c25be2c907c85", + "shared_backbone_unchanged": true, + "selected_head_epochs": { + "faced": 5, + "tuev": 24, + "ad65": 0, + "openbmi": 0, + "longitudinal": 0 + } + }, + "clinical_spectral_refinement": { + "source": "/workspace/research/runs/head_dropout1/epoch-016", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "head_estimation": { + "method": "class/subject-balanced Gaussian linear discriminant; covariance augmented by class-conditional subject/session mean variation before shrinkage", + "selected_shrinkage": { + "faced": "inherited", + "tuev": "inherited", + "ad65": "inherited", + "openbmi": "inherited", + "longitudinal": { + "shrinkage": 0.9, + "domain_strength": 1.0 + } + }, + "feature_scaling": "fitted on training data and folded into linear coefficients" + }, + "clinical_asymmetry_refinement": { + "source": "/workspace/research/runs/domain_lda_heads1/epoch-001", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "alpha_rhythm_adapter": { + "training_normalization_only": true, + "regions": [ + "occipital", + "parietal", + "central", + "frontal", + "left_posterior", + "right_posterior" + ], + "features": "per-window alpha prominence relative to adjacent frequencies", + "shared_backbone_unchanged": true + }, + "clinical_envelope_refinement": { + "source": "/workspace/research/runs/clinical_asymmetry1/epoch-001", + "zero_initialized_input_adapter": true, + "backbone_unchanged": true + }, + "independent_adapter_merge": { + "alpha_source": "/workspace/research/runs/alpha_calibrated1/epoch-003", + "clinical_source": "/workspace/research/runs/clinical_envelope1/epoch-002", + "all_shared_and_head_tensors_equal": true + }, + "frequency_montage_refinement": { + "six_frequency_bands": true, + "shared_encoder_unchanged": true, + "selected_track_epochs": { + "faced": 0, + "tuev": 1, + "ad65": 0, + "openbmi": 10, + "longitudinal": 2 + } + }, + "private_track_selection": { + "track": "tuev", + "donor": "/workspace/research/replicates/frequency_head_control1/epoch-001" + }, + "clinical_sampling_refinement": { + "subject_exponent": 0.0, + "class_balanced": true, + "only_clinical_head_updated": true + }, + "temporal_statistics_readout": { + "statistics": [ + "mean", + "standard deviation", + "maximum", + "minimum" + ], + "shared_encoder_and_prior_heads_unchanged": true, + "selected_pool_epochs": { + "faced": 2, + "tuev": 0, + "ad65": 0, + "openbmi": 33, + "longitudinal": 3 + } + }, + "temporal_evidence_readout": { + "pooling": "log mean exp of per-patch class evidence", + "temperature": 0.25, + "shared_encoder_and_prior_heads_unchanged": true, + "selected_evidence_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 6, + "longitudinal": 8 + } + }, + "fourier_basis_readout": { + "basis_functions": 256, + "bandwidths": [ + 0.5, + 1.0, + 2.0 + ], + "shared_encoder_and_prior_heads_unchanged": true, + "selected_fourier_epochs": { + "faced": 21, + "tuev": 0, + "ad65": 0, + "openbmi": 0, + "longitudinal": 2 + } + }, + "shared_tangent_readout": { + "one_shared_tangent_module": true, + "original_and_corrected_shared_features_retained": true, + "private_head_scalar_gains": { + "faced": 0.0, + "tuev": 0.1, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 0.1 + }, + "all_common_weights_fixed_during_gain_refinement": true + }, + "shared_context_correction": { + "source": "/workspace/research/runs/hybrid_codebrain_fusion_control1/epoch-002", + "zero_token_input_preserved": true, + "unused_native_CodeBrain_core_and_input_parameters_removed": true, + "common_patch_and_context_layers_retained": true, + "same_one_shared_backbone_and_five_classifiers": true + }, + "shared_wave_coactivation": { + "channels": 64, + "statistics": 2080, + "diagonal_only_control": false, + "common_encoder_updated_by_all_five_tracks": true, + "gain_selection_within_one_common_checkpoint": { + "faced": 1.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 1.0 + } + }, + "fixed_common_coactivation_readouts": { + "all_common_weights_exactly_unchanged": true, + "selected_private_epochs": { + "faced": 25, + "tuev": 0, + "ad65": 0, + "openbmi": 8, + "longitudinal": 2 + } + }, + "shared_ordinal_context": { + "per_channel_features": 130, + "normalization_fit_on_training_only": true, + "entropy_only_control": false, + "new_common_layers_trained_on_all_five_tracks": true, + "gains_within_one_common_checkpoint": { + "faced": 1.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 0.0 + } + }, + "shared_complex_coherence": { + "features": 5520, + "normalization_fit_on_training_only": true, + "real_only_control": false, + "all_five_tracks_update_common_encoder": true, + "gains_within_one_common_checkpoint": { + "faced": 0.1, + "tuev": 1.0, + "ad65": 0.0, + "openbmi": 0.3, + "longitudinal": 0.0 + } + }, + "shared_cross_frequency": { + "per_channel_features": 30, + "normalization_fit_on_training_only": true, + "amplitude_only_control": false, + "all_five_tracks_update_common_encoder": true, + "gains_within_one_common_checkpoint": { + "faced": 0.3, + "tuev": 0.1, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 0.0 + } + }, + "inherited_private_readout_refresh": { + "child": "/workspace/research/runs/coupling_patient1/epoch-007", + "donor": "/workspace/research/runs/phase_readout1/epoch-016", + "common_ancestor": "/workspace/research/runs/phase_coherence1/epoch-007", + "source_weight_sha256": { + "child": "f8466c6838ff01e54d1619f55668c1a4af26a243b54c67a956a3422d9604632a", + "donor": "ffd219d1480b81720b5aa4014cb2ed2b9cd31b7c92ad4717abc2a9625d30dc1a", + "ancestor": "e53ede409be523d8f4746251f7d46353621049f0378a88d4f7cfe2ba71a57d95" + }, + "changed_private_tensors": [ + "heads.openbmi.prior.projection.weight", + "heads.openbmi.prior.projection.bias" + ], + "all_ancestor_common_and_input_tensors_equal": true, + "all_child_common_and_input_tensors_unchanged": true, + "new_branch_gain_for_refreshed_track": 0.0, + "donor_changes_only_requested_private_projection": true, + "prediction_sources": { + "faced": { + "source": "/workspace/research/runs/coupling_patient1/faced-e007.npy", + "sha256": "68b617c8ecf347c79b23c20b70f6b4981c2f26b7b8c71dc7cd5fa0d7f4285ea6" + }, + "tuev": { + "source": "/workspace/research/runs/coupling_patient1/tuev-e007.npy", + "sha256": "9f0743450f1104d395e9daac0600aaf20755b5590b9f5c3e3137732c479dd647" + }, + "ad65": { + "source": "/workspace/research/runs/coupling_patient1/ad65-e007.npy", + "sha256": "7a3b74c58580b7ba952322bf6d527ebc9a40a6e04c7cdbbaea14e84a7a298d54" + }, + "openbmi": { + "source": "/workspace/research/runs/phase_readout1/openbmi-e016.npy", + "sha256": "14f630543e1df88c88d8f3e0effb4506ba33f533b3484de3c7aaf6554507341c" + }, + "longitudinal": { + "source": "/workspace/research/runs/coupling_patient1/longitudinal-e007.npy", + "sha256": "e93b0a319eaa3ddca9d71b0e786b808ba1630c1d3ce125f8e08036e517741b74" + } + } + }, + "shared_student_residual": { + "dimension": 8448, + "summary_dimension": 256, + "ordered_time_bins": 4, + "student_weights_sha256": "19dfe912cceed997699b5b526c8c2ece55945c5f9bd111c4c13704d0fc460e8b", + "summary_only_control": false, + "normalization_fit_on_training_only": true, + "new_common_readout_jointly_trained_on_all_five": true, + "class_projection_initialized_zero": true, + "student_classifiers_discarded": true, + "gains_within_one_common_checkpoint": { + "faced": 1.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 1.0 + }, + "zero_gain_preserves_complete_parent": true + }, + "private_head_refresh": { + "reference": "/workspace/research/pilots/short_private_pilot1/epoch-001", + "donor": "/workspace/research/runs/short_private1/epoch-030", + "track": "tuev", + "source_sha256": { + "reference": "afacd7c1a4f7329c01148a17a7a2ca15b8db3c6b38446f40fb92e58eb7d64ef2", + "donor": "f060de6d5bf41c8e332ae8cc58cdf7dfa5ea98ab610ef2b4fdc3d00eae4929e6" + }, + "changed_private_tensors": [ + "heads.tuev.correction_gain", + "heads.tuev.projection.weight", + "heads.tuev.projection.bias" + ], + "all_common_input_and_prior_head_tensors_exactly_equal": true, + "executable_code_and_architecture_exactly_equal": true, + "one_common_checkpoint": true, + "prediction_sources": { + "faced": "/workspace/research/pilots/short_private_pilot1/faced-e001.npy", + "tuev": "/workspace/research/runs/short_private1/tuev-e030.npy", + "ad65": "/workspace/research/pilots/short_private_pilot1/ad65-e001.npy", + "openbmi": "/workspace/research/pilots/short_private_pilot1/openbmi-e001.npy", + "longitudinal": "/workspace/research/pilots/short_private_pilot1/longitudinal-e001.npy" + } + }, + "shared_student_extension_residual": { + "dimension": 128, + "input_representation": "fixed jointly trained common student embedding", + "activation": "identity", + "student_weights_sha256": "19dfe912cceed997699b5b526c8c2ece55945c5f9bd111c4c13704d0fc460e8b", + "summary_only_control": false, + "normalization_fit_on_training_only": true, + "new_common_readout_jointly_trained_on_all_five": true, + "class_projection_initialized_zero": true, + "student_classifiers_discarded": true, + "gains_within_one_common_checkpoint": { + "faced": 0.30000001192092896, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 0.30000001192092896, + "longitudinal": 0.30000001192092896 + }, + "zero_gain_preserves_complete_parent": true + }, + "fixed_common_embedding_readouts": { + "all_common_weights_exactly_unchanged": true, + "selected_private_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 0, + "longitudinal": 1 + } + }, + "shared_center_context_residual": { + "dimension": 128, + "crop": "center", + "samples": 400, + "sample_rate": 200, + "feature_types": [ + "spectral", + "cross_frequency_coupling" + ], + "normalization_fit_on_training_only": true, + "new_common_block_jointly_trained_on_all_five": true, + "class_projection_initialized_zero": true, + "gains_within_one_common_checkpoint": { + "faced": 0.10000000149011612, + "tuev": 0.30000001192092896, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 1.0 + }, + "zero_gain_preserves_complete_parent": true + }, + "private_input_head_refresh": { + "reference": "/workspace/research/sources/emotion_private_input_source", + "donor": "/workspace/research/runs/emotion_input_adapt_full1/epoch-001", + "track": "longitudinal", + "source_sha256": { + "reference": "90904cd9b33d59b1ed531dcda90f95b9dce3e59661187242b6b26a06daba6d04", + "donor": "b4a858b3dab746a6600aa1fd194e7cc42b277fd11eb07d8561aff980f3a26b9d" + }, + "changed_private_tensors": [ + "adapters.longitudinal.emotion_projection.weight", + "adapters.longitudinal.emotion_projection.bias", + "heads.longitudinal.correction_gain", + "heads.longitudinal.projection.weight", + "heads.longitudinal.projection.bias" + ], + "all_common_old_input_normalizer_and_prior_head_tensors_exactly_equal": true, + "executable_code_and_architecture_exactly_equal": true, + "one_common_checkpoint": true, + "prediction_sources": { + "faced": "/workspace/research/runs/emotion_geometry_log_full1/faced-e002.npy", + "tuev": "/workspace/research/runs/emotion_geometry_log_full1/tuev-e002.npy", + "ad65": "/workspace/research/runs/emotion_geometry_log_full1/ad65-e002.npy", + "openbmi": "/workspace/research/runs/emotion_geometry_log_full1/openbmi-e002.npy", + "longitudinal": "/workspace/research/runs/emotion_input_adapt_full1/longitudinal-e001.npy" + } + }, + "shared_short_context_residual": { + "dimension": 128, + "crop": "first", + "samples": 200, + "sample_rate": 200, + "feature_types": [ + "spectral", + "cross_frequency_coupling" + ], + "normalization_fit_on_training_only": true, + "new_common_block_jointly_trained_on_all_five": true, + "class_projection_initialized_zero": true, + "gains_within_one_common_checkpoint": { + "faced": 0.30000001192092896, + "tuev": 0.30000001192092896, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 0.30000001192092896 + }, + "zero_gain_preserves_complete_parent": true + }, + "shared_dual_context_residual": { + "dimension": 128, + "crop": "clinical-dual", + "samples_per_view": 200, + "clinical_views": 2, + "other_track_views": 1, + "sample_rate": 200, + "feature_types": [ + "spectral", + "cross_frequency_coupling" + ], + "normalization_fit_on_training_only": true, + "new_common_block_jointly_trained_on_all_five": true, + "class_projection_initialized_zero": true, + "gains_within_one_common_checkpoint": { + "faced": 0.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 1.0 + }, + "zero_gain_preserves_complete_parent": true + }, + "shared_geometry_residual": { + "dimension": 128, + "mode": "mi-linear", + "motor_native_covariance_bands": 7, + "motor_channels": 62, + "motor_input_dimension": 13671, + "motor_covariance_shrinkage": 0.05, + "other_track_crop": "first1s", + "normalization_fit_on_training_only": true, + "new_common_block_jointly_trained_on_all_five": true, + "class_projection_initialized_zero": true, + "gains_within_one_common_checkpoint": { + "faced": 0.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 1.0 + }, + "zero_gain_preserves_complete_parent": true + }, + "fixed_common_geometry_input_readouts": { + "all_common_weights_exactly_unchanged": true, + "input_lr": 1e-05, + "class_projection_lr": 0.0003, + "selected_private_epochs": { + "faced": 0, + "tuev": 0, + "ad65": 0, + "openbmi": 0, + "longitudinal": 1 + }, + "separate_input_and_class_gradient_clipping": 1.0 + }, + "shared_emotion_residual": { + "dimension": 128, + "mode": "faced-log", + "emotion_native_covariance_bands": 7, + "emotion_channels": 32, + "emotion_input_dimension": 3696, + "emotion_covariance_shrinkage": 0.05, + "other_track_crop": "first1s", + "normalization_fit_on_training_only": true, + "new_common_block_jointly_trained_on_all_five": true, + "class_projection_initialized_zero": true, + "gains_within_one_common_checkpoint": { + "faced": 0.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 1.0, + "longitudinal": 0.10000000149011612 + }, + "zero_gain_preserves_complete_parent": true + }, + "shared_refinement_residual": { + "dimension": 128, + "mode": "faced-log", + "refinement_native_covariance_bands": 7, + "refinement_channels": 32, + "refinement_input_dimension": 3696, + "refinement_covariance_shrinkage": 0.05, + "other_track_crop": "first1s", + "normalization_fit_on_training_only": true, + "new_common_block_jointly_trained_on_all_five": true, + "class_projection_initialized_zero": true, + "gains_within_one_common_checkpoint": { + "faced": 0.0, + "tuev": 0.10000000149011612, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 1.0 + }, + "zero_gain_preserves_complete_parent": true + }, + "fixed_common_refinement_input_readouts": { + "all_common_weights_exactly_unchanged": true, + "input_lr": 0.0, + "class_projection_lr": 0.0003, + "selected_private_epochs": { + "faced": 0, + "tuev": 4, + "ad65": 0, + "openbmi": 0, + "longitudinal": 0 + }, + "separate_input_and_class_gradient_clipping": 1.0 + }, + "shared_spatial_residual": { + "dimension": 128, + "mode": "native", + "motor_context_channels": 6, + "motor_input_dimension": 981, + "motor_channel_names": [ + "Fp1", + "Fp2", + "F7", + "F3", + "Fz", + "F4", + "F8", + "FC5", + "FC1", + "FC2", + "FC6", + "T7", + "C3", + "Cz", + "C4", + "T8", + "TP9", + "CP5", + "CP1", + "CP2", + "CP6", + "TP10", + "P7", + "P3", + "Pz", + "P4", + "P8", + "PO9", + "O1", + "Oz", + "O2", + "PO10", + "FC3", + "FC4", + "C5", + "C1", + "C2", + "C6", + "CP3", + "CPz", + "CP4", + "P1", + "P2", + "POz", + "FT9", + "FTT9h", + "TTP7h", + "TP7", + "TPP9h", + "FT10", + "FTT10h", + "TPP8h", + "TP8", + "TPP10h", + "F9", + "F10", + "AF7", + "AF3", + "AF4", + "AF8", + "PO3", + "PO4" + ], + "other_track_inputs": "FACED native log covariance; TUEV/AD65/Longitudinal first1s", + "normalization_fit_on_training_only": true, + "new_common_block_jointly_trained_on_all_five": true, + "class_projection_initialized_zero": true, + "gains_within_one_common_checkpoint": { + "faced": 0.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 0.1, + "longitudinal": 1.0 + }, + "zero_gain_preserves_complete_parent": true + } +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/coupling_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/coupling_features.py new file mode 100644 index 0000000000000000000000000000000000000000..3a4e51bd7ce07bcec1f0f5b80054d6ff387ac87f --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/coupling_features.py @@ -0,0 +1,34 @@ +"""Per-window cross-frequency envelope and phase-amplitude relationships.""" +import torch +BANDS=((1,4),(4,8),(8,13),(13,30),(30,48)) +PAIRS=tuple((i,j) for i in range(5) for j in range(i+1,5)) +PER_CHANNEL=30 + +@torch.no_grad() +def coupling_features(track,x): + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + n=x.shape[-1];spectrum=torch.fft.fft(x,dim=-1);frequency=torch.fft.fftfreq(n,1/200,device=x.device) + masks=torch.stack([2*((frequency>=lo)&(frequency=lo)&(frequencynbf',w,covariances.float(),w).clamp_min(1e-8).log() + return torch.cat([power,power-power.mean(1,keepdim=True)],1).flatten(1) + def wave_signal(self,x,components=None): + if components is None:components=frequency_components(x) + correction=torch.einsum('blc,nbct->nlt',self.frequency_weight,components.to(self.frequency_weight.dtype)) + return (self.signal(x)+correction.to(x.dtype)).unsqueeze(1) + def forward(self,x,features,covariance_features): + return self.wave_signal(x),self.spectral_features(features,signal=x),self.neural(x),covariance_features + +class SharedBackbone(nn.Module): + def __init__(self,channels,width,depth,dropout,wave_filters): + super().__init__() + self.waveform=nn.Sequential( + nn.Conv2d(1,wave_filters,(1,64),padding=(0,32),bias=False),nn.GroupNorm(1,wave_filters), + nn.Conv2d(wave_filters,2*wave_filters,(channels,1),groups=wave_filters,bias=False),nn.GroupNorm(1,2*wave_filters),nn.ELU(), + nn.AvgPool2d((1,4)),nn.Dropout(.35), + nn.Conv2d(2*wave_filters,2*wave_filters,(1,16),padding=(0,8),groups=2*wave_filters,bias=False),nn.Conv2d(2*wave_filters,2*wave_filters,1,bias=False), + nn.GroupNorm(1,2*wave_filters),nn.ELU(),nn.AvgPool2d((1,8)),nn.Dropout(.35)) + self.wave_summary=nn.Sequential(nn.AdaptiveAvgPool2d((1,8)),nn.Flatten(),nn.Linear(2*wave_filters*8,width)) + self.fusion=nn.Sequential(nn.LayerNorm(width),nn.GELU(),nn.Dropout(dropout), + *[Residual(width,dropout) for _ in range(depth)],nn.LayerNorm(width)) + # Both representations interact before the shared residual stack. + self.phase_encoder=nn.Sequential(nn.LayerNorm(PHASE_DIM),nn.Linear(PHASE_DIM,width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width)) + self.register_buffer('phase_imaginary_enabled',torch.ones(())) + self.coupling_encoder=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width),nn.LayerNorm(width)) + self.wave_gain=nn.Parameter(torch.tensor(.1)) + self.biot=BIOT(n_chans=18,n_outputs=2,n_times=400,sfreq=200) + self.biot.final_layer=nn.Identity() + self.biot_projection=nn.Sequential(nn.LayerNorm(256),nn.Linear(256,width),nn.Dropout(.2)) + nn.init.normal_(self.biot_projection[1].weight,std=.001);nn.init.zeros_(self.biot_projection[1].bias) + self.covariance_encoder=nn.Sequential(nn.LayerNorm(len(BANDS)*24*2),nn.Linear(len(BANDS)*24*2,width),nn.GELU(),nn.Dropout(.4), + *[Residual(width,.4) for _ in range(2)],nn.LayerNorm(width)) + self.covariance_projection=nn.Linear(width,width) + nn.init.zeros_(self.covariance_projection.weight);nn.init.zeros_(self.covariance_projection.bias) + self.tangent_encoder=nn.Sequential(nn.LayerNorm(TANGENT_DIM),nn.Linear(TANGENT_DIM,width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width),nn.Linear(width,width)) + self.ordinal_context=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width)) + nn.init.zeros_(self.ordinal_context[-1].weight);nn.init.zeros_(self.ordinal_context[-1].bias) + self.register_buffer('codebrain_enabled',torch.ones(())) + self.codebrain_patch_encoder=nn.Sequential(nn.LayerNorm(24*64),nn.Linear(24*64,width),nn.GELU(),nn.Dropout(.3)) + self.codebrain_context=nn.Sequential(nn.LayerNorm(width*4),nn.Linear(width*4,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width)) + nn.init.zeros_(self.codebrain_context[-1].weight);nn.init.zeros_(self.codebrain_context[-1].bias) + def codebrain_correction(self,tokens,representation,fusion_input): + with torch.autocast(tokens.device.type,enabled=False): + encoded=self.codebrain_patch_encoder(self.codebrain_enabled*tokens.float()) + pooled=torch.cat([encoded.mean(1),encoded.std(1,correction=0),representation[:,-512:-384].float(),representation[:,-128:].float()],-1) + delta=self.codebrain_context(pooled) + added=.001*nn.functional.linear(delta,self.covariance_projection.weight,None) + corrected=self.fusion(fusion_input+added.to(fusion_input.dtype)) + return corrected-representation[:,-512:-384],delta + def forward(self,signal,spectral,neural_signal,covariance_features,tangent_features): + wave=self.waveform(signal) + neural=self.biot(neural_signal.float()) + neural=self.biot_projection[0](neural) + projected=self.biot_projection[2](self.biot_projection[1](neural)) + with torch.autocast(signal.device.type,enabled=False): + covariance_embedding=self.covariance_encoder(covariance_features.float()) + original=spectral+self.wave_gain*self.wave_summary(wave)+.01*projected + coupled=.001*self.covariance_projection(covariance_embedding).to(original.dtype) + fused=self.fusion(original+coupled) + with torch.autocast(signal.device.type,enabled=False):delta=self.tangent_encoder(tangent_features.float()) + added=.001*nn.functional.linear(delta,self.covariance_projection.weight,None) + corrected=self.fusion((original+coupled)+added.to(original.dtype)) + return torch.cat([wave.flatten(1),fused,neural,covariance_embedding],-1),corrected-fused,delta,original+coupled + +class ResidualHead(nn.Module): + """A small nonlinear classifier correction around an inherited linear readout.""" + def __init__(self,features,classes,width=64,dropout=.3,full_precision=False): + super().__init__();self.full_precision=full_precision + self.base=nn.Linear(features,classes) + self.delta=nn.Sequential(nn.LayerNorm(features),nn.Linear(features,width),nn.GELU(),nn.Dropout(dropout),nn.Linear(width,classes)) + nn.init.zeros_(self.delta[-1].weight);nn.init.zeros_(self.delta[-1].bias) + def forward(self,x): + if self.full_precision: + with torch.autocast(x.device.type,enabled=False):return self.base(x.float())+self.delta(x.float()) + prior=nn.functional.linear(x[:,:-128].contiguous(),self.base.weight[:,:-128].contiguous(),self.base.bias) + added=nn.functional.linear(x[:,-128:].contiguous(),self.base.weight[:,-128:].contiguous()) + value=prior+added + return value+self.delta(x).to(value.dtype) + +class TemporalPoolHead(nn.Module): + def __init__(self,prior,channels=64): + super().__init__();self.prior=prior;self.channels=channels + self.register_buffer('pool_output_scale',torch.ones(()));self.register_buffer('pool_mean',torch.zeros(channels*4));self.register_buffer('pool_scale',torch.ones(channels*4)) + self.pool_projection=nn.Linear(channels*4,prior.base.out_features) + nn.init.zeros_(self.pool_projection.weight);nn.init.zeros_(self.pool_projection.bias) + def statistics(self,x): + with torch.autocast(x.device.type,enabled=False): + wave=x[:,:-512].float().reshape(len(x),self.channels,-1) + return torch.cat([wave.mean(-1),wave.std(-1,correction=0),wave.amax(-1),wave.amin(-1)],-1) + def forward(self,x): + prior=self.prior(x) + with torch.autocast(x.device.type,enabled=False): + values=((self.statistics(x)-self.pool_mean)/self.pool_scale).clamp(-8,8) + added=self.pool_output_scale*self.pool_projection(values) + return prior+added.to(prior.dtype) + +class TemporalEvidenceHead(nn.Module): + """Pool class evidence over the shared waveform time axis.""" + def __init__(self,prior,channels=64,temperature=.25): + super().__init__();self.prior=prior;self.channels=channels;self.temperature=temperature + self.register_buffer('evidence_output_scale',torch.ones(())) + self.register_buffer('evidence_mean',torch.zeros(channels)) + self.register_buffer('evidence_scale',torch.ones(channels)) + self.evidence_projection=nn.Linear(channels,prior.prior.base.out_features,bias=False) + nn.init.zeros_(self.evidence_projection.weight) + def patches(self,x): + with torch.autocast(x.device.type,enabled=False): + wave=x[:,:-512].float().reshape(len(x),self.channels,-1).transpose(1,2) + return ((wave-self.evidence_mean)/self.evidence_scale).clamp(-8,8) + def evidence(self,patches): + with torch.autocast(patches.device.type,enabled=False): + values=self.evidence_projection(patches.float())/self.temperature + maximum=values.amax(1,keepdim=True) + pooled=self.temperature*((values-maximum).exp().mean(1).log()+maximum.squeeze(1)) + return self.evidence_output_scale*pooled + def forward(self,x): + prior=self.prior(x) + return prior+self.evidence(self.patches(x)).to(prior.dtype) + +class FourierResidualHead(nn.Module): + """A fixed random Fourier basis and trainable linear classifier correction.""" + def __init__(self,prior,features,classes,basis=256): + super().__init__();self.prior=prior + self.register_buffer('rff_mean',torch.zeros(features));self.register_buffer('rff_scale',torch.ones(features)) + self.register_buffer('rff_frequency',torch.randn(features,basis)/features**.5) + self.register_buffer('rff_phase',torch.rand(basis)*2*torch.pi) + self.register_buffer('rff_output_scale',torch.ones(())) + self.rff_projection=nn.Linear(3*basis,classes);nn.init.zeros_(self.rff_projection.weight);nn.init.zeros_(self.rff_projection.bias) + def basis(self,x): + with torch.autocast(x.device.type,enabled=False): + values=((x.float()-self.rff_mean)/self.rff_scale).clamp(-8,8)@self.rff_frequency + return 2**.5*torch.cat([(values/sigma+self.rff_phase).cos() for sigma in (.5,1.,2.)],-1) + def forward(self,x): + prior=self.prior(x) + with torch.autocast(x.device.type,enabled=False):added=self.rff_output_scale*self.rff_projection(self.basis(x)) + return prior+added.to(prior.dtype) + +class TangentFeatureHead(nn.Module): + """Select a shared feature correction before the inherited classifier.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.feature_gain=nn.Parameter(torch.zeros(())) + def forward(self,values): + old=values[:,:-256];fusion_delta=values[:,-256:-128];covariance_delta=values[:,-128:] + adjusted=torch.cat([old[:,:-512],old[:,-512:-384]+self.feature_gain*fusion_delta,old[:,-384:-128],old[:,-128:]+self.feature_gain*covariance_delta],-1) + return self.prior(adjusted) + +class CodeBrainFeatureHead(nn.Module): + """Private use of a jointly trained common feature correction.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.codebrain_gain=nn.Parameter(torch.ones(())) + def forward(self,values): + previous=values[:,:-256];native=previous[:,:-256] + fusion_delta=values[:,-256:-128];covariance_delta=values[:,-128:] + adjusted=torch.cat([native[:,:-512],native[:,-512:-384]+self.codebrain_gain*fusion_delta,native[:,-384:-128],native[:,-128:]+self.codebrain_gain*covariance_delta],-1) + return self.prior(torch.cat([adjusted,previous[:,-256:]],-1)) + +class WaveCoactivationContext(nn.Module): + """One common encoder of coactivation among the learned waveform channels.""" + def __init__(self,channels=64,width=128): + super().__init__();self.channels=channels + ii,jj=torch.triu_indices(channels,channels,offset=1) + self.register_buffer('pair_i',ii);self.register_buffer('pair_j',jj) + self.register_buffer('offdiagonal_enabled',torch.ones(())) + self.encoder=nn.Sequential(nn.LayerNorm(channels+len(ii)),nn.Linear(channels+len(ii),width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width)) + def statistics(self,native): + with torch.autocast(native.device.type,enabled=False): + wave=native[:,:-512].float().reshape(len(native),self.channels,-1) + centered=wave-wave.mean(-1,keepdim=True) + previous_tf32=torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32=False + covariance=centered@centered.transpose(-1,-2)/wave.shape[-1] + torch.backends.cuda.matmul.allow_tf32=previous_tf32 + variance=covariance.diagonal(dim1=-2,dim2=-1).clamp_min(1e-8) + correlation=covariance/(variance.sqrt()[:,:,None]*variance.sqrt()[:,None,:]) + return torch.cat([variance.log(),correlation[:,self.pair_i,self.pair_j].clamp(-1,1)],-1) + def encode_statistics(self,values): + with torch.autocast(values.device.type,enabled=False): + value=torch.cat([values[:,:self.channels],self.offdiagonal_enabled*values[:,self.channels:]],-1) + return self.encoder(value.float()) + def forward(self,native):return self.encode_statistics(self.statistics(native)) + +class WaveCoactivationHead(nn.Module): + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=self.correction_gain*self.output_scale*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class OrdinalFeatureHead(nn.Module): + """Private strength of one common ordinal-dynamics feature correction.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.ordinal_gain=nn.Parameter(torch.ones(())) + def forward(self,values): + previous=values[:,:-256];native=previous[:,:-640] + adjusted=torch.cat([native[:,:-512],native[:,-512:-384]+self.ordinal_gain*values[:,-256:-128],native[:,-384:-128],native[:,-128:]+self.ordinal_gain*values[:,-128:],previous[:,-640:]],-1) + return self.prior(adjusted) + +class PhaseReadoutHead(nn.Module): + """Private class evidence from the common complex-coherence encoder.""" + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=(self.correction_gain*self.output_scale)*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class CouplingReadoutHead(nn.Module): + """Private class evidence from the common cross-frequency coupling encoder.""" + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-128]) + with torch.autocast(values.device.type,enabled=False):delta=(self.correction_gain*self.output_scale)*self.projection(values[:,-128:].float()) + return prior+delta.to(prior.dtype) + +class HybridModel(nn.Module): + def __init__(self,channels=32,width=128,depth=2,dropout=.5,wave_filters=32,head_width=64,head_dropout=.3,clinical_asymmetry=True,alpha_regions=None,clinical_envelope=False,temporal_pool=True,temporal_evidence=False,evidence_temperature=.25,random_fourier=False,fourier_features=256,tangent_readout=True,shared_context_correction=True,wave_coactivation=True,ordinal_context=True,phase_coherence=True,cross_frequency=True,cbramod_feature_transfer=True,student_architecture=None,student_extension=True,post_embedding_extension=True,extension_activation='gelu',center_context_extension=True,context_crop='center',short_context_extension=True,short_crop='center',dual_context_extension=True,dual_crop='clinical-dual',geometry_extension=True,geometry_mode='mi-log',emotion_extension=True,emotion_mode='faced-log',emotion_activation='gelu',refinement_extension=True,refinement_mode='faced-log',refinement_activation='gelu',spatial_extension=True,spatial_mode='local',spatial_activation='gelu',spatial_motor_channels=None): + super().__init__() + self.adapters=nn.ModuleDict({t:InputAdapter(c,width,channels,spectral_enabled=t not in ("faced","tuev","openbmi"),asymmetry=clinical_asymmetry and t=="tuev",alpha_regions=alpha_regions if t=="longitudinal" else None,envelope=clinical_envelope and t=="tuev") for t,(c,s,k) in SPECS.items()}) + self.backbone=SharedBackbone(channels,width,depth,dropout,wave_filters) + self.backbone.student_encoder=CBraModFeatures(**(student_architecture or {})) + self.backbone.register_buffer('student_ordered_enabled',torch.ones(())) + self.backbone.student_readout=nn.Sequential(nn.Linear(self.backbone.student_encoder.output_dim,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + for t,(c,s,k) in SPECS.items(): + self.adapters[t].student_input=FrequencyAdapter(c,32) + self.adapters[t].student_normalizer=Standardize(self.backbone.student_encoder.output_dim) + self.backbone.wave_coactivation=WaveCoactivationContext(2*wave_filters,width) + self.heads=nn.ModuleDict({t:ResidualHead(2*wave_filters*(((s*200+1)//4+1)//8)+width+256+width,k,head_width,head_dropout,full_precision=t=='ad65') for t,(c,s,k) in SPECS.items()}) + if temporal_pool:self.heads=nn.ModuleDict({t:TemporalPoolHead(head,wave_filters*2) for t,head in self.heads.items()}) + if temporal_evidence:self.heads=nn.ModuleDict({t:TemporalEvidenceHead(head,wave_filters*2,evidence_temperature) for t,head in self.heads.items()}) + if random_fourier:self.heads=nn.ModuleDict({t:FourierResidualHead(head,2*wave_filters*(((SPECS[t][1]*200+1)//4+1)//8)+width+256+width,SPECS[t][2],fourier_features) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:TangentFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CodeBrainFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:WaveCoactivationHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:OrdinalFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:PhaseReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert student_extension and post_embedding_extension + assert extension_activation in ('gelu','identity') + self.backbone.student_extension=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU() if extension_activation=='gelu' else nn.Identity(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert center_context_extension and context_crop in ('center','first') + self.context_crop=context_crop + for t,(c,s,k) in SPECS.items(): + self.adapters[t].center_normalizer=Standardize(feature_dim(c)+30*c) + self.adapters[t].center_projection=nn.Linear(feature_dim(c)+30*c,width) + self.backbone.center_encoder=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert short_context_extension and short_crop in ('center','first') + self.short_crop=short_crop + for t,(c,s,k) in SPECS.items(): + self.adapters[t].short_normalizer=Standardize(feature_dim(c)+30*c) + self.adapters[t].short_projection=nn.Linear(feature_dim(c)+30*c,width) + self.backbone.short_encoder=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert dual_context_extension and dual_crop in ('clinical-dual','clinical-duplicate') + self.dual_crop=dual_crop + for t,(c,s,k) in SPECS.items(): + self.adapters[t].dual_normalizer=Standardize((feature_dim(c)+30*c)*(2 if t=='tuev' else 1)) + self.adapters[t].dual_projection=nn.Linear((feature_dim(c)+30*c)*(2 if t=='tuev' else 1),width) + self.backbone.dual_encoder=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert geometry_extension and geometry_mode in ('mi-log','mi-linear') + self.geometry_mode=geometry_mode + for t,(c,s,k) in SPECS.items(): + dimension=7*c*(c+1)//2 if t=='openbmi' else feature_dim(c)+30*c + self.adapters[t].geometry_normalizer=Standardize(dimension) + self.adapters[t].geometry_projection=nn.Linear(dimension,width) + self.backbone.geometry_encoder=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert emotion_extension and emotion_mode in ('faced-log','faced-linear') + self.emotion_mode=emotion_mode + for t,(c,s,k) in SPECS.items(): + dimension=7*c*(c+1)//2 if t=='faced' else feature_dim(c)+30*c + self.adapters[t].emotion_normalizer=Standardize(dimension) + self.adapters[t].emotion_projection=nn.Linear(dimension,width) + assert emotion_activation in ('gelu','identity') + self.backbone.emotion_encoder=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU() if emotion_activation=='gelu' else nn.Identity(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert refinement_extension and refinement_mode in ('faced-log','faced-linear') + self.refinement_mode=refinement_mode + for t,(c,s,k) in SPECS.items(): + dimension=7*c*(c+1)//2 if t=='faced' else feature_dim(c)+30*c + self.adapters[t].refinement_normalizer=Standardize(dimension) + self.adapters[t].refinement_projection=nn.Linear(dimension,width) + assert refinement_activation in ('gelu','identity') + self.backbone.refinement_encoder=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU() if refinement_activation=='gelu' else nn.Identity(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert spatial_extension and spatial_mode in ('local','native') and spatial_activation=='gelu' + self.spatial_mode=spatial_mode + self.spatial_motor_channels=tuple(spatial_motor_channels or MOTOR_CHANNELS) + assert len(self.spatial_motor_channels)==62 + for t,(c,s,k) in SPECS.items(): + dimension=981 if t=='openbmi' else (7*c*(c+1)//2 if t=='faced' else feature_dim(c)+30*c) + self.adapters[t].spatial_normalizer=Standardize(dimension) + self.adapters[t].spatial_projection=nn.Linear(dimension,width) + self.backbone.spatial_encoder=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + def spatial_features(self,t,x): + if t!='openbmi':return self.refinement_features(t,x) + from local_channel_features import local_channel_signals + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(x.device.type,enabled=False): + signals=local_channel_signals(x,self.spatial_motor_channels,self.spatial_mode=='local') + return torch.cat([extract_features('tuev',signals),coupling_features('tuev',signals)],-1) + finally:torch.backends.cuda.matmul.allow_tf32=old + def spatial_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].spatial_normalizer(values.float()) + return self.backbone.spatial_encoder(self.adapters[t].spatial_projection(normalized)) + def refinement_features(self,t,x): + from native_log_covariance_features import connectivity + from short_context_features import short_spectral_features + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(x.device.type,enabled=False): + if t=='faced':return connectivity(t,x,logarithmic=self.refinement_mode=='faced-log') + view=x.flatten(2)[...,:200] + return torch.cat([short_spectral_features(t,view),coupling_features(t,view)],-1) + finally:torch.backends.cuda.matmul.allow_tf32=old + def refinement_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].refinement_normalizer(values.float()) + return self.backbone.refinement_encoder(self.adapters[t].refinement_projection(normalized)) + def emotion_features(self,t,x): + from native_log_covariance_features import connectivity + from short_context_features import short_spectral_features + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(x.device.type,enabled=False): + if t=='faced':return connectivity(t,x,logarithmic=self.emotion_mode=='faced-log') + view=x.flatten(2)[...,:200] + return torch.cat([short_spectral_features(t,view),coupling_features(t,view)],-1) + finally:torch.backends.cuda.matmul.allow_tf32=old + def emotion_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].emotion_normalizer(values.float()) + return self.backbone.emotion_encoder(self.adapters[t].emotion_projection(normalized)) + def geometry_features(self,t,x): + from native_log_covariance_features import connectivity + from short_context_features import short_spectral_features + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(x.device.type,enabled=False): + if t=='openbmi':return connectivity(t,x,logarithmic=self.geometry_mode=='mi-log') + view=x.flatten(2)[...,:200] + return torch.cat([short_spectral_features(t,view),coupling_features(t,view)],-1) + finally:torch.backends.cuda.matmul.allow_tf32=old + def geometry_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].geometry_normalizer(values.float()) + return self.backbone.geometry_encoder(self.adapters[t].geometry_projection(normalized)) + def dual_features(self,t,x): + from short_context_features import short_spectral_features + raw=x.flatten(2);first=raw[...,:200];views=[first] + if t=='tuev': + start=(raw.shape[-1]-200)//2 + views.append(raw[...,start:start+200] if self.dual_crop=='clinical-dual' else first) + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(raw.device.type,enabled=False):return torch.cat([torch.cat([short_spectral_features(t,v),coupling_features(t,v)],-1) for v in views],-1) + finally:torch.backends.cuda.matmul.allow_tf32=old + def dual_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].dual_normalizer(values.float()) + return self.backbone.dual_encoder(self.adapters[t].dual_projection(normalized)) + def short_features(self,t,x): + from short_context_features import short_spectral_features + raw=x.flatten(2);start=(raw.shape[-1]-200)//2 if self.short_crop=='center' else 0 + cropped=raw[...,start:start+200];assert cropped.shape[-1]==200 + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(raw.device.type,enabled=False):return torch.cat([short_spectral_features(t,cropped),coupling_features(t,cropped)],-1) + finally:torch.backends.cuda.matmul.allow_tf32=old + def short_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].short_normalizer(values.float()) + return self.backbone.short_encoder(self.adapters[t].short_projection(normalized)) + def center_features(self,t,x): + raw=x.flatten(2);start=(raw.shape[-1]-400)//2 if self.context_crop=='center' else 0 + cropped=raw[...,start:start+400];assert cropped.shape[-1]==400 + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(raw.device.type,enabled=False):return torch.cat([extract_features(t,cropped),coupling_features(t,cropped)],-1) + finally:torch.backends.cuda.matmul.allow_tf32=old + def center_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].center_normalizer(values.float()) + return self.backbone.center_encoder(self.adapters[t].center_projection(normalized)) + def student_extension_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + assert values.shape[-1]==128 + return self.backbone.student_extension(values.float()) + + def student_features(self,t,x): + outputs=[];old_fastpath=torch.backends.mha.get_fastpath_enabled();torch.backends.mha.set_fastpath_enabled(False) + try: + for raw in x.split(16): + signal=torch.nan_to_num(raw.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + with torch.autocast(signal.device.type,dtype=torch.bfloat16,enabled=signal.device.type=='cuda'): + outputs.append(self.backbone.student_encoder(self.adapters[t].student_input(signal))) + finally:torch.backends.mha.set_fastpath_enabled(old_fastpath) + return torch.cat(outputs).float() + def student_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].student_normalizer(values.float()) + normalized=torch.cat([normalized[:,:256],self.backbone.student_ordered_enabled*normalized[:,256:]],-1) + return self.backbone.student_readout(normalized) + def coupling_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False):return self.backbone.coupling_encoder(self.adapters[t].coupling_embedding(values.float())) + def phase_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].phase_normalizer(values.float()) + normalized=torch.cat([normalized[:,:PHASE_HALF],self.backbone.phase_imaginary_enabled*normalized[:,PHASE_HALF:]],-1) + return self.backbone.phase_encoder(normalized) + def forward(self,t,x,features=None,covariances=None,covariance_features=None): + if features is None:features=extract_features(t,x) + if covariance_features is None: + if covariances is None:covariances=extract_covariances(t,x) + covariance_features=self.adapters[t].spatial_features(covariances) + signal=x.flatten(2);signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + adapted=self.adapters[t](signal,features,covariance_features) + if covariances is None:covariances=extract_covariances(t,x) + tangent=extract_tangent_features(covariances,self.adapters[t].spatial_weight) + representation,fusion_delta,covariance_delta,fusion_input=self.backbone(*adapted,tangent_features=tangent) + if t in ('faced','openbmi'): + representation=torch.cat([representation[:,:-384],torch.zeros_like(representation[:,-384:-128]),representation[:,-128:]],-1) + tokens=torch.zeros(len(signal),signal.shape[-1]//200,24*64,device=signal.device,dtype=torch.bfloat16) + code_fusion,code_covariance=self.backbone.codebrain_correction(tokens,representation,fusion_input) + coactivation=self.backbone.wave_coactivation(representation) + with torch.autocast(signal.device.type,enabled=False): + ordinal=self.adapters[t].ordinal_embedding(ordinal_features(t,x)) + ordinal_covariance=self.backbone.ordinal_context(ordinal.float()) + added=.001*nn.functional.linear(ordinal_covariance,self.backbone.covariance_projection.weight,None) + ordinal_fusion=self.backbone.fusion(fusion_input+added.to(fusion_input.dtype))-representation[:,-512:-384] + phase=self.phase_embedding(t,phase_features(t,x,self.adapters[t].spatial_weight)) + coupling=self.coupling_embedding(t,coupling_features(t,x)) + student_values=self.student_features(t,x) + student=self.student_embedding(t,student_values) + extension=self.student_extension_embedding(t,student) + return self.heads[t](torch.cat([representation,fusion_delta,covariance_delta,code_fusion,code_covariance,coactivation,ordinal_fusion,ordinal_covariance,phase,coupling,student,extension,self.center_embedding(t,self.center_features(t,x)),self.short_embedding(t,self.short_features(t,x)),self.dual_embedding(t,self.dual_features(t,x)),self.geometry_embedding(t,self.geometry_features(t,x)),self.emotion_embedding(t,self.emotion_features(t,x)),self.refinement_embedding(t,self.refinement_features(t,x)),self.spatial_embedding(t,self.spatial_features(t,x))],-1)) + +def widen_state_dict(state,multiplier=2): + """Duplicate temporal features and divide downstream sums to preserve outputs.""" + result={} + for key,value in state.items(): + if key.startswith('backbone.waveform.'): + layer=int(key.split('.')[2]) + if layer in (0,2,7):value=value.repeat(multiplier,1,1,1) + elif layer in (1,3,9):value=value.repeat(multiplier) + elif layer==8:value=value.repeat(multiplier,multiplier,1,1)/multiplier + elif key=='backbone.wave_summary.2.weight':value=value.repeat(1,multiplier)/multiplier + elif key.startswith('heads.') and key.endswith('.weight'): + raw=value[:,:-128]/multiplier + value=torch.cat([raw]*multiplier+[value[:,-128:]],1) + result[key]=value + return result + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/phase_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/phase_features.py new file mode 100644 index 0000000000000000000000000000000000000000..8d98822995bf37b499795dfd7e2e401040a01969 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/phase_features.py @@ -0,0 +1,37 @@ +"""Complex spectral coherence of the existing 24 spatial filters in ten bands.""" +import torch +from covariances import BANDS +CHANNELS=24 +PHASE_HALF=len(BANDS)*CHANNELS*(CHANNELS-1)//2 +PHASE_DIM=2*PHASE_HALF + +@torch.no_grad() +def phase_features(track,x,spatial_weight): + previous_tf32=torch.backends.cuda.matmul.allow_tf32 + try: + torch.backends.cuda.matmul.allow_tf32=False + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if track in ('faced','tuev'):x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + else:x=x-x.mean(1,keepdim=True) + x=x/x.square().mean((1,2),keepdim=True).clamp_min(1e-12).sqrt() + frames=x.unfold(-1,400,200);frames=frames-frames.mean(-1,keepdim=True) + z=torch.fft.rfft(frames*torch.hann_window(400,device=x.device),dim=-1)/200 + w=spatial_weight.float()/spatial_weight.float().norm(dim=-1,keepdim=True).clamp_min(1e-6) + index=torch.triu_indices(CHANNELS,CHANNELS,1,device=x.device) + real_parts=[];imaginary_parts=[] + for band,(lo,hi) in enumerate(BANDS): + v=z[...,2*lo:2*hi].flatten(2) + vr=w[band][None]@v.real;vi=w[band][None]@v.imag + real=(vr@vr.transpose(-1,-2)+vi@vi.transpose(-1,-2))/v.shape[-1] + imaginary=(vi@vr.transpose(-1,-2)-vr@vi.transpose(-1,-2))/v.shape[-1] + # Signals have unit global RMS; this floor suppresses phase of numerical silence. + power=real.diagonal(dim1=-2,dim2=-1).clamp_min(1e-6) + denominator=(power[:,:,None]*power[:,None,:]).sqrt().clamp_min(1e-12) + real=(real/denominator).clamp(-.999,.999) + imaginary=(imaginary/denominator).clamp(-.999,.999) + real_parts.append(torch.atanh(real[:,index[0],index[1]])) + imaginary_parts.append(torch.atanh(imaginary[:,index[0],index[1]])) + return torch.cat(real_parts+imaginary_parts,-1) + finally:torch.backends.cuda.matmul.allow_tf32=previous_tf32 diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/private-head-refresh-audit.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/private-head-refresh-audit.json new file mode 100644 index 0000000000000000000000000000000000000000..5dd5c82010999cc1705bb4ec45237cd790f65990 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/private-head-refresh-audit.json @@ -0,0 +1,26 @@ +{ + "reference": "/workspace/research/sources/emotion_private_input_source", + "donor": "/workspace/research/runs/emotion_input_adapt_full1/epoch-001", + "track": "longitudinal", + "source_sha256": { + "reference": "90904cd9b33d59b1ed531dcda90f95b9dce3e59661187242b6b26a06daba6d04", + "donor": "b4a858b3dab746a6600aa1fd194e7cc42b277fd11eb07d8561aff980f3a26b9d" + }, + "changed_private_tensors": [ + "adapters.longitudinal.emotion_projection.weight", + "adapters.longitudinal.emotion_projection.bias", + "heads.longitudinal.correction_gain", + "heads.longitudinal.projection.weight", + "heads.longitudinal.projection.bias" + ], + "all_common_old_input_normalizer_and_prior_head_tensors_exactly_equal": true, + "executable_code_and_architecture_exactly_equal": true, + "one_common_checkpoint": true, + "prediction_sources": { + "faced": "/workspace/research/runs/emotion_geometry_log_full1/faced-e002.npy", + "tuev": "/workspace/research/runs/emotion_geometry_log_full1/tuev-e002.npy", + "ad65": "/workspace/research/runs/emotion_geometry_log_full1/ad65-e002.npy", + "openbmi": "/workspace/research/runs/emotion_geometry_log_full1/openbmi-e002.npy", + "longitudinal": "/workspace/research/runs/emotion_input_adapt_full1/longitudinal-e001.npy" + } +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/private-readout-refresh-audit.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/private-readout-refresh-audit.json new file mode 100644 index 0000000000000000000000000000000000000000..1d02ef9e4aa8d0782c67157b160ef5667bfa1193 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/private-readout-refresh-audit.json @@ -0,0 +1,40 @@ +{ + "child": "/workspace/research/runs/coupling_patient1/epoch-007", + "donor": "/workspace/research/runs/phase_readout1/epoch-016", + "common_ancestor": "/workspace/research/runs/phase_coherence1/epoch-007", + "source_weight_sha256": { + "child": "f8466c6838ff01e54d1619f55668c1a4af26a243b54c67a956a3422d9604632a", + "donor": "ffd219d1480b81720b5aa4014cb2ed2b9cd31b7c92ad4717abc2a9625d30dc1a", + "ancestor": "e53ede409be523d8f4746251f7d46353621049f0378a88d4f7cfe2ba71a57d95" + }, + "changed_private_tensors": [ + "heads.openbmi.prior.projection.weight", + "heads.openbmi.prior.projection.bias" + ], + "all_ancestor_common_and_input_tensors_equal": true, + "all_child_common_and_input_tensors_unchanged": true, + "new_branch_gain_for_refreshed_track": 0.0, + "donor_changes_only_requested_private_projection": true, + "prediction_sources": { + "faced": { + "source": "/workspace/research/runs/coupling_patient1/faced-e007.npy", + "sha256": "68b617c8ecf347c79b23c20b70f6b4981c2f26b7b8c71dc7cd5fa0d7f4285ea6" + }, + "tuev": { + "source": "/workspace/research/runs/coupling_patient1/tuev-e007.npy", + "sha256": "9f0743450f1104d395e9daac0600aaf20755b5590b9f5c3e3137732c479dd647" + }, + "ad65": { + "source": "/workspace/research/runs/coupling_patient1/ad65-e007.npy", + "sha256": "7a3b74c58580b7ba952322bf6d527ebc9a40a6e04c7cdbbaea14e84a7a298d54" + }, + "openbmi": { + "source": "/workspace/research/runs/phase_readout1/openbmi-e016.npy", + "sha256": "14f630543e1df88c88d8f3e0effb4506ba33f533b3484de3c7aaf6554507341c" + }, + "longitudinal": { + "source": "/workspace/research/runs/coupling_patient1/longitudinal-e007.npy", + "sha256": "e93b0a319eaa3ddca9d71b0e786b808ba1630c1d3ce125f8e08036e517741b74" + } + } +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/short_context_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/short_context_features.py new file mode 100644 index 0000000000000000000000000000000000000000..f677f7a4319f4afb9071665bf7804558bfdd69d8 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/short_context_features.py @@ -0,0 +1,22 @@ +"""One/two-second fixed spectral descriptors with physical-frequency bands.""" +import torch +from features import EDGES,COV_BANDS +@torch.no_grad() +def short_spectral_features(track,x): + x=x.float().flatten(2) + x=torch.nan_to_num(x,nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + assert x.shape[-1] in (200,400) + x=x-x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + rms=x.square().mean(-1).clamp_min(1e-12).sqrt();norm=x/rms.unsqueeze(-1) + moments=torch.stack([rms.log(),norm.abs().amax(-1).clamp_min(1).log(),norm.pow(4).mean(-1).clamp_min(1).log(),(norm[...,1:]-norm[...,:-1]).square().mean(-1).clamp_min(1e-10).log()],-1) + n=x.shape[-1];frames=x.unfold(-1,n,n//2);frames=frames-frames.mean(-1,keepdim=True) + z=torch.fft.rfft(frames*torch.hann_window(n,device=x.device),dim=-1)/(n//2) + power=z.abs().square() + bands=torch.stack([power[...,n*lo//200:n*hi//200].mean(-1) for lo,hi in zip(EDGES[:-1],EDGES[1:])],-1) + lp=bands.mean(-2).clamp_min(1e-12).log();variation=bands.clamp_min(1e-12).log().std(-2,correction=0) + parts=[torch.cat([lp,lp-lp.mean(-1,keepdim=True),lp-lp.mean(1,keepdim=True),variation,moments],-1).flatten(1)] + ii,jj=torch.triu_indices(x.shape[1],x.shape[1],offset=1,device=x.device) + for lo,hi in COV_BANDS: + v=z[...,n*lo//200:n*hi//200].flatten(2);cov=v.real@v.real.transpose(-1,-2)+v.imag@v.imag.transpose(-1,-2);d=cov.diagonal(dim1=-2,dim2=-1).clamp_min(1e-12).sqrt();cor=cov/(d.unsqueeze(1)*d.unsqueeze(2)).clamp_min(1e-12);parts.append(cor[:,ii,jj].clamp(-1,1)) + return torch.nan_to_num(torch.cat(parts,-1)).clamp(-40,40) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/tangent_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/tangent_features.py new file mode 100644 index 0000000000000000000000000000000000000000..314f0cf2f58e4b4a1c1d808edbd4acc3b7b6f85b --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/tangent_features.py @@ -0,0 +1,25 @@ +"""Window-local log-correlation geometry in the existing spatial-filter basis.""" +import torch + +TANGENT_DIM=10*24*25//2 + +@torch.no_grad() +def extract_tangent_features(covariances,spatial_weight): + old_tf32=torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(covariances.device.type,enabled=False): + w=spatial_weight.float() + w=w/w.norm(dim=-1,keepdim=True).clamp_min(1e-6) + projected=torch.einsum('bfc,nbcd,bgd->nbfg',w,covariances.float(),w) + d=projected.diagonal(dim1=-2,dim2=-1).clamp_min(1e-10).sqrt() + correlation=(projected/(d.unsqueeze(-1)*d.unsqueeze(-2))).clamp(-1,1) + correlation=(correlation+correlation.transpose(-1,-2))/2 + correlation=.95*correlation+.05*torch.eye(24,device=correlation.device) + values,vectors=torch.linalg.eigh(correlation) + logarithm=(vectors*values.clamp_min(1e-6).log().unsqueeze(-2))@vectors.transpose(-1,-2) + i,j=torch.triu_indices(24,24,device=correlation.device) + scale=torch.where(i==j,1.,2.**.5) + return (logarithm[...,i,j]*scale).flatten(1) + finally: + torch.backends.cuda.matmul.allow_tf32=old_tf32 diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/training.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/training.json new file mode 100644 index 0000000000000000000000000000000000000000..3e74a325f17ba8fda909ccf830e38e65c78ff595 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S099/training.json @@ -0,0 +1,2268 @@ +{ + "history": [ + { + "epoch": 1, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 155, + 183, + 180, + 166, + 313, + 148, + 185, + 175, + 175 + ], + "confusion_matrix": [ + [ + 93, + 11, + 2, + 16, + 24, + 6, + 10, + 12, + 6 + ], + [ + 10, + 86, + 6, + 13, + 27, + 9, + 11, + 7, + 11 + ], + [ + 7, + 7, + 103, + 15, + 16, + 6, + 9, + 7, + 10 + ], + [ + 7, + 20, + 7, + 68, + 38, + 5, + 16, + 11, + 8 + ], + [ + 11, + 14, + 17, + 14, + 133, + 10, + 14, + 19, + 8 + ], + [ + 3, + 10, + 14, + 5, + 17, + 101, + 8, + 13, + 9 + ], + [ + 6, + 10, + 10, + 8, + 22, + 4, + 103, + 7, + 10 + ], + [ + 6, + 14, + 11, + 19, + 19, + 6, + 7, + 94, + 4 + ], + [ + 12, + 11, + 10, + 8, + 17, + 1, + 7, + 5, + 109 + ] + ], + "per_class_recall": [ + 0.5166666666666667, + 0.4777777777777778, + 0.5722222222222222, + 0.37777777777777777, + 0.5541666666666667, + 0.5611111111111111, + 0.5722222222222222, + 0.5222222222222223, + 0.6055555555555555 + ], + "balanced_accuracy": 0.528858024691358, + "accuracy": 0.5297619047619048, + "weighted_f1": 0.5313844597197926, + "macro_f1": 0.5332500819972722, + "kappa": 0.4693789430757791, + "samples": 1680, + "reward": 0.528858024691358, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 372, + 722, + 224, + 214, + 1198, + 12757 + ], + "confusion_matrix": [ + [ + 38, + 38, + 3, + 0, + 3, + 37 + ], + [ + 0, + 225, + 0, + 17, + 49, + 0 + ], + [ + 109, + 151, + 220, + 26, + 155, + 8 + ], + [ + 5, + 0, + 0, + 77, + 0, + 4 + ], + [ + 0, + 0, + 1, + 0, + 468, + 31 + ], + [ + 220, + 308, + 0, + 94, + 523, + 12677 + ] + ], + "per_class_recall": [ + 0.31932773109243695, + 0.7731958762886598, + 0.32884902840059793, + 0.8953488372093024, + 0.936, + 0.917161047605267 + ], + "balanced_accuracy": 0.6949804200993773, + "accuracy": 0.8849357525666688, + "weighted_f1": 0.9028244428833873, + "macro_f1": 0.5183689090280728, + "kappa": 0.5584225391144733, + "samples": 15487, + "reward": 0.6949804200993773, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2020, + 2380 + ], + "confusion_matrix": [ + [ + 1714, + 486 + ], + [ + 306, + 1894 + ] + ], + "per_class_recall": [ + 0.7790909090909091, + 0.860909090909091 + ], + "balanced_accuracy": 0.8200000000000001, + "accuracy": 0.82, + "weighted_f1": 0.8196982553446884, + "macro_f1": 0.8196982553446883, + "kappa": 0.64, + "samples": 4400, + "subject_scores": { + "19": 0.8775, + "35": 0.9475, + "34": 0.6575, + "51": 0.775, + "20": 0.84, + "44": 0.94, + "24": 0.6125, + "15": 0.895, + "31": 0.9099999999999999, + "26": 0.8325, + "23": 0.7324999999999999 + }, + "reward": 0.82, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4598, + 3820 + ], + "confusion_matrix": [ + [ + 3812, + 448 + ], + [ + 786, + 3372 + ] + ], + "per_class_recall": [ + 0.8948356807511737, + 0.810966810966811 + ], + "balanced_accuracy": 0.8529012458589924, + "accuracy": 0.8534093608933239, + "weighted_f1": 0.8531008674719543, + "macro_f1": 0.8530077718240854, + "kappa": 0.7064900330823478, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.863612442263009, + "sub-G2007": 0.8299250399061653, + "sub-G2019": 0.8440852372684741, + "sub-G2031": 0.8283388381080545, + "sub-G2015": 0.8947069504089128, + "sub-CTR002": 0.9934852728970376, + "sub-G2011": 0.8044618188957405, + "sub-G2035": 0.9615119970436341, + "sub-CTR003": 0.6360930735930737 + }, + "reward": 0.8506911855982335, + "subjects": 9 + } + }, + "correction_gains": { + "faced": 0.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 0.1, + "longitudinal": 1.0 + }, + "gain_validation_scores": { + "faced": { + "0.0": 0.528858024691358, + "0.1": 0.5282407407407407, + "0.3": 0.5280864197530863, + "1.0": 0.5239197530864197 + }, + "tuev": { + "0.0": 0.6949804200993773, + "0.1": 0.6870026504814316, + "0.3": 0.6659798788638065, + "1.0": 0.6453578012764926 + }, + "ad65": { + "0.0": 0.8380952380952381, + "0.1": 0.8380952380952381, + "0.3": 0.8380952380952381, + "1.0": 0.8380952380952381 + }, + "openbmi": { + "0.0": 0.8197727272727273, + "0.1": 0.82, + "0.3": 0.82, + "1.0": 0.8188636363636363 + }, + "longitudinal": { + "0.0": 0.8502852505339522, + "0.1": 0.8497905449536611, + "0.3": 0.8505324025203342, + "1.0": 0.8506911855982335 + } + }, + "training_losses": { + "faced": 2.0111914217472076, + "tuev": 1.5330690681934356, + "ad65": 0.9663564264774323, + "openbmi": 0.6570032149553299, + "longitudinal": 0.7385762900114059 + } + } + ], + "settings": { + "source": "/workspace/research/sources/motor_local_source", + "cache": "/workspace/research/motor_local_parent_v1/native", + "parent_cache": "/workspace/research/motor_local_parent_v1/parent", + "output": "/workspace/research/pilots/motor_local_native_pilot1", + "epochs": 1, + "steps": 100, + "batch_size": 128, + "lr": 0.0003, + "auxiliary_classification": 0.25, + "retention": 0.0, + "summary_only": false, + "host_cache": true, + "seed": 7, + "patient_objective": "mean-probability", + "parent_dropout": 0.5, + "spatial_mode": "native", + "spatial_activation": "gelu" + }, + "parent_training_receipt": { + "history": [ + { + "epoch": 4, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 155, + 183, + 180, + 166, + 313, + 148, + 185, + 175, + 175 + ], + "confusion_matrix": [ + [ + 93, + 11, + 2, + 16, + 24, + 6, + 10, + 12, + 6 + ], + [ + 10, + 86, + 6, + 13, + 27, + 9, + 11, + 7, + 11 + ], + [ + 7, + 7, + 103, + 15, + 16, + 6, + 9, + 7, + 10 + ], + [ + 7, + 20, + 7, + 68, + 38, + 5, + 16, + 11, + 8 + ], + [ + 11, + 14, + 17, + 14, + 133, + 10, + 14, + 19, + 8 + ], + [ + 3, + 10, + 14, + 5, + 17, + 101, + 8, + 13, + 9 + ], + [ + 6, + 10, + 10, + 8, + 22, + 4, + 103, + 7, + 10 + ], + [ + 6, + 14, + 11, + 19, + 19, + 6, + 7, + 94, + 4 + ], + [ + 12, + 11, + 10, + 8, + 17, + 1, + 7, + 5, + 109 + ] + ], + "per_class_recall": [ + 0.5166666666666667, + 0.4777777777777778, + 0.5722222222222222, + 0.37777777777777777, + 0.5541666666666667, + 0.5611111111111111, + 0.5722222222222222, + 0.5222222222222223, + 0.6055555555555555 + ], + "balanced_accuracy": 0.528858024691358, + "accuracy": 0.5297619047619048, + "weighted_f1": 0.5313844597197926, + "macro_f1": 0.5332500819972722, + "kappa": 0.4693789430757791, + "samples": 1680, + "reward": 0.528858024691358, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 372, + 722, + 224, + 214, + 1198, + 12757 + ], + "confusion_matrix": [ + [ + 38, + 38, + 3, + 0, + 3, + 37 + ], + [ + 0, + 225, + 0, + 17, + 49, + 0 + ], + [ + 109, + 151, + 220, + 26, + 155, + 8 + ], + [ + 5, + 0, + 0, + 77, + 0, + 4 + ], + [ + 0, + 0, + 1, + 0, + 468, + 31 + ], + [ + 220, + 308, + 0, + 94, + 523, + 12677 + ] + ], + "per_class_recall": [ + 0.31932773109243695, + 0.7731958762886598, + 0.32884902840059793, + 0.8953488372093024, + 0.936, + 0.917161047605267 + ], + "balanced_accuracy": 0.6949804200993773, + "accuracy": 0.8849357525666688, + "weighted_f1": 0.9028244428833873, + "macro_f1": 0.5183689090280728, + "kappa": 0.5584225391144733, + "samples": 15487, + "reward": 0.6949804200993773, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2019, + 2381 + ], + "confusion_matrix": [ + [ + 1713, + 487 + ], + [ + 306, + 1894 + ] + ], + "per_class_recall": [ + 0.7786363636363637, + 0.860909090909091 + ], + "balanced_accuracy": 0.8197727272727273, + "accuracy": 0.8197727272727273, + "weighted_f1": 0.8194672296441308, + "macro_f1": 0.8194672296441308, + "kappa": 0.6395454545454545, + "samples": 4400, + "subject_scores": { + "19": 0.8775, + "35": 0.9475, + "34": 0.66, + "51": 0.775, + "20": 0.84, + "44": 0.94, + "24": 0.6125, + "15": 0.8925, + "31": 0.9075, + "26": 0.8325, + "23": 0.7324999999999999 + }, + "reward": 0.8197727272727273, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4557, + 3861 + ], + "confusion_matrix": [ + [ + 3787, + 473 + ], + [ + 770, + 3388 + ] + ], + "per_class_recall": [ + 0.8889671361502347, + 0.8148148148148148 + ], + "balanced_accuracy": 0.8518909754825248, + "accuracy": 0.8523402233309575, + "weighted_f1": 0.8520927374098584, + "macro_f1": 0.8520077422450363, + "kappa": 0.7043842916571105, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8627793239279558, + "sub-G2007": 0.8170341679949338, + "sub-G2019": 0.8440591920674063, + "sub-G2031": 0.8293459495480183, + "sub-G2015": 0.8930622135668076, + "sub-CTR002": 0.9934852728970376, + "sub-G2011": 0.8116734429970227, + "sub-G2035": 0.9615173021959981, + "sub-CTR003": 0.6396103896103896 + }, + "reward": 0.8502852505339522, + "subjects": 9 + } + }, + "selected_private_epochs": { + "faced": 0, + "tuev": 4, + "ad65": 0, + "openbmi": 0, + "longitudinal": 0 + } + } + ], + "settings": { + "source": "/workspace/research/pilots/refinement_input_fixed_pilot1/epoch-001", + "cache": "/workspace/research/shared_refinement_parent_v1/descriptors", + "parent_cache": "/workspace/research/shared_refinement_parent_v1/parent", + "output": "/workspace/research/runs/refinement_input_fixed_full1", + "epochs": 30, + "steps": 200, + "batch_size": 128, + "lr": 0.0003, + "retention": 0.0, + "input_lr": 0.0 + }, + "full_receipt_reference": { + "path": "/workspace/research/sources/motor_local_source/training.json", + "sha256": "42fa405d4292c9e6d9d33f1c8ed60cbc379c7a8b4072387e359c6ced3eaa9f82", + "bytes": 85162 + }, + "shared_backbone_training": "Full immutable original joint training ancestry is hash-bound by this receipt reference." + }, + "all_tracks_update_shared_backbone": true, + "shared_gradient_audit": [ + { + "track": "faced", + "common_gradient_norms": { + "0.weight": 0.005554957780987024, + "0.bias": 0.0010099404025822878, + "1.weight": 0.00034154471359215677, + "1.bias": 0.00033453849027864635, + "4.weight": 0.007036804221570492, + "4.bias": 0.0007834684802219272, + "5.weight": 0.0002646586508490145, + "5.bias": 0.00034636110649444163 + }, + "private_class_projection_gradient_norm": 0.8268738985061646, + "common_embedding_input_gradient_norm": 0.03095870092511177 + }, + { + "track": "tuev", + "common_gradient_norms": { + "0.weight": 0.008011266589164734, + "0.bias": 0.0011841199593618512, + "1.weight": 0.00042904680594801903, + "1.bias": 0.000410587468650192, + "4.weight": 0.010127697139978409, + "4.bias": 0.000685357314068824, + "5.weight": 0.0004279142012819648, + "5.bias": 0.0002584595058578998 + }, + "private_class_projection_gradient_norm": 1.0755102634429932, + "common_embedding_input_gradient_norm": 0.04150320217013359 + }, + { + "track": "ad65", + "common_gradient_norms": { + "0.weight": 0.009143608622252941, + "0.bias": 0.002143602352589369, + "1.weight": 0.000614811317063868, + "1.bias": 0.0006583580980077386, + "4.weight": 0.013997680507600307, + "4.bias": 0.0017604384338483214, + "5.weight": 0.0005348137929104269, + "5.bias": 0.0008206783677451313 + }, + "private_class_projection_gradient_norm": 1.5632424354553223, + "common_embedding_input_gradient_norm": 0.054304927587509155 + }, + { + "track": "openbmi", + "common_gradient_norms": { + "0.weight": 0.006447882391512394, + "0.bias": 0.00086830003419891, + "1.weight": 0.0003228632267564535, + "1.bias": 0.0002872960176318884, + "4.weight": 0.006952621974050999, + "4.bias": 0.0004111777525395155, + "5.weight": 0.00028086197562515736, + "5.bias": 0.0001816378498915583 + }, + "private_class_projection_gradient_norm": 0.6631720066070557, + "common_embedding_input_gradient_norm": 0.01845531351864338 + }, + { + "track": "longitudinal", + "common_gradient_norms": { + "0.weight": 0.006071922369301319, + "0.bias": 0.0009224270470440388, + "1.weight": 0.0002898380917031318, + "1.bias": 0.000293154880637303, + "4.weight": 0.007737975101917982, + "4.bias": 0.0006117901066318154, + "5.weight": 0.0002807079872582108, + "5.bias": 0.0002737204195000231 + }, + "private_class_projection_gradient_norm": 0.6638067960739136, + "common_embedding_input_gradient_norm": 0.08714403212070465 + } + ], + "source_cache_provenance": { + "source": "/workspace/research/sources/motor_local_source", + "weights_sha256": "0294a80709824e9f2b86c365b8c7893be19f001dd200ff50efb6cb5d97c43e00", + "ancestor_weights_sha256": "b4a858b3dab746a6600aa1fd194e7cc42b277fd11eb07d8561aff980f3a26b9d", + "model_code_sha256": "10c6b9f71faf3a43cdfb6bfac6330d58e894d29d8a54710fce45aa0f73de7e90", + "all_prior_tensors_exact": true, + "manifests": { + "faced-train": "24f7c5c2165944b3544cd0935cc3dc84b9d9df9eb4fa347656d5135c0824ab4b", + "faced-val": "a3074299e9ebd90194bf2ca365529d5ce4806adbe63fb45fb8818ce7b00c70c5", + "tuev-train": "49b7880052e6d093633e6e03d52bfd7df9084271ebf8e4f60e4fbe12da398354", + "tuev-val": "b3e38b33be594d2e5904000be876a8f85b96869dc26c24f1dcc07444c476c5d3", + "ad65-train": "f11857b9ef2fda74fef95b5a692afcc4ad6df740f014223780e04580e69dd93e", + "ad65-val": "81f42305bb52728391c7cf2f07cd550c13fc7934b8bd42770252d966dac37a05", + "openbmi-train": "35446de7b6e3e536f735e935c7eb74cc720f198a60d700da1db5fa39f315f5d5", + "openbmi-val": "56622533f8fa28c2f7e1a619b04b2350f902494e9de1e58fa5e3abea59f8259c", + "longitudinal-train": "6ec8c8090a099cd4e4bf5faaf4bf97be7701916f7333a4e3b5c87b1d0b9f1acc", + "longitudinal-val": "fae612fca74139815b5b53e20ed7af7f50083026b0126962bdd5f954b9047edb" + }, + "finite": { + "faced-train": true, + "faced-val": true, + "tuev-train": true, + "tuev-val": true, + "ad65-train": true, + "ad65-val": true, + "openbmi-train": true, + "openbmi-val": true, + "longitudinal-train": true, + "longitudinal-val": true + }, + "raw_parent_logit_errors": { + "faced": 0.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 0.0 + }, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 155, + 183, + 180, + 166, + 313, + 148, + 185, + 175, + 175 + ], + "confusion_matrix": [ + [ + 93, + 11, + 2, + 16, + 24, + 6, + 10, + 12, + 6 + ], + [ + 10, + 86, + 6, + 13, + 27, + 9, + 11, + 7, + 11 + ], + [ + 7, + 7, + 103, + 15, + 16, + 6, + 9, + 7, + 10 + ], + [ + 7, + 20, + 7, + 68, + 38, + 5, + 16, + 11, + 8 + ], + [ + 11, + 14, + 17, + 14, + 133, + 10, + 14, + 19, + 8 + ], + [ + 3, + 10, + 14, + 5, + 17, + 101, + 8, + 13, + 9 + ], + [ + 6, + 10, + 10, + 8, + 22, + 4, + 103, + 7, + 10 + ], + [ + 6, + 14, + 11, + 19, + 19, + 6, + 7, + 94, + 4 + ], + [ + 12, + 11, + 10, + 8, + 17, + 1, + 7, + 5, + 109 + ] + ], + "per_class_recall": [ + 0.5166666666666667, + 0.4777777777777778, + 0.5722222222222222, + 0.37777777777777777, + 0.5541666666666667, + 0.5611111111111111, + 0.5722222222222222, + 0.5222222222222223, + 0.6055555555555555 + ], + "balanced_accuracy": 0.528858024691358, + "accuracy": 0.5297619047619048, + "weighted_f1": 0.5313844597197926, + "macro_f1": 0.5332500819972722, + "kappa": 0.4693789430757791, + "samples": 1680, + "reward": 0.528858024691358, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 372, + 722, + 224, + 214, + 1198, + 12757 + ], + "confusion_matrix": [ + [ + 38, + 38, + 3, + 0, + 3, + 37 + ], + [ + 0, + 225, + 0, + 17, + 49, + 0 + ], + [ + 109, + 151, + 220, + 26, + 155, + 8 + ], + [ + 5, + 0, + 0, + 77, + 0, + 4 + ], + [ + 0, + 0, + 1, + 0, + 468, + 31 + ], + [ + 220, + 308, + 0, + 94, + 523, + 12677 + ] + ], + "per_class_recall": [ + 0.31932773109243695, + 0.7731958762886598, + 0.32884902840059793, + 0.8953488372093024, + 0.936, + 0.917161047605267 + ], + "balanced_accuracy": 0.6949804200993773, + "accuracy": 0.8849357525666688, + "weighted_f1": 0.9028244428833873, + "macro_f1": 0.5183689090280728, + "kappa": 0.5584225391144733, + "samples": 15487, + "reward": 0.6949804200993773, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2019, + 2381 + ], + "confusion_matrix": [ + [ + 1713, + 487 + ], + [ + 306, + 1894 + ] + ], + "per_class_recall": [ + 0.7786363636363637, + 0.860909090909091 + ], + "balanced_accuracy": 0.8197727272727273, + "accuracy": 0.8197727272727273, + "weighted_f1": 0.8194672296441308, + "macro_f1": 0.8194672296441308, + "kappa": 0.6395454545454545, + "samples": 4400, + "subject_scores": { + "19": 0.8775, + "35": 0.9475, + "34": 0.66, + "51": 0.775, + "20": 0.84, + "44": 0.94, + "24": 0.6125, + "15": 0.8925, + "31": 0.9075, + "26": 0.8325, + "23": 0.7324999999999999 + }, + "reward": 0.8197727272727273, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4557, + 3861 + ], + "confusion_matrix": [ + [ + 3787, + 473 + ], + [ + 770, + 3388 + ] + ], + "per_class_recall": [ + 0.8889671361502347, + 0.8148148148148148 + ], + "balanced_accuracy": 0.8518909754825248, + "accuracy": 0.8523402233309575, + "weighted_f1": 0.8520927374098584, + "macro_f1": 0.8520077422450363, + "kappa": 0.7043842916571105, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8627793239279558, + "sub-G2007": 0.8170341679949338, + "sub-G2019": 0.8440591920674063, + "sub-G2031": 0.8293459495480183, + "sub-G2015": 0.8930622135668076, + "sub-CTR002": 0.9934852728970376, + "sub-G2011": 0.8116734429970227, + "sub-G2035": 0.9615173021959981, + "sub-CTR003": 0.6396103896103896 + }, + "reward": 0.8502852505339522, + "subjects": 9 + } + }, + "fitted_statistics": false, + "complete": true, + "composition": { + "faced-train": { + "parent_refinement_features": "/workspace/research/shared_refinement_parent_v1/descriptors/faced-train-student.npy", + "features_sha256": "11a7fcbb8b4ab21111ab40355290de1893beaf75a2cb2cd168cbb1ca74b223c4", + "complete_b4_logits": "/workspace/research/shared_refinement_parent_v1/parent/faced-train-logits.npy", + "ancestor_logits_sha256": "15f19946fb89a4e2cb56c1691320cd5fab13a9b771420d0da9ed7b4dfd8b9f19", + "result_logits_sha256": "15f19946fb89a4e2cb56c1691320cd5fab13a9b771420d0da9ed7b4dfd8b9f19" + }, + "faced-val": { + "parent_refinement_features": "/workspace/research/shared_refinement_parent_v1/descriptors/faced-val-student.npy", + "features_sha256": "7e7263a966d0e0491f8037fdd358d6fef915ac4ca9e5d903d01d051e57eeb000", + "complete_b4_logits": "/workspace/research/shared_refinement_parent_v1/parent/faced-val-logits.npy", + "ancestor_logits_sha256": "0de28ca13758f66d1491f52be67f9f9028b03467045668f978c10e2be0ed1813", + "result_logits_sha256": "0de28ca13758f66d1491f52be67f9f9028b03467045668f978c10e2be0ed1813", + "exact_prediction_source": { + "path": "/workspace/research/runs/refinement_input_fixed_full1/faced-e004.npy", + "sha256": "3d81f119aa8e419420b17a92ad283d8f33315876eddcda8c44313ae1df7797db" + } + }, + "tuev-train": { + "parent_refinement_features": "/workspace/research/shared_refinement_parent_v1/descriptors/tuev-train-student.npy", + "features_sha256": "26317c591adf8a99bd70dba71b2b89de1fe6d6ee147d0112719fc367f47fbb56", + "complete_b4_logits": "/workspace/research/shared_refinement_parent_v1/parent/tuev-train-logits.npy", + "ancestor_logits_sha256": "ee2b58ee119338babafdb2894c867bca799ea45d3394820fb25d8906fcc84596", + "result_logits_sha256": "55d578471a53df4a4c7fbd268943d490a0b62b39e41dfe3c18da54c041e34fd8" + }, + "tuev-val": { + "parent_refinement_features": "/workspace/research/shared_refinement_parent_v1/descriptors/tuev-val-student.npy", + "features_sha256": "fd162749b02bed9e69a520c74b0ea5dd5b530a41294eaf0a4a2a682d4945b373", + "complete_b4_logits": "/workspace/research/shared_refinement_parent_v1/parent/tuev-val-logits.npy", + "ancestor_logits_sha256": "b0c0e5a9da48ea7f046c4775930a345d3c39710f1f56519be4d570126996d432", + "result_logits_sha256": "ca72825465c64c301efccaa4463c2b86a0b4c8516fafb2d82b46710c0bbf5a05", + "exact_prediction_source": { + "path": "/workspace/research/runs/refinement_input_fixed_full1/tuev-e004.npy", + "sha256": "3ef7dcb6ab5afb05bfce06e01ef0d07790bf6efd27d70089d6a362445129025b" + } + }, + "ad65-train": { + "parent_refinement_features": "/workspace/research/shared_refinement_parent_v1/descriptors/ad65-train-student.npy", + "features_sha256": "2eeb0a3b9b5e36de637111d59aa85db3d3952303a74c2aeb67c1a90b8d065384", + "complete_b4_logits": "/workspace/research/shared_refinement_parent_v1/parent/ad65-train-logits.npy", + "ancestor_logits_sha256": "b14ea003791eb950aab7696d55c7204d2575c5eabb7ba3c7bb0f76525d581623", + "result_logits_sha256": "b14ea003791eb950aab7696d55c7204d2575c5eabb7ba3c7bb0f76525d581623" + }, + "ad65-val": { + "parent_refinement_features": "/workspace/research/shared_refinement_parent_v1/descriptors/ad65-val-student.npy", + "features_sha256": "2ab476e81a73bd900e93369fba0a1ea011714f77b9f0869d16ba01b844602589", + "complete_b4_logits": "/workspace/research/shared_refinement_parent_v1/parent/ad65-val-logits.npy", + "ancestor_logits_sha256": "6ddaaac7f2c4acc252b10ee108286cf6ecd498235363106237bbfc96ab2acde1", + "result_logits_sha256": "6ddaaac7f2c4acc252b10ee108286cf6ecd498235363106237bbfc96ab2acde1", + "exact_prediction_source": { + "path": "/workspace/research/runs/refinement_input_fixed_full1/ad65-e004.npy", + "sha256": "7a3b74c58580b7ba952322bf6d527ebc9a40a6e04c7cdbbaea14e84a7a298d54" + } + }, + "openbmi-train": { + "parent_refinement_features": "/workspace/research/shared_refinement_parent_v1/descriptors/openbmi-train-student.npy", + "features_sha256": "c24becfda341416b934b9257ea18fb31f2d5cc566dbe5c63e997fc03ac3305cd", + "complete_b4_logits": "/workspace/research/shared_refinement_parent_v1/parent/openbmi-train-logits.npy", + "ancestor_logits_sha256": "153ab441ea4705e1699c55c02dfa7697c6e9b5bdf96117e76122173efa75ea56", + "result_logits_sha256": "153ab441ea4705e1699c55c02dfa7697c6e9b5bdf96117e76122173efa75ea56" + }, + "openbmi-val": { + "parent_refinement_features": "/workspace/research/shared_refinement_parent_v1/descriptors/openbmi-val-student.npy", + "features_sha256": "86918167cef1c77911eedfdda6a3fbbeea820afe53a5e1513954a983f2b21373", + "complete_b4_logits": "/workspace/research/shared_refinement_parent_v1/parent/openbmi-val-logits.npy", + "ancestor_logits_sha256": "b0a05c2e7fbdb0a8574c2497edea8105afb9434f8f68d34bdbd3013789e0c2b9", + "result_logits_sha256": "b0a05c2e7fbdb0a8574c2497edea8105afb9434f8f68d34bdbd3013789e0c2b9", + "exact_prediction_source": { + "path": "/workspace/research/runs/refinement_input_fixed_full1/openbmi-e004.npy", + "sha256": "18d98d6de568ebc38c5dcfd6008d5aa8a10a318f3937b7d6c609f47ee5312a59" + } + }, + "longitudinal-train": { + "parent_refinement_features": "/workspace/research/shared_refinement_parent_v1/descriptors/longitudinal-train-student.npy", + "features_sha256": "527d83ccd11bbe32525f5526f638fe87762742fbb6f980b8a8c286405e4aa1d8", + "complete_b4_logits": "/workspace/research/shared_refinement_parent_v1/parent/longitudinal-train-logits.npy", + "ancestor_logits_sha256": "7083a13dde45371b763c50d2e7b5596c909fadb2263a5f0463bf83ecae3950e2", + "result_logits_sha256": "33ab1a968bc52701920873bb209b065829bbc4194e530192142c77c76c98146d" + }, + "longitudinal-val": { + "parent_refinement_features": "/workspace/research/shared_refinement_parent_v1/descriptors/longitudinal-val-student.npy", + "features_sha256": "667132645712a02e2d933b10f779e8f48b07f7a29e25ac73c276689912d17984", + "complete_b4_logits": "/workspace/research/shared_refinement_parent_v1/parent/longitudinal-val-logits.npy", + "ancestor_logits_sha256": "c4a77c163aef9a9fd9b1c7401e34de38a6654cc6cf83b5491e6d971ba8596d3e", + "result_logits_sha256": "708af14ce1f8bc3f6e84e2a8b769d838b66a53f42f386670ca641821794e2233", + "exact_prediction_source": { + "path": "/workspace/research/runs/refinement_input_fixed_full1/longitudinal-e004.npy", + "sha256": "0ebfa01da119ecfab6e850ca643719d02596f18446c1c599197fa3fe0ef19d9b" + } + } + }, + "created_at": "2026-11-01T11:59:13.544995+00:00", + "crop": "native", + "spatial_mode": "native", + "descriptor_provenance_sha256": "a73be624c8be7557485290d38ee5573ee2b8cdc28372f1de5ba21aeb1354e619", + "descriptor_files": { + "faced-train-student.npy": { + "source": "/workspace/research/shared_refinement_parent_v1/descriptors/faced-train-student.npy", + "sha256": "11a7fcbb8b4ab21111ab40355290de1893beaf75a2cb2cd168cbb1ca74b223c4", + "copied_exactly": true, + "shape": [ + 6720, + 3696 + ] + }, + "faced-val-student.npy": { + "source": "/workspace/research/shared_refinement_parent_v1/descriptors/faced-val-student.npy", + "sha256": "7e7263a966d0e0491f8037fdd358d6fef915ac4ca9e5d903d01d051e57eeb000", + "copied_exactly": true, + "shape": [ + 1680, + 3696 + ] + }, + "tuev-train-student.npy": { + "source": "/workspace/research/shared_refinement_parent_v1/descriptors/tuev-train-student.npy", + "sha256": "26317c591adf8a99bd70dba71b2b89de1fe6d6ee147d0112719fc367f47fbb56", + "copied_exactly": true, + "shape": [ + 68445, + 3176 + ] + }, + "tuev-val-student.npy": { + "source": "/workspace/research/shared_refinement_parent_v1/descriptors/tuev-val-student.npy", + "sha256": "fd162749b02bed9e69a520c74b0ea5dd5b530a41294eaf0a4a2a682d4945b373", + "copied_exactly": true, + "shape": [ + 15487, + 3176 + ] + }, + "ad65-train-student.npy": { + "source": "/workspace/research/shared_refinement_parent_v1/descriptors/ad65-train-student.npy", + "sha256": "2eeb0a3b9b5e36de637111d59aa85db3d3952303a74c2aeb67c1a90b8d065384", + "copied_exactly": true, + "shape": [ + 3774, + 3971 + ] + }, + "ad65-val-student.npy": { + "source": "/workspace/research/shared_refinement_parent_v1/descriptors/ad65-val-student.npy", + "sha256": "2ab476e81a73bd900e93369fba0a1ea011714f77b9f0869d16ba01b844602589", + "copied_exactly": true, + "shape": [ + 1343, + 3971 + ] + }, + "openbmi-train-student.npy": { + "sha256": "79dd138a5b7000bb4d5cf56bdc3573f1a68bb5d829cd44c274d263f043728a3c", + "computed_from_provided_raw_inputs": true, + "finite": true, + "shape": [ + 12800, + 981 + ] + }, + "openbmi-val-student.npy": { + "sha256": "05f728579bf04dd9e57caff8b0675cce215a28a9624a61f1cb313d3185f3100d", + "computed_from_provided_raw_inputs": true, + "finite": true, + "shape": [ + 4400, + 981 + ] + }, + "longitudinal-train-student.npy": { + "source": "/workspace/research/shared_refinement_parent_v1/descriptors/longitudinal-train-student.npy", + "sha256": "527d83ccd11bbe32525f5526f638fe87762742fbb6f980b8a8c286405e4aa1d8", + "copied_exactly": true, + "shape": [ + 28523, + 20039 + ] + }, + "longitudinal-val-student.npy": { + "source": "/workspace/research/shared_refinement_parent_v1/descriptors/longitudinal-val-student.npy", + "sha256": "667132645712a02e2d933b10f779e8f48b07f7a29e25ac73c276689912d17984", + "copied_exactly": true, + "shape": [ + 8418, + 20039 + ] + } + }, + "raw_context_feature_errors": { + "faced": 0.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 0.0 + } + }, + "raw_initialization_logit_errors": { + "faced": 0.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 0.0 + }, + "raw_context_feature_errors": { + "faced": 0.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 0.0 + }, + "parent_cache_provenance": { + "source": "/workspace/research/sources/motor_local_source", + "weights_sha256": "0294a80709824e9f2b86c365b8c7893be19f001dd200ff50efb6cb5d97c43e00", + "ancestor_weights_sha256": "b4a858b3dab746a6600aa1fd194e7cc42b277fd11eb07d8561aff980f3a26b9d", + "model_code_sha256": "10c6b9f71faf3a43cdfb6bfac6330d58e894d29d8a54710fce45aa0f73de7e90", + "all_prior_tensors_exact": true, + "manifests": { + "faced-train": "24f7c5c2165944b3544cd0935cc3dc84b9d9df9eb4fa347656d5135c0824ab4b", + "faced-val": "a3074299e9ebd90194bf2ca365529d5ce4806adbe63fb45fb8818ce7b00c70c5", + "tuev-train": "49b7880052e6d093633e6e03d52bfd7df9084271ebf8e4f60e4fbe12da398354", + "tuev-val": "b3e38b33be594d2e5904000be876a8f85b96869dc26c24f1dcc07444c476c5d3", + "ad65-train": "f11857b9ef2fda74fef95b5a692afcc4ad6df740f014223780e04580e69dd93e", + "ad65-val": "81f42305bb52728391c7cf2f07cd550c13fc7934b8bd42770252d966dac37a05", + "openbmi-train": "35446de7b6e3e536f735e935c7eb74cc720f198a60d700da1db5fa39f315f5d5", + "openbmi-val": "56622533f8fa28c2f7e1a619b04b2350f902494e9de1e58fa5e3abea59f8259c", + "longitudinal-train": "6ec8c8090a099cd4e4bf5faaf4bf97be7701916f7333a4e3b5c87b1d0b9f1acc", + "longitudinal-val": "fae612fca74139815b5b53e20ed7af7f50083026b0126962bdd5f954b9047edb" + }, + "finite": { + "faced-train": true, + "faced-val": true, + "tuev-train": true, + "tuev-val": true, + "ad65-train": true, + "ad65-val": true, + "openbmi-train": true, + "openbmi-val": true, + "longitudinal-train": true, + "longitudinal-val": true + }, + "raw_parent_logit_errors": { + "faced": 0.0, + "tuev": 0.0, + "ad65": 0.0, + "openbmi": 0.0, + "longitudinal": 0.0 + }, + "validation": { + "faced": { + "class_counts": [ + 180, + 180, + 180, + 180, + 240, + 180, + 180, + 180, + 180 + ], + "predicted_class_counts": [ + 155, + 183, + 180, + 166, + 313, + 148, + 185, + 175, + 175 + ], + "confusion_matrix": [ + [ + 93, + 11, + 2, + 16, + 24, + 6, + 10, + 12, + 6 + ], + [ + 10, + 86, + 6, + 13, + 27, + 9, + 11, + 7, + 11 + ], + [ + 7, + 7, + 103, + 15, + 16, + 6, + 9, + 7, + 10 + ], + [ + 7, + 20, + 7, + 68, + 38, + 5, + 16, + 11, + 8 + ], + [ + 11, + 14, + 17, + 14, + 133, + 10, + 14, + 19, + 8 + ], + [ + 3, + 10, + 14, + 5, + 17, + 101, + 8, + 13, + 9 + ], + [ + 6, + 10, + 10, + 8, + 22, + 4, + 103, + 7, + 10 + ], + [ + 6, + 14, + 11, + 19, + 19, + 6, + 7, + 94, + 4 + ], + [ + 12, + 11, + 10, + 8, + 17, + 1, + 7, + 5, + 109 + ] + ], + "per_class_recall": [ + 0.5166666666666667, + 0.4777777777777778, + 0.5722222222222222, + 0.37777777777777777, + 0.5541666666666667, + 0.5611111111111111, + 0.5722222222222222, + 0.5222222222222223, + 0.6055555555555555 + ], + "balanced_accuracy": 0.528858024691358, + "accuracy": 0.5297619047619048, + "weighted_f1": 0.5313844597197926, + "macro_f1": 0.5332500819972722, + "kappa": 0.4693789430757791, + "samples": 1680, + "reward": 0.528858024691358, + "subjects": 20 + }, + "tuev": { + "class_counts": [ + 119, + 291, + 669, + 86, + 500, + 13822 + ], + "predicted_class_counts": [ + 372, + 722, + 224, + 214, + 1198, + 12757 + ], + "confusion_matrix": [ + [ + 38, + 38, + 3, + 0, + 3, + 37 + ], + [ + 0, + 225, + 0, + 17, + 49, + 0 + ], + [ + 109, + 151, + 220, + 26, + 155, + 8 + ], + [ + 5, + 0, + 0, + 77, + 0, + 4 + ], + [ + 0, + 0, + 1, + 0, + 468, + 31 + ], + [ + 220, + 308, + 0, + 94, + 523, + 12677 + ] + ], + "per_class_recall": [ + 0.31932773109243695, + 0.7731958762886598, + 0.32884902840059793, + 0.8953488372093024, + 0.936, + 0.917161047605267 + ], + "balanced_accuracy": 0.6949804200993773, + "accuracy": 0.8849357525666688, + "weighted_f1": 0.9028244428833873, + "macro_f1": 0.5183689090280728, + "kappa": 0.5584225391144733, + "samples": 15487, + "reward": 0.6949804200993773, + "subjects": 58 + }, + "ad65": { + "class_counts": [ + 464, + 393, + 486 + ], + "predicted_class_counts": [ + 440, + 309, + 594 + ], + "confusion_matrix": [ + [ + 287, + 86, + 91 + ], + [ + 96, + 185, + 112 + ], + [ + 57, + 38, + 391 + ] + ], + "per_class_recall": [ + 0.6185344827586207, + 0.4707379134860051, + 0.8045267489711934 + ], + "balanced_accuracy": 0.6312663817386064, + "accuracy": 0.6425912137006702, + "weighted_f1": 0.6356338206725993, + "macro_f1": 0.6286984511173302, + "kappa": 0.4579978610488933, + "samples": 1343, + "subject_metrics": { + "class_counts": [ + 7, + 5, + 6 + ], + "predicted_class_counts": [ + 5, + 6, + 7 + ], + "confusion_matrix": [ + [ + 5, + 2, + 0 + ], + [ + 0, + 4, + 1 + ], + [ + 0, + 0, + 6 + ] + ], + "per_class_recall": [ + 0.7142857142857143, + 0.8, + 1.0 + ], + "balanced_accuracy": 0.8380952380952381, + "accuracy": 0.8333333333333334, + "weighted_f1": 0.8337865837865839, + "macro_f1": 0.8278943278943279, + "kappa": 0.7511520737327189 + }, + "reward": 0.8380952380952381, + "subjects": 18 + }, + "openbmi": { + "class_counts": [ + 2200, + 2200 + ], + "predicted_class_counts": [ + 2019, + 2381 + ], + "confusion_matrix": [ + [ + 1713, + 487 + ], + [ + 306, + 1894 + ] + ], + "per_class_recall": [ + 0.7786363636363637, + 0.860909090909091 + ], + "balanced_accuracy": 0.8197727272727273, + "accuracy": 0.8197727272727273, + "weighted_f1": 0.8194672296441308, + "macro_f1": 0.8194672296441308, + "kappa": 0.6395454545454545, + "samples": 4400, + "subject_scores": { + "19": 0.8775, + "35": 0.9475, + "34": 0.66, + "51": 0.775, + "20": 0.84, + "44": 0.94, + "24": 0.6125, + "15": 0.8925, + "31": 0.9075, + "26": 0.8325, + "23": 0.7324999999999999 + }, + "reward": 0.8197727272727273, + "subjects": 11 + }, + "longitudinal": { + "class_counts": [ + 4260, + 4158 + ], + "predicted_class_counts": [ + 4557, + 3861 + ], + "confusion_matrix": [ + [ + 3787, + 473 + ], + [ + 770, + 3388 + ] + ], + "per_class_recall": [ + 0.8889671361502347, + 0.8148148148148148 + ], + "balanced_accuracy": 0.8518909754825248, + "accuracy": 0.8523402233309575, + "weighted_f1": 0.8520927374098584, + "macro_f1": 0.8520077422450363, + "kappa": 0.7043842916571105, + "samples": 8418, + "subject_scores": { + "sub-G2021": 0.8627793239279558, + "sub-G2007": 0.8170341679949338, + "sub-G2019": 0.8440591920674063, + "sub-G2031": 0.8293459495480183, + "sub-G2015": 0.8930622135668076, + "sub-CTR002": 0.9934852728970376, + "sub-G2011": 0.8116734429970227, + "sub-G2035": 0.9615173021959981, + "sub-CTR003": 0.6396103896103896 + }, + "reward": 0.8502852505339522, + "subjects": 9 + } + }, + "fitted_statistics": false, + "complete": true, + "composition": { + "faced-train": { + "parent_refinement_features": "/workspace/research/shared_refinement_parent_v1/descriptors/faced-train-student.npy", + "features_sha256": "11a7fcbb8b4ab21111ab40355290de1893beaf75a2cb2cd168cbb1ca74b223c4", + "complete_b4_logits": "/workspace/research/shared_refinement_parent_v1/parent/faced-train-logits.npy", + "ancestor_logits_sha256": "15f19946fb89a4e2cb56c1691320cd5fab13a9b771420d0da9ed7b4dfd8b9f19", + "result_logits_sha256": "15f19946fb89a4e2cb56c1691320cd5fab13a9b771420d0da9ed7b4dfd8b9f19" + }, + "faced-val": { + "parent_refinement_features": "/workspace/research/shared_refinement_parent_v1/descriptors/faced-val-student.npy", + "features_sha256": "7e7263a966d0e0491f8037fdd358d6fef915ac4ca9e5d903d01d051e57eeb000", + "complete_b4_logits": "/workspace/research/shared_refinement_parent_v1/parent/faced-val-logits.npy", + "ancestor_logits_sha256": "0de28ca13758f66d1491f52be67f9f9028b03467045668f978c10e2be0ed1813", + "result_logits_sha256": "0de28ca13758f66d1491f52be67f9f9028b03467045668f978c10e2be0ed1813", + "exact_prediction_source": { + "path": "/workspace/research/runs/refinement_input_fixed_full1/faced-e004.npy", + "sha256": "3d81f119aa8e419420b17a92ad283d8f33315876eddcda8c44313ae1df7797db" + } + }, + "tuev-train": { + "parent_refinement_features": "/workspace/research/shared_refinement_parent_v1/descriptors/tuev-train-student.npy", + "features_sha256": "26317c591adf8a99bd70dba71b2b89de1fe6d6ee147d0112719fc367f47fbb56", + "complete_b4_logits": "/workspace/research/shared_refinement_parent_v1/parent/tuev-train-logits.npy", + "ancestor_logits_sha256": "ee2b58ee119338babafdb2894c867bca799ea45d3394820fb25d8906fcc84596", + "result_logits_sha256": "55d578471a53df4a4c7fbd268943d490a0b62b39e41dfe3c18da54c041e34fd8" + }, + "tuev-val": { + "parent_refinement_features": "/workspace/research/shared_refinement_parent_v1/descriptors/tuev-val-student.npy", + "features_sha256": "fd162749b02bed9e69a520c74b0ea5dd5b530a41294eaf0a4a2a682d4945b373", + "complete_b4_logits": "/workspace/research/shared_refinement_parent_v1/parent/tuev-val-logits.npy", + "ancestor_logits_sha256": "b0c0e5a9da48ea7f046c4775930a345d3c39710f1f56519be4d570126996d432", + "result_logits_sha256": "ca72825465c64c301efccaa4463c2b86a0b4c8516fafb2d82b46710c0bbf5a05", + "exact_prediction_source": { + "path": "/workspace/research/runs/refinement_input_fixed_full1/tuev-e004.npy", + "sha256": "3ef7dcb6ab5afb05bfce06e01ef0d07790bf6efd27d70089d6a362445129025b" + } + }, + "ad65-train": { + "parent_refinement_features": "/workspace/research/shared_refinement_parent_v1/descriptors/ad65-train-student.npy", + "features_sha256": "2eeb0a3b9b5e36de637111d59aa85db3d3952303a74c2aeb67c1a90b8d065384", + "complete_b4_logits": "/workspace/research/shared_refinement_parent_v1/parent/ad65-train-logits.npy", + "ancestor_logits_sha256": "b14ea003791eb950aab7696d55c7204d2575c5eabb7ba3c7bb0f76525d581623", + "result_logits_sha256": "b14ea003791eb950aab7696d55c7204d2575c5eabb7ba3c7bb0f76525d581623" + }, + "ad65-val": { + "parent_refinement_features": "/workspace/research/shared_refinement_parent_v1/descriptors/ad65-val-student.npy", + "features_sha256": "2ab476e81a73bd900e93369fba0a1ea011714f77b9f0869d16ba01b844602589", + "complete_b4_logits": "/workspace/research/shared_refinement_parent_v1/parent/ad65-val-logits.npy", + "ancestor_logits_sha256": "6ddaaac7f2c4acc252b10ee108286cf6ecd498235363106237bbfc96ab2acde1", + "result_logits_sha256": "6ddaaac7f2c4acc252b10ee108286cf6ecd498235363106237bbfc96ab2acde1", + "exact_prediction_source": { + "path": "/workspace/research/runs/refinement_input_fixed_full1/ad65-e004.npy", + "sha256": "7a3b74c58580b7ba952322bf6d527ebc9a40a6e04c7cdbbaea14e84a7a298d54" + } + }, + "openbmi-train": { + "parent_refinement_features": "/workspace/research/shared_refinement_parent_v1/descriptors/openbmi-train-student.npy", + "features_sha256": "c24becfda341416b934b9257ea18fb31f2d5cc566dbe5c63e997fc03ac3305cd", + "complete_b4_logits": "/workspace/research/shared_refinement_parent_v1/parent/openbmi-train-logits.npy", + "ancestor_logits_sha256": "153ab441ea4705e1699c55c02dfa7697c6e9b5bdf96117e76122173efa75ea56", + "result_logits_sha256": "153ab441ea4705e1699c55c02dfa7697c6e9b5bdf96117e76122173efa75ea56" + }, + "openbmi-val": { + "parent_refinement_features": "/workspace/research/shared_refinement_parent_v1/descriptors/openbmi-val-student.npy", + "features_sha256": "86918167cef1c77911eedfdda6a3fbbeea820afe53a5e1513954a983f2b21373", + "complete_b4_logits": "/workspace/research/shared_refinement_parent_v1/parent/openbmi-val-logits.npy", + "ancestor_logits_sha256": "b0a05c2e7fbdb0a8574c2497edea8105afb9434f8f68d34bdbd3013789e0c2b9", + "result_logits_sha256": "b0a05c2e7fbdb0a8574c2497edea8105afb9434f8f68d34bdbd3013789e0c2b9", + "exact_prediction_source": { + "path": "/workspace/research/runs/refinement_input_fixed_full1/openbmi-e004.npy", + "sha256": "18d98d6de568ebc38c5dcfd6008d5aa8a10a318f3937b7d6c609f47ee5312a59" + } + }, + "longitudinal-train": { + "parent_refinement_features": "/workspace/research/shared_refinement_parent_v1/descriptors/longitudinal-train-student.npy", + "features_sha256": "527d83ccd11bbe32525f5526f638fe87762742fbb6f980b8a8c286405e4aa1d8", + "complete_b4_logits": "/workspace/research/shared_refinement_parent_v1/parent/longitudinal-train-logits.npy", + "ancestor_logits_sha256": "7083a13dde45371b763c50d2e7b5596c909fadb2263a5f0463bf83ecae3950e2", + "result_logits_sha256": "33ab1a968bc52701920873bb209b065829bbc4194e530192142c77c76c98146d" + }, + "longitudinal-val": { + "parent_refinement_features": "/workspace/research/shared_refinement_parent_v1/descriptors/longitudinal-val-student.npy", + "features_sha256": "667132645712a02e2d933b10f779e8f48b07f7a29e25ac73c276689912d17984", + "complete_b4_logits": "/workspace/research/shared_refinement_parent_v1/parent/longitudinal-val-logits.npy", + "ancestor_logits_sha256": "c4a77c163aef9a9fd9b1c7401e34de38a6654cc6cf83b5491e6d971ba8596d3e", + "result_logits_sha256": "708af14ce1f8bc3f6e84e2a8b769d838b66a53f42f386670ca641821794e2233", + "exact_prediction_source": { + "path": "/workspace/research/runs/refinement_input_fixed_full1/longitudinal-e004.npy", + "sha256": "0ebfa01da119ecfab6e850ca643719d02596f18446c1c599197fa3fe0ef19d9b" + } + } + }, + "created_at": "2026-11-01T11:59:13.544995+00:00" + }, + "training_only_loss_temperatures": { + "faced": 0.7079457640647888, + "tuev": 1.0, + "ad65": 1.0, + "openbmi": 0.7943282723426819, + "longitudinal": 35.4813346862793 + }, + "all_complete_parent_weights_exactly_unchanged": true, + "old_normalization_entries_exactly_preserved": true, + "new_normalizers_fit_on_training_only": true, + "zero_gain_preserves_complete_parent": true, + "training_parent_dropout": { + "probability": 0.5, + "counts": { + "faced": { + "removed": 1279, + "groups": 2560 + }, + "tuev": { + "removed": 1290, + "groups": 2560 + }, + "ad65": { + "removed": 57, + "groups": 120 + }, + "openbmi": { + "removed": 1271, + "groups": 2560 + }, + "longitudinal": { + "removed": 1283, + "groups": 2560 + } + }, + "ad65_one_mask_per_patient": true, + "targets_from_original_unmasked_parent": true, + "validation_and_inference_parent_always_present": true + }, + "auxiliary_classification_weight": 0.25, + "auxiliary_classifier_uses_the_same_residual_projection": true, + "spatial_initialization": { + "every_parent_state_tensor_exact": true, + "new_private_class_projections_initialized_zero": true, + "zero_gain_preserves_complete_parent": true, + "new_keys": [ + "adapters.faced.spatial_normalizer.mean", + "adapters.faced.spatial_normalizer.scale", + "adapters.faced.spatial_projection.weight", + "adapters.faced.spatial_projection.bias", + "adapters.tuev.spatial_normalizer.mean", + "adapters.tuev.spatial_normalizer.scale", + "adapters.tuev.spatial_projection.weight", + "adapters.tuev.spatial_projection.bias", + "adapters.ad65.spatial_normalizer.mean", + "adapters.ad65.spatial_normalizer.scale", + "adapters.ad65.spatial_projection.weight", + "adapters.ad65.spatial_projection.bias", + "adapters.openbmi.spatial_normalizer.mean", + "adapters.openbmi.spatial_normalizer.scale", + "adapters.openbmi.spatial_projection.weight", + "adapters.openbmi.spatial_projection.bias", + "adapters.longitudinal.spatial_normalizer.mean", + "adapters.longitudinal.spatial_normalizer.scale", + "adapters.longitudinal.spatial_projection.weight", + "adapters.longitudinal.spatial_projection.bias", + "backbone.spatial_encoder.0.weight", + "backbone.spatial_encoder.0.bias", + "backbone.spatial_encoder.1.weight", + "backbone.spatial_encoder.1.bias", + "backbone.spatial_encoder.4.weight", + "backbone.spatial_encoder.4.bias", + "backbone.spatial_encoder.5.weight", + "backbone.spatial_encoder.5.bias", + "heads.faced.output_scale", + "heads.faced.correction_gain", + "heads.faced.projection.weight", + "heads.faced.projection.bias", + "heads.tuev.output_scale", + "heads.tuev.correction_gain", + "heads.tuev.projection.weight", + "heads.tuev.projection.bias", + "heads.ad65.output_scale", + "heads.ad65.correction_gain", + "heads.ad65.projection.weight", + "heads.ad65.projection.bias", + "heads.openbmi.output_scale", + "heads.openbmi.correction_gain", + "heads.openbmi.projection.weight", + "heads.openbmi.projection.bias", + "heads.longitudinal.output_scale", + "heads.longitudinal.correction_gain", + "heads.longitudinal.projection.weight", + "heads.longitudinal.projection.bias" + ] + }, + "all_five_validation_splits_evaluated": true, + "ad65_patient_objective": "mean-probability", + "ad65_sampler": "two training patients per class, all windows", + "ad65_batch_window_range": [ + 376, + 510 + ], + "training_sampler": { + "device": "cpu", + "dedicated_generator_seed": 1587, + "isolated_from_cuda_dropout_rng": true + } +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/alpha_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/alpha_features.py new file mode 100644 index 0000000000000000000000000000000000000000..455154d715e86d45e4e17113bed69adbcd946b29 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/alpha_features.py @@ -0,0 +1,45 @@ +"""Fixed alpha prominence features from each individual two-second window.""" +import torch + +REGION_NAMES=('occipital','parietal','central','frontal','left_posterior','right_posterior') +REGIONS=(('PO7','PO5','PO3','POZ','PO4','PO6','PO8','O1','OZ','O2'), + ('P7','P5','P3','P1','PZ','P2','P4','P6','P8'), + ('FC5','FC3','FC1','FCZ','FC2','FC4','FC6','C5','C3','C1','CZ','C2','C4','C6'), + ('FP1','FPZ','FP2','AF3','AF4','F7','F5','F3','F1','FZ','F2','F4','F6','F8'), + ('P7','P5','P3','P1','PO7','PO5','PO3','O1'), + ('P2','P4','P6','P8','PO4','PO6','PO8','O2')) +ALPHA_DIM=58*7+6*22 + +def region_matrix(channels): + result=torch.zeros(len(REGIONS),len(channels)) + for i,names in enumerate(REGIONS): + for name in names:result[i,channels.index(name)]=1/len(names) + return result.tolist() + +@torch.no_grad() +def extract_alpha_features(signal,regions): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();x=x-x.mean(-1,keepdim=True) + spectrum=torch.fft.rfft(x*torch.hann_window(400,device=x.device),dim=-1)/200 + power=spectrum.abs().square().clamp_min(1e-12) + lp=power.log() + # Geometric regional means resist domination by one high-amplitude channel. + regional=torch.einsum('rc,ncf->nrf',regions.float(),lp) + lp=torch.cat([lp,regional],1) + low=lp[...,8:13].mean(-1,keepdim=True) + high=lp[...,36:49].mean(-1,keepdim=True) + freq=torch.arange(7.,14.5,.5,device=x.device) + alpha=lp[...,14:29] + baseline=low+(high-low)*((freq-5)/16) + prominence=alpha-baseline + normalized=alpha.softmax(-1) + center=(normalized*freq).sum(-1) + entropy=-(normalized*normalized.clamp_min(1e-12).log()).sum(-1) + alpha_mean=torch.logsumexp(alpha,-1)-torch.log(torch.tensor(15.,device=x.device)) + def log_band(lo,hi): + return torch.logsumexp(lp[...,lo:hi],-1)-torch.log(torch.tensor(float(hi-lo),device=x.device)) + summaries=torch.stack([alpha_mean-log_band(2,81),alpha_mean-log_band(8,14), + alpha_mean-log_band(30,61),prominence.max(-1).values, + prominence.mean(-1),center,entropy],-1) + return torch.cat([summaries[:,:58].flatten(1),summaries[:,58:].flatten(1), + prominence[:,58:].flatten(1)],1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/covariances.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/covariances.py new file mode 100644 index 0000000000000000000000000000000000000000..a65153f3b18f31995ff206a8e2fb8a7fd7a254dd --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/covariances.py @@ -0,0 +1,25 @@ +"""Shared neural filter-bank covariance decoder with spatial input adapters.""" +import torch +from torch import nn +SPECS={'faced':(32,10,9),'tuev':(16,5,6),'ad65':(19,10,3),'openbmi':(62,4,2),'longitudinal':(58,2,2)} +TRACKS=tuple(SPECS) +BANDS=[(1,4),(4,8),(8,12),(12,16),(16,20),(20,24),(24,28),(28,32),(32,40),(40,48)] + +@torch.no_grad() +def extract_covariances(t,x): + x=torch.nan_to_num(x.float().flatten(2)).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if t in ('faced','tuev'): + x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + else:x=x-x.mean(1,keepdim=True) + # Per-window normalization, preserving spatial and frequency power ratios. + x=x/x.square().mean((1,2),keepdim=True).clamp_min(1e-12).sqrt() + frames=x.unfold(-1,400,200);frames=frames-frames.mean(-1,keepdim=True) + z=torch.fft.rfft(frames*torch.hann_window(400,device=x.device),dim=-1)/200 + covs=[] + for lo,hi in BANDS: + v=z[...,2*lo:2*hi].flatten(2) + cov=(v.real@v.real.transpose(-1,-2)+v.imag@v.imag.transpose(-1,-2))/v.shape[-1] + covs.append(cov) + return torch.stack(covs,1) + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/envelope_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/envelope_features.py new file mode 100644 index 0000000000000000000000000000000000000000..2251a6f03a3a6daaa3faed0bbc803bf182224da6 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/envelope_features.py @@ -0,0 +1,44 @@ +"""Per-window burst-envelope regularity and bilateral synchrony, without fitting.""" +import torch +import torch.nn.functional as F + +BANDS=((1,4),(4,8),(8,13),(13,30),(30,45)) +ENVELOPE_DIM=16*5*12+8*5*2 + +@torch.no_grad() +def extract_envelope_features(signal): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();x=x-x.mean(-1,keepdim=True) + spectrum=torch.fft.fft(x,dim=-1) + frequency=torch.fft.fftfreq(x.shape[-1],1/200,device=x.device) + envelopes=[] + for lo,hi in BANDS: + mask=((frequency>=lo)&(frequency2).float().mean(-1),(relative>4).float().mean(-1), + ((relative[...,1:]>2)&(relative[...,:-1]<=2)).float().mean(-1), + acf_peak,(acf_index.float()+4)/40, + acf[...,0],acf[...,6],acf[...,16],acf[...,36]] + left=torch.tensor([0,1,2,3,8,9,10,11],device=x.device);right=left+4 + synchrony=(normalized[:,left]*normalized[:,right]).mean(-1).clamp(-1,1) + imbalance=(std[:,left].squeeze(-1).log()-std[:,right].squeeze(-1).log()).abs() + return torch.cat([torch.stack(summaries,-1).flatten(1),synchrony.flatten(1),imbalance.flatten(1)],1) + +def mirrored_features(features): + channels=torch.tensor([4,5,6,7,0,1,2,3,12,13,14,15,8,9,10,11],device=features.device) + return torch.cat([features[:,:16*5*12].reshape(-1,16,5,12)[:,channels].flatten(1),features[:,16*5*12:]],1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/features.py new file mode 100644 index 0000000000000000000000000000000000000000..88f7e8b14c9fab44733d5224ede6d6b5c7f76a45 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/features.py @@ -0,0 +1,63 @@ +"""One shared residual backbone, five linear input adapters and output heads.""" +import torch +from torch import nn + +SPECS = {'faced': (32, 10, 9), 'tuev': (16, 5, 6), 'ad65': (19, 10, 3), + 'openbmi': (62, 4, 2), 'longitudinal': (58, 2, 2)} +TRACKS = tuple(SPECS) +EDGES = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,18,20,22,25,28,32,36,40,45,50,60,70,80,95] +COV_BANDS = [(1,4),(4,8),(8,12),(12,16),(16,20),(20,28),(28,40)] + +def feature_dim(channels): + return channels * (4*(len(EDGES)-1)+4) + len(COV_BANDS)*channels*(channels-1)//2 + +@torch.no_grad() +def extract_features(track, x): + """Fixed features; no batch statistics or fitted inference transformations.""" + x = x.float().flatten(2) + x = torch.nan_to_num(x, nan=0., posinf=1e5, neginf=-1e5).clamp(-1e5,1e5) + x = x - x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'): + x = x - x.mean(1,keepdim=True) + rms = x.square().mean(-1).clamp_min(1e-12).sqrt() + norm = x / rms.unsqueeze(-1) + moments = torch.stack([rms.log(), norm.abs().amax(-1).clamp_min(1).log(), + norm.pow(4).mean(-1).clamp_min(1).log(), + (norm[...,1:]-norm[...,:-1]).square().mean(-1).clamp_min(1e-10).log()],-1) + frames = x.unfold(-1,400,200) + frames = frames - frames.mean(-1,keepdim=True) + window = torch.hann_window(400,device=x.device) + z = torch.fft.rfft(frames*window,dim=-1)/200 + power = z.abs().square() + bands = torch.stack([power[...,2*lo:2*hi].mean(-1) for lo,hi in zip(EDGES[:-1],EDGES[1:])],-1) + lp = bands.mean(-2).clamp_min(1e-12).log() + variation = bands.clamp_min(1e-12).log().std(-2,correction=0) + relative_frequency = lp - lp.mean(-1,keepdim=True) + relative_channel = lp - lp.mean(1,keepdim=True) + parts = [torch.cat([lp, relative_frequency, relative_channel, variation, moments],-1).flatten(1)] + ii,jj = torch.triu_indices(x.shape[1],x.shape[1],offset=1,device=x.device) + for lo,hi in COV_BANDS: + v = z[...,2*lo:2*hi].flatten(2) + cov = v.real @ v.real.transpose(-1,-2) + v.imag @ v.imag.transpose(-1,-2) + d = cov.diagonal(dim1=-2,dim2=-1).clamp_min(1e-12).sqrt() + cor = cov / (d.unsqueeze(1)*d.unsqueeze(2)).clamp_min(1e-12) + parts.append(cor[:,ii,jj].clamp(-1,1)) + result = torch.cat(parts,-1) + return torch.nan_to_num(result).clamp(-40,40) + +class Standardize(nn.Module): + def __init__(self, dim): + super().__init__() + self.register_buffer('mean',torch.zeros(dim)) + self.register_buffer('scale',torch.ones(dim)) + def forward(self,x): + return ((x-self.mean)/self.scale).clamp(-8,8) + +class Residual(nn.Module): + def __init__(self,width,dropout): + super().__init__() + self.net=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(), + nn.Dropout(dropout),nn.Linear(width*2,width),nn.Dropout(dropout)) + def forward(self,x): + return x+self.net(x) + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/infer.sh b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/infer.sh new file mode 100644 index 0000000000000000000000000000000000000000..3aae9b42834f2f278e52148d5a07835d9960a4ea --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/infer.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -euo pipefail +exec python "$(dirname -- "$0")/infer.py" "$1" "$2" diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/local_channel_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/local_channel_features.py new file mode 100644 index 0000000000000000000000000000000000000000..fa80cf5248a4f1d0e472e39c12d828992909feff --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/local_channel_features.py @@ -0,0 +1,26 @@ +"""Named local channel differences. These are fixed differences, not a physical CSD model.""" +import torch +ALIASES={'T3':'T7','T4':'T8','T5':'P7','T6':'P8'} +NEIGHBORS={'C3':('F3','CZ','P3','T7'),'CZ':('FZ','C3','C4','PZ'),'C4':('F4','CZ','P4','T8'),'P3':('C3','PZ','O1','P7'),'PZ':('CZ','P3','P4','O1','O2'),'P4':('C4','PZ','O2','P8')} +def canonical(channels): + result=[ALIASES.get(name.upper(),name.upper()) for name in channels] + assert len(set(result))==len(result) + return result + +def projection_matrix(channels,local=True): + names=canonical(channels);matrix=torch.zeros(len(NEIGHBORS),len(names)) + for i,(center,neighbors) in enumerate(NEIGHBORS.items()): + matrix[i,names.index(center)]=1 + if local: + for name in neighbors:matrix[i,names.index(name)]-=1/len(neighbors) + else:matrix[i]-=1/len(names) + return matrix + +@torch.no_grad() +def local_channel_signals(signal,channels,local=True): + with torch.autocast(signal.device.type,enabled=False): + x=torch.nan_to_num(signal.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + names=canonical(channels) + if local: + return torch.stack([(x[:,names.index(center),None]-x[:,[names.index(n) for n in neighbors]]).mean(1) for center,neighbors in NEIGHBORS.items()],1) + return x[:,[names.index(center) for center in NEIGHBORS]]-x.mean(1,keepdim=True) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/native_log_covariance_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/native_log_covariance_features.py new file mode 100644 index 0000000000000000000000000000000000000000..17ef28a907f75094488fb5a6a3890e35463a38bb --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/native_log_covariance_features.py @@ -0,0 +1,35 @@ +"""Native-channel trace-normalized covariance geometry, with a matched linear control.""" +import torch +BANDS=((1,4),(4,8),(8,12),(12,16),(16,20),(20,28),(28,40)) + +@torch.no_grad() +def band_matrices(track,x): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x[...,:1];x=x-x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + reference=x.square().mean((-1,-2),keepdim=True) + n=x.shape[-1];c=x.shape[1];z=torch.fft.rfft(x,dim=-1);f=torch.fft.rfftfreq(n,1/200,device=x.device);eye=torch.eye(c,device=x.device);parts=[] + for low,high in BANDS: + v=torch.fft.irfft(z*((f>=low)&(f(1e-10*reference).clamp_min(1e-20) + normalized=covariance/power.clamp_min(1e-20) + normalized=torch.where(active,normalized,eye) + matrix=.95*normalized+.05*eye + parts.append((matrix+matrix.transpose(-1,-2))*.5) + return torch.stack(parts,1) + +@torch.no_grad() +def connectivity(track,x,logarithmic=True): + matrix=band_matrices(track,x);c=matrix.shape[-1] + if logarithmic: + # CUDA eigh can perturb exactly degenerate identity eigenvalues. + # Preserve the mathematical log(I)=0 for exactly silent/isotropic bands. + nonidentity=(matrix-torch.eye(c,device=matrix.device)).abs().amax((-1,-2))>0 + values,vectors=torch.linalg.eigh(matrix) + matrix=(vectors*values.clamp_min(1e-6).log().unsqueeze(-2))@vectors.transpose(-1,-2) + matrix=torch.where(nonidentity[...,None,None],matrix,torch.zeros_like(matrix)) + else:matrix=matrix-torch.eye(c,device=matrix.device) + i,j=torch.triu_indices(c,c,device=matrix.device);scale=torch.where(i==j,1.,2.**.5) + return (matrix[...,i,j]*scale).flatten(1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/short_context_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/short_context_features.py new file mode 100644 index 0000000000000000000000000000000000000000..f677f7a4319f4afb9071665bf7804558bfdd69d8 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/short_context_features.py @@ -0,0 +1,22 @@ +"""One/two-second fixed spectral descriptors with physical-frequency bands.""" +import torch +from features import EDGES,COV_BANDS +@torch.no_grad() +def short_spectral_features(track,x): + x=x.float().flatten(2) + x=torch.nan_to_num(x,nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + assert x.shape[-1] in (200,400) + x=x-x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + rms=x.square().mean(-1).clamp_min(1e-12).sqrt();norm=x/rms.unsqueeze(-1) + moments=torch.stack([rms.log(),norm.abs().amax(-1).clamp_min(1).log(),norm.pow(4).mean(-1).clamp_min(1).log(),(norm[...,1:]-norm[...,:-1]).square().mean(-1).clamp_min(1e-10).log()],-1) + n=x.shape[-1];frames=x.unfold(-1,n,n//2);frames=frames-frames.mean(-1,keepdim=True) + z=torch.fft.rfft(frames*torch.hann_window(n,device=x.device),dim=-1)/(n//2) + power=z.abs().square() + bands=torch.stack([power[...,n*lo//200:n*hi//200].mean(-1) for lo,hi in zip(EDGES[:-1],EDGES[1:])],-1) + lp=bands.mean(-2).clamp_min(1e-12).log();variation=bands.clamp_min(1e-12).log().std(-2,correction=0) + parts=[torch.cat([lp,lp-lp.mean(-1,keepdim=True),lp-lp.mean(1,keepdim=True),variation,moments],-1).flatten(1)] + ii,jj=torch.triu_indices(x.shape[1],x.shape[1],offset=1,device=x.device) + for lo,hi in COV_BANDS: + v=z[...,n*lo//200:n*hi//200].flatten(2);cov=v.real@v.real.transpose(-1,-2)+v.imag@v.imag.transpose(-1,-2);d=cov.diagonal(dim1=-2,dim2=-1).clamp_min(1e-12).sqrt();cor=cov/(d.unsqueeze(1)*d.unsqueeze(2)).clamp_min(1e-12);parts.append(cor[:,ii,jj].clamp(-1,1)) + return torch.nan_to_num(torch.cat(parts,-1)).clamp(-40,40) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/tangent_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/tangent_features.py new file mode 100644 index 0000000000000000000000000000000000000000..314f0cf2f58e4b4a1c1d808edbd4acc3b7b6f85b --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S108/tangent_features.py @@ -0,0 +1,25 @@ +"""Window-local log-correlation geometry in the existing spatial-filter basis.""" +import torch + +TANGENT_DIM=10*24*25//2 + +@torch.no_grad() +def extract_tangent_features(covariances,spatial_weight): + old_tf32=torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(covariances.device.type,enabled=False): + w=spatial_weight.float() + w=w/w.norm(dim=-1,keepdim=True).clamp_min(1e-6) + projected=torch.einsum('bfc,nbcd,bgd->nbfg',w,covariances.float(),w) + d=projected.diagonal(dim1=-2,dim2=-1).clamp_min(1e-10).sqrt() + correlation=(projected/(d.unsqueeze(-1)*d.unsqueeze(-2))).clamp(-1,1) + correlation=(correlation+correlation.transpose(-1,-2))/2 + correlation=.95*correlation+.05*torch.eye(24,device=correlation.device) + values,vectors=torch.linalg.eigh(correlation) + logarithm=(vectors*values.clamp_min(1e-6).log().unsqueeze(-2))@vectors.transpose(-1,-2) + i,j=torch.triu_indices(24,24,device=correlation.device) + scale=torch.where(i==j,1.,2.**.5) + return (logarithm[...,i,j]*scale).flatten(1) + finally: + torch.backends.cuda.matmul.allow_tf32=old_tf32 diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S115/frequency_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S115/frequency_features.py new file mode 100644 index 0000000000000000000000000000000000000000..9194c9e81f801b3833e551e4967991774fa9e398 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S115/frequency_features.py @@ -0,0 +1,11 @@ +"""Fixed per-window frequency decomposition for a linear montage adapter.""" +import torch + +FREQUENCY_BANDS=((1,4),(4,8),(8,13),(13,20),(20,30),(30,45)) + +def frequency_components(signal): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();spectrum=torch.fft.rfft(x,dim=-1) + frequency=torch.fft.rfftfreq(x.shape[-1],d=1/200,device=x.device) + masks=torch.stack([((frequency>=lo)&(frequencynbf',w,covariances.float(),w).clamp_min(1e-8).log() + return torch.cat([power,power-power.mean(1,keepdim=True)],1).flatten(1) + def wave_signal(self,x,components=None): + if components is None:components=frequency_components(x) + correction=torch.einsum('blc,nbct->nlt',self.frequency_weight,components.to(self.frequency_weight.dtype)) + return (self.signal(x)+correction.to(x.dtype)).unsqueeze(1) + def forward(self,x,features,covariance_features): + return self.wave_signal(x),self.spectral_features(features,signal=x),self.neural(x),covariance_features + +class SharedBackbone(nn.Module): + def __init__(self,channels,width,depth,dropout,wave_filters): + super().__init__() + self.waveform=nn.Sequential( + nn.Conv2d(1,wave_filters,(1,64),padding=(0,32),bias=False),nn.GroupNorm(1,wave_filters), + nn.Conv2d(wave_filters,2*wave_filters,(channels,1),groups=wave_filters,bias=False),nn.GroupNorm(1,2*wave_filters),nn.ELU(), + nn.AvgPool2d((1,4)),nn.Dropout(.35), + nn.Conv2d(2*wave_filters,2*wave_filters,(1,16),padding=(0,8),groups=2*wave_filters,bias=False),nn.Conv2d(2*wave_filters,2*wave_filters,1,bias=False), + nn.GroupNorm(1,2*wave_filters),nn.ELU(),nn.AvgPool2d((1,8)),nn.Dropout(.35)) + self.wave_summary=nn.Sequential(nn.AdaptiveAvgPool2d((1,8)),nn.Flatten(),nn.Linear(2*wave_filters*8,width)) + self.fusion=nn.Sequential(nn.LayerNorm(width),nn.GELU(),nn.Dropout(dropout), + *[Residual(width,dropout) for _ in range(depth)],nn.LayerNorm(width)) + # Both representations interact before the shared residual stack. + self.phase_encoder=nn.Sequential(nn.LayerNorm(PHASE_DIM),nn.Linear(PHASE_DIM,width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width)) + self.register_buffer('phase_imaginary_enabled',torch.ones(())) + self.coupling_encoder=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width),nn.LayerNorm(width)) + self.wave_gain=nn.Parameter(torch.tensor(.1)) + self.biot=BIOT(n_chans=18,n_outputs=2,n_times=400,sfreq=200) + self.biot.final_layer=nn.Identity() + self.biot_projection=nn.Sequential(nn.LayerNorm(256),nn.Linear(256,width),nn.Dropout(.2)) + nn.init.normal_(self.biot_projection[1].weight,std=.001);nn.init.zeros_(self.biot_projection[1].bias) + self.covariance_encoder=nn.Sequential(nn.LayerNorm(len(BANDS)*24*2),nn.Linear(len(BANDS)*24*2,width),nn.GELU(),nn.Dropout(.4), + *[Residual(width,.4) for _ in range(2)],nn.LayerNorm(width)) + self.covariance_projection=nn.Linear(width,width) + nn.init.zeros_(self.covariance_projection.weight);nn.init.zeros_(self.covariance_projection.bias) + self.tangent_encoder=nn.Sequential(nn.LayerNorm(TANGENT_DIM),nn.Linear(TANGENT_DIM,width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width),nn.Linear(width,width)) + self.ordinal_context=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width)) + nn.init.zeros_(self.ordinal_context[-1].weight);nn.init.zeros_(self.ordinal_context[-1].bias) + self.register_buffer('codebrain_enabled',torch.ones(())) + self.codebrain_patch_encoder=nn.Sequential(nn.LayerNorm(24*64),nn.Linear(24*64,width),nn.GELU(),nn.Dropout(.3)) + self.codebrain_context=nn.Sequential(nn.LayerNorm(width*4),nn.Linear(width*4,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width)) + nn.init.zeros_(self.codebrain_context[-1].weight);nn.init.zeros_(self.codebrain_context[-1].bias) + def codebrain_correction(self,tokens,representation,fusion_input): + with torch.autocast(tokens.device.type,enabled=False): + encoded=self.codebrain_patch_encoder(self.codebrain_enabled*tokens.float()) + pooled=torch.cat([encoded.mean(1),encoded.std(1,correction=0),representation[:,-512:-384].float(),representation[:,-128:].float()],-1) + delta=self.codebrain_context(pooled) + added=.001*nn.functional.linear(delta,self.covariance_projection.weight,None) + corrected=self.fusion(fusion_input+added.to(fusion_input.dtype)) + return corrected-representation[:,-512:-384],delta + def forward(self,signal,spectral,neural_signal,covariance_features,tangent_features): + wave=self.waveform(signal) + neural=self.biot(neural_signal.float()) + neural=self.biot_projection[0](neural) + projected=self.biot_projection[2](self.biot_projection[1](neural)) + with torch.autocast(signal.device.type,enabled=False): + covariance_embedding=self.covariance_encoder(covariance_features.float()) + original=spectral+self.wave_gain*self.wave_summary(wave)+.01*projected + coupled=.001*self.covariance_projection(covariance_embedding).to(original.dtype) + fused=self.fusion(original+coupled) + with torch.autocast(signal.device.type,enabled=False):delta=self.tangent_encoder(tangent_features.float()) + added=.001*nn.functional.linear(delta,self.covariance_projection.weight,None) + corrected=self.fusion((original+coupled)+added.to(original.dtype)) + return torch.cat([wave.flatten(1),fused,neural,covariance_embedding],-1),corrected-fused,delta,original+coupled + +class ResidualHead(nn.Module): + """A small nonlinear classifier correction around an inherited linear readout.""" + def __init__(self,features,classes,width=64,dropout=.3,full_precision=False): + super().__init__();self.full_precision=full_precision + self.base=nn.Linear(features,classes) + self.delta=nn.Sequential(nn.LayerNorm(features),nn.Linear(features,width),nn.GELU(),nn.Dropout(dropout),nn.Linear(width,classes)) + nn.init.zeros_(self.delta[-1].weight);nn.init.zeros_(self.delta[-1].bias) + def forward(self,x): + if self.full_precision: + with torch.autocast(x.device.type,enabled=False):return self.base(x.float())+self.delta(x.float()) + prior=nn.functional.linear(x[:,:-128].contiguous(),self.base.weight[:,:-128].contiguous(),self.base.bias) + added=nn.functional.linear(x[:,-128:].contiguous(),self.base.weight[:,-128:].contiguous()) + value=prior+added + return value+self.delta(x).to(value.dtype) + +class TemporalPoolHead(nn.Module): + def __init__(self,prior,channels=64): + super().__init__();self.prior=prior;self.channels=channels + self.register_buffer('pool_output_scale',torch.ones(()));self.register_buffer('pool_mean',torch.zeros(channels*4));self.register_buffer('pool_scale',torch.ones(channels*4)) + self.pool_projection=nn.Linear(channels*4,prior.base.out_features) + nn.init.zeros_(self.pool_projection.weight);nn.init.zeros_(self.pool_projection.bias) + def statistics(self,x): + with torch.autocast(x.device.type,enabled=False): + wave=x[:,:-512].float().reshape(len(x),self.channels,-1) + return torch.cat([wave.mean(-1),wave.std(-1,correction=0),wave.amax(-1),wave.amin(-1)],-1) + def forward(self,x): + prior=self.prior(x) + with torch.autocast(x.device.type,enabled=False): + values=((self.statistics(x)-self.pool_mean)/self.pool_scale).clamp(-8,8) + added=self.pool_output_scale*self.pool_projection(values) + return prior+added.to(prior.dtype) + +class TemporalEvidenceHead(nn.Module): + """Pool class evidence over the shared waveform time axis.""" + def __init__(self,prior,channels=64,temperature=.25): + super().__init__();self.prior=prior;self.channels=channels;self.temperature=temperature + self.register_buffer('evidence_output_scale',torch.ones(())) + self.register_buffer('evidence_mean',torch.zeros(channels)) + self.register_buffer('evidence_scale',torch.ones(channels)) + self.evidence_projection=nn.Linear(channels,prior.prior.base.out_features,bias=False) + nn.init.zeros_(self.evidence_projection.weight) + def patches(self,x): + with torch.autocast(x.device.type,enabled=False): + wave=x[:,:-512].float().reshape(len(x),self.channels,-1).transpose(1,2) + return ((wave-self.evidence_mean)/self.evidence_scale).clamp(-8,8) + def evidence(self,patches): + with torch.autocast(patches.device.type,enabled=False): + values=self.evidence_projection(patches.float())/self.temperature + maximum=values.amax(1,keepdim=True) + pooled=self.temperature*((values-maximum).exp().mean(1).log()+maximum.squeeze(1)) + return self.evidence_output_scale*pooled + def forward(self,x): + prior=self.prior(x) + return prior+self.evidence(self.patches(x)).to(prior.dtype) + +class FourierResidualHead(nn.Module): + """A fixed random Fourier basis and trainable linear classifier correction.""" + def __init__(self,prior,features,classes,basis=256): + super().__init__();self.prior=prior + self.register_buffer('rff_mean',torch.zeros(features));self.register_buffer('rff_scale',torch.ones(features)) + self.register_buffer('rff_frequency',torch.randn(features,basis)/features**.5) + self.register_buffer('rff_phase',torch.rand(basis)*2*torch.pi) + self.register_buffer('rff_output_scale',torch.ones(())) + self.rff_projection=nn.Linear(3*basis,classes);nn.init.zeros_(self.rff_projection.weight);nn.init.zeros_(self.rff_projection.bias) + def basis(self,x): + with torch.autocast(x.device.type,enabled=False): + values=((x.float()-self.rff_mean)/self.rff_scale).clamp(-8,8)@self.rff_frequency + return 2**.5*torch.cat([(values/sigma+self.rff_phase).cos() for sigma in (.5,1.,2.)],-1) + def forward(self,x): + prior=self.prior(x) + with torch.autocast(x.device.type,enabled=False):added=self.rff_output_scale*self.rff_projection(self.basis(x)) + return prior+added.to(prior.dtype) + +class TangentFeatureHead(nn.Module): + """Select a shared feature correction before the inherited classifier.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.feature_gain=nn.Parameter(torch.zeros(())) + def forward(self,values): + old=values[:,:-256];fusion_delta=values[:,-256:-128];covariance_delta=values[:,-128:] + adjusted=torch.cat([old[:,:-512],old[:,-512:-384]+self.feature_gain*fusion_delta,old[:,-384:-128],old[:,-128:]+self.feature_gain*covariance_delta],-1) + return self.prior(adjusted) + +class CodeBrainFeatureHead(nn.Module): + """Private use of a jointly trained common feature correction.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.codebrain_gain=nn.Parameter(torch.ones(())) + def forward(self,values): + previous=values[:,:-256];native=previous[:,:-256] + fusion_delta=values[:,-256:-128];covariance_delta=values[:,-128:] + adjusted=torch.cat([native[:,:-512],native[:,-512:-384]+self.codebrain_gain*fusion_delta,native[:,-384:-128],native[:,-128:]+self.codebrain_gain*covariance_delta],-1) + return self.prior(torch.cat([adjusted,previous[:,-256:]],-1)) + +class WaveCoactivationContext(nn.Module): + """One common encoder of coactivation among the learned waveform channels.""" + def __init__(self,channels=64,width=128): + super().__init__();self.channels=channels + ii,jj=torch.triu_indices(channels,channels,offset=1) + self.register_buffer('pair_i',ii);self.register_buffer('pair_j',jj) + self.register_buffer('offdiagonal_enabled',torch.ones(())) + self.encoder=nn.Sequential(nn.LayerNorm(channels+len(ii)),nn.Linear(channels+len(ii),width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width)) + def statistics(self,native): + with torch.autocast(native.device.type,enabled=False): + wave=native[:,:-512].float().reshape(len(native),self.channels,-1) + centered=wave-wave.mean(-1,keepdim=True) + previous_tf32=torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32=False + covariance=centered@centered.transpose(-1,-2)/wave.shape[-1] + torch.backends.cuda.matmul.allow_tf32=previous_tf32 + variance=covariance.diagonal(dim1=-2,dim2=-1).clamp_min(1e-8) + correlation=covariance/(variance.sqrt()[:,:,None]*variance.sqrt()[:,None,:]) + return torch.cat([variance.log(),correlation[:,self.pair_i,self.pair_j].clamp(-1,1)],-1) + def encode_statistics(self,values): + with torch.autocast(values.device.type,enabled=False): + value=torch.cat([values[:,:self.channels],self.offdiagonal_enabled*values[:,self.channels:]],-1) + return self.encoder(value.float()) + def forward(self,native):return self.encode_statistics(self.statistics(native)) + +class WaveCoactivationHead(nn.Module): + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.width=width;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-self.width]) + with torch.autocast(values.device.type,enabled=False):delta=self.correction_gain*self.output_scale*self.projection(values[:,-self.width:].float()) + return prior+delta.to(prior.dtype) + +class OrdinalFeatureHead(nn.Module): + """Private strength of one common ordinal-dynamics feature correction.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.ordinal_gain=nn.Parameter(torch.ones(())) + def forward(self,values): + previous=values[:,:-256];native=previous[:,:-640] + adjusted=torch.cat([native[:,:-512],native[:,-512:-384]+self.ordinal_gain*values[:,-256:-128],native[:,-384:-128],native[:,-128:]+self.ordinal_gain*values[:,-128:],previous[:,-640:]],-1) + return self.prior(adjusted) + +class PhaseReadoutHead(nn.Module): + """Private class evidence from the common complex-coherence encoder.""" + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.width=width;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-self.width]) + with torch.autocast(values.device.type,enabled=False):delta=(self.correction_gain*self.output_scale)*self.projection(values[:,-self.width:].float()) + return prior+delta.to(prior.dtype) + +class SplitLayerNorm(nn.Module): + """Two LayerNorm groups; surrounding dense matrices train across both groups.""" + def __init__(self,width): + super().__init__();assert width%2==0;self.width=width + self.weight=nn.Parameter(torch.ones(width));self.bias=nn.Parameter(torch.zeros(width)) + def forward(self,x): + n=self.width//2 + return torch.cat([nn.functional.layer_norm(x[:,:n],(n,),self.weight[:n],self.bias[:n],1e-5),nn.functional.layer_norm(x[:,n:],(n,),self.weight[n:],self.bias[n:],1e-5)],-1) + +class CouplingReadoutHead(nn.Module): + """Private class evidence from the common cross-frequency coupling encoder.""" + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.width=width;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-self.width]) + with torch.autocast(values.device.type,enabled=False):delta=(self.correction_gain*self.output_scale)*self.projection(values[:,-self.width:].float()) + return prior+delta.to(prior.dtype) + +class HybridModel(nn.Module): + def __init__(self,channels=32,width=128,depth=2,dropout=.5,wave_filters=32,head_width=64,head_dropout=.3,clinical_asymmetry=True,alpha_regions=None,clinical_envelope=False,temporal_pool=True,temporal_evidence=False,evidence_temperature=.25,random_fourier=False,fourier_features=256,tangent_readout=True,shared_context_correction=True,wave_coactivation=True,ordinal_context=True,phase_coherence=True,cross_frequency=True,cbramod_feature_transfer=True,student_architecture=None,student_extension=True,post_embedding_extension=True,extension_activation='gelu',center_context_extension=True,context_crop='center',short_context_extension=True,short_crop='center',dual_context_extension=True,dual_crop='clinical-dual',geometry_extension=True,geometry_mode='mi-log',emotion_extension=True,emotion_mode='faced-log',emotion_activation='gelu',refinement_extension=True,refinement_mode='faced-log',refinement_activation='gelu',spatial_extension=True,spatial_mode='local',spatial_activation='gelu',spatial_motor_channels=None,conditional_extension=True,conditional_mode='partial',conditional_width=128): + super().__init__() + self.adapters=nn.ModuleDict({t:InputAdapter(c,width,channels,spectral_enabled=t not in ("faced","tuev","openbmi"),asymmetry=clinical_asymmetry and t=="tuev",alpha_regions=alpha_regions if t=="longitudinal" else None,envelope=clinical_envelope and t=="tuev") for t,(c,s,k) in SPECS.items()}) + self.backbone=SharedBackbone(channels,width,depth,dropout,wave_filters) + self.backbone.student_encoder=CBraModFeatures(**(student_architecture or {})) + self.backbone.register_buffer('student_ordered_enabled',torch.ones(())) + self.backbone.student_readout=nn.Sequential(nn.Linear(self.backbone.student_encoder.output_dim,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + for t,(c,s,k) in SPECS.items(): + self.adapters[t].student_input=FrequencyAdapter(c,32) + self.adapters[t].student_normalizer=Standardize(self.backbone.student_encoder.output_dim) + self.backbone.wave_coactivation=WaveCoactivationContext(2*wave_filters,width) + self.heads=nn.ModuleDict({t:ResidualHead(2*wave_filters*(((s*200+1)//4+1)//8)+width+256+width,k,head_width,head_dropout,full_precision=t=='ad65') for t,(c,s,k) in SPECS.items()}) + if temporal_pool:self.heads=nn.ModuleDict({t:TemporalPoolHead(head,wave_filters*2) for t,head in self.heads.items()}) + if temporal_evidence:self.heads=nn.ModuleDict({t:TemporalEvidenceHead(head,wave_filters*2,evidence_temperature) for t,head in self.heads.items()}) + if random_fourier:self.heads=nn.ModuleDict({t:FourierResidualHead(head,2*wave_filters*(((SPECS[t][1]*200+1)//4+1)//8)+width+256+width,SPECS[t][2],fourier_features) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:TangentFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CodeBrainFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:WaveCoactivationHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:OrdinalFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:PhaseReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert student_extension and post_embedding_extension + assert extension_activation in ('gelu','identity') + self.backbone.student_extension=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU() if extension_activation=='gelu' else nn.Identity(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert center_context_extension and context_crop in ('center','first') + self.context_crop=context_crop + for t,(c,s,k) in SPECS.items(): + self.adapters[t].center_normalizer=Standardize(feature_dim(c)+30*c) + self.adapters[t].center_projection=nn.Linear(feature_dim(c)+30*c,width) + self.backbone.center_encoder=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert short_context_extension and short_crop in ('center','first') + self.short_crop=short_crop + for t,(c,s,k) in SPECS.items(): + self.adapters[t].short_normalizer=Standardize(feature_dim(c)+30*c) + self.adapters[t].short_projection=nn.Linear(feature_dim(c)+30*c,width) + self.backbone.short_encoder=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert dual_context_extension and dual_crop in ('clinical-dual','clinical-duplicate') + self.dual_crop=dual_crop + for t,(c,s,k) in SPECS.items(): + self.adapters[t].dual_normalizer=Standardize((feature_dim(c)+30*c)*(2 if t=='tuev' else 1)) + self.adapters[t].dual_projection=nn.Linear((feature_dim(c)+30*c)*(2 if t=='tuev' else 1),width) + self.backbone.dual_encoder=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert geometry_extension and geometry_mode in ('mi-log','mi-linear') + self.geometry_mode=geometry_mode + for t,(c,s,k) in SPECS.items(): + dimension=7*c*(c+1)//2 if t=='openbmi' else feature_dim(c)+30*c + self.adapters[t].geometry_normalizer=Standardize(dimension) + self.adapters[t].geometry_projection=nn.Linear(dimension,width) + self.backbone.geometry_encoder=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert emotion_extension and emotion_mode in ('faced-log','faced-linear') + self.emotion_mode=emotion_mode + for t,(c,s,k) in SPECS.items(): + dimension=7*c*(c+1)//2 if t=='faced' else feature_dim(c)+30*c + self.adapters[t].emotion_normalizer=Standardize(dimension) + self.adapters[t].emotion_projection=nn.Linear(dimension,width) + assert emotion_activation in ('gelu','identity') + self.backbone.emotion_encoder=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU() if emotion_activation=='gelu' else nn.Identity(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert refinement_extension and refinement_mode in ('faced-log','faced-linear') + self.refinement_mode=refinement_mode + for t,(c,s,k) in SPECS.items(): + dimension=7*c*(c+1)//2 if t=='faced' else feature_dim(c)+30*c + self.adapters[t].refinement_normalizer=Standardize(dimension) + self.adapters[t].refinement_projection=nn.Linear(dimension,width) + assert refinement_activation in ('gelu','identity') + self.backbone.refinement_encoder=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU() if refinement_activation=='gelu' else nn.Identity(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert spatial_extension and spatial_mode in ('local','native') and spatial_activation=='gelu' + self.spatial_mode=spatial_mode + self.spatial_motor_channels=tuple(spatial_motor_channels or MOTOR_CHANNELS) + assert len(self.spatial_motor_channels)==62 + for t,(c,s,k) in SPECS.items(): + dimension=981 if t=='openbmi' else (7*c*(c+1)//2 if t=='faced' else feature_dim(c)+30*c) + self.adapters[t].spatial_normalizer=Standardize(dimension) + self.adapters[t].spatial_projection=nn.Linear(dimension,width) + self.backbone.spatial_encoder=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert conditional_extension and conditional_mode in ('partial','marginal') + assert conditional_width in (128,256) + self.conditional_mode=conditional_mode + for t,(c,s,k) in SPECS.items(): + dimension=952 if t=='tuev' else self.adapters[t].spatial_projection.in_features + self.adapters[t].conditional_normalizer=Standardize(dimension) + self.adapters[t].conditional_projection=nn.Linear(dimension,conditional_width) + norm=SplitLayerNorm if conditional_width==256 else nn.LayerNorm + self.backbone.conditional_encoder=nn.Sequential(nn.Linear(conditional_width,2*conditional_width),norm(2*conditional_width),nn.GELU(),nn.Dropout(.3),nn.Linear(2*conditional_width,conditional_width),norm(conditional_width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],conditional_width) for t,head in self.heads.items()}) + def conditional_features(self,t,x): + if t!='tuev':return self.spatial_features(t,x) + from partial_covariance_features import partial_covariance_features + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(x.device.type,enabled=False):return partial_covariance_features(t,x,self.conditional_mode=='partial') + finally:torch.backends.cuda.matmul.allow_tf32=old + def conditional_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + return self.backbone.conditional_encoder(self.adapters[t].conditional_projection(self.adapters[t].conditional_normalizer(values.float()))) + def spatial_features(self,t,x): + if t!='openbmi':return self.refinement_features(t,x) + from local_channel_features import local_channel_signals + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(x.device.type,enabled=False): + signals=local_channel_signals(x,self.spatial_motor_channels,self.spatial_mode=='local') + return torch.cat([extract_features('tuev',signals),coupling_features('tuev',signals)],-1) + finally:torch.backends.cuda.matmul.allow_tf32=old + def spatial_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].spatial_normalizer(values.float()) + return self.backbone.spatial_encoder(self.adapters[t].spatial_projection(normalized)) + def refinement_features(self,t,x): + from native_log_covariance_features import connectivity + from short_context_features import short_spectral_features + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(x.device.type,enabled=False): + if t=='faced':return connectivity(t,x,logarithmic=self.refinement_mode=='faced-log') + view=x.flatten(2)[...,:200] + return torch.cat([short_spectral_features(t,view),coupling_features(t,view)],-1) + finally:torch.backends.cuda.matmul.allow_tf32=old + def refinement_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].refinement_normalizer(values.float()) + return self.backbone.refinement_encoder(self.adapters[t].refinement_projection(normalized)) + def emotion_features(self,t,x): + from native_log_covariance_features import connectivity + from short_context_features import short_spectral_features + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(x.device.type,enabled=False): + if t=='faced':return connectivity(t,x,logarithmic=self.emotion_mode=='faced-log') + view=x.flatten(2)[...,:200] + return torch.cat([short_spectral_features(t,view),coupling_features(t,view)],-1) + finally:torch.backends.cuda.matmul.allow_tf32=old + def emotion_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].emotion_normalizer(values.float()) + return self.backbone.emotion_encoder(self.adapters[t].emotion_projection(normalized)) + def geometry_features(self,t,x): + from native_log_covariance_features import connectivity + from short_context_features import short_spectral_features + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(x.device.type,enabled=False): + if t=='openbmi':return connectivity(t,x,logarithmic=self.geometry_mode=='mi-log') + view=x.flatten(2)[...,:200] + return torch.cat([short_spectral_features(t,view),coupling_features(t,view)],-1) + finally:torch.backends.cuda.matmul.allow_tf32=old + def geometry_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].geometry_normalizer(values.float()) + return self.backbone.geometry_encoder(self.adapters[t].geometry_projection(normalized)) + def dual_features(self,t,x): + from short_context_features import short_spectral_features + raw=x.flatten(2);first=raw[...,:200];views=[first] + if t=='tuev': + start=(raw.shape[-1]-200)//2 + views.append(raw[...,start:start+200] if self.dual_crop=='clinical-dual' else first) + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(raw.device.type,enabled=False):return torch.cat([torch.cat([short_spectral_features(t,v),coupling_features(t,v)],-1) for v in views],-1) + finally:torch.backends.cuda.matmul.allow_tf32=old + def dual_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].dual_normalizer(values.float()) + return self.backbone.dual_encoder(self.adapters[t].dual_projection(normalized)) + def short_features(self,t,x): + from short_context_features import short_spectral_features + raw=x.flatten(2);start=(raw.shape[-1]-200)//2 if self.short_crop=='center' else 0 + cropped=raw[...,start:start+200];assert cropped.shape[-1]==200 + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(raw.device.type,enabled=False):return torch.cat([short_spectral_features(t,cropped),coupling_features(t,cropped)],-1) + finally:torch.backends.cuda.matmul.allow_tf32=old + def short_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].short_normalizer(values.float()) + return self.backbone.short_encoder(self.adapters[t].short_projection(normalized)) + def center_features(self,t,x): + raw=x.flatten(2);start=(raw.shape[-1]-400)//2 if self.context_crop=='center' else 0 + cropped=raw[...,start:start+400];assert cropped.shape[-1]==400 + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(raw.device.type,enabled=False):return torch.cat([extract_features(t,cropped),coupling_features(t,cropped)],-1) + finally:torch.backends.cuda.matmul.allow_tf32=old + def center_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].center_normalizer(values.float()) + return self.backbone.center_encoder(self.adapters[t].center_projection(normalized)) + def student_extension_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + assert values.shape[-1]==128 + return self.backbone.student_extension(values.float()) + + def student_features(self,t,x): + outputs=[];old_fastpath=torch.backends.mha.get_fastpath_enabled();torch.backends.mha.set_fastpath_enabled(False) + try: + for raw in x.split(16): + signal=torch.nan_to_num(raw.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + with torch.autocast(signal.device.type,dtype=torch.bfloat16,enabled=signal.device.type=='cuda'): + outputs.append(self.backbone.student_encoder(self.adapters[t].student_input(signal))) + finally:torch.backends.mha.set_fastpath_enabled(old_fastpath) + return torch.cat(outputs).float() + def student_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].student_normalizer(values.float()) + normalized=torch.cat([normalized[:,:256],self.backbone.student_ordered_enabled*normalized[:,256:]],-1) + return self.backbone.student_readout(normalized) + def coupling_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False):return self.backbone.coupling_encoder(self.adapters[t].coupling_embedding(values.float())) + def phase_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].phase_normalizer(values.float()) + normalized=torch.cat([normalized[:,:PHASE_HALF],self.backbone.phase_imaginary_enabled*normalized[:,PHASE_HALF:]],-1) + return self.backbone.phase_encoder(normalized) + def forward(self,t,x,features=None,covariances=None,covariance_features=None): + if features is None:features=extract_features(t,x) + if covariance_features is None: + if covariances is None:covariances=extract_covariances(t,x) + covariance_features=self.adapters[t].spatial_features(covariances) + signal=x.flatten(2);signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + adapted=self.adapters[t](signal,features,covariance_features) + if covariances is None:covariances=extract_covariances(t,x) + tangent=extract_tangent_features(covariances,self.adapters[t].spatial_weight) + representation,fusion_delta,covariance_delta,fusion_input=self.backbone(*adapted,tangent_features=tangent) + if t in ('faced','openbmi'): + representation=torch.cat([representation[:,:-384],torch.zeros_like(representation[:,-384:-128]),representation[:,-128:]],-1) + tokens=torch.zeros(len(signal),signal.shape[-1]//200,24*64,device=signal.device,dtype=torch.bfloat16) + code_fusion,code_covariance=self.backbone.codebrain_correction(tokens,representation,fusion_input) + coactivation=self.backbone.wave_coactivation(representation) + with torch.autocast(signal.device.type,enabled=False): + ordinal=self.adapters[t].ordinal_embedding(ordinal_features(t,x)) + ordinal_covariance=self.backbone.ordinal_context(ordinal.float()) + added=.001*nn.functional.linear(ordinal_covariance,self.backbone.covariance_projection.weight,None) + ordinal_fusion=self.backbone.fusion(fusion_input+added.to(fusion_input.dtype))-representation[:,-512:-384] + phase=self.phase_embedding(t,phase_features(t,x,self.adapters[t].spatial_weight)) + coupling=self.coupling_embedding(t,coupling_features(t,x)) + student_values=self.student_features(t,x) + student=self.student_embedding(t,student_values) + extension=self.student_extension_embedding(t,student) + return self.heads[t](torch.cat([representation,fusion_delta,covariance_delta,code_fusion,code_covariance,coactivation,ordinal_fusion,ordinal_covariance,phase,coupling,student,extension,self.center_embedding(t,self.center_features(t,x)),self.short_embedding(t,self.short_features(t,x)),self.dual_embedding(t,self.dual_features(t,x)),self.geometry_embedding(t,self.geometry_features(t,x)),self.emotion_embedding(t,self.emotion_features(t,x)),self.refinement_embedding(t,self.refinement_features(t,x)),self.spatial_embedding(t,self.spatial_features(t,x)),self.conditional_embedding(t,self.conditional_features(t,x))],-1)) + +def widen_state_dict(state,multiplier=2): + """Duplicate temporal features and divide downstream sums to preserve outputs.""" + result={} + for key,value in state.items(): + if key.startswith('backbone.waveform.'): + layer=int(key.split('.')[2]) + if layer in (0,2,7):value=value.repeat(multiplier,1,1,1) + elif layer in (1,3,9):value=value.repeat(multiplier) + elif layer==8:value=value.repeat(multiplier,multiplier,1,1)/multiplier + elif key=='backbone.wave_summary.2.weight':value=value.repeat(1,multiplier)/multiplier + elif key.startswith('heads.') and key.endswith('.weight'): + raw=value[:,:-128]/multiplier + value=torch.cat([raw]*multiplier+[value[:,-128:]],1) + result[key]=value + return result + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S115/phase_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S115/phase_features.py new file mode 100644 index 0000000000000000000000000000000000000000..8d98822995bf37b499795dfd7e2e401040a01969 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S115/phase_features.py @@ -0,0 +1,37 @@ +"""Complex spectral coherence of the existing 24 spatial filters in ten bands.""" +import torch +from covariances import BANDS +CHANNELS=24 +PHASE_HALF=len(BANDS)*CHANNELS*(CHANNELS-1)//2 +PHASE_DIM=2*PHASE_HALF + +@torch.no_grad() +def phase_features(track,x,spatial_weight): + previous_tf32=torch.backends.cuda.matmul.allow_tf32 + try: + torch.backends.cuda.matmul.allow_tf32=False + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if track in ('faced','tuev'):x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + else:x=x-x.mean(1,keepdim=True) + x=x/x.square().mean((1,2),keepdim=True).clamp_min(1e-12).sqrt() + frames=x.unfold(-1,400,200);frames=frames-frames.mean(-1,keepdim=True) + z=torch.fft.rfft(frames*torch.hann_window(400,device=x.device),dim=-1)/200 + w=spatial_weight.float()/spatial_weight.float().norm(dim=-1,keepdim=True).clamp_min(1e-6) + index=torch.triu_indices(CHANNELS,CHANNELS,1,device=x.device) + real_parts=[];imaginary_parts=[] + for band,(lo,hi) in enumerate(BANDS): + v=z[...,2*lo:2*hi].flatten(2) + vr=w[band][None]@v.real;vi=w[band][None]@v.imag + real=(vr@vr.transpose(-1,-2)+vi@vi.transpose(-1,-2))/v.shape[-1] + imaginary=(vi@vr.transpose(-1,-2)-vr@vi.transpose(-1,-2))/v.shape[-1] + # Signals have unit global RMS; this floor suppresses phase of numerical silence. + power=real.diagonal(dim1=-2,dim2=-1).clamp_min(1e-6) + denominator=(power[:,:,None]*power[:,None,:]).sqrt().clamp_min(1e-12) + real=(real/denominator).clamp(-.999,.999) + imaginary=(imaginary/denominator).clamp(-.999,.999) + real_parts.append(torch.atanh(real[:,index[0],index[1]])) + imaginary_parts.append(torch.atanh(imaginary[:,index[0],index[1]])) + return torch.cat(real_parts+imaginary_parts,-1) + finally:torch.backends.cuda.matmul.allow_tf32=previous_tf32 diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S115/private-selection-audit.json b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S115/private-selection-audit.json new file mode 100644 index 0000000000000000000000000000000000000000..c2611aa523432a56f09fd1849a8d9c49b5f0246d --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S115/private-selection-audit.json @@ -0,0 +1,55 @@ +{ + "reference": "/workspace/research/experiments311/combined/epoch-001", + "donor": "/workspace/research/experiments313/adam_pilot/epoch-005", + "track": "faced", + "source_weights_sha256": { + "reference": "ff7d9725ef69cbc18f4c84a3a5867d49b4a29323164c3fe469441bc6d914bab9", + "donor": "9303528189dfc8d76fce2949f5eb70af187c61f3075167ef596c75594a9dc704" + }, + "source_receipt_sha256": { + "reference": "3db2763055470bae144a554014414a7a3e6ef331e27075433c4cc42e4aca4a6b", + "donor": "0524d764eb8a7905fcd88a56fce211efe24e4d5b306febc8a65f75c81153f7e4" + }, + "all1141_nonprivate_states_exact_between_donors": true, + "only_selected_track_five_private_states_may_change": true, + "changed_private_states": [ + "heads.faced.projection.weight", + "heads.faced.projection.bias" + ], + "runtime_sha256": { + "frequency_features.py": "f6cc7980d66510e26d7fdda5de225220b1b6f627ff18fb6c8ae9f0a1b97c9cf6", + "envelope_features.py": "dd0eae287072e20573a0da4d9fa5d1aacd037d551b6bb15fbacd27d8ed073fa6", + "phase_features.py": "2dc4de1384e1d2b20233e8999870de39470e91563054f7dae6b1296bf8baf729", + "features.py": "c4331dd4752c5cd0ea4d486b3b3b390a2cb823fd4488281bdb23595014705ee3", + "ordinal_features.py": "ff868e9f75005aaceb0842cc117fc069ba14d3fe58b0a6ef8869fc9fe6193859", + "infer.sh": "019575f98918008e6ab7b5ce3e8c540e5632f4b7cf96ac73d9c38501ec592369", + "local_channel_features.py": "1c10cfcea275590a5169dec445162de6c3df2ac73baa1ac26b5bd0a96a647f70", + "data.py": "9ad497551e09a2293a65fdada12b1987250fef21ad4066f03eee5160cfdad7d0", + "model.py": "7b48ae7c211cbbd03577fa5d40ea36bfa0c93745c508ef3d438e20b7725b6e48", + "partial_covariance_features.py": "830e2a7371a8f13c4d951d0006e67af0e5a20df23ee9f73f5d95d4dec014c9d6", + "covariances.py": "70cfc3a878a5e7f0d0b3ffb2ebabbb5efdeb270298871dad415fc1bce7de88f6", + "tangent_features.py": "a78cb06d3cf95169d2d63e5a312218374eaeb441a9ae1036211ea38d6f798d7e", + "native_log_covariance_features.py": "5de99a49381d51ba32495a80b9c0a3ac9e94f2250dd71b78e2b32608a9e0bd0d", + "infer.py": "4d16000c59ac88da7efa52c509f4db0970941e29e898d79d44013276489f2225", + "alpha_features.py": "d3d265855a2c04af5e76115de4f0dc613f1864d854c54a5613f376c262c59bac", + "short_context_features.py": "eb8fe1619a644c700659995e4fb862d100a65845ec56fd66ee92368f98f814f2", + "student_features.py": "67006312eae7435a5e138c05957d9d719a23af9211829bd8290e4a22503d84e8", + "coupling_features.py": "89830d79b0030713032a9eced00a5b0a36109da36ae342090e78d9c65f03f081" + }, + "architecture_exact": true, + "prediction_sources": { + "faced": "/workspace/research/experiments313/adam_pilot/faced-e005.npy", + "tuev": "/workspace/research/experiments311/combined/tuev-e001.npy", + "ad65": "/workspace/research/experiments311/combined/ad65-e001.npy", + "openbmi": "/workspace/research/experiments311/combined/openbmi-e001.npy", + "longitudinal": "/workspace/research/experiments311/combined/longitudinal-e001.npy" + }, + "prediction_sha256": { + "faced": "f2cb3cbdfc4847044ed4a897c07b3eb59ec5a2311814c4ffa238e2f3939d9856", + "tuev": "ba9af7721410c2b3b3b0d0013361fe7692887dff5a7b2c8a2c0b430d59cdfa00", + "ad65": "7a3b74c58580b7ba952322bf6d527ebc9a40a6e04c7cdbbaea14e84a7a298d54", + "openbmi": "1f25afa530e1c933202d3ea58a5ff20bd4079570b4d361917b910a66b7e073d0", + "longitudinal": "5dc96f17f93682200b47a1698f8b5f1052ed2af61e4b02bdba7724be07c70c78" + }, + "one_common_checkpoint_one_head_per_track": true +} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S115/tangent_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S115/tangent_features.py new file mode 100644 index 0000000000000000000000000000000000000000..314f0cf2f58e4b4a1c1d808edbd4acc3b7b6f85b --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S115/tangent_features.py @@ -0,0 +1,25 @@ +"""Window-local log-correlation geometry in the existing spatial-filter basis.""" +import torch + +TANGENT_DIM=10*24*25//2 + +@torch.no_grad() +def extract_tangent_features(covariances,spatial_weight): + old_tf32=torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(covariances.device.type,enabled=False): + w=spatial_weight.float() + w=w/w.norm(dim=-1,keepdim=True).clamp_min(1e-6) + projected=torch.einsum('bfc,nbcd,bgd->nbfg',w,covariances.float(),w) + d=projected.diagonal(dim1=-2,dim2=-1).clamp_min(1e-10).sqrt() + correlation=(projected/(d.unsqueeze(-1)*d.unsqueeze(-2))).clamp(-1,1) + correlation=(correlation+correlation.transpose(-1,-2))/2 + correlation=.95*correlation+.05*torch.eye(24,device=correlation.device) + values,vectors=torch.linalg.eigh(correlation) + logarithm=(vectors*values.clamp_min(1e-6).log().unsqueeze(-2))@vectors.transpose(-1,-2) + i,j=torch.triu_indices(24,24,device=correlation.device) + scale=torch.where(i==j,1.,2.**.5) + return (logarithm[...,i,j]*scale).flatten(1) + finally: + torch.backends.cuda.matmul.allow_tf32=old_tf32 diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S122/MODEL_CARD.md b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S122/MODEL_CARD.md new file mode 100644 index 0000000000000000000000000000000000000000..22cdd8fb9281d5194739e06554ca2a0591132a32 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S122/MODEL_CARD.md @@ -0,0 +1,93 @@ +# Shared EEG decoder + +This package contains one coupled backbone used by all five tracks, with private input adapters and classifiers. Every trainable common component was trained with all five training splits. It is a single model; inference performs no parameter updates or dataset-level fitting. + +The common backbone combines waveform convolutions, an audited pretrained BIOT feature path, covariance and log-correlation encoders, and shared feature corrections. The waveform coactivation extension encodes 64 within-window log variances and 2,016 correlations between common waveform channels. A matched experimental control removes the correlation inputs. `config.json` identifies the packaged variant and its five fixed correction gains. All original backbone parameters are fixed during this extension's joint training. + +Weights originate only from the supplied training data and audited initialization checkpoints. Training details, parent provenance, raw/cache checks, shared-gradient checks and the five separate validation metrics are recorded in `training.json`. Validation selects checkpoints and fixed gains; it does not fit normalization or update parameters. Reported validation results belong to selected checkpoints, not to private test evaluation or five-seed means. + +Run `bash infer.sh INPUT_DIR OUTPUT_DIR`. The input manifest specifies a track and opaque sample IDs, shard paths and indices. Signals are in microvolts and are scaled by 1/100. The package writes one probability vector per input ID to `OUTPUT_DIR/predictions.jsonl`. It needs only the packaged files and the contract's installed Python dependencies, works after relocation, and does not need labels, subject IDs, training caches or network access. + +FACED and TUEV use window balanced accuracy. AD65 uses mean window probabilities per patient before balanced accuracy. OpenBMI averages within-subject balanced accuracy. Longitudinal averages within-session balanced accuracy within each subject, then over subjects. These five metrics remain separate. + +This checkpoint adds fixed within-window ordinal pattern probabilities, permutation entropy and statistical complexity at five delays. Training-only normalization and five input projections feed one common correction MLP trained by all five tracks. The common correction enters the existing covariance and fusion representations; fixed per-track gains select its strength. All earlier model tensors remain unchanged. + +Fixed real and imaginary spectral coherence between the inherited 24 spatial filters is normalized using training windows only and encoded by one new common network. Five private linear heads add class evidence. All five training splits update the new common encoder; all earlier model tensors remain unchanged. + +Fixed per-window relative band powers, envelope variability, envelope correlations and phase-amplitude coupling feed training-normalized private input projections and one new shared encoder. Five linear heads add class evidence. All five training splits update the new common encoder; all prior model tensors remain unchanged. AD65 updates use all windows from six class-balanced training patients; objective: mean-probability. + +The inherited OpenBMI phase-classifier projection was refreshed from a separately validated private-readout fit. Every common tensor and input adapter of this jointly trained model is unchanged. Exact ancestor checks confirm that all common tensors used by this inherited readout are identical; the new cross-frequency correction remains disabled for OpenBMI. No shared checkpoints or predictions are ensembled. + +A common CBraMod feature encoder, itself jointly trained on all five training splits, supplies its shared summary and tokens pooled into four ordered time bins. Its classifiers are discarded. A new common feature MLP and five zero-initialized private linear projections learn residual class evidence jointly on all five training splits. Training may randomly remove the earlier decoder logits for half of training groups, using one mask per AD patient and one per other window; labels and teacher targets remain unchanged. Validation and inference always retain the complete earlier decoder. The same new class projection also receives an auxiliary standalone classification loss when configured, with the same patient-pooled AD objective; this adds no inference module. The complete earlier decoder and feature extractor remain tensor-identical; selecting zero residual gain preserves its predictions exactly. The summary-only control masks the 8192 ordered features after training-fitted per-feature normalization. One feature backbone and one classifier per track run at inference, with no prediction ensemble or external runtime cache. + +The five outer private student-feature class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. + +The longitudinal private outer projection is selected from another training-only readout fit using exactly the same common/input/prior-head tensors. All other private heads are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +The complete stronger parent is retained, including its common CBraMod feature encoder, common readout and all private classifiers. The CBraMod features and existing common128-dimensional embedding are computed once and reused. An additional common128-to256-to128 MLP with the configured GELU or identity activation and five zero-initialized private linear projections learn residual class evidence jointly on all five training splits. Training may randomly remove the earlier decoder logits for half of training groups, using one mask per AD patient and one per other window; labels and teacher targets remain unchanged. Validation and inference always retain the complete earlier decoder. The same new class projection also receives an auxiliary standalone classification loss when configured, with the same patient-pooled AD objective; this adds no inference module. The complete earlier decoder and feature extractor remain tensor-identical; selecting zero residual gain preserves its predictions exactly. One feature backbone and one classifier per track run at inference, with no prediction ensemble or external runtime cache. + +The five outer private student-feature class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. + +The openbmi private outer projection is selected from another training-only readout fit using exactly the same common/input/prior-head tensors. All other private heads are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +A fixed two-second crop supplies spectral and cross-frequency coupling features, with no short-window envelope autocorrelation. The crop is configured as center or first. Each track has a training-fitted normalizer and linear input adapter to128 dimensions; one common128-to256-to128 GELU/LayerNorm block and five zero-initialized class projections are jointly trained on all five training splits. All complete-parent tensors are preserved exactly. Normalization statistics use training windows only. The parent is randomly removed from the training loss at the configured probability; it is always present at inference. AD uses mean patient probabilities over all sampled patient windows. Auxiliary classification uses the same class projection. There is one composed feature backbone and head per track; no prediction ensemble, external runtime cache, test adaptation, or evaluation-metadata features. Zero residual gain exactly retains the complete parent. + +The five outer private center-context class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. + +The tuev private outer projection is selected from another training-only readout fit using exactly the same common/input/prior-head tensors. All other private heads are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +The faced private context input and outer class projections are selected from another training-only readout fit using exactly the same common/oldinput/normalizer/prior-head tensors. All other private input/head pairs are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +A fixed one-second crop supplies spectral and cross-frequency coupling features, with no short-window envelope autocorrelation. The crop is configured as center or first. Each track has a training-fitted normalizer and linear input adapter to128 dimensions; one common128-to256-to128 GELU/LayerNorm block and five zero-initialized class projections are jointly trained on all five training splits. All complete-parent tensors are preserved exactly. Normalization statistics use training windows only. The parent is randomly removed from the training loss at the configured probability; it is always present at inference. AD uses mean patient probabilities over all sampled patient windows. Auxiliary classification uses the same class projection. There is one composed feature backbone and head per track; no prediction ensemble, external runtime cache, test adaptation, or evaluation-metadata features. Zero residual gain exactly retains the complete parent. + +The five outer private short-context class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. + +The tuev private outer projection is selected from another training-only readout fit using exactly the same common/input/prior-head tensors. All other private heads are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +An additional common context block preserves every existing short-context parent tensor and correction. A fixed one-second crop supplies spectral and cross-frequency coupling features, with no short-window envelope autocorrelation. TUEV concatenates first and center one-second descriptors; the parameter-matched control repeats first descriptors. Other tracks use first one-second descriptors. Each track has a training-fitted normalizer and linear input adapter to128 dimensions; one common128-to256-to128 GELU/LayerNorm block and five zero-initialized class projections are jointly trained on all five training splits. All complete-parent tensors are preserved exactly. Normalization statistics use training windows only. The parent is randomly removed from the training loss at the configured probability; it is always present at inference. AD uses mean patient probabilities over all sampled patient windows. Auxiliary classification uses the same class projection. There is one composed feature backbone and head per track; no prediction ensemble, external runtime cache, test adaptation, or evaluation-metadata features. Zero residual gain exactly retains the complete parent. + +An additional shared128-to256-to128 GELU/LayerNorm block is jointly trained by all five tracks. OpenBMI uses seven native-channel trace-normalized covariance matrices with fixed5percent identity shrinkage: matrix-log upper triangles in the main arm, covariance-minus-identity in the matched control. Other four new inputs are first-one-second spectral/coupling descriptors. Every complete-parent tensor is preserved exactly. Input normalization uses training windows only; zero outer gain retains the parent. Five private adapters and class projections, one composed shared backbone, no evaluation adaptation or external runtime cache. + +The five outer private geometry-block input adapters and class projections are refined on all five training splits. Every common backbone, fitted normalizer and earlier input/prior-head tensor remains exactly fixed. Common parameters are excluded from optimization; differentiable evaluation of the fixed common block permits gradients to the private input maps. AD uses the exact patient-mean probability objective. Private input/head checkpoints may be selected independently only because the common parameter state is identical and every track uses its own private adapter/head; all five metrics are evaluated for every exported package. + +An additional shared128-to256-to128 GELU/LayerNorm block is jointly trained by all five tracks. FACED uses seven native-channel trace-normalized covariance matrices with fixed5percent identity shrinkage: matrix-log upper triangles in the main arm, covariance-minus-identity in the matched control. Other four new inputs are first-one-second spectral/coupling descriptors. Every complete-parent tensor is preserved exactly. Input normalization uses training windows only; zero outer gain retains the parent. Five private adapters and class projections, one composed shared backbone, no evaluation adaptation or external runtime cache. + +The longitudinal private context input and outer class projections are selected from another training-only readout fit using exactly the same common/oldinput/normalizer/prior-head tensors. All other private input/head pairs are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +An additional shared128-to256-to128 gelu/LayerNorm block is jointly trained by all five tracks. FACED uses seven native-channel trace-normalized covariance matrices with fixed5percent identity shrinkage and matrix-log upper triangles in both activation conditions. Other four new inputs are first-one-second spectral/coupling descriptors. Every complete-parent tensor is preserved exactly. Input normalization uses training windows only; zero outer gain retains the parent. Five private adapters and class projections, one composed shared backbone, no evaluation adaptation or external runtime cache. + +The five outer private refinement-block input adapters and class projections are refined on all five training splits. Every common backbone, fitted normalizer and earlier input/prior-head tensor remains exactly fixed. Common parameters are excluded from optimization; differentiable evaluation of the fixed common block permits gradients to the private input maps. AD uses the exact patient-mean probability objective. Private input/head checkpoints may be selected independently only because the common parameter state is identical and every track uses its own private adapter/head; all five metrics are evaluated for every exported package. + +The five outer private refinement-block input adapters and class projections are refined on all five training splits. Every common backbone, fitted normalizer and earlier input/prior-head tensor remains exactly fixed. Common parameters are excluded from optimization; differentiable evaluation of the fixed common block permits gradients to the private input maps. AD uses the exact patient-mean probability objective. Private input/head checkpoints may be selected independently only because the common parameter state is identical and every track uses its own private adapter/head; all five metrics are evaluated for every exported package. + +An additional shared128-to256-to128 gelu/LayerNorm block is jointly trained by all five tracks. OpenBMI uses full-window spectral and cross-frequency features from six central/parietal local differences or the matched six native channels under common-average reference. FACED retains native log covariance descriptors; TUEV/AD65/Longitudinal retain first1s descriptors. Both conditions have identical parameter dimensions. Every complete-parent tensor is preserved exactly. Input normalization uses training windows only; zero outer gain retains the parent. Five private adapters and class projections, one composed shared backbone, no evaluation adaptation or external runtime cache. + +The five outer private spatial-block input adapters and class projections are refined on all five training splits. Every common backbone, fitted normalizer and earlier input/prior-head tensor remains exactly fixed. Common parameters are excluded from optimization; differentiable evaluation of the fixed common block permits gradients to the private input maps. AD uses the exact patient-mean probability objective. Private input/head checkpoints may be selected independently only because the common parameter state is identical and every track uses its own private adapter/head; all five metrics are evaluated for every exported package. + +The five outer private spatial-block input adapters and class projections are refined on all five training splits. Every common backbone, fitted normalizer and earlier input/prior-head tensor remains exactly fixed. Common parameters are excluded from optimization; differentiable evaluation of the fixed common block permits gradients to the private input maps. AD uses the exact patient-mean probability objective. Private input/head checkpoints may be selected independently only because the common parameter state is identical and every track uses its own private adapter/head; all five metrics are evaluated for every exported package. + +A widened shared256-to512-to256 dense GELU block with two LayerNorm groups is jointly trained by all five tracks. Matching complete input/common representations are transferred from two audited all-five-trained ancestors, then dense cross-half connections train without task routing. Each track has one 256-to-class projection. This is a newly jointly trained common architecture. TUEV uses952conditional partial ormatchedmarginal nativebipolar covariance descriptors; theotherfour fixeddescriptors retain the completeparent spatial-feature recipe. Bothconditions haveidentical dimensions. Every completeparent tensor ispreserved; normalizationusestrainingwindowsonly. Onecomposedsharedbackbone, fiveprivateadapters/classheads, noevaluationadaptation/externalcache. + +Five outer private scalar gains were selected from a bounded fifteen-value grid on the provided validation splits. Every trained common backbone, input adapter, classifier and earlier gain remains exactly unchanged. This is additional model selection on the same validation people, not an independent test result. Inference uses fixed selected gains and no adaptation. + +The complete coherent selected1166-state model is jointly continued on all five training splits with fixed source gains, fresh AdamW, and main-gradient-protected standalone auxiliary supervision. Every1118-state earlier parent remains exact. The current conditional common encoder, five private input maps and heads update together. Source gains remain eligible during finite validation selection; no inference adaptation. + +Only the FACED outer private input adapter and class projection use learning rate1e-6; the common encoder and other four private inputs/heads use1e-7. Every track jointly trains the same common parameter set. The optimizer has two disjoint exhaustive groups and the original shared cosine schedule, global clipping, AdamW betas and decay. + +The five outer private conditional-block input adapters and class projections are refined on all five training splits. Every common backbone, fitted normalizer and earlier input/prior-head tensor remains exactly fixed. Common parameters are excluded from optimization; differentiable evaluation of the fixed common block permits gradients to the private input maps. AD uses the exact patient-mean probability objective. Private input/head checkpoints may be selected independently only because the common parameter state is identical and every track uses its own private adapter/head; all five metrics are evaluated for every exported package. + +The openbmi outer private input map and classifier are selected from a separately trained private fit with every common, normalizer and prior tensor exactly identical. The other four private pairs remain from the reference package. There is one shared backbone and one classifier per track. Both donor training stages are replayed and the combined package is checked directly on all five validation splits. + +The faced outer private input map and classifier are selected from a separately trained private fit with every common, normalizer and prior tensor exactly identical. The other four private pairs remain from the reference package. There is one shared backbone and one classifier per track. Both donor training stages are replayed and the combined package is checked directly on all five validation splits. + +One shared confidence encoder transforms fixed per-window entropy and probability margin from the frozen earlier prior. Five private scalar projections modulate the existing conditional residual by a bounded multiplier in [0.75,1.25]. Every1166 existing source state stays fixed and the old conditional encoder remains in eval mode during fitting. All five training splits update the new shared confidence encoder and their private scalar gates. Confidence gate enabled=1.0. All source1166 states initialize exactly. Native head addition precision is preserved. No evaluation adaptation or external inference cache. + +The final private confidence gates are selected between their trained values and exact zero at the single final shared checkpoint. All five original outer gains are restored to the verified source values. All1166 original model states remain exact; the six new common confidence parameters retain their joint all-five training. Zero private gates restore each track's original function independently of the new common weights. This construction performs no additional training or validation-input adaptation. Selected gates on: {"ad65": false, "faced": false, "longitudinal": false, "openbmi": true, "tuev": false}. + +A new common descriptor encoder is trained jointly on all five tracks, with five input adapters and new class projections. OpenBMI uses multitaper native covariance; the other four use the source conditional descriptors. All 1183 source states are fixed. Normalizers use 8192 matched TRAIN-only draws per track; no evaluation adaptation. New class weights initialize to zero. Validation selects private gains within one complete new common checkpoint, with exact source fallback at zero. The new addition uses float32 over complete source336 logits. Current enabled=1.0. + +A new common descriptor encoder is trained jointly on all five tracks, with five input adapters and new class projections. FACED, OpenBMI and Longitudinal use weighted amplitude-weighted ordinal pattern features; TUEV and AD65 reuse existing source descriptor inputs. All 1232 source states are fixed. Normalizers use 8192 matched TRAIN-only draws per track; no evaluation adaptation. New class weights initialize to zero. Validation selects private gains within one complete new common checkpoint, with exact source fallback at zero. The new addition uses float32 over complete source374 logits. Current enabled=1.0. + +Seven Gaussian spectral filters feed one new common encoder trained jointly on all five tracks, with five input adapters and class projections. Filter centers and widths are shared across all tracks; their training learning rate is 0.0. All 1281 source states remain fixed. Per-window Welch log-relative spectra use fixed preprocessing, and new normalizers fit only 8192 balanced TRAIN draws per track at the initial filter parameters. No evaluation adaptation. New class weights initialize to zero. Validation selects private gains within one complete common checkpoint, with exact complete388 fallback at zero. All additions use float32. Current enabled=1.0. + +Two shared nonlinear feature blocks are trained jointly on all five tracks over the existing weighted ordinal and clinical/dementia descriptors. Both shared blocks are evaluated for every input; bounded softmax routing keeps both weights positive. Routing mode is input. Five private input maps, task biases and class heads accompany the common blocks and router. All 1333 source states and inherited TRAIN-only normalization statistics remain fixed. New class weights initialize to zero. Validation chooses private gains within one complete common checkpoint, with exact complete431 fallback at zero. There is no evaluation adaptation or cross-checkpoint head combination. Current enabled=1.0. diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S122/covariances.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S122/covariances.py new file mode 100644 index 0000000000000000000000000000000000000000..a65153f3b18f31995ff206a8e2fb8a7fd7a254dd --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S122/covariances.py @@ -0,0 +1,25 @@ +"""Shared neural filter-bank covariance decoder with spatial input adapters.""" +import torch +from torch import nn +SPECS={'faced':(32,10,9),'tuev':(16,5,6),'ad65':(19,10,3),'openbmi':(62,4,2),'longitudinal':(58,2,2)} +TRACKS=tuple(SPECS) +BANDS=[(1,4),(4,8),(8,12),(12,16),(16,20),(20,24),(24,28),(28,32),(32,40),(40,48)] + +@torch.no_grad() +def extract_covariances(t,x): + x=torch.nan_to_num(x.float().flatten(2)).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if t in ('faced','tuev'): + x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + else:x=x-x.mean(1,keepdim=True) + # Per-window normalization, preserving spatial and frequency power ratios. + x=x/x.square().mean((1,2),keepdim=True).clamp_min(1e-12).sqrt() + frames=x.unfold(-1,400,200);frames=frames-frames.mean(-1,keepdim=True) + z=torch.fft.rfft(frames*torch.hann_window(400,device=x.device),dim=-1)/200 + covs=[] + for lo,hi in BANDS: + v=z[...,2*lo:2*hi].flatten(2) + cov=(v.real@v.real.transpose(-1,-2)+v.imag@v.imag.transpose(-1,-2))/v.shape[-1] + covs.append(cov) + return torch.stack(covs,1) + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S122/partial_covariance_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S122/partial_covariance_features.py new file mode 100644 index 0000000000000000000000000000000000000000..3cbef5528aa7424e7ffc878afb40f80509b661d3 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S122/partial_covariance_features.py @@ -0,0 +1,33 @@ +"""Native regularized partial and marginal covariance statistics; no causal claims.""" +import torch +from native_log_covariance_features import BANDS + +@torch.no_grad() +def summarize_matrix(matrix,partial=True): + c=matrix.shape[-1];value=matrix.double() + if partial:value=torch.linalg.inv(value) + diagonal=value.diagonal(dim1=-2,dim2=-1).clamp_min(1e-12) + correlation=value/(diagonal[...,None]*diagonal[...,None,:]).sqrt() + if partial:correlation=-correlation + ii,jj=torch.triu_indices(c,c,offset=1,device=matrix.device) + variance=(-1. if partial else 1.)*diagonal.log() + pairs=torch.atanh(correlation[...,ii,jj].clamp(-.999,.999)) + return torch.cat([variance,pairs],-1).flatten(1).float() + + +@torch.no_grad() +def stable_band_matrices(track,x): + x=torch.nan_to_num(x.double().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x[...,:1];x=x-x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + reference=x.square().mean((-1,-2),keepdim=True);n=x.shape[-1];c=x.shape[1] + z=torch.fft.rfft(x,dim=-1);f=torch.fft.rfftfreq(n,1/200,device=x.device,dtype=torch.float64);eye=torch.eye(c,device=x.device,dtype=torch.float64);parts=[] + for lo,hi in BANDS: + v=torch.fft.irfft(z*((f>=lo)&(f(1e-10*reference).clamp_min(1e-20),cov/power.clamp_min(1e-20),eye);matrix=.95*normalized+.05*eye;parts.append((matrix+matrix.transpose(-1,-2))*.5) + return torch.stack(parts,1) + +@torch.no_grad() +def partial_covariance_features(track,x,partial=True): + with torch.autocast(x.device.type,enabled=False): + return summarize_matrix(stable_band_matrices(track,x),partial) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S122/shared_expert_routing_math.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S122/shared_expert_routing_math.py new file mode 100644 index 0000000000000000000000000000000000000000..516adabe6b0c1807b1d5dae4a9ffdb8993ba815b --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S122/shared_expert_routing_math.py @@ -0,0 +1,14 @@ +"""443 bounded two-expert routing; no data or fitted state.""" +import torch + + +def bounded_expert_weights(router_logits,task_bias,mode): + if mode=='input':scores=router_logits+task_bias + elif mode=='task':scores=router_logits*0.+task_bias + elif mode=='uniform':scores=(router_logits+task_bias)*0. + else:raise ValueError(mode) + return (2*torch.tanh(scores)).softmax(-1) + + +def mix_expert_outputs(first,second,weights): + return first+weights[...,1:2]*(second-first) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S122/tangent_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S122/tangent_features.py new file mode 100644 index 0000000000000000000000000000000000000000..314f0cf2f58e4b4a1c1d808edbd4acc3b7b6f85b --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S122/tangent_features.py @@ -0,0 +1,25 @@ +"""Window-local log-correlation geometry in the existing spatial-filter basis.""" +import torch + +TANGENT_DIM=10*24*25//2 + +@torch.no_grad() +def extract_tangent_features(covariances,spatial_weight): + old_tf32=torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(covariances.device.type,enabled=False): + w=spatial_weight.float() + w=w/w.norm(dim=-1,keepdim=True).clamp_min(1e-6) + projected=torch.einsum('bfc,nbcd,bgd->nbfg',w,covariances.float(),w) + d=projected.diagonal(dim1=-2,dim2=-1).clamp_min(1e-10).sqrt() + correlation=(projected/(d.unsqueeze(-1)*d.unsqueeze(-2))).clamp(-1,1) + correlation=(correlation+correlation.transpose(-1,-2))/2 + correlation=.95*correlation+.05*torch.eye(24,device=correlation.device) + values,vectors=torch.linalg.eigh(correlation) + logarithm=(vectors*values.clamp_min(1e-6).log().unsqueeze(-2))@vectors.transpose(-1,-2) + i,j=torch.triu_indices(24,24,device=correlation.device) + scale=torch.where(i==j,1.,2.**.5) + return (logarithm[...,i,j]*scale).flatten(1) + finally: + torch.backends.cuda.matmul.allow_tf32=old_tf32 diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S122/weighted_ordinal_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S122/weighted_ordinal_features.py new file mode 100644 index 0000000000000000000000000000000000000000..1045da783f13240049acd50af59810968b934657 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S122/weighted_ordinal_features.py @@ -0,0 +1,44 @@ +"""Fixed per-window amplitude-weighted ordinal patterns; no learned state.""" +import functools,math +import numpy as np +import torch +LAGS=(1,2,4,8,16) + +@functools.lru_cache(maxsize=32) +def permutations(n,lag): + length=n-3*lag + return tuple(np.random.default_rng(386000+1000*lag+n+j).permutation(length) for j in range(4)) + +def summarize(p): + h=-(p*p.clamp_min(1e-300).log()).sum(-1);u=1/24;hu=math.log(24);q=(p+u)/2 + hq=-(q*q.log()).sum(-1);m=(1+u)/2;r=u/2;maximum=-m*math.log(m)-23*r*math.log(r)-hu/2 + complexity=((hq-.5*h-.5*hu)/maximum).clamp(0,1)*(h/hu) + return torch.cat([p,(h/hu).unsqueeze(-1),complexity.unsqueeze(-1)],-1) + +def histograms(code,weights): + plain=torch.stack([(code==k).double().mean(-1) for k in range(24)],-1) + total=weights.sum(-1,keepdim=True) + weighted=torch.stack([torch.where(code==k,weights,0.).sum(-1) for k in range(24)],-1)/total.clamp_min(1e-20) + return torch.where(total>1e-20,weighted,plain),plain + +@torch.no_grad() +def weighted_ordinal_features(track,x): + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.double().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + power=x.square().mean(-1,keepdim=True);active=power>1e-20;x=x/power.clamp_min(1e-20).sqrt();n=x.shape[-1] + parts={k:[] for k in ['weighted','plain','shuffled']} + for lag in LAGS: + length=n-3*lag + if length<=0:raise ValueError('window too short') + samples=torch.stack([x[...,j*lag:j*lag+length] for j in range(4)],-1) + order=(samples*1e10).round().argsort(dim=-1,stable=True) + code=6*((order[...,0,None]>order[...,1:]).sum(-1))+2*((order[...,1,None]>order[...,2:]).sum(-1))+(order[...,2]>order[...,3]).long() + weights=(samples-samples.mean(-1,keepdim=True)).square().mean(-1) + weighted,plain=histograms(code,weights);shuffled=[] + for perm in permutations(n,lag): + value,_=histograms(code,weights.index_select(-1,torch.as_tensor(perm,device=x.device)));shuffled.append(value) + values={'weighted':weighted,'plain':plain,'shuffled':torch.stack(shuffled).mean(0)} + for k,v in values.items():parts[k].append(torch.where(active,summarize(v),0.)) + return {k:torch.cat(v,-1).flatten(1).float() for k,v in parts.items()} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/MODEL_CARD.md b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/MODEL_CARD.md new file mode 100644 index 0000000000000000000000000000000000000000..8bfe7c9655d78d5da66b934807b7a0b576e2b712 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/MODEL_CARD.md @@ -0,0 +1,103 @@ +# Shared EEG decoder + +This package contains one coupled backbone used by all five tracks, with private input adapters and classifiers. Every trainable common component was trained with all five training splits. It is a single model; inference performs no parameter updates or dataset-level fitting. + +The common backbone combines waveform convolutions, an audited pretrained BIOT feature path, covariance and log-correlation encoders, and shared feature corrections. The waveform coactivation extension encodes 64 within-window log variances and 2,016 correlations between common waveform channels. A matched experimental control removes the correlation inputs. `config.json` identifies the packaged variant and its five fixed correction gains. All original backbone parameters are fixed during this extension's joint training. + +Weights originate only from the supplied training data and audited initialization checkpoints. Training details, parent provenance, raw/cache checks, shared-gradient checks and the five separate validation metrics are recorded in `training.json`. Validation selects checkpoints and fixed gains; it does not fit normalization or update parameters. Reported validation results belong to selected checkpoints, not to private test evaluation or five-seed means. + +Run `bash infer.sh INPUT_DIR OUTPUT_DIR`. The input manifest specifies a track and opaque sample IDs, shard paths and indices. Signals are in microvolts and are scaled by 1/100. The package writes one probability vector per input ID to `OUTPUT_DIR/predictions.jsonl`. It needs only the packaged files and the contract's installed Python dependencies, works after relocation, and does not need labels, subject IDs, training caches or network access. + +FACED and TUEV use window balanced accuracy. AD65 uses mean window probabilities per patient before balanced accuracy. OpenBMI averages within-subject balanced accuracy. Longitudinal averages within-session balanced accuracy within each subject, then over subjects. These five metrics remain separate. + +This checkpoint adds fixed within-window ordinal pattern probabilities, permutation entropy and statistical complexity at five delays. Training-only normalization and five input projections feed one common correction MLP trained by all five tracks. The common correction enters the existing covariance and fusion representations; fixed per-track gains select its strength. All earlier model tensors remain unchanged. + +Fixed real and imaginary spectral coherence between the inherited 24 spatial filters is normalized using training windows only and encoded by one new common network. Five private linear heads add class evidence. All five training splits update the new common encoder; all earlier model tensors remain unchanged. + +Fixed per-window relative band powers, envelope variability, envelope correlations and phase-amplitude coupling feed training-normalized private input projections and one new shared encoder. Five linear heads add class evidence. All five training splits update the new common encoder; all prior model tensors remain unchanged. AD65 updates use all windows from six class-balanced training patients; objective: mean-probability. + +The inherited OpenBMI phase-classifier projection was refreshed from a separately validated private-readout fit. Every common tensor and input adapter of this jointly trained model is unchanged. Exact ancestor checks confirm that all common tensors used by this inherited readout are identical; the new cross-frequency correction remains disabled for OpenBMI. No shared checkpoints or predictions are ensembled. + +A common CBraMod feature encoder, itself jointly trained on all five training splits, supplies its shared summary and tokens pooled into four ordered time bins. Its classifiers are discarded. A new common feature MLP and five zero-initialized private linear projections learn residual class evidence jointly on all five training splits. Training may randomly remove the earlier decoder logits for half of training groups, using one mask per AD patient and one per other window; labels and teacher targets remain unchanged. Validation and inference always retain the complete earlier decoder. The same new class projection also receives an auxiliary standalone classification loss when configured, with the same patient-pooled AD objective; this adds no inference module. The complete earlier decoder and feature extractor remain tensor-identical; selecting zero residual gain preserves its predictions exactly. The summary-only control masks the 8192 ordered features after training-fitted per-feature normalization. One feature backbone and one classifier per track run at inference, with no prediction ensemble or external runtime cache. + +The five outer private student-feature class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. + +The longitudinal private outer projection is selected from another training-only readout fit using exactly the same common/input/prior-head tensors. All other private heads are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +The complete stronger parent is retained, including its common CBraMod feature encoder, common readout and all private classifiers. The CBraMod features and existing common128-dimensional embedding are computed once and reused. An additional common128-to256-to128 MLP with the configured GELU or identity activation and five zero-initialized private linear projections learn residual class evidence jointly on all five training splits. Training may randomly remove the earlier decoder logits for half of training groups, using one mask per AD patient and one per other window; labels and teacher targets remain unchanged. Validation and inference always retain the complete earlier decoder. The same new class projection also receives an auxiliary standalone classification loss when configured, with the same patient-pooled AD objective; this adds no inference module. The complete earlier decoder and feature extractor remain tensor-identical; selecting zero residual gain preserves its predictions exactly. One feature backbone and one classifier per track run at inference, with no prediction ensemble or external runtime cache. + +The five outer private student-feature class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. + +The openbmi private outer projection is selected from another training-only readout fit using exactly the same common/input/prior-head tensors. All other private heads are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +A fixed two-second crop supplies spectral and cross-frequency coupling features, with no short-window envelope autocorrelation. The crop is configured as center or first. Each track has a training-fitted normalizer and linear input adapter to128 dimensions; one common128-to256-to128 GELU/LayerNorm block and five zero-initialized class projections are jointly trained on all five training splits. All complete-parent tensors are preserved exactly. Normalization statistics use training windows only. The parent is randomly removed from the training loss at the configured probability; it is always present at inference. AD uses mean patient probabilities over all sampled patient windows. Auxiliary classification uses the same class projection. There is one composed feature backbone and head per track; no prediction ensemble, external runtime cache, test adaptation, or evaluation-metadata features. Zero residual gain exactly retains the complete parent. + +The five outer private center-context class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. + +The tuev private outer projection is selected from another training-only readout fit using exactly the same common/input/prior-head tensors. All other private heads are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +The faced private context input and outer class projections are selected from another training-only readout fit using exactly the same common/oldinput/normalizer/prior-head tensors. All other private input/head pairs are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +A fixed one-second crop supplies spectral and cross-frequency coupling features, with no short-window envelope autocorrelation. The crop is configured as center or first. Each track has a training-fitted normalizer and linear input adapter to128 dimensions; one common128-to256-to128 GELU/LayerNorm block and five zero-initialized class projections are jointly trained on all five training splits. All complete-parent tensors are preserved exactly. Normalization statistics use training windows only. The parent is randomly removed from the training loss at the configured probability; it is always present at inference. AD uses mean patient probabilities over all sampled patient windows. Auxiliary classification uses the same class projection. There is one composed feature backbone and head per track; no prediction ensemble, external runtime cache, test adaptation, or evaluation-metadata features. Zero residual gain exactly retains the complete parent. + +The five outer private short-context class projections are refined on all five training splits while every common/input/prior-head tensor remains exactly fixed. AD uses the exact patient-mean probability objective. Private checkpoints may be selected independently only because the common representation is identical; all five metrics are evaluated for every exported package. + +The tuev private outer projection is selected from another training-only readout fit using exactly the same common/input/prior-head tensors. All other private heads are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +An additional common context block preserves every existing short-context parent tensor and correction. A fixed one-second crop supplies spectral and cross-frequency coupling features, with no short-window envelope autocorrelation. TUEV concatenates first and center one-second descriptors; the parameter-matched control repeats first descriptors. Other tracks use first one-second descriptors. Each track has a training-fitted normalizer and linear input adapter to128 dimensions; one common128-to256-to128 GELU/LayerNorm block and five zero-initialized class projections are jointly trained on all five training splits. All complete-parent tensors are preserved exactly. Normalization statistics use training windows only. The parent is randomly removed from the training loss at the configured probability; it is always present at inference. AD uses mean patient probabilities over all sampled patient windows. Auxiliary classification uses the same class projection. There is one composed feature backbone and head per track; no prediction ensemble, external runtime cache, test adaptation, or evaluation-metadata features. Zero residual gain exactly retains the complete parent. + +An additional shared128-to256-to128 GELU/LayerNorm block is jointly trained by all five tracks. OpenBMI uses seven native-channel trace-normalized covariance matrices with fixed5percent identity shrinkage: matrix-log upper triangles in the main arm, covariance-minus-identity in the matched control. Other four new inputs are first-one-second spectral/coupling descriptors. Every complete-parent tensor is preserved exactly. Input normalization uses training windows only; zero outer gain retains the parent. Five private adapters and class projections, one composed shared backbone, no evaluation adaptation or external runtime cache. + +The five outer private geometry-block input adapters and class projections are refined on all five training splits. Every common backbone, fitted normalizer and earlier input/prior-head tensor remains exactly fixed. Common parameters are excluded from optimization; differentiable evaluation of the fixed common block permits gradients to the private input maps. AD uses the exact patient-mean probability objective. Private input/head checkpoints may be selected independently only because the common parameter state is identical and every track uses its own private adapter/head; all five metrics are evaluated for every exported package. + +An additional shared128-to256-to128 GELU/LayerNorm block is jointly trained by all five tracks. FACED uses seven native-channel trace-normalized covariance matrices with fixed5percent identity shrinkage: matrix-log upper triangles in the main arm, covariance-minus-identity in the matched control. Other four new inputs are first-one-second spectral/coupling descriptors. Every complete-parent tensor is preserved exactly. Input normalization uses training windows only; zero outer gain retains the parent. Five private adapters and class projections, one composed shared backbone, no evaluation adaptation or external runtime cache. + +The longitudinal private context input and outer class projections are selected from another training-only readout fit using exactly the same common/oldinput/normalizer/prior-head tensors. All other private input/head pairs are retained. Exact equality of every common tensor and executable runtime is audited; this package has one common checkpoint and one head per track. + +An additional shared128-to256-to128 gelu/LayerNorm block is jointly trained by all five tracks. FACED uses seven native-channel trace-normalized covariance matrices with fixed5percent identity shrinkage and matrix-log upper triangles in both activation conditions. Other four new inputs are first-one-second spectral/coupling descriptors. Every complete-parent tensor is preserved exactly. Input normalization uses training windows only; zero outer gain retains the parent. Five private adapters and class projections, one composed shared backbone, no evaluation adaptation or external runtime cache. + +The five outer private refinement-block input adapters and class projections are refined on all five training splits. Every common backbone, fitted normalizer and earlier input/prior-head tensor remains exactly fixed. Common parameters are excluded from optimization; differentiable evaluation of the fixed common block permits gradients to the private input maps. AD uses the exact patient-mean probability objective. Private input/head checkpoints may be selected independently only because the common parameter state is identical and every track uses its own private adapter/head; all five metrics are evaluated for every exported package. + +The five outer private refinement-block input adapters and class projections are refined on all five training splits. Every common backbone, fitted normalizer and earlier input/prior-head tensor remains exactly fixed. Common parameters are excluded from optimization; differentiable evaluation of the fixed common block permits gradients to the private input maps. AD uses the exact patient-mean probability objective. Private input/head checkpoints may be selected independently only because the common parameter state is identical and every track uses its own private adapter/head; all five metrics are evaluated for every exported package. + +An additional shared128-to256-to128 gelu/LayerNorm block is jointly trained by all five tracks. OpenBMI uses full-window spectral and cross-frequency features from six central/parietal local differences or the matched six native channels under common-average reference. FACED retains native log covariance descriptors; TUEV/AD65/Longitudinal retain first1s descriptors. Both conditions have identical parameter dimensions. Every complete-parent tensor is preserved exactly. Input normalization uses training windows only; zero outer gain retains the parent. Five private adapters and class projections, one composed shared backbone, no evaluation adaptation or external runtime cache. + +The five outer private spatial-block input adapters and class projections are refined on all five training splits. Every common backbone, fitted normalizer and earlier input/prior-head tensor remains exactly fixed. Common parameters are excluded from optimization; differentiable evaluation of the fixed common block permits gradients to the private input maps. AD uses the exact patient-mean probability objective. Private input/head checkpoints may be selected independently only because the common parameter state is identical and every track uses its own private adapter/head; all five metrics are evaluated for every exported package. + +The five outer private spatial-block input adapters and class projections are refined on all five training splits. Every common backbone, fitted normalizer and earlier input/prior-head tensor remains exactly fixed. Common parameters are excluded from optimization; differentiable evaluation of the fixed common block permits gradients to the private input maps. AD uses the exact patient-mean probability objective. Private input/head checkpoints may be selected independently only because the common parameter state is identical and every track uses its own private adapter/head; all five metrics are evaluated for every exported package. + +A widened shared256-to512-to256 dense GELU block with two LayerNorm groups is jointly trained by all five tracks. Matching complete input/common representations are transferred from two audited all-five-trained ancestors, then dense cross-half connections train without task routing. Each track has one 256-to-class projection. This is a newly jointly trained common architecture. TUEV uses952conditional partial ormatchedmarginal nativebipolar covariance descriptors; theotherfour fixeddescriptors retain the completeparent spatial-feature recipe. Bothconditions haveidentical dimensions. Every completeparent tensor ispreserved; normalizationusestrainingwindowsonly. Onecomposedsharedbackbone, fiveprivateadapters/classheads, noevaluationadaptation/externalcache. + +Five outer private scalar gains were selected from a bounded fifteen-value grid on the provided validation splits. Every trained common backbone, input adapter, classifier and earlier gain remains exactly unchanged. This is additional model selection on the same validation people, not an independent test result. Inference uses fixed selected gains and no adaptation. + +The complete coherent selected1166-state model is jointly continued on all five training splits with fixed source gains, fresh AdamW, and main-gradient-protected standalone auxiliary supervision. Every1118-state earlier parent remains exact. The current conditional common encoder, five private input maps and heads update together. Source gains remain eligible during finite validation selection; no inference adaptation. + +Only the FACED outer private input adapter and class projection use learning rate1e-6; the common encoder and other four private inputs/heads use1e-7. Every track jointly trains the same common parameter set. The optimizer has two disjoint exhaustive groups and the original shared cosine schedule, global clipping, AdamW betas and decay. + +The five outer private conditional-block input adapters and class projections are refined on all five training splits. Every common backbone, fitted normalizer and earlier input/prior-head tensor remains exactly fixed. Common parameters are excluded from optimization; differentiable evaluation of the fixed common block permits gradients to the private input maps. AD uses the exact patient-mean probability objective. Private input/head checkpoints may be selected independently only because the common parameter state is identical and every track uses its own private adapter/head; all five metrics are evaluated for every exported package. + +The openbmi outer private input map and classifier are selected from a separately trained private fit with every common, normalizer and prior tensor exactly identical. The other four private pairs remain from the reference package. There is one shared backbone and one classifier per track. Both donor training stages are replayed and the combined package is checked directly on all five validation splits. + +The faced outer private input map and classifier are selected from a separately trained private fit with every common, normalizer and prior tensor exactly identical. The other four private pairs remain from the reference package. There is one shared backbone and one classifier per track. Both donor training stages are replayed and the combined package is checked directly on all five validation splits. + +One shared confidence encoder transforms fixed per-window entropy and probability margin from the frozen earlier prior. Five private scalar projections modulate the existing conditional residual by a bounded multiplier in [0.75,1.25]. Every1166 existing source state stays fixed and the old conditional encoder remains in eval mode during fitting. All five training splits update the new shared confidence encoder and their private scalar gates. Confidence gate enabled=1.0. All source1166 states initialize exactly. Native head addition precision is preserved. No evaluation adaptation or external inference cache. + +The final private confidence gates are selected between their trained values and exact zero at the single final shared checkpoint. All five original outer gains are restored to the verified source values. All1166 original model states remain exact; the six new common confidence parameters retain their joint all-five training. Zero private gates restore each track's original function independently of the new common weights. This construction performs no additional training or validation-input adaptation. Selected gates on: {"ad65": false, "faced": false, "longitudinal": false, "openbmi": true, "tuev": false}. + +A new common descriptor encoder is trained jointly on all five tracks, with five input adapters and new class projections. OpenBMI uses multitaper native covariance; the other four use the source conditional descriptors. All 1183 source states are fixed. Normalizers use 8192 matched TRAIN-only draws per track; no evaluation adaptation. New class weights initialize to zero. Validation selects private gains within one complete new common checkpoint, with exact source fallback at zero. The new addition uses float32 over complete source336 logits. Current enabled=1.0. + +A new common descriptor encoder is trained jointly on all five tracks, with five input adapters and new class projections. FACED, OpenBMI and Longitudinal use weighted amplitude-weighted ordinal pattern features; TUEV and AD65 reuse existing source descriptor inputs. All 1232 source states are fixed. Normalizers use 8192 matched TRAIN-only draws per track; no evaluation adaptation. New class weights initialize to zero. Validation selects private gains within one complete new common checkpoint, with exact source fallback at zero. The new addition uses float32 over complete source374 logits. Current enabled=1.0. + +Seven Gaussian spectral filters feed one new common encoder trained jointly on all five tracks, with five input adapters and class projections. Filter centers and widths are shared across all tracks; their training learning rate is 0.0. All 1281 source states remain fixed. Per-window Welch log-relative spectra use fixed preprocessing, and new normalizers fit only 8192 balanced TRAIN draws per track at the initial filter parameters. No evaluation adaptation. New class weights initialize to zero. Validation selects private gains within one complete common checkpoint, with exact complete388 fallback at zero. All additions use float32. Current enabled=1.0. + +Two shared nonlinear feature blocks are trained jointly on all five tracks over the existing weighted ordinal and clinical/dementia descriptors. Both shared blocks are evaluated for every input; bounded softmax routing keeps both weights positive. Routing mode is input. Five private input maps, task biases and class heads accompany the common blocks and router. All 1333 source states and inherited TRAIN-only normalization statistics remain fixed. New class weights initialize to zero. Validation chooses private gains within one complete common checkpoint, with exact complete431 fallback at zero. There is no evaluation adaptation or cross-checkpoint head combination. Current enabled=1.0. + +A new shared 128/256/128 nonlinear block is jointly trained on all five tracks above the complete verified 443 source. Longitudinal alone receives the fixed TRAIN-fitted strong descriptor geometry licensed by screen 458; its map is square. All four maps have the same expanded width and five per-track input projections and class heads. All 1386 source states stay fixed. The 25 Longitudinal geometry buffers use only TRAIN statistics. Other input normalizers are inherited unchanged. New class heads initialize at zero. Validation selects private gains within one common checkpoint, with exact complete443 fallback at zero. No inference adaptation or cross-common-checkpoint head combination. Current enabled=1.0. + +One new shared spectral projection and two shared content-attention blocks are trained jointly on all five tracks above the complete verified459 square source. Five private channel positions and reused TRAIN spectrum normalizers accompany zero-initialized correction heads and normally initialized auxiliary heads. Readout mode: detached. Separate routes auxiliary gradients through its own readout into the shared encoder; coupled uses the correction readout for both objectives; detached blocks auxiliary gradients to the encoder. All conditions have identical parameters and shapes. All1450 source states stay fixed. Validation selects private correction gains inside one complete common checkpoint. No evaluation adaptation, external inference caches, or cross-checkpoint head combination. Enabled=1.0. + +A fresh shared temporal-basis CNN is trained jointly on all five complete TRAIN splits with native label supervision, five private montage maps and classifiers. The complete source remains frozen. Per-track validation selects a declared logit blend within this whole common checkpoint. No evaluation adaptation or external inference caches. Temporal coefficient mode: absolute. + +A fresh shared CNN with a fixed temporal dilation bank and private channel maps is trained jointly on all five complete TRAIN splits with native label supervision, five private montage maps and classifiers. The complete source remains frozen. Per-track validation selects a declared logit blend within this whole common checkpoint. No evaluation adaptation or external inference caches. Temporal dilation mode: local. + +A fresh shared CNN with fixed internal activation-normalization groups and one forward pass is trained jointly on all five complete TRAIN splits with native label supervision, five private montage maps and classifiers. The complete source remains frozen. Per-track validation selects a declared logit blend within this whole common checkpoint. No evaluation adaptation or external inference caches. Fixed common normalization-group mode: all. diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/activation_groups_math.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/activation_groups_math.py new file mode 100644 index 0000000000000000000000000000000000000000..66034f9a9c362b78e61d1d21e214e17ea057be9e --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/activation_groups_math.py @@ -0,0 +1,14 @@ +"""Fixed group counts for the three common CNN activation normalizers.""" +GROUPS = {'all': (1, 1, 1), 'two': (2, 2, 2), 'original': (4, 8, 8)} +MODES = tuple(GROUPS) + + +def configure_groups(block, mode): + assert mode in GROUPS + for name, channels, groups in zip(('norm_temporal', 'norm_spatial', 'norm_separable'), + (16, 32, 64), GROUPS[mode]): + layer = getattr(block, name) + assert layer.num_channels == channels and layer.eps == 1e-5 + assert layer.affine and channels % groups == 0 + layer.num_groups = groups + return block diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/additive_hinge_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/additive_hinge_features.py new file mode 100644 index 0000000000000000000000000000000000000000..982268493992c1bd2155edd6c67bf639f0d68099 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/additive_hinge_features.py @@ -0,0 +1,29 @@ +"""459 portable Longitudinal strong descriptors, with fixed 32-row arithmetic.""" +import torch +from features import extract_features +from coupling_features import coupling_features +from short_context_features import short_spectral_features +from native_log_covariance_features import connectivity +from weighted_ordinal_features import weighted_ordinal_features +BLOCK_DIMENSIONS={'full':20039,'center2':20039,'first1':20039,'log_covariance':11977,'weighted_base':7540} +BLOCK_WEIGHTS={'full':.3375,'center2':.11249999999999999,'first1':.11249999999999999,'log_covariance':.1875,'weighted_base':.25} +RAW_DIMENSION=sum(BLOCK_DIMENSIONS.values()) +PROJECTED_DIMENSION=6*RAW_DIMENSION + +@torch.no_grad() +def longitudinal_hinge_features(raw): + assert raw.ndim==4 and tuple(raw.shape[1:])==(58,2,200) + old=torch.backends.cuda.matmul.allow_tf32 + try: + torch.backends.cuda.matmul.allow_tf32=False + with torch.autocast(raw.device.type,enabled=False): + results=[] + for start in range(0,len(raw),32): + x=raw[start:start+32].float();n=len(x) + if n<32:x=torch.cat([x,x.new_zeros((32-n,*x.shape[1:]))]) + flat=x.flatten(2) + values=[torch.cat([extract_features('longitudinal',x),coupling_features('longitudinal',x)],-1),torch.cat([short_spectral_features('longitudinal',flat),coupling_features('longitudinal',flat)],-1),torch.cat([short_spectral_features('longitudinal',flat[...,:200]),coupling_features('longitudinal',flat[...,:200])],-1),connectivity('longitudinal',x,True),weighted_ordinal_features('longitudinal',x)['weighted']] + assert [v.shape[1] for v in values]==list(BLOCK_DIMENSIONS.values()) + results.append(torch.cat(values,-1)[:n]) + return torch.cat(results,0) if results else raw.new_empty((0,RAW_DIMENSION),dtype=torch.float32) + finally:torch.backends.cuda.matmul.allow_tf32=old diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/additive_hinge_geometry.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/additive_hinge_geometry.py new file mode 100644 index 0000000000000000000000000000000000000000..bfacf0edcc43aa35eb8d3e85a344699d01aac44e --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/additive_hinge_geometry.py @@ -0,0 +1,60 @@ +"""459 fixed TRAIN-fitted coordinate geometry; no inference adaptation.""" +import math +import numpy as np +import torch +from torch import nn +from additive_hinge_features import BLOCK_DIMENSIONS,BLOCK_WEIGHTS,PROJECTED_DIMENSION +from additive_hinge_kernel import basis +MODES=('hinge','rotated','square','linear') + +class AdditiveBlock(nn.Module): + def __init__(self,dimension,mode): + super().__init__();assert mode in MODES;self.mode=mode;self.dimension=dimension + self.register_buffer('mean',torch.zeros(dimension,dtype=torch.float64)) + self.register_buffer('scale',torch.ones(dimension,dtype=torch.float64)) + self.register_buffer('basis_mean',torch.zeros(5*dimension,dtype=torch.float64)) + self.register_buffer('trace_factor',torch.ones((),dtype=torch.float64)) + self.register_buffer('permutation',torch.tensor(np.random.default_rng(458000+dimension).permutation(dimension),dtype=torch.int64)) + def normalized(self,values):return ((values.double()-self.mean)/self.scale).clamp(-8,8) + def rotate(self,values): + result=values[:,self.permutation].clone();even=self.dimension//2*2 + pairs=result[:,:even].reshape(len(values),-1,2);a,b=pairs[:,:,0].clone(),pairs[:,:,1].clone() + pairs[:,:,0]=(a+b)/(2**.5);pairs[:,:,1]=(a-b)/(2**.5) + return result + def mapped(self,values): + value=basis(values,self.mode) + return value if self.mode in ('hinge','rotated') else value.repeat_interleave(5,dim=1) + @torch.no_grad() + def fit(self,raw): + assert raw.ndim==2 and raw.shape[1]==self.dimension and len(raw)>1 + raw=raw.double();self.mean.copy_(raw.mean(0));self.scale.copy_(raw.std(0,correction=0).clamp_min(.001)) + values=self.normalized(raw);target=(values-values.mean(0)).square().sum(1).mean()/self.dimension + rotated=self.rotate(values) if self.mode=='rotated' else values + trace=values.new_zeros(()) + for start in range(0,self.dimension,256): + phi=self.mapped(rotated[:,start:start+256]);mean=phi.mean(0);self.basis_mean[start*5:(start+256)*5].copy_(mean) + trace+=(phi-mean).square().sum(1).mean()/(5*self.dimension) + self.trace_factor.copy_(target/trace.clamp_min(1e-20)) + assert torch.isfinite(self.trace_factor) and self.trace_factor>=0 + def forward(self,raw,weight): + x=self.normalized(raw);rotated=self.rotate(x) if self.mode=='rotated' else x + phi=self.mapped(rotated)-self.basis_mean + return x*math.sqrt(.75*weight/self.dimension),phi*(.25*weight*self.trace_factor/(5*self.dimension)).sqrt() + +class AdditiveGeometry(nn.Module): + def __init__(self,mode): + super().__init__();self.blocks=nn.ModuleDict({key:AdditiveBlock(d,mode) for key,d in BLOCK_DIMENSIONS.items()}) + @torch.no_grad() + def fit(self,raw): + offset=0 + for key,block in self.blocks.items(): + block.fit(raw[:,offset:offset+block.dimension]);offset+=block.dimension + assert offset==raw.shape[1] + def forward(self,raw,return_double=False): + pieces=[];offset=0 + for key,block in self.blocks.items(): + pieces.extend(block(raw[:,offset:offset+block.dimension],BLOCK_WEIGHTS[key]));offset+=block.dimension + assert offset==raw.shape[1] + result=torch.cat(pieces,1)*math.sqrt(PROJECTED_DIMENSION) + assert result.shape[1]==PROJECTED_DIMENSION + return result if return_double else result.float() diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/additive_hinge_kernel.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/additive_hinge_kernel.py new file mode 100644 index 0000000000000000000000000000000000000000..d40e57509f6d20d51ff3b0ea8206d646cc7e35ba --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/additive_hinge_kernel.py @@ -0,0 +1,35 @@ +"""458: finite additive coordinate bases with fit-only centering and trace matching.""" +import numpy as np +import torch +KNOTS=(-2.,-1.,0.,1.,2.) + +def rotate(values): + d=values.shape[1];permutation=np.random.default_rng(458000+d).permutation(d) + result=values[:,torch.tensor(permutation,device=values.device)].clone();even=d//2*2 + pairs=result[:,:even].reshape(len(values),-1,2);a,b=pairs[:,:,0].clone(),pairs[:,:,1].clone() + pairs[:,:,0]=(a+b)/(2**.5);pairs[:,:,1]=(a-b)/(2**.5) + return result,permutation + +def basis(values,mode): + if mode in ['hinge','rotated']: + knots=torch.tensor(KNOTS,device=values.device,dtype=values.dtype) + return ((values[:,:,None]-knots).relu()-(-knots).relu()).flatten(1) + if mode=='square':return values.square() + assert mode=='linear';return values + +def kernels(fit,probe,mode): + assert fit.dtype==probe.dtype==torch.float64 and fit.shape[1]==probe.shape[1] + assert mode in ['hinge','rotated','square','linear'] + dimension=fit.shape[1];centered=fit-fit.mean(0);target_trace=centered.square().sum(1).mean()/dimension + permutation=None + if mode=='rotated': + fit,permutation=rotate(fit);probe,other=rotate(probe);assert np.array_equal(permutation,other) + expanded_dimension=dimension*(5 if mode in ['hinge','rotated'] else 1) + kk=fit.new_zeros((len(fit),len(fit)));pk=fit.new_zeros((len(probe),len(fit)));means=[] + for start in range(0,dimension,256): + f=basis(fit[:,start:start+256],mode);q=basis(probe[:,start:start+256],mode);mean=f.mean(0);means.append(mean);f=f-mean;q=q-mean + kk+=(f@f.T)/expanded_dimension;pk+=(q@f.T)/expanded_dimension + actual_trace=kk.diag().mean();factor=target_trace/actual_trace.clamp_min(1e-20);kk=kk*factor;pk=pk*factor + assert torch.isfinite(kk).all() and torch.isfinite(pk).all() + state={'mode':mode,'input_dimension':dimension,'expanded_dimension':expanded_dimension,'fit_basis_mean':torch.cat(means),'target_fit_mean_diagonal':target_trace,'unscaled_fit_mean_diagonal':actual_trace,'trace_factor':factor,'rotation_permutation':permutation} + return (kk,pk),state diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/alpha_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/alpha_features.py new file mode 100644 index 0000000000000000000000000000000000000000..455154d715e86d45e4e17113bed69adbcd946b29 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/alpha_features.py @@ -0,0 +1,45 @@ +"""Fixed alpha prominence features from each individual two-second window.""" +import torch + +REGION_NAMES=('occipital','parietal','central','frontal','left_posterior','right_posterior') +REGIONS=(('PO7','PO5','PO3','POZ','PO4','PO6','PO8','O1','OZ','O2'), + ('P7','P5','P3','P1','PZ','P2','P4','P6','P8'), + ('FC5','FC3','FC1','FCZ','FC2','FC4','FC6','C5','C3','C1','CZ','C2','C4','C6'), + ('FP1','FPZ','FP2','AF3','AF4','F7','F5','F3','F1','FZ','F2','F4','F6','F8'), + ('P7','P5','P3','P1','PO7','PO5','PO3','O1'), + ('P2','P4','P6','P8','PO4','PO6','PO8','O2')) +ALPHA_DIM=58*7+6*22 + +def region_matrix(channels): + result=torch.zeros(len(REGIONS),len(channels)) + for i,names in enumerate(REGIONS): + for name in names:result[i,channels.index(name)]=1/len(names) + return result.tolist() + +@torch.no_grad() +def extract_alpha_features(signal,regions): + with torch.autocast(signal.device.type,enabled=False): + x=signal.float();x=x-x.mean(-1,keepdim=True) + spectrum=torch.fft.rfft(x*torch.hann_window(400,device=x.device),dim=-1)/200 + power=spectrum.abs().square().clamp_min(1e-12) + lp=power.log() + # Geometric regional means resist domination by one high-amplitude channel. + regional=torch.einsum('rc,ncf->nrf',regions.float(),lp) + lp=torch.cat([lp,regional],1) + low=lp[...,8:13].mean(-1,keepdim=True) + high=lp[...,36:49].mean(-1,keepdim=True) + freq=torch.arange(7.,14.5,.5,device=x.device) + alpha=lp[...,14:29] + baseline=low+(high-low)*((freq-5)/16) + prominence=alpha-baseline + normalized=alpha.softmax(-1) + center=(normalized*freq).sum(-1) + entropy=-(normalized*normalized.clamp_min(1e-12).log()).sum(-1) + alpha_mean=torch.logsumexp(alpha,-1)-torch.log(torch.tensor(15.,device=x.device)) + def log_band(lo,hi): + return torch.logsumexp(lp[...,lo:hi],-1)-torch.log(torch.tensor(float(hi-lo),device=x.device)) + summaries=torch.stack([alpha_mean-log_band(2,81),alpha_mean-log_band(8,14), + alpha_mean-log_band(30,61),prominence.max(-1).values, + prominence.mean(-1),center,entropy],-1) + return torch.cat([summaries[:,:58].flatten(1),summaries[:,58:].flatten(1), + prominence[:,58:].flatten(1)],1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/candidate_temporal_basis_model.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/candidate_temporal_basis_model.py new file mode 100644 index 0000000000000000000000000000000000000000..8652ef57c2bf502372443f5a9805772e685126e8 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/candidate_temporal_basis_model.py @@ -0,0 +1,47 @@ +"""Standalone shared CNN with explicit temporal response coefficients. + +No pretrained source, trained state, dataset, split or training recipe is +selected here. A separately bound study is required before EEG fitting. +""" +from torch import nn +from torch.nn import functional as F +from temporal_convolution_math import SharedTemporalConvolution, precise_convolution, raw_convolution_features +from learned_filter_temporal_basis import pool_filter_trajectories, MODES + +TRACKS = ('faced', 'tuev', 'ad65', 'openbmi', 'longitudinal') +SPECS = {'faced': (32, 9), 'tuev': (16, 6), 'ad65': (19, 3), + 'openbmi': (62, 2), 'longitudinal': (58, 2)} + + +class TemporalBasisConvolution(SharedTemporalConvolution): + def __init__(self, pooling_mode='signed'): + assert pooling_mode in MODES + super().__init__() + self.pooling_mode = pooling_mode + self.embedding = nn.Linear(384, 128) + + def forward(self, x): + x = self.norm_temporal(self.temporal(x.unsqueeze(1))) + x = self.dropout_spatial(F.avg_pool2d(F.elu(self.norm_spatial(self.spatial(x))), (1, 4))) + x = self.dropout_separable(F.avg_pool2d(F.elu(self.norm_separable(self.pointwise(self.depthwise(x)))), (1, 8))) + x = pool_filter_trajectories(x.squeeze(2), self.pooling_mode) + return self.dropout_embedding(self.norm_embedding(F.gelu(self.embedding(x)))) + + +class TemporalBasisModel(nn.Module): + def __init__(self, pooling_mode='signed'): + super().__init__() + self.adapters = nn.ModuleDict({track: nn.Linear(SPECS[track][0], 16, bias=False) for track in TRACKS}) + self.backbone = TemporalBasisConvolution(pooling_mode) + self.heads = nn.ModuleDict({track: nn.Linear(128, SPECS[track][1]) for track in TRACKS}) + for head in self.heads.values(): + nn.init.normal_(head.weight, std=.02) + nn.init.zeros_(head.bias) + + def forward_features(self, track, preprocessed): + with precise_convolution(preprocessed.device.type): + x = self.adapters[track](preprocessed.float().transpose(1, 2)).transpose(1, 2) + return self.heads[track](self.backbone(x)) + + def forward(self, track, raw): + return self.forward_features(track, raw_convolution_features(track, raw, 'raw')) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/confidence_model.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/confidence_model.py new file mode 100644 index 0000000000000000000000000000000000000000..f5328eaf8991493d705eddedf5ac7e4f274fc2e2 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/confidence_model.py @@ -0,0 +1,46 @@ +"""One shared confidence encoder modulates the existing residual readout per window.""" +import math +from legacy_model import * +LegacyHybridModel=HybridModel + +def confidence_features(prior,scale): + with torch.autocast(prior.device.type,enabled=False): + probability=(prior.detach().float()/scale).softmax(-1) + entropy=-(probability*probability.clamp_min(1e-12).log()).sum(-1)/math.log(probability.shape[-1]) + top=probability.topk(2,dim=-1).values;margin=top[:,0]-top[:,1] + return torch.stack([entropy,entropy.square(),margin,margin.square()],-1) + +class ConfidenceEncoder(nn.Module): + def __init__(self,enabled): + super().__init__();self.net=nn.Sequential(nn.Linear(4,16),nn.GELU(),nn.Linear(16,16),nn.LayerNorm(16)) + self.register_buffer('enabled',torch.tensor(float(enabled))) + def forward(self,x):return self.net(x) + +class ConfidenceReadoutHead(nn.Module): + def __init__(self,old,encoder): + super().__init__();self.prior=old.prior;self.width=old.width;self.projection=old.projection + self.register_buffer('output_scale',old.output_scale);self.register_buffer('correction_gain',old.correction_gain) + self.confidence_projection=nn.Linear(16,1);nn.init.zeros_(self.confidence_projection.weight);nn.init.zeros_(self.confidence_projection.bias) + # The backbone owns and registers this ONE encoder; all five heads reference it. + object.__setattr__(self,'_confidence_encoder',encoder) + def gated_logits(self,prior,embedding): + with torch.autocast(prior.device.type,enabled=False): + logits=self.projection(embedding.float());encoder=self._confidence_encoder + hidden=encoder(confidence_features(prior,self.output_scale));modulation=self.confidence_projection(hidden).tanh() + multiplier=1.+encoder.enabled*.25*modulation + return logits*multiplier + def predict_from_prior(self,prior,embedding,gain=None,return_standalone=False): + with torch.autocast(prior.device.type,enabled=False): + standalone=self.gated_logits(prior,embedding);gain=self.correction_gain if gain is None else gain + delta=(gain*self.output_scale)*standalone;result=prior+delta.to(prior.dtype) + return (result,standalone) if return_standalone else result + def forward(self,values): + prior=self.prior(values[:,:-self.width]);return self.predict_from_prior(prior,values[:,-self.width:]) + +class HybridModel(LegacyHybridModel): + def __init__(self,confidence_gating=False,confidence_gate_enabled=1.,**kwargs): + super().__init__(**kwargs);self.confidence_gating=confidence_gating + if confidence_gating: + with torch.random.fork_rng(devices=[]): + self.backbone.confidence_encoder=ConfidenceEncoder(confidence_gate_enabled) + self.heads=nn.ModuleDict({t:ConfidenceReadoutHead(head,self.backbone.confidence_encoder) for t,head in self.heads.items()}) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/coupling_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/coupling_features.py new file mode 100644 index 0000000000000000000000000000000000000000..3a4e51bd7ce07bcec1f0f5b80054d6ff387ac87f --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/coupling_features.py @@ -0,0 +1,34 @@ +"""Per-window cross-frequency envelope and phase-amplitude relationships.""" +import torch +BANDS=((1,4),(4,8),(8,13),(13,30),(30,48)) +PAIRS=tuple((i,j) for i in range(5) for j in range(i+1,5)) +PER_CHANNEL=30 + +@torch.no_grad() +def coupling_features(track,x): + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + n=x.shape[-1];spectrum=torch.fft.fft(x,dim=-1);frequency=torch.fft.fftfreq(n,1/200,device=x.device) + masks=torch.stack([2*((frequency>=lo)&(frequency=lo)&(frequency0 + assert all(a.shape==b.shape and a.device==b.device and torch.isfinite(a).all() and torch.isfinite(b).all() for a,b in zip(total,main)) + g=torch.cat([v.detach().double().flatten() for v in total]);m=torch.cat([v.detach().double().flatten() for v in main]) + main_squared=torch.dot(m,m);dot=torch.dot(g-m,m);conflict=bool(main_squared>0 and dot<0);coefficient=float(-dot/main_squared) if conflict else 0. + before=float(torch.dot(g,m));original_norm=float(g.norm()) + if strength and conflict: + offset=0;updated=g+coefficient*m + with torch.no_grad(): + for target in total: + size=target.numel();target.copy_(updated[offset:offset+size].reshape_as(target).to(target.dtype));offset+=size + after=sum(float(torch.dot(a.detach().double().flatten(),b.detach().double().flatten())) for a,b in zip(total,main)) + rounding_relative=max(1e-6,2*max(torch.finfo(v.dtype).eps for v in total)) + tolerance=rounding_relative*max(float(main_squared),abs(before),abs(after),1e-30) + if strength:assert after>=float(main_squared)-tolerance,(after,float(main_squared),before,coefficient) + return {'main_squared_norm':float(main_squared),'effective_auxiliary_main_dot':float(dot),'conflict':conflict,'applied':bool(strength and conflict),'coefficient':coefficient if strength else 0.,'total_main_dot_before':before,'total_main_dot_after':after,'total_norm_before':original_norm,'total_norm_after':float(torch.cat([v.detach().double().flatten() for v in total]).norm())} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/legacy_model.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/legacy_model.py new file mode 100644 index 0000000000000000000000000000000000000000..c11d3ef8fb1cde0d6f535ed7b8aa7a484ab64a8d --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/legacy_model.py @@ -0,0 +1,592 @@ +from student_features import CBraModFeatures,FrequencyAdapter +"""One fused waveform/spectral backbone used identically by all five tasks.""" +import torch +from torch import nn +MOTOR_CHANNELS=('Fp1', 'Fp2', 'F7', 'F3', 'Fz', 'F4', 'F8', 'FC5', 'FC1', 'FC2', 'FC6', 'T7', 'C3', 'Cz', 'C4', 'T8', 'TP9', 'CP5', 'CP1', 'CP2', 'CP6', 'TP10', 'P7', 'P3', 'Pz', 'P4', 'P8', 'PO9', 'O1', 'Oz', 'O2', 'PO10', 'FC3', 'FC4', 'C5', 'C1', 'C2', 'C6', 'CP3', 'CPz', 'CP4', 'P1', 'P2', 'POz', 'FT9', 'FTT9h', 'TTP7h', 'TP7', 'TPP9h', 'FT10', 'FTT10h', 'TPP8h', 'TP8', 'TPP10h', 'F9', 'F10', 'AF7', 'AF3', 'AF4', 'AF8', 'PO3', 'PO4') +from braindecode.models import BIOT +from features import SPECS,TRACKS,feature_dim,extract_features,Standardize,Residual,EDGES,COV_BANDS +from covariances import BANDS,extract_covariances +from alpha_features import extract_alpha_features,ALPHA_DIM +from envelope_features import extract_envelope_features,ENVELOPE_DIM +from frequency_features import frequency_components,FREQUENCY_BANDS +from tangent_features import extract_tangent_features,TANGENT_DIM +from phase_features import phase_features,PHASE_DIM,PHASE_HALF +from coupling_features import coupling_features,PER_CHANNEL as COUPLING_PER_CHANNEL +from ordinal_features import ordinal_features,PER_CHANNEL as ORDINAL_PER_CHANNEL + +def clinical_asymmetry_features(features): + """Bipolar homologous-channel amplitude and coherence, invariant to mirroring.""" + bands=len(EDGES)-1;per_channel=4*bands+4 + block=features[:,:16*per_channel].reshape(-1,16,per_channel) + left=torch.tensor([0,1,2,3,8,9,10,11],device=features.device);right=left+4 + pair_power=(block[:,left,:bands]-block[:,right,:bands]).abs().flatten(1) + pair_rms=(block[:,left,4*bands]-block[:,right,4*bands]).abs() + hemisphere=(block[:,left,:bands].mean(1)-block[:,right,:bands].mean(1)).abs() + index=left*(32-left-1)//2+(right-left-1) + correlations=features[:,16*per_channel:].reshape(-1,len(COV_BANDS),120)[:,:,index].flatten(1) + return torch.cat([pair_power,pair_rms,hemisphere,correlations],1) + +class InputAdapter(nn.Module): + def __init__(self,c,width,channels,spectral_enabled=True,asymmetry=False,alpha_regions=None,envelope=False): + super().__init__() + self.ordinal_normalizer=Standardize(c*ORDINAL_PER_CHANNEL) + self.ordinal_projection=nn.Linear(c*ORDINAL_PER_CHANNEL,width) + self.ordinal_dropout=nn.Dropout(.3) + self.register_buffer('ordinal_probabilities_enabled',torch.ones(())) + self.coupling_normalizer=Standardize(c*COUPLING_PER_CHANNEL) + self.coupling_projection=nn.Linear(c*COUPLING_PER_CHANNEL,width) + self.coupling_dropout=nn.Dropout(.3) + self.register_buffer('coupling_dependence_enabled',torch.ones(())) + self.phase_normalizer=Standardize(PHASE_DIM) + self.signal=nn.Conv1d(c,channels,1,bias=False) + self.frequency_weight=nn.Parameter(torch.zeros(len(FREQUENCY_BANDS),channels,c)) + self.neural=nn.Conv1d(c,18,1,bias=False) + self.normalizer=Standardize(feature_dim(c)) + self.spectral=nn.Linear(feature_dim(c),width) + self.dropout=nn.Dropout(.1) + self.register_buffer("spectral_enabled",torch.tensor(float(spectral_enabled))) + self.spatial_weight=nn.Parameter(torch.randn(len(BANDS),24,c)/c**.5) + self.asymmetry_projection=nn.Linear(316,width,bias=False) if asymmetry else None + if asymmetry: + nn.init.zeros_(self.asymmetry_projection.weight) + self.asymmetry_normalizer=Standardize(316) + self.asymmetry_dropout=nn.Dropout(.1) + self.alpha_projection=None + if alpha_regions is not None: + self.register_buffer('alpha_regions',torch.tensor(alpha_regions,dtype=torch.float32)) + self.alpha_normalizer=Standardize(ALPHA_DIM) + self.alpha_projection=nn.Linear(ALPHA_DIM,width,bias=False) + nn.init.zeros_(self.alpha_projection.weight) + self.alpha_dropout=nn.Dropout(.3) + self.envelope_projection=None + if envelope: + self.envelope_normalizer=Standardize(ENVELOPE_DIM) + self.envelope_projection=nn.Linear(ENVELOPE_DIM,width,bias=False) + nn.init.zeros_(self.envelope_projection.weight) + self.envelope_dropout=nn.Dropout(.3) + def coupling_embedding(self,features): + values=self.coupling_normalizer(features).reshape(len(features),-1,COUPLING_PER_CHANNEL) + values=torch.cat([values[...,:10],self.coupling_dependence_enabled*values[...,10:]],-1).flatten(1) + return self.coupling_projection(self.coupling_dropout(values)) + def ordinal_embedding(self,features): + values=self.ordinal_normalizer(features).reshape(len(features),-1,5,26) + values=torch.cat([self.ordinal_probabilities_enabled*values[...,:24],values[...,24:]],-1).flatten(1) + return self.ordinal_projection(self.ordinal_dropout(values)) + def spectral_features(self,features,signal=None,alpha_features=None,envelope_features=None): + value=self.spectral_enabled*self.spectral(self.dropout(self.normalizer(features))) + if self.asymmetry_projection is not None: + extra=self.asymmetry_dropout(self.asymmetry_normalizer(clinical_asymmetry_features(features))) + value=value+self.asymmetry_projection(extra) + if self.alpha_projection is not None: + if alpha_features is None:alpha_features=extract_alpha_features(signal,self.alpha_regions) + value=value+self.alpha_projection(self.alpha_dropout(self.alpha_normalizer(alpha_features))) + if self.envelope_projection is not None: + if envelope_features is None:envelope_features=extract_envelope_features(signal) + value=value+self.envelope_projection(self.envelope_dropout(self.envelope_normalizer(envelope_features))) + return value + def spatial_features(self,covariances): + with torch.autocast(covariances.device.type,enabled=False): + w=self.spatial_weight.float()/self.spatial_weight.float().norm(dim=-1,keepdim=True).clamp_min(1e-6) + power=torch.einsum('bfc,nbcd,bfd->nbf',w,covariances.float(),w).clamp_min(1e-8).log() + return torch.cat([power,power-power.mean(1,keepdim=True)],1).flatten(1) + def wave_signal(self,x,components=None): + if components is None:components=frequency_components(x) + correction=torch.einsum('blc,nbct->nlt',self.frequency_weight,components.to(self.frequency_weight.dtype)) + return (self.signal(x)+correction.to(x.dtype)).unsqueeze(1) + def forward(self,x,features,covariance_features): + return self.wave_signal(x),self.spectral_features(features,signal=x),self.neural(x),covariance_features + +class SharedBackbone(nn.Module): + def __init__(self,channels,width,depth,dropout,wave_filters): + super().__init__() + self.waveform=nn.Sequential( + nn.Conv2d(1,wave_filters,(1,64),padding=(0,32),bias=False),nn.GroupNorm(1,wave_filters), + nn.Conv2d(wave_filters,2*wave_filters,(channels,1),groups=wave_filters,bias=False),nn.GroupNorm(1,2*wave_filters),nn.ELU(), + nn.AvgPool2d((1,4)),nn.Dropout(.35), + nn.Conv2d(2*wave_filters,2*wave_filters,(1,16),padding=(0,8),groups=2*wave_filters,bias=False),nn.Conv2d(2*wave_filters,2*wave_filters,1,bias=False), + nn.GroupNorm(1,2*wave_filters),nn.ELU(),nn.AvgPool2d((1,8)),nn.Dropout(.35)) + self.wave_summary=nn.Sequential(nn.AdaptiveAvgPool2d((1,8)),nn.Flatten(),nn.Linear(2*wave_filters*8,width)) + self.fusion=nn.Sequential(nn.LayerNorm(width),nn.GELU(),nn.Dropout(dropout), + *[Residual(width,dropout) for _ in range(depth)],nn.LayerNorm(width)) + # Both representations interact before the shared residual stack. + self.phase_encoder=nn.Sequential(nn.LayerNorm(PHASE_DIM),nn.Linear(PHASE_DIM,width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width)) + self.register_buffer('phase_imaginary_enabled',torch.ones(())) + self.coupling_encoder=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width),nn.LayerNorm(width)) + self.wave_gain=nn.Parameter(torch.tensor(.1)) + self.biot=BIOT(n_chans=18,n_outputs=2,n_times=400,sfreq=200) + self.biot.final_layer=nn.Identity() + self.biot_projection=nn.Sequential(nn.LayerNorm(256),nn.Linear(256,width),nn.Dropout(.2)) + nn.init.normal_(self.biot_projection[1].weight,std=.001);nn.init.zeros_(self.biot_projection[1].bias) + self.covariance_encoder=nn.Sequential(nn.LayerNorm(len(BANDS)*24*2),nn.Linear(len(BANDS)*24*2,width),nn.GELU(),nn.Dropout(.4), + *[Residual(width,.4) for _ in range(2)],nn.LayerNorm(width)) + self.covariance_projection=nn.Linear(width,width) + nn.init.zeros_(self.covariance_projection.weight);nn.init.zeros_(self.covariance_projection.bias) + self.tangent_encoder=nn.Sequential(nn.LayerNorm(TANGENT_DIM),nn.Linear(TANGENT_DIM,width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width),nn.Linear(width,width)) + self.ordinal_context=nn.Sequential(nn.LayerNorm(width),nn.Linear(width,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width)) + nn.init.zeros_(self.ordinal_context[-1].weight);nn.init.zeros_(self.ordinal_context[-1].bias) + self.register_buffer('codebrain_enabled',torch.ones(())) + self.codebrain_patch_encoder=nn.Sequential(nn.LayerNorm(24*64),nn.Linear(24*64,width),nn.GELU(),nn.Dropout(.3)) + self.codebrain_context=nn.Sequential(nn.LayerNorm(width*4),nn.Linear(width*4,width*2),nn.GELU(),nn.Dropout(.3),nn.Linear(width*2,width)) + nn.init.zeros_(self.codebrain_context[-1].weight);nn.init.zeros_(self.codebrain_context[-1].bias) + def codebrain_correction(self,tokens,representation,fusion_input): + with torch.autocast(tokens.device.type,enabled=False): + encoded=self.codebrain_patch_encoder(self.codebrain_enabled*tokens.float()) + pooled=torch.cat([encoded.mean(1),encoded.std(1,correction=0),representation[:,-512:-384].float(),representation[:,-128:].float()],-1) + delta=self.codebrain_context(pooled) + added=.001*nn.functional.linear(delta,self.covariance_projection.weight,None) + corrected=self.fusion(fusion_input+added.to(fusion_input.dtype)) + return corrected-representation[:,-512:-384],delta + def forward(self,signal,spectral,neural_signal,covariance_features,tangent_features): + wave=self.waveform(signal) + neural=self.biot(neural_signal.float()) + neural=self.biot_projection[0](neural) + projected=self.biot_projection[2](self.biot_projection[1](neural)) + with torch.autocast(signal.device.type,enabled=False): + covariance_embedding=self.covariance_encoder(covariance_features.float()) + original=spectral+self.wave_gain*self.wave_summary(wave)+.01*projected + coupled=.001*self.covariance_projection(covariance_embedding).to(original.dtype) + fused=self.fusion(original+coupled) + with torch.autocast(signal.device.type,enabled=False):delta=self.tangent_encoder(tangent_features.float()) + added=.001*nn.functional.linear(delta,self.covariance_projection.weight,None) + corrected=self.fusion((original+coupled)+added.to(original.dtype)) + return torch.cat([wave.flatten(1),fused,neural,covariance_embedding],-1),corrected-fused,delta,original+coupled + +class ResidualHead(nn.Module): + """A small nonlinear classifier correction around an inherited linear readout.""" + def __init__(self,features,classes,width=64,dropout=.3,full_precision=False): + super().__init__();self.full_precision=full_precision + self.base=nn.Linear(features,classes) + self.delta=nn.Sequential(nn.LayerNorm(features),nn.Linear(features,width),nn.GELU(),nn.Dropout(dropout),nn.Linear(width,classes)) + nn.init.zeros_(self.delta[-1].weight);nn.init.zeros_(self.delta[-1].bias) + def forward(self,x): + if self.full_precision: + with torch.autocast(x.device.type,enabled=False):return self.base(x.float())+self.delta(x.float()) + prior=nn.functional.linear(x[:,:-128].contiguous(),self.base.weight[:,:-128].contiguous(),self.base.bias) + added=nn.functional.linear(x[:,-128:].contiguous(),self.base.weight[:,-128:].contiguous()) + value=prior+added + return value+self.delta(x).to(value.dtype) + +class TemporalPoolHead(nn.Module): + def __init__(self,prior,channels=64): + super().__init__();self.prior=prior;self.channels=channels + self.register_buffer('pool_output_scale',torch.ones(()));self.register_buffer('pool_mean',torch.zeros(channels*4));self.register_buffer('pool_scale',torch.ones(channels*4)) + self.pool_projection=nn.Linear(channels*4,prior.base.out_features) + nn.init.zeros_(self.pool_projection.weight);nn.init.zeros_(self.pool_projection.bias) + def statistics(self,x): + with torch.autocast(x.device.type,enabled=False): + wave=x[:,:-512].float().reshape(len(x),self.channels,-1) + return torch.cat([wave.mean(-1),wave.std(-1,correction=0),wave.amax(-1),wave.amin(-1)],-1) + def forward(self,x): + prior=self.prior(x) + with torch.autocast(x.device.type,enabled=False): + values=((self.statistics(x)-self.pool_mean)/self.pool_scale).clamp(-8,8) + added=self.pool_output_scale*self.pool_projection(values) + return prior+added.to(prior.dtype) + +class TemporalEvidenceHead(nn.Module): + """Pool class evidence over the shared waveform time axis.""" + def __init__(self,prior,channels=64,temperature=.25): + super().__init__();self.prior=prior;self.channels=channels;self.temperature=temperature + self.register_buffer('evidence_output_scale',torch.ones(())) + self.register_buffer('evidence_mean',torch.zeros(channels)) + self.register_buffer('evidence_scale',torch.ones(channels)) + self.evidence_projection=nn.Linear(channels,prior.prior.base.out_features,bias=False) + nn.init.zeros_(self.evidence_projection.weight) + def patches(self,x): + with torch.autocast(x.device.type,enabled=False): + wave=x[:,:-512].float().reshape(len(x),self.channels,-1).transpose(1,2) + return ((wave-self.evidence_mean)/self.evidence_scale).clamp(-8,8) + def evidence(self,patches): + with torch.autocast(patches.device.type,enabled=False): + values=self.evidence_projection(patches.float())/self.temperature + maximum=values.amax(1,keepdim=True) + pooled=self.temperature*((values-maximum).exp().mean(1).log()+maximum.squeeze(1)) + return self.evidence_output_scale*pooled + def forward(self,x): + prior=self.prior(x) + return prior+self.evidence(self.patches(x)).to(prior.dtype) + +class FourierResidualHead(nn.Module): + """A fixed random Fourier basis and trainable linear classifier correction.""" + def __init__(self,prior,features,classes,basis=256): + super().__init__();self.prior=prior + self.register_buffer('rff_mean',torch.zeros(features));self.register_buffer('rff_scale',torch.ones(features)) + self.register_buffer('rff_frequency',torch.randn(features,basis)/features**.5) + self.register_buffer('rff_phase',torch.rand(basis)*2*torch.pi) + self.register_buffer('rff_output_scale',torch.ones(())) + self.rff_projection=nn.Linear(3*basis,classes);nn.init.zeros_(self.rff_projection.weight);nn.init.zeros_(self.rff_projection.bias) + def basis(self,x): + with torch.autocast(x.device.type,enabled=False): + values=((x.float()-self.rff_mean)/self.rff_scale).clamp(-8,8)@self.rff_frequency + return 2**.5*torch.cat([(values/sigma+self.rff_phase).cos() for sigma in (.5,1.,2.)],-1) + def forward(self,x): + prior=self.prior(x) + with torch.autocast(x.device.type,enabled=False):added=self.rff_output_scale*self.rff_projection(self.basis(x)) + return prior+added.to(prior.dtype) + +class TangentFeatureHead(nn.Module): + """Select a shared feature correction before the inherited classifier.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.feature_gain=nn.Parameter(torch.zeros(())) + def forward(self,values): + old=values[:,:-256];fusion_delta=values[:,-256:-128];covariance_delta=values[:,-128:] + adjusted=torch.cat([old[:,:-512],old[:,-512:-384]+self.feature_gain*fusion_delta,old[:,-384:-128],old[:,-128:]+self.feature_gain*covariance_delta],-1) + return self.prior(adjusted) + +class CodeBrainFeatureHead(nn.Module): + """Private use of a jointly trained common feature correction.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.codebrain_gain=nn.Parameter(torch.ones(())) + def forward(self,values): + previous=values[:,:-256];native=previous[:,:-256] + fusion_delta=values[:,-256:-128];covariance_delta=values[:,-128:] + adjusted=torch.cat([native[:,:-512],native[:,-512:-384]+self.codebrain_gain*fusion_delta,native[:,-384:-128],native[:,-128:]+self.codebrain_gain*covariance_delta],-1) + return self.prior(torch.cat([adjusted,previous[:,-256:]],-1)) + +class WaveCoactivationContext(nn.Module): + """One common encoder of coactivation among the learned waveform channels.""" + def __init__(self,channels=64,width=128): + super().__init__();self.channels=channels + ii,jj=torch.triu_indices(channels,channels,offset=1) + self.register_buffer('pair_i',ii);self.register_buffer('pair_j',jj) + self.register_buffer('offdiagonal_enabled',torch.ones(())) + self.encoder=nn.Sequential(nn.LayerNorm(channels+len(ii)),nn.Linear(channels+len(ii),width),nn.GELU(),nn.Dropout(.3),Residual(width,.3),nn.LayerNorm(width)) + def statistics(self,native): + with torch.autocast(native.device.type,enabled=False): + wave=native[:,:-512].float().reshape(len(native),self.channels,-1) + centered=wave-wave.mean(-1,keepdim=True) + previous_tf32=torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32=False + covariance=centered@centered.transpose(-1,-2)/wave.shape[-1] + torch.backends.cuda.matmul.allow_tf32=previous_tf32 + variance=covariance.diagonal(dim1=-2,dim2=-1).clamp_min(1e-8) + correlation=covariance/(variance.sqrt()[:,:,None]*variance.sqrt()[:,None,:]) + return torch.cat([variance.log(),correlation[:,self.pair_i,self.pair_j].clamp(-1,1)],-1) + def encode_statistics(self,values): + with torch.autocast(values.device.type,enabled=False): + value=torch.cat([values[:,:self.channels],self.offdiagonal_enabled*values[:,self.channels:]],-1) + return self.encoder(value.float()) + def forward(self,native):return self.encode_statistics(self.statistics(native)) + +class WaveCoactivationHead(nn.Module): + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.width=width;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-self.width]) + with torch.autocast(values.device.type,enabled=False):delta=self.correction_gain*self.output_scale*self.projection(values[:,-self.width:].float()) + return prior+delta.to(prior.dtype) + +class OrdinalFeatureHead(nn.Module): + """Private strength of one common ordinal-dynamics feature correction.""" + def __init__(self,prior): + super().__init__();self.prior=prior;self.ordinal_gain=nn.Parameter(torch.ones(())) + def forward(self,values): + previous=values[:,:-256];native=previous[:,:-640] + adjusted=torch.cat([native[:,:-512],native[:,-512:-384]+self.ordinal_gain*values[:,-256:-128],native[:,-384:-128],native[:,-128:]+self.ordinal_gain*values[:,-128:],previous[:,-640:]],-1) + return self.prior(adjusted) + +class PhaseReadoutHead(nn.Module): + """Private class evidence from the common complex-coherence encoder.""" + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.width=width;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-self.width]) + with torch.autocast(values.device.type,enabled=False):delta=(self.correction_gain*self.output_scale)*self.projection(values[:,-self.width:].float()) + return prior+delta.to(prior.dtype) + +class SplitLayerNorm(nn.Module): + """Two LayerNorm groups; surrounding dense matrices train across both groups.""" + def __init__(self,width): + super().__init__();assert width%2==0;self.width=width + self.weight=nn.Parameter(torch.ones(width));self.bias=nn.Parameter(torch.zeros(width)) + def forward(self,x): + n=self.width//2 + return torch.cat([nn.functional.layer_norm(x[:,:n],(n,),self.weight[:n],self.bias[:n],1e-5),nn.functional.layer_norm(x[:,n:],(n,),self.weight[n:],self.bias[n:],1e-5)],-1) + +class CouplingReadoutHead(nn.Module): + """Private class evidence from the common cross-frequency coupling encoder.""" + def __init__(self,prior,classes,width=128): + super().__init__();self.prior=prior;self.width=width;self.projection=nn.Linear(width,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',torch.ones(()));self.register_buffer('correction_gain',torch.ones(())) + def forward(self,values): + prior=self.prior(values[:,:-self.width]) + with torch.autocast(values.device.type,enabled=False):delta=(self.correction_gain*self.output_scale)*self.projection(values[:,-self.width:].float()) + return prior+delta.to(prior.dtype) + +class HybridModel(nn.Module): + def __init__(self,channels=32,width=128,depth=2,dropout=.5,wave_filters=32,head_width=64,head_dropout=.3,clinical_asymmetry=True,alpha_regions=None,clinical_envelope=False,temporal_pool=True,temporal_evidence=False,evidence_temperature=.25,random_fourier=False,fourier_features=256,tangent_readout=True,shared_context_correction=True,wave_coactivation=True,ordinal_context=True,phase_coherence=True,cross_frequency=True,cbramod_feature_transfer=True,student_architecture=None,student_extension=True,post_embedding_extension=True,extension_activation='gelu',center_context_extension=True,context_crop='center',short_context_extension=True,short_crop='center',dual_context_extension=True,dual_crop='clinical-dual',geometry_extension=True,geometry_mode='mi-log',emotion_extension=True,emotion_mode='faced-log',emotion_activation='gelu',refinement_extension=True,refinement_mode='faced-log',refinement_activation='gelu',spatial_extension=True,spatial_mode='local',spatial_activation='gelu',spatial_motor_channels=None,conditional_extension=True,conditional_mode='partial',conditional_width=128): + super().__init__() + self.adapters=nn.ModuleDict({t:InputAdapter(c,width,channels,spectral_enabled=t not in ("faced","tuev","openbmi"),asymmetry=clinical_asymmetry and t=="tuev",alpha_regions=alpha_regions if t=="longitudinal" else None,envelope=clinical_envelope and t=="tuev") for t,(c,s,k) in SPECS.items()}) + self.backbone=SharedBackbone(channels,width,depth,dropout,wave_filters) + self.backbone.student_encoder=CBraModFeatures(**(student_architecture or {})) + self.backbone.register_buffer('student_ordered_enabled',torch.ones(())) + self.backbone.student_readout=nn.Sequential(nn.Linear(self.backbone.student_encoder.output_dim,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + for t,(c,s,k) in SPECS.items(): + self.adapters[t].student_input=FrequencyAdapter(c,32) + self.adapters[t].student_normalizer=Standardize(self.backbone.student_encoder.output_dim) + self.backbone.wave_coactivation=WaveCoactivationContext(2*wave_filters,width) + self.heads=nn.ModuleDict({t:ResidualHead(2*wave_filters*(((s*200+1)//4+1)//8)+width+256+width,k,head_width,head_dropout,full_precision=t=='ad65') for t,(c,s,k) in SPECS.items()}) + if temporal_pool:self.heads=nn.ModuleDict({t:TemporalPoolHead(head,wave_filters*2) for t,head in self.heads.items()}) + if temporal_evidence:self.heads=nn.ModuleDict({t:TemporalEvidenceHead(head,wave_filters*2,evidence_temperature) for t,head in self.heads.items()}) + if random_fourier:self.heads=nn.ModuleDict({t:FourierResidualHead(head,2*wave_filters*(((SPECS[t][1]*200+1)//4+1)//8)+width+256+width,SPECS[t][2],fourier_features) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:TangentFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CodeBrainFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:WaveCoactivationHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:OrdinalFeatureHead(head) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:PhaseReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert student_extension and post_embedding_extension + assert extension_activation in ('gelu','identity') + self.backbone.student_extension=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU() if extension_activation=='gelu' else nn.Identity(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert center_context_extension and context_crop in ('center','first') + self.context_crop=context_crop + for t,(c,s,k) in SPECS.items(): + self.adapters[t].center_normalizer=Standardize(feature_dim(c)+30*c) + self.adapters[t].center_projection=nn.Linear(feature_dim(c)+30*c,width) + self.backbone.center_encoder=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert short_context_extension and short_crop in ('center','first') + self.short_crop=short_crop + for t,(c,s,k) in SPECS.items(): + self.adapters[t].short_normalizer=Standardize(feature_dim(c)+30*c) + self.adapters[t].short_projection=nn.Linear(feature_dim(c)+30*c,width) + self.backbone.short_encoder=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert dual_context_extension and dual_crop in ('clinical-dual','clinical-duplicate') + self.dual_crop=dual_crop + for t,(c,s,k) in SPECS.items(): + self.adapters[t].dual_normalizer=Standardize((feature_dim(c)+30*c)*(2 if t=='tuev' else 1)) + self.adapters[t].dual_projection=nn.Linear((feature_dim(c)+30*c)*(2 if t=='tuev' else 1),width) + self.backbone.dual_encoder=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert geometry_extension and geometry_mode in ('mi-log','mi-linear') + self.geometry_mode=geometry_mode + for t,(c,s,k) in SPECS.items(): + dimension=7*c*(c+1)//2 if t=='openbmi' else feature_dim(c)+30*c + self.adapters[t].geometry_normalizer=Standardize(dimension) + self.adapters[t].geometry_projection=nn.Linear(dimension,width) + self.backbone.geometry_encoder=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert emotion_extension and emotion_mode in ('faced-log','faced-linear') + self.emotion_mode=emotion_mode + for t,(c,s,k) in SPECS.items(): + dimension=7*c*(c+1)//2 if t=='faced' else feature_dim(c)+30*c + self.adapters[t].emotion_normalizer=Standardize(dimension) + self.adapters[t].emotion_projection=nn.Linear(dimension,width) + assert emotion_activation in ('gelu','identity') + self.backbone.emotion_encoder=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU() if emotion_activation=='gelu' else nn.Identity(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert refinement_extension and refinement_mode in ('faced-log','faced-linear') + self.refinement_mode=refinement_mode + for t,(c,s,k) in SPECS.items(): + dimension=7*c*(c+1)//2 if t=='faced' else feature_dim(c)+30*c + self.adapters[t].refinement_normalizer=Standardize(dimension) + self.adapters[t].refinement_projection=nn.Linear(dimension,width) + assert refinement_activation in ('gelu','identity') + self.backbone.refinement_encoder=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU() if refinement_activation=='gelu' else nn.Identity(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert spatial_extension and spatial_mode in ('local','native') and spatial_activation=='gelu' + self.spatial_mode=spatial_mode + self.spatial_motor_channels=tuple(spatial_motor_channels or MOTOR_CHANNELS) + assert len(self.spatial_motor_channels)==62 + for t,(c,s,k) in SPECS.items(): + dimension=981 if t=='openbmi' else (7*c*(c+1)//2 if t=='faced' else feature_dim(c)+30*c) + self.adapters[t].spatial_normalizer=Standardize(dimension) + self.adapters[t].spatial_projection=nn.Linear(dimension,width) + self.backbone.spatial_encoder=nn.Sequential(nn.Linear(width,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,width),nn.LayerNorm(width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],width) for t,head in self.heads.items()}) + assert conditional_extension and conditional_mode in ('partial','marginal') + assert conditional_width in (128,256) + self.conditional_mode=conditional_mode + for t,(c,s,k) in SPECS.items(): + dimension=952 if t=='tuev' else self.adapters[t].spatial_projection.in_features + self.adapters[t].conditional_normalizer=Standardize(dimension) + self.adapters[t].conditional_projection=nn.Linear(dimension,conditional_width) + norm=SplitLayerNorm if conditional_width==256 else nn.LayerNorm + self.backbone.conditional_encoder=nn.Sequential(nn.Linear(conditional_width,2*conditional_width),norm(2*conditional_width),nn.GELU(),nn.Dropout(.3),nn.Linear(2*conditional_width,conditional_width),norm(conditional_width)) + self.heads=nn.ModuleDict({t:CouplingReadoutHead(head,SPECS[t][2],conditional_width) for t,head in self.heads.items()}) + def conditional_features(self,t,x): + if t!='tuev':return self.spatial_features(t,x) + from partial_covariance_features import partial_covariance_features + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(x.device.type,enabled=False):return partial_covariance_features(t,x,self.conditional_mode=='partial') + finally:torch.backends.cuda.matmul.allow_tf32=old + def conditional_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + return self.backbone.conditional_encoder(self.adapters[t].conditional_projection(self.adapters[t].conditional_normalizer(values.float()))) + def spatial_features(self,t,x): + if t!='openbmi':return self.refinement_features(t,x) + from local_channel_features import local_channel_signals + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(x.device.type,enabled=False): + signals=local_channel_signals(x,self.spatial_motor_channels,self.spatial_mode=='local') + return torch.cat([extract_features('tuev',signals),coupling_features('tuev',signals)],-1) + finally:torch.backends.cuda.matmul.allow_tf32=old + def spatial_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].spatial_normalizer(values.float()) + return self.backbone.spatial_encoder(self.adapters[t].spatial_projection(normalized)) + def refinement_features(self,t,x): + from native_log_covariance_features import connectivity + from short_context_features import short_spectral_features + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(x.device.type,enabled=False): + if t=='faced':return connectivity(t,x,logarithmic=self.refinement_mode=='faced-log') + view=x.flatten(2)[...,:200] + return torch.cat([short_spectral_features(t,view),coupling_features(t,view)],-1) + finally:torch.backends.cuda.matmul.allow_tf32=old + def refinement_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].refinement_normalizer(values.float()) + return self.backbone.refinement_encoder(self.adapters[t].refinement_projection(normalized)) + def emotion_features(self,t,x): + from native_log_covariance_features import connectivity + from short_context_features import short_spectral_features + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(x.device.type,enabled=False): + if t=='faced':return connectivity(t,x,logarithmic=self.emotion_mode=='faced-log') + view=x.flatten(2)[...,:200] + return torch.cat([short_spectral_features(t,view),coupling_features(t,view)],-1) + finally:torch.backends.cuda.matmul.allow_tf32=old + def emotion_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].emotion_normalizer(values.float()) + return self.backbone.emotion_encoder(self.adapters[t].emotion_projection(normalized)) + def geometry_features(self,t,x): + from native_log_covariance_features import connectivity + from short_context_features import short_spectral_features + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(x.device.type,enabled=False): + if t=='openbmi':return connectivity(t,x,logarithmic=self.geometry_mode=='mi-log') + view=x.flatten(2)[...,:200] + return torch.cat([short_spectral_features(t,view),coupling_features(t,view)],-1) + finally:torch.backends.cuda.matmul.allow_tf32=old + def geometry_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].geometry_normalizer(values.float()) + return self.backbone.geometry_encoder(self.adapters[t].geometry_projection(normalized)) + def dual_features(self,t,x): + from short_context_features import short_spectral_features + raw=x.flatten(2);first=raw[...,:200];views=[first] + if t=='tuev': + start=(raw.shape[-1]-200)//2 + views.append(raw[...,start:start+200] if self.dual_crop=='clinical-dual' else first) + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(raw.device.type,enabled=False):return torch.cat([torch.cat([short_spectral_features(t,v),coupling_features(t,v)],-1) for v in views],-1) + finally:torch.backends.cuda.matmul.allow_tf32=old + def dual_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].dual_normalizer(values.float()) + return self.backbone.dual_encoder(self.adapters[t].dual_projection(normalized)) + def short_features(self,t,x): + from short_context_features import short_spectral_features + raw=x.flatten(2);start=(raw.shape[-1]-200)//2 if self.short_crop=='center' else 0 + cropped=raw[...,start:start+200];assert cropped.shape[-1]==200 + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(raw.device.type,enabled=False):return torch.cat([short_spectral_features(t,cropped),coupling_features(t,cropped)],-1) + finally:torch.backends.cuda.matmul.allow_tf32=old + def short_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].short_normalizer(values.float()) + return self.backbone.short_encoder(self.adapters[t].short_projection(normalized)) + def center_features(self,t,x): + raw=x.flatten(2);start=(raw.shape[-1]-400)//2 if self.context_crop=='center' else 0 + cropped=raw[...,start:start+400];assert cropped.shape[-1]==400 + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(raw.device.type,enabled=False):return torch.cat([extract_features(t,cropped),coupling_features(t,cropped)],-1) + finally:torch.backends.cuda.matmul.allow_tf32=old + def center_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].center_normalizer(values.float()) + return self.backbone.center_encoder(self.adapters[t].center_projection(normalized)) + def student_extension_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + assert values.shape[-1]==128 + return self.backbone.student_extension(values.float()) + + def student_features(self,t,x): + outputs=[];old_fastpath=torch.backends.mha.get_fastpath_enabled();torch.backends.mha.set_fastpath_enabled(False) + try: + for raw in x.split(16): + signal=torch.nan_to_num(raw.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + with torch.autocast(signal.device.type,dtype=torch.bfloat16,enabled=signal.device.type=='cuda'): + outputs.append(self.backbone.student_encoder(self.adapters[t].student_input(signal))) + finally:torch.backends.mha.set_fastpath_enabled(old_fastpath) + return torch.cat(outputs).float() + def student_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].student_normalizer(values.float()) + normalized=torch.cat([normalized[:,:256],self.backbone.student_ordered_enabled*normalized[:,256:]],-1) + return self.backbone.student_readout(normalized) + def coupling_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False):return self.backbone.coupling_encoder(self.adapters[t].coupling_embedding(values.float())) + def phase_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + normalized=self.adapters[t].phase_normalizer(values.float()) + normalized=torch.cat([normalized[:,:PHASE_HALF],self.backbone.phase_imaginary_enabled*normalized[:,PHASE_HALF:]],-1) + return self.backbone.phase_encoder(normalized) + def forward(self,t,x,features=None,covariances=None,covariance_features=None): + if features is None:features=extract_features(t,x) + if covariance_features is None: + if covariances is None:covariances=extract_covariances(t,x) + covariance_features=self.adapters[t].spatial_features(covariances) + signal=x.flatten(2);signal=signal-signal.mean(-1,keepdim=True) + if t in ('faced','tuev'):signal=signal/signal.std(-1,keepdim=True,correction=0).clamp_min(1e-6) + else:signal=signal-signal.mean(1,keepdim=True) + signal=signal.clamp(-20,20) + adapted=self.adapters[t](signal,features,covariance_features) + if covariances is None:covariances=extract_covariances(t,x) + tangent=extract_tangent_features(covariances,self.adapters[t].spatial_weight) + representation,fusion_delta,covariance_delta,fusion_input=self.backbone(*adapted,tangent_features=tangent) + if t in ('faced','openbmi'): + representation=torch.cat([representation[:,:-384],torch.zeros_like(representation[:,-384:-128]),representation[:,-128:]],-1) + tokens=torch.zeros(len(signal),signal.shape[-1]//200,24*64,device=signal.device,dtype=torch.bfloat16) + code_fusion,code_covariance=self.backbone.codebrain_correction(tokens,representation,fusion_input) + coactivation=self.backbone.wave_coactivation(representation) + with torch.autocast(signal.device.type,enabled=False): + ordinal=self.adapters[t].ordinal_embedding(ordinal_features(t,x)) + ordinal_covariance=self.backbone.ordinal_context(ordinal.float()) + added=.001*nn.functional.linear(ordinal_covariance,self.backbone.covariance_projection.weight,None) + ordinal_fusion=self.backbone.fusion(fusion_input+added.to(fusion_input.dtype))-representation[:,-512:-384] + phase=self.phase_embedding(t,phase_features(t,x,self.adapters[t].spatial_weight)) + coupling=self.coupling_embedding(t,coupling_features(t,x)) + student_values=self.student_features(t,x) + student=self.student_embedding(t,student_values) + extension=self.student_extension_embedding(t,student) + return self.heads[t](torch.cat([representation,fusion_delta,covariance_delta,code_fusion,code_covariance,coactivation,ordinal_fusion,ordinal_covariance,phase,coupling,student,extension,self.center_embedding(t,self.center_features(t,x)),self.short_embedding(t,self.short_features(t,x)),self.dual_embedding(t,self.dual_features(t,x)),self.geometry_embedding(t,self.geometry_features(t,x)),self.emotion_embedding(t,self.emotion_features(t,x)),self.refinement_embedding(t,self.refinement_features(t,x)),self.spatial_embedding(t,self.spatial_features(t,x)),self.conditional_embedding(t,self.conditional_features(t,x))],-1)) + +def widen_state_dict(state,multiplier=2): + """Duplicate temporal features and divide downstream sums to preserve outputs.""" + result={} + for key,value in state.items(): + if key.startswith('backbone.waveform.'): + layer=int(key.split('.')[2]) + if layer in (0,2,7):value=value.repeat(multiplier,1,1,1) + elif layer in (1,3,9):value=value.repeat(multiplier) + elif layer==8:value=value.repeat(multiplier,multiplier,1,1)/multiplier + elif key=='backbone.wave_summary.2.weight':value=value.repeat(1,multiplier)/multiplier + elif key.startswith('heads.') and key.endswith('.weight'): + raw=value[:,:-128]/multiplier + value=torch.cat([raw]*multiplier+[value[:,-128:]],1) + result[key]=value + return result + diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/local_channel_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/local_channel_features.py new file mode 100644 index 0000000000000000000000000000000000000000..fa80cf5248a4f1d0e472e39c12d828992909feff --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/local_channel_features.py @@ -0,0 +1,26 @@ +"""Named local channel differences. These are fixed differences, not a physical CSD model.""" +import torch +ALIASES={'T3':'T7','T4':'T8','T5':'P7','T6':'P8'} +NEIGHBORS={'C3':('F3','CZ','P3','T7'),'CZ':('FZ','C3','C4','PZ'),'C4':('F4','CZ','P4','T8'),'P3':('C3','PZ','O1','P7'),'PZ':('CZ','P3','P4','O1','O2'),'P4':('C4','PZ','O2','P8')} +def canonical(channels): + result=[ALIASES.get(name.upper(),name.upper()) for name in channels] + assert len(set(result))==len(result) + return result + +def projection_matrix(channels,local=True): + names=canonical(channels);matrix=torch.zeros(len(NEIGHBORS),len(names)) + for i,(center,neighbors) in enumerate(NEIGHBORS.items()): + matrix[i,names.index(center)]=1 + if local: + for name in neighbors:matrix[i,names.index(name)]-=1/len(neighbors) + else:matrix[i]-=1/len(names) + return matrix + +@torch.no_grad() +def local_channel_signals(signal,channels,local=True): + with torch.autocast(signal.device.type,enabled=False): + x=torch.nan_to_num(signal.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + names=canonical(channels) + if local: + return torch.stack([(x[:,names.index(center),None]-x[:,[names.index(n) for n in neighbors]]).mean(1) for center,neighbors in NEIGHBORS.items()],1) + return x[:,[names.index(center) for center in NEIGHBORS]]-x.mean(1,keepdim=True) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/multitaper_covariance_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/multitaper_covariance_features.py new file mode 100644 index 0000000000000000000000000000000000000000..2b262abac50ebc9e3cdb14a320606af5cd24c0c4 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/multitaper_covariance_features.py @@ -0,0 +1,28 @@ +"""Fixed DPSS covariance geometry; no fitted reference or adaptive spectral weights.""" +from functools import lru_cache +import numpy as np,torch +from scipy.signal.windows import dpss +from native_log_covariance_features import BANDS +from partial_covariance_features import summarize_matrix +@lru_cache(maxsize=8) +def tapers(n): + v=np.array(dpss(n,3.,Kmax=5,sym=True,norm=2),dtype=np.float64,copy=True);v*=np.sqrt(n)/np.linalg.norm(v,axis=1,keepdims=True);return v +@torch.no_grad() +def tapered_matrices(track,raw): + x=torch.nan_to_num(raw.double().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5);x=x-x[...,:1];x=x-x.mean(-1,keepdim=True) + if track in ['ad65','openbmi','longitudinal']:x=x-x.mean(1,keepdim=True) + b,c,n=x.shape;reference=x.square().mean((-1,-2))[:,None,None];window=torch.tensor(np.concatenate([tapers(n),np.ones((1,n))]),device=x.device);z=torch.fft.rfft(x[None]*window[:,None,None,:],dim=-1);freq=torch.fft.rfftfreq(n,1/200,device=x.device,dtype=torch.float64);eye=torch.eye(c,device=x.device,dtype=torch.float64);parts={k:[] for k in ['multitaper','single','rectangle']} + for lo,hi in BANDS: + v=torch.fft.irfft(z*((freq>=lo)&(freq(1e-10*reference).clamp_min(1e-20),value/power.clamp_min(1e-20),eye);matrix=.95*normal+.05*eye;parts[key].append((matrix+matrix.transpose(-1,-2))*.5) + return {k:torch.stack(v,1) for k,v in parts.items()} +@torch.no_grad() +def multitaper_covariance(track,raw): + matrices=tapered_matrices(track,raw);result={} + for key,matrix in matrices.items(): + if track=='tuev':value=summarize_matrix(matrix,True) + else: + c=matrix.shape[-1];nonidentity=(matrix-torch.eye(c,device=matrix.device)).abs().amax((-1,-2))>0;values,vectors=torch.linalg.eigh(matrix);log=(vectors*values.clamp_min(1e-6).log().unsqueeze(-2))@vectors.transpose(-1,-2);log=torch.where(nonidentity[...,None,None],log,0.);i,j=torch.triu_indices(c,c,device=matrix.device);scale=torch.ones(i.shape,device=matrix.device,dtype=torch.float64);scale[i!=j]=2.**.5;value=(log[...,i,j]*scale).flatten(1).float() + assert torch.isfinite(value).all();result[key]=value + return result diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/multitaper_model.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/multitaper_model.py new file mode 100644 index 0000000000000000000000000000000000000000..d9c2c7317a62e62aaf71172e891941ebf598712e --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/multitaper_model.py @@ -0,0 +1,27 @@ +"""One new shared descriptor decoder over the complete fixed336 shared model.""" +from confidence_model import * +SourceHybridModel=HybridModel +class MultitaperReadout(nn.Module): + def __init__(self,classes,scale): + super().__init__();self.projection=nn.Linear(128,classes);nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias);self.register_buffer('output_scale',scale.detach().clone());self.register_buffer('correction_gain',torch.tensor(1.)) +class HybridModel(SourceHybridModel): + def __init__(self,multitaper_refinement=False,multitaper_mode='multitaper',multitaper_enabled=1.,**kwargs): + super().__init__(**kwargs);assert multitaper_refinement and multitaper_mode in ['multitaper','single','rectangle'];self.multitaper_mode=multitaper_mode + for t in TRACKS: + dimension=13671 if t=='openbmi' else self.adapters[t].conditional_projection.in_features;self.adapters[t].multitaper_normalizer=Standardize(dimension);self.adapters[t].multitaper_projection=nn.Linear(dimension,128) + self.backbone.multitaper_encoder=nn.Sequential(nn.Linear(128,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,128),nn.LayerNorm(128));self.backbone.register_buffer('multitaper_enabled',torch.tensor(float(multitaper_enabled)));self.multitaper_heads=nn.ModuleDict({t:MultitaperReadout(SPECS[t][2],self.heads[t].output_scale) for t in TRACKS}) + def multitaper_features(self,t,x): + if t!='openbmi':return super().conditional_features(t,x) + from multitaper_covariance_features import multitaper_covariance + old=torch.backends.cuda.matmul.allow_tf32;torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(x.device.type,enabled=False):return torch.cat([multitaper_covariance(t,x[start:start+32])[self.multitaper_mode] for start in range(0,len(x),32)],0) + finally:torch.backends.cuda.matmul.allow_tf32=old + def multitaper_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False):return self.backbone.multitaper_encoder(self.adapters[t].multitaper_projection(self.adapters[t].multitaper_normalizer(values.float()))) + def multitaper_predict(self,t,values,prior,gain=None,return_standalone=False): + with torch.autocast(values.device.type,enabled=False): + h=self.multitaper_heads[t];standalone=h.projection(self.multitaper_embedding(t,values))*self.backbone.multitaper_enabled;g=h.correction_gain if gain is None else gain;result=prior.float()+(g*h.output_scale)*standalone + return (result,standalone) if return_standalone else result + def forward(self,t,x,features=None,covariances=None,covariance_features=None): + prior=super().forward(t,x,features,covariances=covariances,covariance_features=covariance_features);return self.multitaper_predict(t,self.multitaper_features(t,x),prior) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/native_log_covariance_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/native_log_covariance_features.py new file mode 100644 index 0000000000000000000000000000000000000000..17ef28a907f75094488fb5a6a3890e35463a38bb --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/native_log_covariance_features.py @@ -0,0 +1,35 @@ +"""Native-channel trace-normalized covariance geometry, with a matched linear control.""" +import torch +BANDS=((1,4),(4,8),(8,12),(12,16),(16,20),(20,28),(28,40)) + +@torch.no_grad() +def band_matrices(track,x): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x[...,:1];x=x-x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + reference=x.square().mean((-1,-2),keepdim=True) + n=x.shape[-1];c=x.shape[1];z=torch.fft.rfft(x,dim=-1);f=torch.fft.rfftfreq(n,1/200,device=x.device);eye=torch.eye(c,device=x.device);parts=[] + for low,high in BANDS: + v=torch.fft.irfft(z*((f>=low)&(f(1e-10*reference).clamp_min(1e-20) + normalized=covariance/power.clamp_min(1e-20) + normalized=torch.where(active,normalized,eye) + matrix=.95*normalized+.05*eye + parts.append((matrix+matrix.transpose(-1,-2))*.5) + return torch.stack(parts,1) + +@torch.no_grad() +def connectivity(track,x,logarithmic=True): + matrix=band_matrices(track,x);c=matrix.shape[-1] + if logarithmic: + # CUDA eigh can perturb exactly degenerate identity eigenvalues. + # Preserve the mathematical log(I)=0 for exactly silent/isotropic bands. + nonidentity=(matrix-torch.eye(c,device=matrix.device)).abs().amax((-1,-2))>0 + values,vectors=torch.linalg.eigh(matrix) + matrix=(vectors*values.clamp_min(1e-6).log().unsqueeze(-2))@vectors.transpose(-1,-2) + matrix=torch.where(nonidentity[...,None,None],matrix,torch.zeros_like(matrix)) + else:matrix=matrix-torch.eye(c,device=matrix.device) + i,j=torch.triu_indices(c,c,device=matrix.device);scale=torch.where(i==j,1.,2.**.5) + return (matrix[...,i,j]*scale).flatten(1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/ordinal_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/ordinal_features.py new file mode 100644 index 0000000000000000000000000000000000000000..6e3d5ff8264253f058f71b04d9cc8454196592b1 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/ordinal_features.py @@ -0,0 +1,25 @@ +"""Fixed within-window ordinal dynamics, independent of amplitude scaling.""" +import math +import torch +LAGS=(1,2,4,8,16) +PATTERNS=24 +PER_CHANNEL=len(LAGS)*(PATTERNS+2) + +def ordinal_features(track,x): + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + parts=[];uniform=1/PATTERNS;maximum_entropy=math.log(PATTERNS);m0=(1+uniform)/2;mr=uniform/2;maximum_js=-m0*math.log(m0)-(PATTERNS-1)*mr*math.log(mr)-maximum_entropy/2 + for lag in LAGS: + length=x.shape[-1]-3*lag + if length<=0:raise ValueError('window too short for ordinal dynamics') + samples=torch.stack([x[...,i*lag:i*lag+length] for i in range(4)],-1) + order=samples.argsort(dim=-1,stable=True) + code=6*((order[...,0,None]>order[...,1:]).sum(-1))+2*((order[...,1,None]>order[...,2:]).sum(-1))+(order[...,2]>order[...,3]).long() + histogram=torch.zeros(*x.shape[:2],PATTERNS,device=x.device,dtype=torch.float32) + histogram.scatter_add_(-1,code,torch.ones_like(code,dtype=torch.float32));probability=histogram/length + entropy=-(probability*probability.clamp_min(1e-12).log()).sum(-1) + mixture=(probability+uniform)/2;mixture_entropy=-(mixture*mixture.log()).sum(-1) + complexity=((mixture_entropy-.5*entropy-.5*maximum_entropy)/maximum_js).clamp(0,1)*(entropy/maximum_entropy) + parts.append(torch.cat([probability,(entropy/maximum_entropy)[...,None],complexity[...,None]],-1)) + return torch.cat(parts,-1).flatten(1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/partial_covariance_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/partial_covariance_features.py new file mode 100644 index 0000000000000000000000000000000000000000..3cbef5528aa7424e7ffc878afb40f80509b661d3 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/partial_covariance_features.py @@ -0,0 +1,33 @@ +"""Native regularized partial and marginal covariance statistics; no causal claims.""" +import torch +from native_log_covariance_features import BANDS + +@torch.no_grad() +def summarize_matrix(matrix,partial=True): + c=matrix.shape[-1];value=matrix.double() + if partial:value=torch.linalg.inv(value) + diagonal=value.diagonal(dim1=-2,dim2=-1).clamp_min(1e-12) + correlation=value/(diagonal[...,None]*diagonal[...,None,:]).sqrt() + if partial:correlation=-correlation + ii,jj=torch.triu_indices(c,c,offset=1,device=matrix.device) + variance=(-1. if partial else 1.)*diagonal.log() + pairs=torch.atanh(correlation[...,ii,jj].clamp(-.999,.999)) + return torch.cat([variance,pairs],-1).flatten(1).float() + + +@torch.no_grad() +def stable_band_matrices(track,x): + x=torch.nan_to_num(x.double().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x[...,:1];x=x-x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + reference=x.square().mean((-1,-2),keepdim=True);n=x.shape[-1];c=x.shape[1] + z=torch.fft.rfft(x,dim=-1);f=torch.fft.rfftfreq(n,1/200,device=x.device,dtype=torch.float64);eye=torch.eye(c,device=x.device,dtype=torch.float64);parts=[] + for lo,hi in BANDS: + v=torch.fft.irfft(z*((f>=lo)&(f(1e-10*reference).clamp_min(1e-20),cov/power.clamp_min(1e-20),eye);matrix=.95*normalized+.05*eye;parts.append((matrix+matrix.transpose(-1,-2))*.5) + return torch.stack(parts,1) + +@torch.no_grad() +def partial_covariance_features(track,x,partial=True): + with torch.autocast(x.device.type,enabled=False): + return summarize_matrix(stable_band_matrices(track,x),partial) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/phase_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/phase_features.py new file mode 100644 index 0000000000000000000000000000000000000000..8d98822995bf37b499795dfd7e2e401040a01969 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/phase_features.py @@ -0,0 +1,37 @@ +"""Complex spectral coherence of the existing 24 spatial filters in ten bands.""" +import torch +from covariances import BANDS +CHANNELS=24 +PHASE_HALF=len(BANDS)*CHANNELS*(CHANNELS-1)//2 +PHASE_DIM=2*PHASE_HALF + +@torch.no_grad() +def phase_features(track,x,spatial_weight): + previous_tf32=torch.backends.cuda.matmul.allow_tf32 + try: + torch.backends.cuda.matmul.allow_tf32=False + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.float().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if track in ('faced','tuev'):x=x/x.square().mean(-1,keepdim=True).clamp_min(1e-12).sqrt() + else:x=x-x.mean(1,keepdim=True) + x=x/x.square().mean((1,2),keepdim=True).clamp_min(1e-12).sqrt() + frames=x.unfold(-1,400,200);frames=frames-frames.mean(-1,keepdim=True) + z=torch.fft.rfft(frames*torch.hann_window(400,device=x.device),dim=-1)/200 + w=spatial_weight.float()/spatial_weight.float().norm(dim=-1,keepdim=True).clamp_min(1e-6) + index=torch.triu_indices(CHANNELS,CHANNELS,1,device=x.device) + real_parts=[];imaginary_parts=[] + for band,(lo,hi) in enumerate(BANDS): + v=z[...,2*lo:2*hi].flatten(2) + vr=w[band][None]@v.real;vi=w[band][None]@v.imag + real=(vr@vr.transpose(-1,-2)+vi@vi.transpose(-1,-2))/v.shape[-1] + imaginary=(vi@vr.transpose(-1,-2)-vr@vi.transpose(-1,-2))/v.shape[-1] + # Signals have unit global RMS; this floor suppresses phase of numerical silence. + power=real.diagonal(dim1=-2,dim2=-1).clamp_min(1e-6) + denominator=(power[:,:,None]*power[:,None,:]).sqrt().clamp_min(1e-12) + real=(real/denominator).clamp(-.999,.999) + imaginary=(imaginary/denominator).clamp(-.999,.999) + real_parts.append(torch.atanh(real[:,index[0],index[1]])) + imaginary_parts.append(torch.atanh(imaginary[:,index[0],index[1]])) + return torch.cat(real_parts+imaginary_parts,-1) + finally:torch.backends.cuda.matmul.allow_tf32=previous_tf32 diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/requirements.txt b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..27a518851383b887d41658124d6fa7ef74cdb090 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/requirements.txt @@ -0,0 +1,4 @@ +numpy +scipy +torch==2.8.0 +braindecode==1.8.1 diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/shared_activation_groups_parent_model.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/shared_activation_groups_parent_model.py new file mode 100644 index 0000000000000000000000000000000000000000..3ee733591c275ef58da798b68e166c8af8b2f8e0 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/shared_activation_groups_parent_model.py @@ -0,0 +1,52 @@ +"""Portable temporal-scale bank integration over the complete frozen490 source.""" +from shared_temporal_basis_model import * +from torch.nn import functional as F +from temporal_scale_math import temporal_scale_bank, MODES +from temporal_convolution_math import SharedTemporalConvolution, raw_convolution_features, precise_convolution + +SourceHybridModel = HybridModel + + +class TemporalScaleHead(nn.Module): + def __init__(self, classes): + super().__init__() + self.projection = nn.Linear(128, classes) + nn.init.normal_(self.projection.weight, std=.02) + nn.init.zeros_(self.projection.bias) + self.register_buffer('blend_strength', torch.tensor(0.)) + + +class HybridModel(SourceHybridModel): + def __init__(self, temporal_scale_refinement=False, temporal_scale_mode='diverse', **kwargs): + super().__init__(**kwargs) + assert temporal_scale_refinement and temporal_scale_mode in MODES + self.temporal_scale_mode = temporal_scale_mode + for track in TRACKS: + self.adapters[track].temporal_scale_projection = nn.Linear(SPECS[track][0],16,bias=False) + self.backbone.temporal_scale_encoder = SharedTemporalConvolution() + self.backbone.temporal_scale_encoder.temporal = nn.Conv2d(1,16,(1,17),stride=(1,2),padding=(0,8),bias=False) + self.temporal_scale_heads = nn.ModuleDict({track:TemporalScaleHead(SPECS[track][2]) for track in TRACKS}) + + def temporal_scale_logits(self, track, values): + with precise_convolution(values.device.type): + block = self.backbone.temporal_scale_encoder + x = self.adapters[track].temporal_scale_projection(values.float().transpose(1,2)).transpose(1,2).unsqueeze(1) + x = temporal_scale_bank(x,block.temporal.weight,self.temporal_scale_mode) + x = block.norm_temporal(x) + x = block.dropout_spatial(F.avg_pool2d(F.elu(block.norm_spatial(block.spatial(x))),(1,4))) + x = block.dropout_separable(F.avg_pool2d(F.elu(block.norm_separable(block.pointwise(block.depthwise(x)))),(1,8))) + x = x.squeeze(2) + mean = x.mean(-1) + std = ((x-mean[...,None]).square().mean(-1)+1e-6).sqrt() + x = block.dropout_embedding(block.norm_embedding(F.gelu(block.embedding(torch.cat([mean,std],-1))))) + return self.temporal_scale_heads[track].projection(x) + + def temporal_scale_predict(self, track, values, prior, strength=None): + logits = self.temporal_scale_logits(track,values) + strength = self.temporal_scale_heads[track].blend_strength if strength is None else strength + return (1-strength)*prior.float()+strength*logits + + def forward(self, track, raw, features=None, covariances=None, covariance_features=None): + prior = super().forward(track,raw,features,covariances=covariances,covariance_features=covariance_features) + values = raw_convolution_features(track,raw,'raw') + return self.temporal_scale_predict(track,values,prior) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/shared_additive_hinge_model.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/shared_additive_hinge_model.py new file mode 100644 index 0000000000000000000000000000000000000000..21f9c2367738045875aa29f0da9a5b4699af1a9a --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/shared_additive_hinge_model.py @@ -0,0 +1,36 @@ +"""459: Longitudinal hinge input geometry and one new shared five-track block.""" +from shared_expert_routing_model import * +from additive_hinge_features import longitudinal_hinge_features,PROJECTED_DIMENSION +from additive_hinge_geometry import AdditiveGeometry,MODES +SourceHybridModel=HybridModel + +class AdditiveHingeReadout(nn.Module): + def __init__(self,classes,scale): + super().__init__();self.projection=nn.Linear(128,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',scale.detach().clone());self.register_buffer('correction_gain',torch.tensor(1.)) + +class HybridModel(SourceHybridModel): + def __init__(self,additive_hinge_refinement=False,additive_hinge_mode='hinge',additive_hinge_enabled=1.,**kwargs): + super().__init__(**kwargs);assert additive_hinge_refinement and additive_hinge_mode in MODES;self.additive_hinge_mode=additive_hinge_mode + for t in TRACKS: + d=PROJECTED_DIMENSION if t=='longitudinal' else self.adapters[t].weighted_pattern_projection.in_features + self.adapters[t].additive_hinge_projection=nn.Linear(d,128) + self.adapters['longitudinal'].additive_hinge_geometry=AdditiveGeometry(additive_hinge_mode) + self.backbone.additive_hinge_encoder=nn.Sequential(nn.Linear(128,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,128),nn.LayerNorm(128)) + self.backbone.register_buffer('additive_hinge_enabled',torch.tensor(float(additive_hinge_enabled))) + self.additive_hinge_heads=nn.ModuleDict({t:AdditiveHingeReadout(SPECS[t][2],self.heads[t].output_scale) for t in TRACKS}) + def additive_hinge_features(self,t,raw,features=None): + return longitudinal_hinge_features(raw) if t=='longitudinal' else self.weighted_pattern_features(t,raw,features=features) + def additive_hinge_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False): + a=self.adapters[t];x=a.additive_hinge_geometry(values) if t=='longitudinal' else a.weighted_pattern_normalizer(values.float()) + return self.backbone.additive_hinge_encoder(a.additive_hinge_projection(x)) + def additive_hinge_predict(self,t,values,prior,gain=None,return_standalone=False): + with torch.autocast(values.device.type,enabled=False): + h=self.additive_hinge_heads[t];standalone=h.projection(self.additive_hinge_embedding(t,values))*self.backbone.additive_hinge_enabled + strength=h.correction_gain if gain is None else gain;result=prior.float()+(strength*h.output_scale)*standalone + return (result,standalone) if return_standalone else result + def forward(self,t,raw,features=None,covariances=None,covariance_features=None): + prior=super().forward(t,raw,features,covariances=covariances,covariance_features=covariance_features) + return self.additive_hinge_predict(t,self.additive_hinge_features(t,raw,features=features),prior) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/shared_dual_readout_model.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/shared_dual_readout_model.py new file mode 100644 index 0000000000000000000000000000000000000000..47fcb92b9a437e90ccf6e6870f7a6d8389a08769 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/shared_dual_readout_model.py @@ -0,0 +1,70 @@ +"""472: separate correction and auxiliary readouts of one shared representation.""" +from shared_additive_hinge_model import * +from shared_spectral_features import log_relative_spectrum +from channel_attention_math import SharedChannelAttention +MODES = ('separate', 'coupled', 'detached') +SourceHybridModel = HybridModel + +class DualReadout(nn.Module): + def __init__(self, classes, scale): + super().__init__() + self.projection = nn.Linear(128, classes) + nn.init.zeros_(self.projection.weight) + nn.init.zeros_(self.projection.bias) + self.auxiliary = nn.Linear(128, classes) + nn.init.normal_(self.auxiliary.weight, std=.02) + nn.init.zeros_(self.auxiliary.bias) + self.register_buffer('output_scale', scale.detach().clone()) + self.register_buffer('correction_gain', torch.tensor(1.)) + +def readouts(embedding, head, mode, enabled): + residual = head.projection(embedding) + auxiliary = head.auxiliary(embedding.detach() if mode == 'detached' else embedding) + correction = (residual + auxiliary * 0.) * enabled + standalone = ((residual + auxiliary * 0.) if mode == 'coupled' else (auxiliary + residual * 0.)) * enabled + return correction, standalone + +class HybridModel(SourceHybridModel): + def __init__(self, dual_readout_refinement=False, dual_readout_mode='separate', dual_readout_enabled=1., **kwargs): + super().__init__(**kwargs) + assert dual_readout_refinement and dual_readout_mode in MODES + self.dual_readout_mode = dual_readout_mode + for t in TRACKS: + channels = SPECS[t][0] + self.adapters[t].dual_readout_normalizer = Standardize(95 * channels) + self.adapters[t].dual_readout_position = nn.Parameter(torch.empty(channels, 128)) + nn.init.normal_(self.adapters[t].dual_readout_position, std=.02) + self.backbone.dual_readout_encoder = SharedChannelAttention('content') + self.backbone.register_buffer('dual_readout_enabled', torch.tensor(float(dual_readout_enabled))) + self.dual_readout_heads = nn.ModuleDict({t: DualReadout(SPECS[t][2], self.heads[t].output_scale) for t in TRACKS}) + + def dual_readout_features(self, t, raw, features=None): + return log_relative_spectrum(t, raw) + + def dual_readout_embedding(self, t, spectra): + old = torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32 = False + try: + with torch.autocast(spectra.device.type, enabled=False): + a = self.adapters[t] + x = a.dual_readout_normalizer(spectra.float().flatten(1)).reshape(len(spectra), SPECS[t][0], 95) + return self.backbone.dual_readout_encoder(x, a.dual_readout_position) + finally: + torch.backends.cuda.matmul.allow_tf32 = old + + def dual_readout_predict(self, t, spectra, prior, gain=None, return_standalone=False): + old = torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32 = False + try: + with torch.autocast(spectra.device.type, enabled=False): + head = self.dual_readout_heads[t] + correction, standalone = readouts(self.dual_readout_embedding(t, spectra), head, self.dual_readout_mode, self.backbone.dual_readout_enabled) + strength = head.correction_gain if gain is None else gain + result = prior.float() + (strength * head.output_scale) * correction + return (result, standalone) if return_standalone else result + finally: + torch.backends.cuda.matmul.allow_tf32 = old + + def forward(self, t, raw, features=None, covariances=None, covariance_features=None): + prior = super().forward(t, raw, features, covariances=covariances, covariance_features=covariance_features) + return self.dual_readout_predict(t, self.dual_readout_features(t, raw), prior) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/shared_expert_routing_math.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/shared_expert_routing_math.py new file mode 100644 index 0000000000000000000000000000000000000000..516adabe6b0c1807b1d5dae4a9ffdb8993ba815b --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/shared_expert_routing_math.py @@ -0,0 +1,14 @@ +"""443 bounded two-expert routing; no data or fitted state.""" +import torch + + +def bounded_expert_weights(router_logits,task_bias,mode): + if mode=='input':scores=router_logits+task_bias + elif mode=='task':scores=router_logits*0.+task_bias + elif mode=='uniform':scores=(router_logits+task_bias)*0. + else:raise ValueError(mode) + return (2*torch.tanh(scores)).softmax(-1) + + +def mix_expert_outputs(first,second,weights): + return first+weights[...,1:2]*(second-first) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/shared_expert_routing_model.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/shared_expert_routing_model.py new file mode 100644 index 0000000000000000000000000000000000000000..db50c505e5654ded143c75748e03f75ac7714bfe --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/shared_expert_routing_model.py @@ -0,0 +1,45 @@ +"""443: one shared backbone with two shared feature experts and bounded routing.""" +from shared_spectral_filter_model import * +from shared_expert_routing_math import bounded_expert_weights,mix_expert_outputs +SourceHybridModel=HybridModel + + +class ExpertRoutingReadout(nn.Module): + def __init__(self,classes,scale): + super().__init__();self.projection=nn.Linear(128,classes) + nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias) + self.register_buffer('output_scale',scale.detach().clone());self.register_buffer('correction_gain',torch.tensor(1.)) + + +class HybridModel(SourceHybridModel): + def __init__(self,expert_routing_refinement=False,expert_routing_mode='input',expert_routing_enabled=1.,**kwargs): + super().__init__(**kwargs);assert expert_routing_refinement and expert_routing_mode in ['input','task','uniform'];self.expert_routing_mode=expert_routing_mode + for track in TRACKS: + dimension=self.adapters[track].weighted_pattern_projection.in_features + self.adapters[track].expert_routing_projection=nn.Linear(dimension,128) + self.adapters[track].expert_task_logits=nn.Parameter(torch.zeros(2)) + self.backbone.expert_blocks=nn.ModuleList([nn.Sequential(nn.Linear(128,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,128),nn.LayerNorm(128)) for _ in range(2)]) + self.backbone.expert_router=nn.Linear(128,2,bias=False);nn.init.zeros_(self.backbone.expert_router.weight) + self.backbone.register_buffer('expert_routing_enabled',torch.tensor(float(expert_routing_enabled))) + self.expert_routing_heads=nn.ModuleDict({track:ExpertRoutingReadout(SPECS[track][2],self.heads[track].output_scale) for track in TRACKS}) + + def expert_routing_features(self,track,raw,features=None): + return self.weighted_pattern_features(track,raw,features=features) + + def expert_routing_embedding(self,track,values,return_routing=False): + with torch.autocast(values.device.type,enabled=False): + adapter=self.adapters[track];z=adapter.expert_routing_projection(adapter.weighted_pattern_normalizer(values.float())) + first=self.backbone.expert_blocks[0](z);second=self.backbone.expert_blocks[1](z) + weights=bounded_expert_weights(self.backbone.expert_router(z),adapter.expert_task_logits,self.expert_routing_mode) + result=mix_expert_outputs(first,second,weights) + return (result,weights) if return_routing else result + + def expert_routing_predict(self,track,values,prior,gain=None,return_standalone=False): + with torch.autocast(values.device.type,enabled=False): + head=self.expert_routing_heads[track];standalone=head.projection(self.expert_routing_embedding(track,values))*self.backbone.expert_routing_enabled + strength=head.correction_gain if gain is None else gain;result=prior.float()+(strength*head.output_scale)*standalone + return (result,standalone) if return_standalone else result + + def forward(self,track,raw,features=None,covariances=None,covariance_features=None): + prior=super().forward(track,raw,features,covariances=covariances,covariance_features=covariance_features) + return self.expert_routing_predict(track,self.expert_routing_features(track,raw,features=features),prior) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/shared_spectral_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/shared_spectral_features.py new file mode 100644 index 0000000000000000000000000000000000000000..f4fa72c8f84c5df6ec9d4b41b9b38aa0651cfe50 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/shared_spectral_features.py @@ -0,0 +1,44 @@ +"""431 deterministic per-window log spectra and seven shared trainable filters.""" +import torch +from torch import nn +INITIAL_CENTERS=(2.5,6.,10.,14.,18.,24.,34.) +INITIAL_WIDTHS=(1.5,2.,2.,2.,2.,4.,6.) + + +@torch.no_grad() +def _log_spectrum_batch(track,raw): + with torch.autocast(raw.device.type,enabled=False): + x=torch.nan_to_num(raw.double().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5);x=x-x[...,:1];x=x-x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + window=torch.hann_window(400,periodic=True,device=x.device,dtype=torch.float64) + power=torch.fft.rfft(x.unfold(-1,400,200)*window,dim=-1).abs().square().mean(-2)[...,2:97] + relative=power/power.sum(-1,keepdim=True).clamp_min(1e-20);logarithm=relative.clamp_min(1e-12).log() + return (torch.round(logarithm*1e9)/1e9).float() + + +@torch.no_grad() +def log_relative_spectrum(track,raw): + outputs=[] + for chunk in raw.split(16) if len(raw) else [raw]: + count=len(chunk) + if count<16:chunk=torch.cat([chunk,raw.new_zeros((16-count,*raw.shape[1:]))]) + outputs.append(_log_spectrum_batch(track,chunk)[:count]) + return torch.cat(outputs) + + +class SharedGaussianSpectralFilters(nn.Module): + def __init__(self): + super().__init__() + centers=(torch.tensor(INITIAL_CENTERS)-1)/47;widths=(torch.tensor(INITIAL_WIDTHS)-.5)/11.5 + self.raw_centers=nn.Parameter(torch.logit(centers));self.raw_widths=nn.Parameter(torch.logit(widths)) + self.register_buffer('frequencies',torch.arange(1.,48.5,.5)) + + def physical_parameters(self): + return 1+47*self.raw_centers.sigmoid(),.5+11.5*self.raw_widths.sigmoid() + + def log_weights(self): + center,width=self.physical_parameters();z=-.5*((self.frequencies[None]-center[:,None])/width[:,None]).square() + return z.log_softmax(-1) + + def forward(self,log_spectrum): + return torch.logsumexp(log_spectrum[:,:,None,:]+self.log_weights()[None,None],-1).flatten(1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/shared_temporal_basis_model.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/shared_temporal_basis_model.py new file mode 100644 index 0000000000000000000000000000000000000000..6defa6c7d9f32e645669dc90240a142c23783b2c --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/shared_temporal_basis_model.py @@ -0,0 +1,45 @@ +"""Unbound portable integration draft, conditional on the complete488 gate. + +An eventual runtime must bundle the unchanged complete472 model under +shared_dual_readout_model.py and the checked temporal-basis helpers. This +module is not imported by488, any active EEG fit, or the submission. +""" +from shared_dual_readout_model import * +from candidate_temporal_basis_model import TemporalBasisConvolution +from temporal_convolution_math import raw_convolution_features, precise_convolution + +SourceHybridModel = HybridModel + + +class TemporalBasisHead(nn.Module): + def __init__(self, classes): + super().__init__() + self.projection = nn.Linear(128, classes) + nn.init.normal_(self.projection.weight, std=.02) + nn.init.zeros_(self.projection.bias) + self.register_buffer('blend_strength', torch.tensor(0.)) + + +class HybridModel(SourceHybridModel): + def __init__(self, temporal_basis_refinement=False, temporal_basis_mode='signed', **kwargs): + super().__init__(**kwargs) + assert temporal_basis_refinement + for track in TRACKS: + self.adapters[track].temporal_basis_projection = nn.Linear(SPECS[track][0], 16, bias=False) + self.backbone.temporal_basis_encoder = TemporalBasisConvolution(temporal_basis_mode) + self.temporal_basis_heads = nn.ModuleDict({track: TemporalBasisHead(SPECS[track][2]) for track in TRACKS}) + + def temporal_basis_logits(self, track, values): + with precise_convolution(values.device.type): + x = self.adapters[track].temporal_basis_projection(values.float().transpose(1, 2)).transpose(1, 2) + return self.temporal_basis_heads[track].projection(self.backbone.temporal_basis_encoder(x)) + + def temporal_basis_predict(self, track, values, prior, strength=None): + logits = self.temporal_basis_logits(track, values) + strength = self.temporal_basis_heads[track].blend_strength if strength is None else strength + return (1-strength)*prior.float()+strength*logits + + def forward(self, track, raw, features=None, covariances=None, covariance_features=None): + prior = super().forward(track, raw, features, covariances=covariances, covariance_features=covariance_features) + values = raw_convolution_features(track, raw, 'raw') + return self.temporal_basis_predict(track, values, prior) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/short_context_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/short_context_features.py new file mode 100644 index 0000000000000000000000000000000000000000..f677f7a4319f4afb9071665bf7804558bfdd69d8 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/short_context_features.py @@ -0,0 +1,22 @@ +"""One/two-second fixed spectral descriptors with physical-frequency bands.""" +import torch +from features import EDGES,COV_BANDS +@torch.no_grad() +def short_spectral_features(track,x): + x=x.float().flatten(2) + x=torch.nan_to_num(x,nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + assert x.shape[-1] in (200,400) + x=x-x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + rms=x.square().mean(-1).clamp_min(1e-12).sqrt();norm=x/rms.unsqueeze(-1) + moments=torch.stack([rms.log(),norm.abs().amax(-1).clamp_min(1).log(),norm.pow(4).mean(-1).clamp_min(1).log(),(norm[...,1:]-norm[...,:-1]).square().mean(-1).clamp_min(1e-10).log()],-1) + n=x.shape[-1];frames=x.unfold(-1,n,n//2);frames=frames-frames.mean(-1,keepdim=True) + z=torch.fft.rfft(frames*torch.hann_window(n,device=x.device),dim=-1)/(n//2) + power=z.abs().square() + bands=torch.stack([power[...,n*lo//200:n*hi//200].mean(-1) for lo,hi in zip(EDGES[:-1],EDGES[1:])],-1) + lp=bands.mean(-2).clamp_min(1e-12).log();variation=bands.clamp_min(1e-12).log().std(-2,correction=0) + parts=[torch.cat([lp,lp-lp.mean(-1,keepdim=True),lp-lp.mean(1,keepdim=True),variation,moments],-1).flatten(1)] + ii,jj=torch.triu_indices(x.shape[1],x.shape[1],offset=1,device=x.device) + for lo,hi in COV_BANDS: + v=z[...,n*lo//200:n*hi//200].flatten(2);cov=v.real@v.real.transpose(-1,-2)+v.imag@v.imag.transpose(-1,-2);d=cov.diagonal(dim1=-2,dim2=-1).clamp_min(1e-12).sqrt();cor=cov/(d.unsqueeze(1)*d.unsqueeze(2)).clamp_min(1e-12);parts.append(cor[:,ii,jj].clamp(-1,1)) + return torch.nan_to_num(torch.cat(parts,-1)).clamp(-40,40) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/student_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/student_features.py new file mode 100644 index 0000000000000000000000000000000000000000..57401f6d2ab760cb1a58af564aef2e62290e8907 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/student_features.py @@ -0,0 +1,34 @@ +"""One audited CBraMod core with full-window shared and ordered representations.""" +import torch +from torch import nn +from braindecode.models import CBraMod +from frequency_features import frequency_components,FREQUENCY_BANDS +SPECS={'faced':(32,10,9),'tuev':(16,5,6),'ad65':(19,10,3),'openbmi':(62,4,2),'longitudinal':(58,2,2)} +TRACKS=tuple(SPECS) + +class FrequencyAdapter(nn.Module): + def __init__(self,channels,virtual_channels=32): + super().__init__();self.signal=nn.Conv1d(channels,virtual_channels,1,bias=False) + self.frequency_weight=nn.Parameter(torch.zeros(len(FREQUENCY_BANDS),virtual_channels,channels)) + def forward(self,x): + components=frequency_components(x) + correction=torch.einsum('blc,nbct->nlt',self.frequency_weight,components.to(self.frequency_weight.dtype)) + return self.signal(x)+correction.to(x.dtype) + +class CBraModFeatures(nn.Module): + def __init__(self,virtual_channels=32,token_width=64,summary_width=256,head_width=128,dropout=.3): + super().__init__();self.virtual_channels=virtual_channels;self.output_dim=summary_width+virtual_channels*token_width*4 + self.backbone=CBraMod(n_chans=virtual_channels,n_outputs=2,n_times=400,sfreq=200) + self.backbone.final_layer=nn.Identity() + self.token_projection=nn.Sequential(nn.LayerNorm(200),nn.Linear(200,token_width),nn.GELU()) + self.summary_projection=nn.Sequential(nn.LayerNorm(virtual_channels*token_width*2),nn.Linear(virtual_channels*token_width*2,summary_width),nn.GELU(),nn.Dropout(dropout)) + def forward(self,signal): + tokens=self.token_projection(self.backbone(signal)) + moments=torch.cat([tokens.mean(2),tokens.float().std(2,correction=0).to(tokens.dtype)],-1).flatten(1) + summary=self.summary_projection(moments) + ordered=torch.nn.functional.adaptive_avg_pool1d(tokens.permute(0,1,3,2).flatten(1,2),4).flatten(1) + return torch.cat([summary,ordered],-1) + + def named_shared_parameters(self): + for prefix,module in [('backbone',self.backbone),('token_projection',self.token_projection),('summary_projection',self.summary_projection)]: + for name,p in module.named_parameters():yield f'{prefix}.{name}',p diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/tangent_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/tangent_features.py new file mode 100644 index 0000000000000000000000000000000000000000..314f0cf2f58e4b4a1c1d808edbd4acc3b7b6f85b --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/tangent_features.py @@ -0,0 +1,25 @@ +"""Window-local log-correlation geometry in the existing spatial-filter basis.""" +import torch + +TANGENT_DIM=10*24*25//2 + +@torch.no_grad() +def extract_tangent_features(covariances,spatial_weight): + old_tf32=torch.backends.cuda.matmul.allow_tf32 + torch.backends.cuda.matmul.allow_tf32=False + try: + with torch.autocast(covariances.device.type,enabled=False): + w=spatial_weight.float() + w=w/w.norm(dim=-1,keepdim=True).clamp_min(1e-6) + projected=torch.einsum('bfc,nbcd,bgd->nbfg',w,covariances.float(),w) + d=projected.diagonal(dim1=-2,dim2=-1).clamp_min(1e-10).sqrt() + correlation=(projected/(d.unsqueeze(-1)*d.unsqueeze(-2))).clamp(-1,1) + correlation=(correlation+correlation.transpose(-1,-2))/2 + correlation=.95*correlation+.05*torch.eye(24,device=correlation.device) + values,vectors=torch.linalg.eigh(correlation) + logarithm=(vectors*values.clamp_min(1e-6).log().unsqueeze(-2))@vectors.transpose(-1,-2) + i,j=torch.triu_indices(24,24,device=correlation.device) + scale=torch.where(i==j,1.,2.**.5) + return (logarithm[...,i,j]*scale).flatten(1) + finally: + torch.backends.cuda.matmul.allow_tf32=old_tf32 diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/temporal_convolution_math.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/temporal_convolution_math.py new file mode 100644 index 0000000000000000000000000000000000000000..3d8b196fa7a7d58a5a001683a2158a7b999db9cf --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/temporal_convolution_math.py @@ -0,0 +1,79 @@ +"""469 deterministic per-window preprocessing and shared temporal convolution.""" +import contextlib, functools, math +import torch +from torch import nn +from torch.nn import functional as F +MODES=('raw','phase','permuted') + +@contextlib.contextmanager +def precise_convolution(device_type): + old=(torch.backends.cuda.matmul.allow_tf32,torch.backends.cudnn.allow_tf32,torch.backends.cudnn.benchmark,torch.backends.cudnn.deterministic) + torch.backends.cuda.matmul.allow_tf32=False + torch.backends.cudnn.allow_tf32=False + torch.backends.cudnn.benchmark=False + torch.backends.cudnn.deterministic=True + try: + with torch.autocast(device_type,enabled=False):yield + finally: + torch.backends.cuda.matmul.allow_tf32,torch.backends.cudnn.allow_tf32,torch.backends.cudnn.benchmark,torch.backends.cudnn.deterministic=old + +@functools.lru_cache(maxsize=4) +def phase_angles(length): + g=torch.Generator(device='cpu').manual_seed(469000+length) + p=(torch.rand(length//2+1,dtype=torch.float64,generator=g)*2-1)*math.pi + p[0]=0. + if length%2==0:p[-1]=0. + return p + +@functools.lru_cache(maxsize=4) +def time_permutation(length): + return torch.randperm(length,generator=torch.Generator(device='cpu').manual_seed(469100+length)) + +def transform_preprocessed(x,mode): + assert mode in MODES + if mode=='raw':return x + if mode=='permuted':return x[...,time_permutation(x.shape[-1]).to(x.device)] + angles=phase_angles(x.shape[-1]).to(x.device) + phasor=torch.complex(angles.cos(),angles.sin()) + y=torch.fft.irfft(torch.fft.rfft(x.double(),dim=-1)*phasor,n=x.shape[-1],dim=-1) + return (torch.round(y*1e8)/1e8).float() + +@torch.no_grad() +def raw_convolution_features(track,raw,mode='raw'): + outputs=[] + with precise_convolution(raw.device.type): + for chunk in raw.split(16) if len(raw) else [raw]: + count=len(chunk) + if count<16:chunk=torch.cat([chunk,raw.new_zeros((16-count,*raw.shape[1:]))]) + x=torch.nan_to_num(chunk.double().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x[...,:1];x=x-x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + power=x.square().mean((1,2),keepdim=True) + x=torch.where(power>1e-20,x/power.clamp_min(1e-20).sqrt(),torch.zeros_like(x)).clamp(-8,8) + x=(torch.round(x*1e8)/1e8).float() + outputs.append(transform_preprocessed(x,mode)[:count]) + return torch.cat(outputs) + +class SharedTemporalConvolution(nn.Module): + def __init__(self): + super().__init__() + self.temporal=nn.Conv2d(1,16,(1,65),stride=(1,2),padding=(0,32),bias=False) + self.norm_temporal=nn.GroupNorm(4,16,eps=1e-5) + self.spatial=nn.Conv2d(16,32,(16,1),groups=16,bias=False) + self.norm_spatial=nn.GroupNorm(8,32,eps=1e-5) + self.dropout_spatial=nn.Dropout(.3) + self.depthwise=nn.Conv2d(32,32,(1,17),padding=(0,8),groups=32,bias=False) + self.pointwise=nn.Conv2d(32,64,1,bias=False) + self.norm_separable=nn.GroupNorm(8,64,eps=1e-5) + self.dropout_separable=nn.Dropout(.3) + self.embedding=nn.Linear(128,128) + self.norm_embedding=nn.LayerNorm(128,eps=1e-5) + self.dropout_embedding=nn.Dropout(.3) + + def forward(self,x): + x=self.norm_temporal(self.temporal(x.unsqueeze(1))) + x=self.dropout_spatial(F.avg_pool2d(F.elu(self.norm_spatial(self.spatial(x))),(1,4))) + x=self.dropout_separable(F.avg_pool2d(F.elu(self.norm_separable(self.pointwise(self.depthwise(x)))),(1,8))) + x=x.squeeze(2);mean=x.mean(-1);std=((x-mean[...,None]).square().mean(-1)+1e-6).sqrt() + x=torch.cat([mean,std],dim=-1) + return self.dropout_embedding(self.norm_embedding(F.gelu(self.embedding(x)))) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/temporal_scale_math.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/temporal_scale_math.py new file mode 100644 index 0000000000000000000000000000000000000000..302fe6d490da6231ec452a909155febf2a34b32d --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/temporal_scale_math.py @@ -0,0 +1,16 @@ +"""Fixed dilation placement for equally sized learned common temporal banks.""" +import torch +from torch.nn import functional as F + +MODES = ('diverse', 'local', 'repeated65') +DILATIONS = {'diverse': (1, 2, 4, 8), 'local': (1, 1, 1, 1), + 'repeated65': (4, 4, 4, 4)} + + +def temporal_scale_bank(x, weight, mode): + assert mode in MODES + assert x.ndim == 4 and x.shape[1] == 1 + assert weight.shape == (16, 1, 1, 17) + return torch.cat([F.conv2d(x, weight[4*i:4*i+4], stride=(1, 2), + padding=(0, 8*d), dilation=(1, d)) + for i, d in enumerate(DILATIONS[mode])], dim=1) diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/weighted_ordinal_features.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/weighted_ordinal_features.py new file mode 100644 index 0000000000000000000000000000000000000000..1045da783f13240049acd50af59810968b934657 --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/weighted_ordinal_features.py @@ -0,0 +1,44 @@ +"""Fixed per-window amplitude-weighted ordinal patterns; no learned state.""" +import functools,math +import numpy as np +import torch +LAGS=(1,2,4,8,16) + +@functools.lru_cache(maxsize=32) +def permutations(n,lag): + length=n-3*lag + return tuple(np.random.default_rng(386000+1000*lag+n+j).permutation(length) for j in range(4)) + +def summarize(p): + h=-(p*p.clamp_min(1e-300).log()).sum(-1);u=1/24;hu=math.log(24);q=(p+u)/2 + hq=-(q*q.log()).sum(-1);m=(1+u)/2;r=u/2;maximum=-m*math.log(m)-23*r*math.log(r)-hu/2 + complexity=((hq-.5*h-.5*hu)/maximum).clamp(0,1)*(h/hu) + return torch.cat([p,(h/hu).unsqueeze(-1),complexity.unsqueeze(-1)],-1) + +def histograms(code,weights): + plain=torch.stack([(code==k).double().mean(-1) for k in range(24)],-1) + total=weights.sum(-1,keepdim=True) + weighted=torch.stack([torch.where(code==k,weights,0.).sum(-1) for k in range(24)],-1)/total.clamp_min(1e-20) + return torch.where(total>1e-20,weighted,plain),plain + +@torch.no_grad() +def weighted_ordinal_features(track,x): + with torch.autocast(x.device.type,enabled=False): + x=torch.nan_to_num(x.double().flatten(2),nan=0.,posinf=1e5,neginf=-1e5).clamp(-1e5,1e5) + x=x-x.mean(-1,keepdim=True) + if track in ('ad65','openbmi','longitudinal'):x=x-x.mean(1,keepdim=True) + power=x.square().mean(-1,keepdim=True);active=power>1e-20;x=x/power.clamp_min(1e-20).sqrt();n=x.shape[-1] + parts={k:[] for k in ['weighted','plain','shuffled']} + for lag in LAGS: + length=n-3*lag + if length<=0:raise ValueError('window too short') + samples=torch.stack([x[...,j*lag:j*lag+length] for j in range(4)],-1) + order=(samples*1e10).round().argsort(dim=-1,stable=True) + code=6*((order[...,0,None]>order[...,1:]).sum(-1))+2*((order[...,1,None]>order[...,2:]).sum(-1))+(order[...,2]>order[...,3]).long() + weights=(samples-samples.mean(-1,keepdim=True)).square().mean(-1) + weighted,plain=histograms(code,weights);shuffled=[] + for perm in permutations(n,lag): + value,_=histograms(code,weights.index_select(-1,torch.as_tensor(perm,device=x.device)));shuffled.append(value) + values={'weighted':weighted,'plain':plain,'shuffled':torch.stack(shuffled).mean(0)} + for k,v in values.items():parts[k].append(torch.where(active,summarize(v),0.)) + return {k:torch.cat(v,-1).flatten(1).float() for k,v in parts.items()} diff --git a/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/weighted_pattern_model.py b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/weighted_pattern_model.py new file mode 100644 index 0000000000000000000000000000000000000000..a42804407117ffde217e87a183fb654f662cd7ee --- /dev/null +++ b/tasks/brain-computer-interface-decoding/brain-computer-interface-decoding-astra-xhigh-1h100-48h-20261031a/submissions/S127/weighted_pattern_model.py @@ -0,0 +1,25 @@ +"""One common weighted-pattern refinement, jointly trained on five EEG tracks.""" +from multitaper_model import * +SourceHybridModel=HybridModel +FEATURE_TRACKS=('faced','openbmi','longitudinal') +class WeightedPatternReadout(nn.Module): + def __init__(self,classes,scale): + super().__init__();self.projection=nn.Linear(128,classes);nn.init.zeros_(self.projection.weight);nn.init.zeros_(self.projection.bias);self.register_buffer('output_scale',scale.detach().clone());self.register_buffer('correction_gain',torch.tensor(1.)) +class HybridModel(SourceHybridModel): + def __init__(self,weighted_pattern_refinement=False,weighted_pattern_mode='weighted',weighted_pattern_enabled=1.,**kwargs): + super().__init__(**kwargs);assert weighted_pattern_refinement and weighted_pattern_mode in ['weighted','plain','shuffled'];self.weighted_pattern_mode=weighted_pattern_mode + for t in TRACKS: + dimension=130*SPECS[t][0] if t in FEATURE_TRACKS else self.adapters[t].multitaper_projection.in_features;self.adapters[t].weighted_pattern_normalizer=Standardize(dimension);self.adapters[t].weighted_pattern_projection=nn.Linear(dimension,128) + self.backbone.weighted_pattern_encoder=nn.Sequential(nn.Linear(128,256),nn.LayerNorm(256),nn.GELU(),nn.Dropout(.3),nn.Linear(256,128),nn.LayerNorm(128));self.backbone.register_buffer('weighted_pattern_enabled',torch.tensor(float(weighted_pattern_enabled)));self.weighted_pattern_heads=nn.ModuleDict({t:WeightedPatternReadout(SPECS[t][2],self.heads[t].output_scale) for t in TRACKS}) + def weighted_pattern_features(self,t,x,features=None): + if t not in FEATURE_TRACKS:return super().multitaper_features(t,x) + from weighted_ordinal_features import weighted_ordinal_features + return weighted_ordinal_features(t,x)[self.weighted_pattern_mode] + def weighted_pattern_embedding(self,t,values): + with torch.autocast(values.device.type,enabled=False):return self.backbone.weighted_pattern_encoder(self.adapters[t].weighted_pattern_projection(self.adapters[t].weighted_pattern_normalizer(values.float()))) + def weighted_pattern_predict(self,t,values,prior,gain=None,return_standalone=False): + with torch.autocast(values.device.type,enabled=False): + h=self.weighted_pattern_heads[t];standalone=h.projection(self.weighted_pattern_embedding(t,values))*self.backbone.weighted_pattern_enabled;g=h.correction_gain if gain is None else gain;result=prior.float()+(g*h.output_scale)*standalone + return (result,standalone) if return_standalone else result + def forward(self,t,x,features=None,covariances=None,covariance_features=None): + prior=super().forward(t,x,features,covariances=covariances,covariance_features=covariance_features);return self.weighted_pattern_predict(t,self.weighted_pattern_features(t,x,features=features),prior)