Skip to main content
Ctrl+K

eqdisco

  • Installation
  • Example gallery
  • API reference
  • The book
  • From the GP-OLS MATLAB toolbox
    • Citing
    • Changelog
    • All textbooks
  • GitHub
  • Installation
  • Example gallery
  • API reference
  • The book
  • From the GP-OLS MATLAB toolbox
  • Citing
  • Changelog
  • All textbooks
  • GitHub

Section Navigation

  • First steps: expressions, equations and a first search
    • Expressions: trees, evaluation, derivatives and bounds
    • A first search: Kepler’s third law from the planets
    • The size of the search space and the meaning of complexity
    • Linear scaling: let regression handle offset and scale
  • Genetic programming for symbolic regression
    • Five selection schemes on one problem
    • Bloat and its control
    • Parameter optimization inside the search
    • The Pareto front and the choice of one model
    • Diversity: semantic crossover and islands
    • Library learning: reusing building blocks (new in eqdisco)
  • Linear-in-parameters models: OLS, multi-gene GP and GP-OLS
    • Orthogonal least squares and the error reduction ratio
    • Multi-gene genetic programming
    • GP-OLS: pruning terms by their error reduction ratio
    • ERR-guided variation: an experimental operator (new in eqdisco)
    • Cooperative GP with OLS credit assignment (new in eqdisco)
  • Deterministic search: sparse regression, FFX and exhaustive enumeration
    • Sparse regression over a library of terms
    • Fast Function Extraction (FFX)
    • Exhaustive search with a description length
  • Probabilistic search: Bayesian sampling, grammars and language models
    • Bayesian sampling of model structures
    • Learning a grammar of good expressions (new in eqdisco)
    • Language models as proposal generators
  • Dynamic systems: NARX models and differential equations
    • Nonlinear input–output identification with GP-OLS
    • Model order selection for NARX models
    • Sparse identification of the Lorenz system
    • Differential equations by genetic programming
  • Beyond regression: classification and symbolic features
    • A critical equation for reactor runaway
    • Goal-oriented projection with symbolic features
    • Symbolic features for a soft sensor
  • Prior knowledge: units, shape constraints and symmetries
    • Physical units: dimensional consistency and Buckingham groups
    • Shape constraints for safe extrapolation
    • Separability and symmetries detected from data
  • Analysis of models: simplification, validation, uncertainty, structure
    • Simplification of evolved models
    • Validation and uncertainty of a discovered law
    • Sensitivity analysis of a discovered model
    • Building blocks and variable interactions
    • Model families: how many different models do the data support? (new in eqdisco)
    • Bootstrap ensembles: model uncertainty and stable structure
  • From model to deployment: export, registry, monitoring, benchmarks
    • Exporting equations to code, spreadsheets and PMML
    • Registry, model card and drift monitoring
    • A small benchmark of methods
    • A one-page report of a search
  • Example gallery
  • Genetic programming for symbolic regression
  • Parameter optimization inside the search

Note

Go to the end to download the full example code or to run this example in your browser via Binder.

Parameter optimization inside the search#

Constants inside nonlinear functions – the 0.8 in \(e^{-0.8x_0}\) – are hard to evolve by mutation. Modern symbolic regression systems tune them by gradient methods during the search (Kommenda et al., 2020; Burlacu et al., 2020). eqdisco applies Levenberg–Marquardt with exact forward-mode Jacobians to the best share of the offspring and writes the tuned values back into the genome (Lamarckian learning). The target is \(y=2.5\,e^{-0.8x_0}\sin x_1\).

import matplotlib.pyplot as plt
import numpy as np

import eqdisco as eq

rng = np.random.default_rng(1)
X = rng.uniform(-2, 2, (200, 2))
y = 2.5 * np.exp(-0.8 * X[:, 0]) * np.sin(X[:, 1])
funcs = ("add", "sub", "mul", "div", "exp", "sin")

With and without Levenberg–Marquardt#

