Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

DeepPySR

DeepPySR discovers symbolic equations from data. It extends the SymbolicRegression.jl engine with multi-layer symbolic regression, dynamic variable pruning, and adaptive parsimony — making it practical on high-dimensional, noisy datasets.


Contents


Features

Feature Description
Multi-layer Symbolic Regression Discovers hierarchical equations: $y = f(g(X))$ across multiple layers
Dynamic Variable Pruning Automatically eliminates irrelevant features during search
Adaptive Parsimony Scaling Prevents expression bloat; forces exploration of diverse sizes
Pareto Frontier Selection Balances accuracy vs. complexity; tune with pareto_r2_weight and pareto_lambda
Visualisation Plot discovered hierarchies as dependency graphs or circular maps
scikit-learn Compatible fit / predict interface; works in standard ML pipelines
SymPy Output Every discovered equation is available as a human-readable SymPy expression

Installation

1. Install Julia (required)

curl -fsSL https://install.julialang.org | sh

Verify: julia --version (requires ≥ 1.9).

2. Install the Python package

# From source (development install)
git clone https://github.com/ICRAR/deeppysr.jl.git
cd deeppysr.jl
pip install -e .

First-run note

The first import deeppysr triggers Julia precompilation (3–10 min, one-time only). Subsequent imports start in seconds.

python -c "import deeppysr"   # pre-warm the cache

See INSTALL.md for troubleshooting and Docker setup.


Python Quickstart

Standard Regression (PySRRegressor)

PySRRegressor searches for a single symbolic equation $y = f(X)$.

import numpy as np
from deeppysr import PySRRegressor

X = np.random.randn(200, 5).astype(np.float32)
y = 2 * np.cos(X[:, 3]) + X[:, 0] ** 2 - 2

model = PySRRegressor(
    binary_operators=["+", "-", "*", "/"],
    unary_operators=["cos", "exp", "sin"],
    niterations=60,
    populations=20,
    maxsize=20,
    variable_names=["a", "b", "c", "d", "e"],
)
model.fit(X, y)

# View the full Pareto front
print(model.equations_[["complexity", "loss", "sympy_format"]])

# Best equation as a SymPy expression
print(model.sympy())          # e.g.  2*cos(d) + a**2 - 2

# Predict
y_pred = model.predict(X)

Multi-layer Regression (DeepPySR)

DeepPySR stacks symbolic regression across multiple layers to discover hierarchical relationships such as:

$$z = g(x_1, x_2) \qquad y = f(z, x_3)$$

import numpy as np
from deeppysr import DeepPySR

X = np.random.randn(300, 4).astype(np.float32)
# Hidden structure: z = x1² + x2,  y = sin(z) + x3/(x4+1)
z = X[:, 0] ** 2 + X[:, 1]
y = np.sin(z) + X[:, 2] / (X[:, 3] + 1)

model = DeepPySR(
    max_layers=2,
    binary_operators=["+", "-", "*", "/"],
    unary_operators=["sin", "cos", "sqrt"],
    niterations=60,
    pareto_r2_weight=2.0,
    pareto_lambda=0.005,
    variable_names=["x1", "x2", "x3", "x4"],
)
model.fit(X, y)

print(model.sympy())      # discovered layer formulas
y_pred = model.predict(X)

Accuracy vs. Simplicity

Both PySRRegressor and DeepPySR expose a Pareto trade-off between accuracy and equation complexity via two parameters:

Parameter Effect
pareto_r2_weight Higher → favour accuracy
pareto_lambda Higher → favour simplicity
# Prioritise accuracy
model = DeepPySR(pareto_r2_weight=10.0, pareto_lambda=0.0001)

# Prioritise simplicity
model = DeepPySR(pareto_r2_weight=1.0,  pareto_lambda=0.01)

Visualisation

# Dependency graph (requires matplotlib + networkx)
model.plot("hierarchy.png")

