ageas.Deck
- class ageas.Deck(squad: dict, n_dataloader_workers: int = 10, accelerator: str = 'cpu', cuda_devices: list = None)
Bases:
HangarSortie deck that trains, evaluates, and explains a squad of units.
Inherits from
Hangarand adds operational logic on top of the candidate squad: aTrainer_Makerto launch the correct trainer per model type, a per-unit report ledger, and thedebrief()aggregation that combines model-wise explanations weighted by their validation/test metrics.- Variables:
squad – Mapping
unit_id -> Unitfor the active operating units.trainer_maker – Factory that produces trainer-model pairs.
n_dataloader_workers – Worker count for prediction/test dataloaders.
report – Per-unit
{'vali': [], 'test': []}metric ledger.accelerator – Default accelerator (
'cpu'or'cuda').cuda_devices – Resolved GPU device indices (
Nonefor CPU).
- __init__(squad: dict, n_dataloader_workers: int = 10, accelerator: str = 'cpu', cuda_devices: list = None) None
Initialize a Deck.
- Parameters:
squad – Mapping
unit_id -> Unitto operate on, typically produced bysortie_generate().n_dataloader_workers – Number of worker processes for the prediction/test dataloaders.
accelerator – Default accelerator (
'cpu'or'cuda') the deck will request from each unit at sortie time.cuda_devices – Optional list of GPU device indices to bind. When
accelerator='cuda'and this isNone, all visible devices are used.
- debrief(exp_dataset: torch.utils.data.Dataset = None, operation: str = 'trail', mission: str = 'final', monitor_type: str = 'min', monitor_metric: str = 'vali.CEL', verbose: bool = True, **kwargs) pandas.DataFrame
Aggregate per-class explanation scores across the squad.
Each unit’s
explainmethod is called onexp_datasetand the resulting per-class score table is weighted by that unit’s metric value (monitor_metric). The weight direction depends onmonitor_type: lower-is-better metrics divide by the score, higher-is-better metrics multiply.- Parameters:
exp_dataset – Dataset to explain. Forwarded unchanged to every unit’s
explainmethod.operation – Operation name used to look up the metric in
unit.report.mission – Mission name (e.g.
'final'or'fold_1') used inside the operation’s report.monitor_type –
'min'for lower-is-better metrics (divide-by-weight),'max'for higher-is-better metrics (multiply-by-weight).monitor_metric – Dotted metric name (e.g.
'vali.CEL','test.accuracy').verbose – If
True, print per-unit weights and the assembled answer.kwargs – Additional keyword arguments forwarded to each
unit.model.explaincall.
- Returns:
The integrated per-class score table. Columns ending in
_Stdare dropped from the final answer.
- make_report(squad: dict = None) dict
Initialize an empty report ledger for a squad of units.
- Parameters:
squad – Mapping
unit_id -> Unitfor which to allocate report slots.Noneuses the deck’s current squad.- Returns:
A nested dict
{unit_id: {'vali': [], 'test': []}}.
- property ops_reports: dict
Aggregate per-operation reports across the entire squad.
Walks the per-unit
unit.reportledger and reshapes it into a nested structure:{operation: {mission: {metric_type: {metric_name: {unit_id: [values]}}}}}
that is convenient for downstream summary plots.
- Returns:
The merged report tree described above.
- predict(query_dataset: torch.utils.data.Dataset = None, batch_size: int = 10, num_workers: int = 1) tuple
Ensemble-predict by averaging probabilities across the squad.
Each unit produces softmax outputs on
query_datasetwhich are averaged uniformly across all units in the squad.- Parameters:
query_dataset – Dataset to score. Each item must yield
(x, y)tuples.batch_size – Batch size for the prediction dataloader.
num_workers – Number of dataloader workers.
- Returns:
Tuple
(all_preds, all_labels)whereall_predsis the averaged probability matrix andall_labelsis the concatenated label tensor in the same order.
- sortie(train_data: torch.utils.data.Dataset, vali_data: torch.utils.data.Dataset, n_classes: int, fea_names: pandas.Index, test_dataset: torch.utils.data.Dataset = None, report: dict = None, save_model: bool = False, save_trainer: bool = False, verbose: bool = True) dict
Train every unit in the squad on a single fold and collect metrics.
Each unit is “spiked” to verify its accelerator, then trained via the appropriate trainer (Lightning, scikit-learn, or XGBoost). Validation metrics are read from the trainer’s callback metrics and an optional test pass is launched on
test_dataset.- Parameters:
train_data – Training split for this sortie.
vali_data – Validation split for this sortie.
n_classes – Number of label classes in the task.
fea_names – Feature names (typically gene symbols/Ensembl IDs).
test_dataset – Optional held-out test split. If provided, each model is also evaluated on it after training.
report – Existing report dict to append to.
Noneuses the deck’s ownself.reportledger.save_model – If
True, retain the trained model on the unit.save_trainer – If
True, retain the trainer object on the unit.verbose – If
True, print per-unit training and evaluation traces.
- Returns:
The updated report mapping
unit_idto lists of validation and test metric snapshots.
- squad_update(unit_ids: list) None
Restrict the squad and report ledger to a subset of unit IDs.
- Parameters:
unit_ids – Whitelist of unit IDs to keep. All other units are dropped from both
self.squadandself.report.