"""Tabular baselines on demographic + morphometric features. Allowed features (NO CDR, NO MMSE — those are label-leaking): age, sex, education, ses, etiv, nwbv, asf. XGBoost is used both as a main baseline (B0) and as the shortcut/confound probe (age-only, demographic-only, full-structured). """ from __future__ import annotations import numpy as np import torch import torch.nn as nn FEATURES_FULL = ["age", "sex", "education", "ses", "etiv", "nwbv", "asf"] FEATURES_DEMO = ["age", "sex", "education", "ses"] FEATURES_AGE = ["age"] def make_xgb(n_classes: int = 3, seed: int = 0): """Return an XGBoost classifier configured for small-n multiclass.""" from xgboost import XGBClassifier return XGBClassifier( n_estimators=300, max_depth=3, learning_rate=0.05, subsample=0.8, colsample_bytree=0.8, reg_lambda=1.0, objective="multi:softprob", num_class=n_classes, eval_metric="mlogloss", tree_method="hist", random_state=seed, n_jobs=4, ) class TabularMLP(nn.Module): """Neural tabular baseline (B1) and the metadata branch reference.""" def __init__(self, n_features: int = 7, n_classes: int = 3, hidden: int = 128, dropout: float = 0.3): super().__init__() self.net = nn.Sequential( nn.Linear(n_features, 64), nn.GELU(), nn.Dropout(dropout), nn.Linear(64, hidden), nn.GELU(), nn.LayerNorm(hidden), nn.Dropout(dropout), nn.Linear(hidden, n_classes), ) def forward(self, tab: torch.Tensor, *_unused) -> torch.Tensor: return self.net(tab)