# Circular dependency map
model.plot_circle("circle.png")

# Save discovered relationships to CSV
model.save_relationships("relationships.csv")

Example Notebooks

The examples/notebooks/ directory contains four runnable Jupyter notebooks:

Notebook What it shows
01_feynman_tests.ipynb Recover Feynman physics equations (Coulomb, relativistic momentum, Boltzmann atmosphere) vs Random Forest / Gradient Boosting
02_bodyfat_dataset.ipynb Predict body fat % — compare against Linear, Ridge, Lasso, RF, GBM; Pareto front plot
03_classification_tests.ipynb Symbolic classification on Iris, Breast Cancer, Two Moons; decision boundary plots
pip install matplotlib networkx scipy jupyter
jupyter notebook examples/notebooks/

Julia Quickstart

DeepPySR.jl can also be used directly from Julia via the MLJ interface.

using Pkg; Pkg.add("DeepPySR")

import DeepPySR: SRRegressor
import MLJ: machine, fit!, predict, report

X = (a = rand(500), b = rand(500))
y = @. 2 * cos(X.a * 23.5) - X.b ^ 2 + randn(500) * 1e-3

model = SRRegressor(
    niterations=50,
    binary_operators=[+, -, *],
    unary_operators=[cos],
)
mach = machine(model, X, y)
fit!(mach)
report(mach)          # view discovered equations
predict(mach, X)      # make predictions

Low-level interface

import DeepPySR: Options, equation_search, calculate_pareto_frontier

X = randn(2, 100)
y = 2 * cos.(X[2, :]) + X[1, :] .^ 2 .- 2

options = Options(
    binary_operators=[+, *, /, -],
    unary_operators=[cos, exp],
    populations=20,
)

hall_of_fame = equation_search(X, y, niterations=40, options=options,
                               parallelism=:multithreading)

dominating = calculate_pareto_frontier(hall_of_fame)

Key Parameters

These apply to both PySRRegressor and DeepPySR (passed through as **kwargs).

Parameter Default Description
binary_operators ["+","*","/","-"] Allowed binary operations
unary_operators ["cos","exp"] Allowed unary operations
niterations 100 Number of evolution iterations
populations 31 Number of independent populations
maxsize 30 Maximum expression tree size
parsimony 0.0 Static complexity penalty
adaptive_parsimony_scaling 1040.0 Dynamic bloat control
variable_prune_start 50 Iteration to begin feature pruning
variable_prune_max 0.6 Maximum fraction of features to prune
extra_constants None Named constants to inject ("pi", "e", "G", …)
warm_start False Resume search from previous fit
parallelism None "multithreading" or "multiprocessing"
timeout_in_seconds None Hard wall-clock limit

DeepPySR-specific:

Parameter Default Description
max_layers 1 Maximum number of symbolic layers
pareto_r2_weight 1.0 Weight on R² in Pareto score
pareto_lambda 0.001 Complexity penalty in Pareto score
stopping_score 2 Stop a layer search when score exceeds this
output_dir "outputs/deepPySR" Where to save intermediate results

Citation

If you use DeepPySR in your research, please cite both DeepPySR and the underlying PySR / SymbolicRegression.jl engine it builds on:

@misc{chen2026deeppysr,
  title  = {DeepPySR - A Symbolic Regression Framework with Dynamic Pruning, Pareto Selection, and Hierarchical Composition for Real-World Scientific Discovery},
  author = {Chen, Fuling and Vinsen, Kevin and Melton, Phillip and Huang, Rae-Chi},
  year   = {2026},
  note   = {arXiv preprint, URL to be added}
}

@article{cranmerInterpretableMachineLearning2023,
  title   = {Interpretable Machine Learning for Science with PySR and SymbolicRegression.jl},
  author  = {Miles Cranmer},
  journal = {arXiv preprint arXiv:2305.01582},
  year    = {2023}
}

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages