A unified framework for symbolic regression (SR) and multi-view symbolic regression (MvSR) designed for complex, nonlinear systems, with particular applicability to ecological datasets. The package implements a four-stage workflow: data subset generation, functional form discovery, numerical parameter optimization, and multi-objective evaluation. It provides a high-level formula-style interface that abstracts and extends multiple discovery engines: genetic programming (via PySR), Reinforcement Learning with Monte Carlo Tree Search (via RSRM), and exhaustive generalized linear model search. 'leaf' extends these methods by enabling multi-view discovery, where functional structures are shared across groups while parameters are fitted locally, and by supporting the enforcement of domain-specific constraints, such as sign consistency across groups. The framework automatically handles data normalization, link functions, and back-transformation, ensuring that discovered symbolic equations remain interpretable and valid on the original data scale. Implements methods following ongoing work by the authors (2026, in preparation).
leaf (Learning Equations for Automated Function discovery) is an R package for symbolic regression designed for ecological modelling. It discovers interpretable mathematical equations from data using a principled four-stage workflow — separating equation discovery from model evaluation — to ensure selected models are accurate, parsimonious, and generalizable.
leaf wraps powerful SR engines including PySR and RSRM, and is built around Multi-view Symbolic Regression (MvSR), which finds a single generalizable equation structure that can be fitted to multiple groups (e.g., species, sites, archipelagos) independently.
You can install leaf from CRAN with:
install.packages("leaf")
After installing, you need to install the Python backend once:
library(leaf)
leaf::install_leaf()
library(leaf)
# Initialize a symbolic regressor
regressor <- SymbolicRegressor$new(
engine = "rsrm",
loss = "MSE"
)
# Search for candidate equations
train_data <- leaf_data("eg_train")
regressor$search_equations(
data = train_data,
formula = "y ~ f(x1, x2)"
)
# Fit parameters and evaluate
regressor$fit(data = train_data)
regressor$evaluate(metrics = c("RMSE", "R2"), data = leaf_data("eg_test"))
# Inspect results
print(regressor$get_pareto_front())
S ~ f(log(Area), Age | species)See the vignettes for detailed usage:
vignette("getting_started", package = "leaf")vignette("minimal_example", package = "leaf")vignette("cross_validation", package = "leaf")vignette("MvSR", package = "leaf")A citation will be available once the accompanying paper is published.
This work was developed at INESC-ID and supported by national funds through FCT - Fundação para a Ciência e a Tecnologia, under project [REF].