Examples
These examples show how to set up a symbolic regression search and adapt it to your data, equation structure, or objective. If you are new to PySR, begin with Getting started. Otherwise, choose the topic that matches your task.
Getting started
- Simple search: fit generated data and inspect the resulting expressions.
- Custom operator: add an operator and define its symbolic export.
- Multiple outputs: fit expressions for several target columns.
- Plotting an expression: export LaTeX and compare predictions with target values.
- Feature selection: reduce the input variables considered by the search.
- Denoising: smooth a noisy target with a Gaussian process before fitting expressions.
Expression specifications
- Expression specifications: constrain equation structure and learn category-dependent parameters.
- Recovering a magnetic field from force measurements: supply the known force law in a template and search for its unknown functions.
Objectives and losses
- Custom objectives: score complete candidate expressions with a Julia function.
- Writing the objective in Python: use a Python function to score candidates during the search.
- Swinging up a cart-pole with a rollout objective: evaluate each candidate controller in a simulation.
- Inventing a pseudorandom generator with no target: score generators without observed target outputs.
Physics and units
- Dimensional constraints: attach physical units to the search problem.
- Using differential operators: include derivatives in an expression template.
- Discovering a PDE: search for a differential equation using sampled field data.
Search behaviour
- Automatic batching on a large dataset: evaluate candidates on batches drawn from the data.
- Operators of any arity: supply operators that take more than two arguments.
- Mutations and plugins: configure mutation weights and search plugins.
- Adaptive mutation weights: adjust mutation choices as the search progresses.
- The backsolve mutation: derive targets for a replacement subtree from the operators above it.
Instrumentation and workflow
- Using TensorBoard for logging: log progress and metrics from the search for inspection in TensorBoard.
- Recording the genealogy of a search: inspect the relationships between expressions in a recorded search.
- Closing an agent loop with
guesses=: supply candidate expressions as guesses for another search round.
Value types
- Complex numbers: fit expressions to complex-valued data.
- Julia packages and types: use a Julia package inside a search operator.
- Custom value types: define the values used by expressions and how PySR handles them.
Beyond numeric values
- Breaking an affine cipher with a letter type: decode text with expressions that operate on letters.
- Rediscovering Conway's Game of Life: learn the update rule from a finite table of cell transitions.
- Searching over machine words: build expressions from bitwise operations.
- Turtle graphics: searching over drawings: search for a program that draws a target shape.
- Evolving a hopping controller: replay a three-joint controller learned through simulated rollouts.
See the Options section for other ways to configure the search.
