eqdisco.models.SymbolicRegressor#
- class eqdisco.models.SymbolicRegressor(population_size=500, generations=50, functions=('add', 'sub', 'mul', 'div', 'sin', 'cos', 'exp', 'log', 'sqrt', 'square'), selection='tournament', tournament_size=5, parsimony=0.0, complexity='size', init_depth=(2, 5), max_depth=10, max_size=60, p_crossover=0.7, crossover='subtree', p_subtree_mutation=0.4, p_point_mutation=0.25, p_hoist_mutation=0.1, p_constant_mutation=0.15, p_shrink_mutation=0.05, p_insert_mutation=0.05, p_constant=0.2, const_range=(-5.0, 5.0), linear_scaling=True, loss='mse', optimize='none', optimize_fraction=0.1, optimize_iterations=10, n_islands=1, migration_interval=10, migration_size=2, elitism=1, lexicase_epsilon='mad', constraints=None, units=None, constraint_weight=10.0, seed_equations=None, library=None, p_library=0.05, library_learning=False, library_interval=5, llm_proposer=None, llm_interval=5, llm_n_proposals=5, validation_fraction=0.0, model_selection='bic', selection_tolerance=0.01, refit=True, early_stopping_loss=None, patience=None, time_limit=None, max_evaluations=None, feature_names=None, random_state=None, verbose=0)[source]#
Bases:
_TreeGP,RegressorMixinGenetic programming for symbolic regression.
- Parameters:
- population_size
int, default=500 Number of individuals \(\mu\) (split equally among the islands).
- generations
int, default=50 Number of generations \(G\).
- functionssequence
ofstr, default=DEFAULT_FUNCTIONS Function set \(\mathcal{F}\) (names of
eqdisco.expr.PRIMITIVES).- selection{“tournament”, “double_tournament”, “lexicase”, “nsga2”, “afp”}
Selection scheme.
- tournament_size
int, default=5 - parsimony
float, default=0.0 Penalty per unit of complexity added to the loss (parsimony pressure).
- complexity
str, default=”size” Complexity measure (
eqdisco.fitness.complexity()).- init_depth
tupleofint, default=(2, 5) Depth range of ramped half-and-half initialization.
- max_depth, max_size
int Limits of the offspring (an offspring that violates them is retried, then replaced by its parent).
- p_crossover
float, default=0.7 Probability of crossover; otherwise one of the mutations is applied, chosen with probabilities proportional to the
p_*_mutationweights.- crossover{“subtree”, “semantic”}
- p_constant
float, default=0.2 Probability that a new leaf is a constant.
- const_range
tupleoffloat, default=(-5, 5) - linear_scalingbool, default=True
Evaluate \(a + b f\) with optimal \(a, b\) (Keijzer, 2003).
- loss
strorcallable(), default=”mse” - optimize{“none”, “lm”}, default=”none”
Local parameter optimization of the best
optimize_fractionof the offspring by Levenberg–Marquardt (Lamarckian: the tuned parameters are inherited).- optimize_fraction
float, default=0.1 - optimize_iterations
int, default=10 - n_islands
int, default=1 - migration_interval, migration_size
int Ring migration of the
migration_sizebest individuals everymigration_intervalgenerations.- elitism
int, default=1 Number of best individuals copied unchanged (generational schemes).
- constraints
listofShapeConstraint,optional Prior knowledge on the shape of the model (monotonicity, convexity, bounds).
- units
dict,optional Physical units of the variables and of the target for dimensional consistency (
{"x0": "m", "x1": "s", "__target__": "m/s"}).- constraint_weight
float, default=10.0 Weight of the constraint and unit penalties (relative to the variance of the target).
- seed_equations
list,optional Equations (strings,
EquationorExpression) placed in the initial population.- library
list,optional Building blocks inserted into offspring with rate
p_library.- library_learningbool, default=False
Mine the library from the frequent subtrees of the best individuals every
library_intervalgenerations (new in eqdisco).- llm_proposer
callable(),optional A proposer (prompt -> text) whose suggestions are added every
llm_intervalgenerations (seeeqdisco.llm).- validation_fraction
float, default=0.0 Share of the data held out to choose the final model.
- model_selection{“bic”, “aic”, “best”, “knee”, “tolerance”, “score”, “validation”}
Rule that picks
equation_from the Pareto front (eqdisco.analysis.pareto.select_model()); the default is the lowest Bayesian information criterion, with exact fits tied and ties broken by size, which guards against selecting bloated models on small data.- selection_tolerance
float, default=0.01 - refitbool, default=True
Re-estimate the parameters of the front by Levenberg–Marquardt at the end.
- early_stopping_loss
float,optional Stop when the best loss is at most this value.
- patience
int,optional Stop after
patiencegenerations without improvement.- time_limit
float,optional Wall-clock limit in seconds.
- random_state
int,optional
- population_size
- Attributes:
- equation_
Equation The selected model.
- pareto_front_
listofEquation Non-dominated models (training error vs size), by increasing size.
- history_
pandas.DataFrame One row per generation.
- n_evaluations_
int Number of distinct fitness evaluations.
- equation_
Examples
>>> import numpy as np >>> from eqdisco import SymbolicRegressor >>> rng = np.random.default_rng(0) >>> X = rng.uniform(-2, 2, size=(200, 2)) >>> y = X[:, 0] ** 2 + 0.5 * X[:, 1] >>> sr = SymbolicRegressor(population_size=200, generations=15, random_state=1, ... functions=("add", "sub", "mul")).fit(X, y) >>> sr.score(X, y) > 0.99 True