A feature is compared with its neighbours
Two values, then a learned transformation
The final outputs therefore have mean and variance . Calling the entire layer's output “zero mean and unit variance” misses the learned affine transformation. Even before that transformation, positive makes the batch variance of equal to , rather than exactly one.
A zero-variance group is different from division by zero: with positive epsilon, centring makes every value zero and the final output is . A library may reject a training input with only one value per feature, but the formula itself does not produce an infinite normalised value in that case.
The model has statistical state
In common implementations, inference substitutes stored training estimates for the current batch's statistics. A prediction can then be evaluated without depending on which other observations happen to arrive alongside it. Those stored means and variances belong in the saved model checkpoint, together with the learned parameters.
track_running_stats=False, PyTorch also uses batch statistics during evaluation. “Evaluation mode always uses running statistics” is therefore too broad.These choices can change outputs even when the learned weights are identical. Record the normalisation configuration and framework version when reproducing a result; do not reconstruct inference by copying the last training batch's mean and variance.
A batching choice can become a timing assumption
Suppose a model scores securities at different times during a trading day. If its normalisation statistics combine an early observation with later observations, the early score depends on information unavailable at its intended decision time. No future target label is needed for this problem: the activations alone supply the extra information. This is a form of preprocessing leakage when the evaluation claims to reproduce those earlier decisions.
A contemporaneous cross-section can be legitimate when every constituent input is available before the joint decision. The research contract must say whether predictions are made jointly or sequentially. Temporal or cross-sectional batching is not automatically safe or automatically invalid.
For an ordinary held-out evaluation, keep the validation period out of updates to running statistics and use the inference behaviour intended for deployment. Leaving BN in training mode can both make predictions depend on validation-batch composition and update the stored state with validation observations. Disabling gradient calculation alone does not select inference behaviour. Any deliberate online adaptation needs a separately specified, time-consistent evaluation.
Small or highly correlated batches can give noisy or unrepresentative statistics; increasing their size does not create independent market observations. Stored statistics can also become unrepresentative after a regime change. There is no universal best batch size, and easier optimisation does not establish better out-of-sample trading performance.
What the mechanism does—and what it explains
Sources
- Ioffe and Szegedy (2015), Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift, §§2–3.2 and Algorithms 1–2.
- Keras, BatchNormalization layer: training, inference and moving-statistic definitions.
- PyTorch, BatchNorm1d: current upstream documentation and implementation.
- Keras, LayerNormalization layer: per-example normalisation axes.
- Santurkar et al. (2018; revised 2019), How Does Batch Normalization Help Optimization?, §§2–3.1.