Learn R Programming

EmpiricalDynamics (version 0.1.2)

symbolic_search: Symbolic Regression and Equation Discovery

Description

Functions for discovering functional forms through symbolic regression using genetic algorithms. Interfaces with Julia's SymbolicRegression.jl for advanced search, with fallback to R-native methods for simpler cases.

Discovers the functional form of a differential equation from data using genetic/evolutionary algorithms. Returns a Pareto front of equations trading off complexity against fit.

Usage

symbolic_search(
  target,
  predictors,
  operators = NULL,
  constraints = NULL,
  n_runs = 5,
  complexity_penalty = 0.05,
  parsimony_pressure = c("adaptive", "constant", "none"),
  backend = c("r_genetic", "julia", "r_exhaustive"),
  julia_options = NULL,
  weights = NULL,
  verbose = TRUE
)

Value

An object of class "symbolic_search_result" containing:

  • pareto_front: Data frame of Pareto-optimal equations

  • all_equations: All discovered equations

  • best_by_complexity: Best equation at each complexity level

  • run_diagnostics: Information about each run

Arguments

target

Numeric vector of target values (typically derivatives).

predictors

Data frame of predictor variables.

operators

List specifying allowed operators:

  • binary: c("+", "-", "*", "/")

  • unary: c("exp", "log", "sqrt", "inv", "square")

  • custom: Custom function names (must be defined)

constraints

List of constraints:

  • forced: Formula of terms that must appear

  • forbidden: Formula of terms that must not appear

  • max_complexity: Maximum expression complexity

n_runs

Number of independent runs for robustness.

complexity_penalty

Penalty per unit complexity.

parsimony_pressure

Type of parsimony: "constant", "adaptive", or "none".

backend

Computation backend: "julia", "r_genetic", or "r_exhaustive".

julia_options

List of options passed to SymbolicRegression.jl.

weights

Optional weight vector for weighted regression.

verbose

Print progress messages?

Examples

Run this code
# \donttest{
# Toy example using R-native exhaustive search (fastest for demo)
data <- data.frame(
  x = seq(1, 10, length.out = 20),
  y = seq(1, 10, length.out = 20)^2 + rnorm(20, sd = 0.1)
)

# Discover y ~ x^2
results <- symbolic_search(
  target = data$y,
  predictors = data["x"],
  backend = "r_exhaustive"
)

print(head(results$pareto_front))
# }

Run the code above in your browser using DataLab