SR-RS: A portable symbolic regression engine in Rust, patterned after Cranmer's SymbolicRegression.jl.
Go to file
Diane Blackwood 591536240d Initial repo files from ChatGPT 2025-09-24 22:01:21 -04:00
.github/workflows Initial repo files from ChatGPT 2025-09-24 22:01:21 -04:00
bindings Initial repo files from ChatGPT 2025-09-24 22:01:21 -04:00
docker Initial repo files from ChatGPT 2025-09-24 22:01:21 -04:00
docs Initial repo files from ChatGPT 2025-09-24 22:01:21 -04:00
examples Initial repo files from ChatGPT 2025-09-24 22:01:21 -04:00
src Initial repo files from ChatGPT 2025-09-24 22:01:21 -04:00
.gitignore Initial repo files from ChatGPT 2025-09-24 22:01:21 -04:00
Cargo.toml Initial repo files from ChatGPT 2025-09-24 22:01:21 -04:00
Makefile Initial repo files from ChatGPT 2025-09-24 22:01:21 -04:00
README.md Initial repo files from ChatGPT 2025-09-24 22:01:21 -04:00
docker-compose.yml Initial repo files from ChatGPT 2025-09-24 22:01:21 -04:00

README.md

sr-rs

SR-RS: A portable symbolic regression engine in Rust, patterned after Cranmer's SymbolicRegression.jl.

Rust symbolic regression with:

  • 🦀 Core in Rust (fast evaluators, SIMD where available)
  • 🐍 Python bindings (PyO3, scikit-learn-style API)
  • 🌐 WASM target (wasm-bindgen, in-browser demo)
  • ♻️ Rewrite-based simplification (optional egg integration)
  • 🎯 Multi-objective search (error vs. complexity), constant-fitting, protected operators, and export to SymPy/LaTeX

Quick start

Native (Rust)

cargo run --example quickstart


Python
# inside container or host with Rust toolchain
make py
python -c "from symreg_rs import SymbolicRegressor; print(SymbolicRegressor().fit_predict([[0.0],[1.0]], [0.0,1.0]))"
WebAssembly demo
make wasm && make demo
# open http://localhost:8000/index.html
Design highlights

Expression AST with typed operations and arity checks

Fast vectorized evaluator (feature simd)

GP loop with tournament selection, variation (mutate/crossover), and Pareto archiving

Constant optimization via LM/Argmin (optional)

Simplification via identities + (optional) egg equality saturation

See docs/DESIGN.md and docs/PORTING.md for details and porting guidance.

9) Usage snippets
Rust
use symreg_rs::{GpConfig, SymbolicRegressor};
let x = vec![vec![0.0], vec![1.0]];
let y = vec![0.0, 1.0];
let sr = SymbolicRegressor::default();
let expr = sr.fit(&x, &y);
Python
from symreg_rs import PySymbolicRegressor as SR
sr = SR(pop_size=256, gens=20, num_vars=1)
preds = sr.fit_predict([[0.0],[1.0]],[0.0,1.0])
10) Next steps (recommended)

Wire up constant fitting (Argmin LM) in fitness.rs.

Add exporters: to SymPy string and LaTeX.

Implement subtree crossover/mutation and depth/size limits.

Add vectorized evaluator (std::simd) + rayon parallelism.

Optional: integrate egg for global simplification.

This scaffold should compile with minor tweaks (crate names/versions). From here, we can iterate on the porting branch to reach feature parity with your preferred SR baseline.