runs = {}
for opt in ("none", "lm"):
    runs[opt] = [
        eq.SymbolicRegressor(population_size=200, generations=20, optimize=opt, optimize_fraction=0.1, optimize_iterations=10, functions=funcs, random_state=s).fit(X, y)
        for s in range(5)
    ]
for opt, rr in runs.items():
    print(opt, [str(r.equation_) for r in rr[:2]])
for opt in ("none", "lm"):
    print(f"{opt:4s} median final NMSE {np.median([r.history_['best_loss'].iloc[-1] for r in runs[opt]]) / np.var(y):.2e}  "
          f"median evaluations {np.median([r.history_['n_evaluations'].iloc[-1] for r in runs[opt]]):.0f}")
fig, axs = plt.subplots(1, 2, figsize=(10, 3.4))
for opt, color in (("none", "#D55E00"), ("lm", "#285780")):
    for r in runs[opt]:
        h = r.history_
        axs[0].semilogy(h["n_evaluations"], h["best_loss"] / np.var(y), color=color, lw=0.8, alpha=0.6)
    axs[0].plot([], [], color=color, label="no tuning" if opt == "none" else "Levenberg-Marquardt")
    eq.viz.plot_pareto(runs[opt][0], ax=axs[1], annotate=False, color=color, label=opt)
axs[0].set_xlabel("fitness evaluations")
axs[0].set_ylabel("normalized MSE of the best")
axs[0].legend(frameon=False, fontsize=8)
fig.tight_layout()
plot 07 parameter optimization
none ['0.03115 + 0.07203 * sin(x1) / exp(-3.266 + x0)', '0.005319 + 0.586 * (sin(x1) / exp(x0 - 0.981) + x1 / exp(exp(x0 - 0.237)) + sin(sin(x1)))']
lm ['-0.05235 + 0.03944 * (x1 + sin(x1) / (exp(-4.312 + exp(-7.193e+13 + x0)) + exp(-3.734 + x0)) + sin(x1) / (exp(-12.53 + x0) + exp(-3.536 + x0)) + exp(-4.817 + x0) + x0 - x0 + exp(sin(x1)))', '-68.73 + 0.611 * (sin(x1) / exp(exp(x0)) + sin(sin(x1)) / exp(x0 - 1.105) + sin(x1) + sin(x1 * 0.01234) + 112.5)']
none median final NMSE 6.03e-03  median evaluations 3262
lm   median final NMSE 2.49e-05  median evaluations 3319

Parameter study: the share of optimized offspring#

fracs = [0.0, 0.05, 0.2, 0.5]
med = []
for f in fracs:
    vals = [eq.SymbolicRegressor(population_size=150, generations=15, optimize="lm", optimize_fraction=f, functions=funcs, random_state=s).fit(X, y).score(X, y) for s in range(3)]
    med.append(np.median(vals))
print("share optimized", fracs, "median 1-R2", [f"{1 - v:.1e}" for v in med])
fig, ax = plt.subplots(figsize=(4.5, 3))
ax.plot(fracs, 1 - np.array(med), "o-", color="#285780")
ax.set_yscale("log")
ax.set_xlabel("share of offspring tuned by LM")
ax.set_ylabel("median $1-R^2$")
plt.show()
plot 07 parameter optimization
share optimized [0.0, 0.05, 0.2, 0.5] median 1-R2 ['2.2e-03', '1.2e-03', '2.1e-04', '3.5e-05']

Total running time of the script: (0 minutes 40.161 seconds)

Launch binder

Download Jupyter notebook: plot_07_parameter_optimization.ipynb

Download Python source code: plot_07_parameter_optimization.py

Download zipped: plot_07_parameter_optimization.zip

Gallery generated by Sphinx-Gallery

previous

Bloat and its control

next

The Pareto front and the choice of one model

On this page
  • With and without Levenberg–Marquardt
  • Parameter study: the share of optimized offspring
Show Source

© Copyright 2026, János Abonyi.

Created using Sphinx 9.1.1.