Skip to contents

Regularized evolution of prefix expression trees over + - * / and chosen unary operators: tournament selection on loss + parsimony x size (mean squared error loss), subtree crossover or one mutation, rejection above maxsize, replacement of the oldest member; a hall of fame keeps the best expression of each size, its Pareto front carries PySR's score -d log(loss) / d size and best is the top-scoring member within 1.5 times the smallest loss. Philox draws; identical to the Python arm morie.fn.symreg.

Usage

PysrRegression(
  X,
  y,
  unary_operators = character(0),
  niterations = 30L,
  population_size = 60L,
  maxsize = 20L,
  tournament_size = 8L,
  crossover_probability = 0.1,
  parsimony = 0.0032,
  seed = 1
)

Arguments

X

Numeric matrix of predictors.

y

Response vector.

unary_operators

Character vector from sin, cos, exp, log, sqrt, square.

niterations

Iterations (each of population_size steps).

population_size

Population size.

maxsize

Largest expression size.

tournament_size

Tournament size.

crossover_probability

Probability of crossover instead of mutation.

parsimony

Size penalty in selection.

seed

Philox seed.

Value

List: equations (data frame of complexity, loss, equation, score), best (list) and prediction.

References

Cranmer, M. (2023). Interpretable machine learning for science with PySR and SymbolicRegression.jl. arXiv:2305.01582.

Real, E., Aggarwal, A., Huang, Y. and Le, Q. V. (2019). Regularized evolution for image classifier architecture search. AAAI 33, 4780-4789.

Examples

X <- matrix(seq(-2, 2, by = 0.25))
r <- PysrRegression(X, 2 * X[, 1]^2 + X[, 1], niterations = 40, seed = 3)
r$best$equation
#> [1] "((x0 * (x0 + x0)) + x0)"