Abstract
Symbolic Regression (SR) is the task of identifying a mathematical expression that best describes the relationship within a dataset. While traditional Genetic Programming (GP) methods are effective, they are computationally expensive and lack generalizability across different problems. Recent transformer-based approaches offer speed but often decouple symbolic structure from numerical constant optimization, leading to suboptimal fits. We introduce SymFormer, a novel transformer architecture that predicts symbols and constants concurrently. By integrating a dual-head decoder and a hybrid inference strategy involving local gradient descent, SymFormer achieves state-of-the-art performance on standard benchmarks with inference times orders of magnitude faster than GP-based methods.
Introduction
Symbolic Regression (SR) represents a "holy grail" in data modeling, aiming to discover interpretable mathematical formulas from raw $(x, y)$ data points. Unlike "black-box" neural networks, SR produces explicit expressions that can reveal underlying physical laws. Historically, this field has been dominated by Genetic Programming (GP), which evolves populations of formulas. However, GP is slow and requires a fresh start for every new dataset.
Recent advancements have leveraged Transformers to treat SR as a sequence-to-sequence problem. While fast, these models typically predict only the "skeleton" of a formula (e.g., $C \cdot \sin(x)$), requiring separate, often difficult, optimization to find the constant $C$. SymFormer addresses this by treating constants as primary outputs during the autoregressive generation process.
Methodology
SymFormer utilizes a specialized architecture designed to bridge discrete symbol prediction and continuous regression.
Architecture
The model employs a "Set Transformer" encoder to process an arbitrary number of input points via cross-attention. The autoregressive decoder features two distinct heads:
- Classification Head: Predicts the next mathematical operator or variable (e.g.,
+,sin,x). - Regression Head: Predicts the numerical value if the classification head identifies a constant.
Constant Handling and Hybrid Inference
To manage constants across multiple scales, SymFormer uses a scientific-like notation, predicting mantissa and exponent separately. During inference, the model generates multiple candidate formulas. The predicted constants provide a "warm start" for a local gradient descent search (using the BFGS algorithm), allowing for rapid fine-tuning of the numerical values to achieve a precise fit.
Experimental Evaluation
SymFormer was trained on a massive synthetic corpus:
- Univariate Dataset: 130 million single-variable equations.
- Bivariate Dataset: 100 million two-variable equations.
Equations were generated via random expression trees and simplified using SymPy. Evaluation was conducted on standard SR benchmarks, including Nguyen, Koza, Keijzer, and Livermore, which feature diverse physical and mathematical functions.
Results and Discussion
SymFormer demonstrates significant improvements in both accuracy and efficiency.
Accuracy and Generalization
The model achieved a perfect $R^2$ score of 1.0000 on several benchmarks where previous state-of-the-art models struggled. Qualitatively, the model often discovers expressions mathematically equivalent to the ground truth, even if structured differently (e.g., recognizing $- \ln(x) = \ln(x^{-1})$). Furthermore, SymFormer shows robust "out-of-domain" performance, maintaining accuracy on data points far outside the training range.
Speed
A key advantage of SymFormer is its inference speed. While GP methods may take minutes or hours to converge, SymFormer generates accurate formulas in seconds, making it suitable for real-time applications.
Conclusion
SymFormer represents a significant step forward in symbolic regression by integrating constant regression directly into the transformer architecture. By providing a "warm start" for numerical optimization, it overcomes the limitations of previous skeleton-based models. Future work will focus on scaling the architecture to higher-dimensional problems, improving robustness to varying input scales, and expanding the mathematical vocabulary.
Summary updated