Skip to content

Transform str expression into tree #550

Answered by MilesCranmer
DenisSvirin asked this question in Q&A
Discussion options

You must be logged in to vote

Sorry, missed this one!

Yes:

from pysr import jl  # Julia Main namespace
from pysr import PySRRegressor
from pysr import SymbolicRegression as SR  # Backend library

# Create `.julia_options_`:
model = PySRRegressor(verbosity=0, max_evals=1)
model.fit([[1]], [1])
options = model.julia_options_

# Define operators for creating trees:
jl.options = options  # Store `options` in Julia namespace
jl.seval("@extend_operators options")  # Declare available operators

x1 = SR.Node(jl.Float32, feature=1) # If x is the first column (index 0 in Python)
# Store x1 in Julia namespace:
jl.x1 = x1
# Create equation from string:
eqn = jl.seval("x1 + 1")

The + operator here gets mapped into an integer base…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by MilesCranmer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
PySR PySR-related discussion
2 participants