Interpretable Machine Learning for Science with PySR and SymbolicRegression.jl

Miles D. CranmerarXiv 2023 · DOI

Introduction

While deep learning has revolutionized predictive modeling, its "black-box" nature remains a significant hurdle for the sciences. Physicists and researchers require more than just accurate predictions; they seek the underlying mathematical laws—such as Kepler’s Third Law ($P^2 \propto a^3$)—that govern natural phenomena. This task, known as Symbolic Regression (SR), is notoriously difficult (NP-hard) because the space of possible mathematical expressions grows exponentially with the number of variables and operators.

PySR (and its backend SymbolicRegression.jl) is a high-performance, open-source library designed to bridge this gap. By combining a flexible Python frontend with a blazing-fast Julia backend, it uses evolutionary algorithms to discover human-interpretable equations from raw, noisy data, outperforming many modern deep learning approaches in recovering historical scientific laws.

Methodology

PySR employs a multi-population evolutionary algorithm with several key technical innovations designed for scientific discovery:

  • The Evolve-Simplify-Optimize Loop: Unlike standard genetic algorithms, PySR periodically simplifies expressions using algebraic rules and explicitly optimizes numerical constants (such as the gravitational constant $G$) using classical optimization techniques like BFGS.
  • Multi-Population Migration: To prevent premature convergence and explore the search space effectively, the algorithm maintains independent "islands" of expressions that periodically exchange individuals.
  • High-Performance Backend: Written in Julia, the backend uses Just-In-Time (JIT) compilation to fuse user-defined operators into SIMD (Single Instruction, Multiple Data) kernels, ensuring that custom operators are as fast as built-in ones.
  • Algorithmic Refinements: PySR utilizes age-regularized evolution to prevent the population from being dominated by "old" local minima and adaptive parsimony to penalize complexity based on the current population's distribution.
The Evolve-Simplify-Optimize Loop in PySR
Multi-population evolution via island migration

Empirical Evaluation

The authors introduced EmpiricalBench, a benchmark specifically designed for scientific SR. Unlike synthetic benchmarks, EmpiricalBench focuses on nine historical laws (including Hubble’s Law, Newton’s Gravitation, and the Ideal Gas Law) using original experimental data or data with realistic noise and unknown constants.

Key Results

  • Benchmark Performance: PySR successfully rediscovered 7 out of 9 laws in EmpiricalBench. It achieved a perfect 5/5 recovery rate on most tasks, while competing methods like DSR or EQL often failed or succeeded only sporadically.
  • Heuristics vs. Deep Learning: Surprisingly, "untrained" algorithms based on evolution and heuristics (PySR, Operon) significantly outperformed "modern" deep learning approaches like SR-Transformers. Deep learning models often struggle with the "long tail" of unique functional forms found in real science.
  • Scalability: The software can distribute populations across thousands of cores, making it one of the most scalable SR tools available for high-dimensional data.

Discussion and Future Work

Performance in SR is not just a matter of convenience; the speed of the Julia backend allows the algorithm to explore orders of magnitude more expressions, which is often the deciding factor in discovering a law. However, limitations remain: PySR failed to recover complex expressions like Planck’s Law and the Rydberg formula, which involve intricate ratios of constants.

Future development aims to explore hybrid methods—using deep learning to distill high-dimensional data into lower-dimensional representations for symbolic searching—and incorporating physical priors such as dimensional analysis and symmetry constraints directly into the search process.

Summary updated

BibTeX
@misc{cranmer2023interpretable,
  author = {Miles D. Cranmer},
  title = {{Interpretable Machine Learning for Science with PySR and SymbolicRegression.jl}},
  year = {2023},
  eprint = {2305.01582},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2305.01582},
}
Figure