Grouped nested cross-validation answers two separate questions without allowing one answer to contaminate the other:
- Model selection: which hyperparameters and design choices work best using training data alone?
- Model assessment: how well does that complete selection procedure generalise to chemically unfamiliar molecules?
For Strange Matter Engine, the unit we ultimately want to generalise to is a new molecule. Our validation design must therefore keep the same molecule—and deliberately similar chemical scaffolds—out of both sides of a training/validation boundary.
We will use chemically grouped nested cross-validation:
- every measurement belonging to the same molecule stays in one group;
- all CYP records for that molecule remain in the same fold;
- molecules sharing a Bemis–Murcko scaffold are grouped together where practical;
- outer folds estimate generalisation;
- inner folds choose hyperparameters;
- preprocessing is fitted again inside every training fold; and
- the official blinded test set remains untouched until the entire pipeline is frozen.
This design is a scientific control against memorisation and chemical leakage.
Our direct-inhibition table contains a molecular structure and potentially several CYP-specific pIC50 values. If each molecule–CYP row were split independently, one molecule could appear as:
- a CYP1A2 training record;
- a CYP2C9 training record; and
- a CYP3A4 validation record.
The validation molecule would then already be known to the model. CYP identity differs, but its atoms, bonds, scaffold, descriptors, and much of its chemical information are identical.
Let molecule
where:
-
$m$ identifies one molecule; -
$c$ identifies one CYP isoform; -
$y_{mc}$ is the measured pIC50 for molecule$m$ against CYP$c$ ; -
$\mathcal C_m$ is the set of CYP isoforms for which molecule$m$ has an observed pIC50; and -
$\mathcal O_m$ is therefore the set of all observed molecule–CYP records belonging to molecule$m$ .
Molecular grouping imposes
for exactly one fold
Keeping exact molecules together prevents identity leakage, but close analogues can still make validation unrealistically easy. Consider a medicinal-chemistry series in which compounds share the same central ring system and differ by one substituent. If members of that series appear in both training and validation, the model may interpolate within a familiar family rather than extrapolate to new chemistry.
The resulting score is useful for measuring interpolation, but it is not a strong estimate of performance on an unfamiliar scaffold.
We therefore introduce a chemical grouping function
Let
Every molecule with the same grouping scaffold enters the same fold.
A Bemis–Murcko scaffold retains the main ring systems and the linkers connecting them while removing most terminal side chains. It provides a reproducible approximation to a molecule's structural core.
For example, several compounds may have:
- the same fused bicyclic core;
- different halogen substitutions;
- different terminal alkyl groups; and
- different measured CYP inhibition.
Their complete molecular graphs are different, but their Bemis–Murcko scaffold can be the same. Placing them together prevents a validation compound from being surrounded by near-identical training analogues.
Scaffold grouping is a useful operational definition, not a perfect statement of chemical similarity. Important limitations include:
- acyclic molecules may collapse to an empty scaffold;
- scaffold definitions can group some compounds too broadly or too narrowly;
- stereochemistry and substituent effects may be lost;
- different scaffolds can still be highly similar; and
- one very common scaffold can create an unusually large group.
We will therefore record the grouping algorithm and inspect group sizes, CYP coverage, and chemical diversity before accepting any split.
In
Here
For fold
Each observation is tested once. If
Here
These are out-of-fold predictions: every prediction is made by a model that excluded the corresponding molecule group from fitting.
Suppose we try 100 combinations of:
- CA state dimension;
- atom and bond channels;
- number of generations;
- learning rate;
- transition-rule architecture;
- regularisation strength; and
- ridge penalty
$\lambda$ .
If we choose the best combination using a set of folds and quote its score on those same folds, the score benefits from repeated selection. Even if many designs are equally uninformative, one can look best by chance.
Nested cross-validation separates selection from assessment:
The outer test fold is invisible to every decision made in the corresponding outer iteration.
The accepted search budget, random sampling, promotion, and multi-seed confirmation are defined in Reproducible Hyperparameter Search.
Let the outer grouped folds be
Here
For outer iteration
- reserve
$\mathcal D^{\rm outer}_k$ as the outer test fold; - use the remaining groups as the outer training set;
- divide only that outer training set into grouped inner folds;
- evaluate each candidate configuration
$h$ across the inner folds; - choose
$h_k^*$ using the prespecified inner metric; - refit the complete pipeline on all outer-training groups using
$h_k^*$ ; and - predict the untouched outer test fold once.
Mathematically, the selected configuration is
The outer score is then
In this expression,
The final nested estimate is summarised across outer folds:
We will also report variability rather than presenting
Imagine 1,000 molecules, with multiple CYP measurements per molecule, grouped into 250 scaffold families. For a five-fold outer split:
- approximately 200 molecules' scaffold groups form each outer test fold;
- the remaining approximately 800 molecules enter inner model selection;
- a four-fold inner split compares candidate hyperparameters;
- the winning inner configuration is refitted on those 800 molecules; and
- it predicts the approximately 200 molecules in the untouched outer fold.
This is repeated five times. Every molecule eventually receives an outer prediction, but no molecule or same-scaffold group is used to select the model that predicts it.
Because group sizes and CYP measurements are unequal, exact fold sizes will differ. We will balance folds at the group level while preserving the grouping constraint.
Every operation that learns from data must be fitted using the current training portion only. This includes:
- molecular-feature scaling;
- imputation rules;
- removal of zero-variance features;
- feature selection;
- learned atom embeddings;
- graph-CA parameters
$\theta$ ; - early stopping;
- dynamical-fingerprint scaling;
- ridge coefficients
$\beta$ ; - ridge penalty selection;
- generation-count selection; and
- any calibration transformation.
For feature
Here
The validation or outer-test observations use the same
Our accepted architecture uses a shared model across CYP1A2, CYP2C9, CYP2D6, and CYP3A4. CYP identity enters as context, but molecular grouping remains the higher-level split constraint.
If molecule
We will calculate:
- an overall regression score across available molecule–CYP observations;
- a separate score for each CYP;
- the number of molecules and observations per CYP in every fold; and
- uncertainty or variability across outer folds.
A strong overall score must not hide failure on one enzyme.
For residual
Mean absolute error is
RMSE gives more influence to large errors. MAE describes the typical absolute error more robustly. Both are in pIC50 units.
An absolute pIC50 error
Thus
Correlation can be informative, but it does not replace error magnitude. A prediction can correlate with the observations while being systematically shifted or badly calibrated.
Nested cross-validation produces several selected configurations $h_1^,\ldots,h_{K_{\rm out}}^$, because each outer training set is slightly different. After the validation protocol and search space are fixed, we need a declared rule for choosing one final configuration.
A defensible procedure is:
- inspect which configurations are consistently selected or perform robustly;
- use a prespecified aggregation rule or repeat inner cross-validation on all released training data;
- choose the final hyperparameters without using blinded test labels;
- refit every learned component on the complete released training set;
- freeze preprocessing,
$\theta$ , fingerprint definitions, scaling,$\beta$ , and all hyperparameters; and - generate predictions for the official blinded test molecules.
The blinded test set is for final inference, not another round of model development.
One assignment of scaffold groups to folds can be unusually favourable or difficult. Repeating the grouped nested procedure with several deterministic seeds can measure split sensitivity.
If repetition
Here
Repetition increases computational cost substantially because every outer fold contains an inner search. We will choose the number of folds, repetitions, and search budget before examining final results.
We will explicitly test for:
- the same canonical molecule appearing in multiple folds;
- salts, tautomers, stereoisomers, or duplicated records evading identity grouping;
- the same scaffold appearing in multiple folds;
- feature scaling performed before splitting;
- early stopping based on an outer test fold;
- hyperparameters chosen from outer-fold performance;
- CYP imbalance producing folds with inadequate target coverage;
- very large scaffold groups dominating a fold;
- random seeds changed selectively after seeing results; and
- the blinded test set influencing any modelling decision.
We will save fold-assignment tables so every prediction can be traced to the model that produced it.
Grouped nested cross-validation can support the claim:
Under the declared chemical grouping and training procedure, the model generalises to held-out molecule groups with the reported error distribution.
It does not prove universal generalisation to every possible chemical series, assay, laboratory, or biological context. The claim is conditional on the dataset, endpoint definitions, grouping rule, and applicability domain.
This process makes the validation boundary part of the scientific model rather than an administrative afterthought.
- Validation and Statistics introduces generalisation, leakage, and baselines.
- Chemistry supplies the structural meaning behind chemical grouping.
- Backpropagation explains how graph-CA parameters are fitted inside each fold.
-
Ridge Regression explains the readout and inner selection of
$\lambda$ .