Linearly Constrained Neural Networks

Johannes N. Hendriks, Carl Jidling, Adrian Wills, Thomas B. SchönarXiv 2020

Abstract

Neural networks are powerful function approximators but often struggle to respect fundamental physical laws when trained on limited data. This paper presents a framework for "hard-coding" linear physical constraints—such as divergence-free or curl-free conditions—directly into the network architecture. By defining the output field as a linear transformation of a latent potential field, we ensure that every prediction is physically valid by construction. Our results show that this approach significantly reduces the required training data and eliminates the trade-off between predictive accuracy and physical consistency.

Introduction

In physical modeling, neural networks often produce predictions that are statistically accurate but physically impossible. For instance, a model predicting fluid flow might create "ghost" sources or sinks, violating the principle of mass conservation. Traditionally, researchers have used "soft constraints" by adding penalty terms to the loss function. However, these methods require delicate hyperparameter tuning and only enforce constraints at specific training points, allowing the model to "cheat" in unobserved regions.

Methodology: Hard-Coding Physics

The proposed method shifts from soft penalties to architectural guarantees. Instead of training a network to output a target vector field $f$ directly, we model $f$ as a linear transformation of an underlying potential field $g$:

$$f = \mathcal{G}_x[g]$$

Here, $g$ is the output of a standard neural network, and $\mathcal{G}_x$ is a linear operator designed such that the physical constraint $\mathcal{C}_x[f] = 0$ is satisfied for any $g$. Because $\mathcal{C}_x[\mathcal{G}_x[g]] = 0$ is a mathematical identity, the network is structurally incapable of producing a physically invalid output.

Comparison of standard (a) and constrained (b) neural network architectures. The constrained version introduces a mapping function $\mathcal{G}_x$ to ensure output validity.

The transformation $\mathcal{G}_x$ can be derived from known physical relations (e.g., using a scalar potential for curl-free fields) or constructed systematically using an "Ansatz method" for more complex linear constraints.

Experimental Evaluation

The authors evaluated the constrained architecture across three scenarios: a synthetic 2D divergence-free field, a simulated strain field for a cantilever beam, and a real-world magnetic field dataset.

Visualization of the real-world magnetic field dataset, showing 16,782 observations collected in a distorted indoor environment.

In the divergence-free study, the constrained model achieved the same accuracy with 500 samples that a standard network required 4,000 samples to reach. For the cantilever beam problem, the constrained approach reduced the Root Mean Square Error (RMSE) by an order of magnitude ($5.52 \times 10^{-5}$ vs $67.7 \times 10^{-5}$). On the real-world magnetic field data, the constrained model not only achieved lower validation error but also maintained physical validity in "void" regions where training data was absent.

Discussion and Conclusion

A key insight from this work is the reduction of the hypothesis space. By restricting the network to physically valid functions, the model can focus its learning capacity on the specific nuances of the data rather than learning the laws of physics from scratch.

However, the method has limitations. It is currently restricted to linear operator constraints and requires prior knowledge of the system's physics. Additionally, if the transformation $\mathcal{G}_x$ involves higher-order derivatives, activation functions like ReLU must be avoided in favor of smooth functions like tanh to ensure derivatives are non-zero. Despite these constraints, the framework represents a significant step toward robust, physics-aware machine learning.

Summary updated

BibTeX
@misc{hendriks2020linearly,
  author = {Johannes N. Hendriks and Carl Jidling and Adrian Wills and Thomas B. Schön},
  title = {{Linearly Constrained Neural Networks}},
  year = {2020},
  eprint = {2002.01600},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2002.01600},
}
Figure