(Almost) Smooth Sailing: Towards Numerical Stability of Neural Networks Through Differentiable Regularization of the Condition Number

Rossen Nenov, Daniel Haider, Péter Balázs · DOI

Abstract

Maintaining numerical stability in machine learning models is crucial for their reliability and performance. One approach to maintain stability of a network layer is to integrate the condition number of the weight matrix as a regularizing term into the optimization algorithm. However, due to its discontinuous nature and lack of differentiability the condition number is not suitable for a gradient descent approach. This paper introduces a novel regularizer that is provably differentiable almost everywhere and promotes matrices with low condition numbers. In particular, we derive a formula for the gradient of this regularizer which can be easily implemented and integrated into existing optimization algorithms. We show the advantages of this approach for noisy classification and denoising of MNIST images.

Introduction

Numerical stability is the "silent engine" of reliable machine learning. A stable model ensures that small perturbations in input—such as sensor noise or rounding errors—do not lead to disproportionately large changes in output. In linear algebra, this stability is quantified by the condition number ($\kappa$) of a matrix. A high condition number indicates an "ill-conditioned" matrix that amplifies errors, leading to unpredictable training and inference behavior.

Ideally, the condition number of a weight matrix should be close to 1, where all input directions are treated equally. However, the condition number is notoriously difficult to optimize directly because it is discontinuous and non-differentiable. While practitioners often use L2 regularization (Tikhonov regularization) as a proxy for stability, it does not guarantee a low condition number and can sometimes worsen it. This research proposes a differentiable alternative that directly targets the condition number.

Methodology

The authors introduce a novel regularizer, $r(S)$, designed as a differentiable proxy for the condition number. For a matrix $S$, the regularizer is defined as:

$$r(S) := \frac{1}{2}\|S\|_2^2 - \frac{1}{2\nu}\|S\|_F^2$$

Where $\|S\|_2$ is the spectral norm (the largest singular value), $\|S\|_F$ is the Frobenius norm, and $\nu$ is the smaller dimension of the matrix.

This approach offers three key advantages:

  1. Provable Stability: The regularizer $r(S) = 0$ if and only if the matrix is full rank and has an optimal condition number of 1.
  2. Differentiability: By utilizing the Mordukhovich subdifferential, the authors derive a gradient formula that works "almost everywhere," allowing for direct integration into standard optimizers like Adam or SGD.
  3. Guaranteed Improvement: The paper provides a mathematical proof that a gradient descent step with respect to this regularizer is guaranteed to decrease the condition number.

Experimental Results

The method was evaluated on MNIST handwritten digits corrupted with varying levels of Gaussian noise (Signal-to-Noise Ratios of $\infty$, 1, and 0.5) for both classification and denoising tasks.

Noisy Classification

In classification tasks, the proposed regularizer significantly outperformed standard training as noise levels increased. While clean-data accuracy remained high across all models, the robustness of the regularized model became evident at lower SNRs.

Table 1: Accuracy on MNIST with varying noise levels (SNR) and regularization parameters.

As shown in the table above, at an SNR of 0.5, a standard network ($\lambda=0$) achieved only 71.91% accuracy. In contrast, the network using the proposed regularizer ($\lambda=1$) reached 84.25%, demonstrating a substantial increase in robustness.

Denoising Performance

In autoencoder experiments, models trained without the stability regularizer often failed to reconstruct images under high noise conditions. This failure is attributed to weight matrices with extremely high condition numbers (often exceeding 600). The regularized models maintained condition numbers between 12 and 23, resulting in significantly clearer reconstructions.

Figure 1: Comparison of denoising performance on MNIST. Top: Noisy input. Middle: Standard reconstruction. Bottom: Reconstruction with the proposed regularizer.

Discussion and Insights

One of the most significant findings is the "L2 Trap": standard Tikhonov (L2) regularization can actually increase the condition number. Because L2 shrinks smaller singular values faster than larger ones, it can make a matrix more lopsided and numerically unstable. The proposed regularizer avoids this by explicitly promoting full-rank matrices, preventing internal representations from collapsing into lower-dimensional subspaces.

While there is a slight trade-off—using the regularizer on perfectly clean data may lower accuracy by 1-2%—it prevents the model from failing catastrophically in noisy real-world environments.

Limitations and Future Work

Calculating the spectral norm and its gradient requires computing the largest singular value (SVD), which may be computationally expensive for very large models like LLMs. Future research could explore extending this approach to structured tensors in convolutional or attention layers and developing automated methods for tuning the regularization hyperparameter $\lambda$.

Summary updated

BibTeX
@inproceedings{nenov2024almost,
  author = {Rossen Nenov and Daniel Haider and Péter Balázs},
  title = {{(Almost) Smooth Sailing: Towards Numerical Stability of Neural Networks Through Differentiable Regularization of the Condition Number}},
  booktitle = {Differentiable Almost Everything @ ICML},
  year = {2024},
  url = {https://openreview.net/forum?id=OJkyvJXk2B},
}
Figure