Results Manager
Accumulation of cross-validation results.
ResultsManager is a preallocated store: the pipeline writes per-fold edges,
metrics, predictions and network strengths into fixed-shape tensors, then
aggregates them into the CSV/npy files the report reads.
It holds no statistics beyond means and argmax -- the permutation inference
that used to live in this file is now in inference.py.
ResultsManager
A class to handle the aggregation, formatting, and saving of results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
str
|
Directory where results will be saved. |
required |
available_models
|
list of str
|
Names of the model variants this run defines. Persisted to
|
None
|
aggregate_inner_folds()
Compute the increment model (full - covariates) across all inner folds.
The per-fold means are read directly by find_best_params, so nothing
else needs to be aggregated or saved here.
calculate_edge_stability(write=True, best_param_id=None)
Calculate and save edge stability.
for the chosen hyperparameter of each run — read straight from the CPU
fold-sum accumulator (cv_edge_sum), so this never touches the compute
device. stability_edges.npy ([Nodes, Nodes, 2, Runs]) is always
written; the per-fold edges.npy is written only when this manager
retained the per-fold masks (the real run — see store_fold_edges).
Both node×node arrays are built on the CPU.
Args: write: whether to save the .npy files. best_param_id: None (assume param index 0 for every run), a single int/0-d tensor (same param for every run), or an array-like of length n_runs (one winning param per run).
load_cv_results(folder)
staticmethod
Load cross-validation results from a CSV file.
:param folder: Directory containing the results file. :return: DataFrame with the loaded results.
save_network_strengths()
Save network strengths to CSV.
save_predictions()
Save predictions to CSV, sorted by sample index. This is the single
writer of cv_predictions.csv (calculate_final_cv_results only
concatenates the per-fold frames into self.cv_predictions).
store_edges(param_idx, fold_idx, edges_tensor, run_idx=slice(None))
Store the edge masks for the positive and negative networks: move the mask to the CPU edge store (freeing VRAM) and accumulate the fold-sum used for stability. The per-fold mask itself is retained only when this manager was built with store_fold_edges=True.
Args:
param_idx: index (int or slice) of the current parameter(s).
fold_idx: index (int) of the current fold.
edges_tensor: boolean tensor shaped to match
cv_edges[:, :, param_idx, fold_idx, run_idx],
i.e. [Features, 2, (Params,) Runs]. Dimension 1 must
be [Positive, Negative].
run_idx: index (int or slice) of the current run(s)/permutation(s).
store_metrics(param_idx, fold_idx, metrics_tensor, run_idx=slice(None))
Stores a batch of metrics returned by FastCPMMetrics.
Args: param_idx: Index (int or slice) of the current parameter configuration(s). fold_idx: Index (int or slice) of the current CV fold(s). metrics_tensor: Tensor [Metrics, Models, Networks, (Params,) (Folds,) Runs], matching whatever param_idx/fold_idx/run_idx slice out. run_idx: Index (int or slice) of the current run(s)/permutation(s). Defaults to every run (today's behaviour).