Replies: 1 comment 1 reply
-
Good question. There isn't anything built-in unfortunately on the PySR side. On the Julia side this is # After model.fit(X, y):
# PyJulia is already initialized, so this just gives us the runtime object:
from julia import Main as jl
from julia import SymbolicRegression
halls_of_fame = model.raw_julia_state_[1]
# This is a Julia object of type `SymbolicRegression.HallOfFame`
# see https://astroautomata.com/SymbolicRegression.jl/v0.16/types/#Hall-of-Fame
jl.halls_of_fame = halls_of_fame
if jl.eval("typeof(halls_of_fame) <: AbstractVector"):
output_column = 0 # set as necessary if you have multiple outputs
hof = halls_of_fame[output_column]
else:
hof = halls_of_fame
dtype = np.float32 if model.precision == 32 else np.float64
# ^ Important to pass the same datatype to functions in Julia
dominating = SymbolicRegression.calculate_pareto_frontier(
X.T.astype(dtype), y.astype(dtype), hof, SymbolicRegression.Options()
)
# This is a Vector of PopMember objects, which have fields:
# `tree` (the expression), and `loss` Once you have this object, you can compute the various properties of interest with SymbolicRegression.jl functions: complexities = [
SymbolicRegression.compute_complexity(member.tree, SymbolicRegression.Options())
for member in dominating
]
losses = [
member.loss
for member in dominating
]
equations = [
jl.string(member.tree)
for member in dominating
] as well as the depth. To help show how you could extend this, let's just write a python version: def compute_depth(tree):
if tree.degree == 0:
return 1
elif tree.degree == 1:
return 1 + compute_depth(tree.l)
else:
return 1 + max(compute_depth(tree.l), compute_depth(tree.r))
# Pure-python equivalent of DynamicExpressions.count_depth
depths = [
compute_depth(member.tree)
for member in dominating
] Hope this helps. Sorry it's not easier. Maybe one could have more properties like this returned from SymbolicRegression.jl? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi! Is there any method to get depth of the equations found by the regressor? Can't seem to find anything on the reference page and doing it by eye is a bit time consuming and error prone. I am using it for tuning the max-depth parameter.
Beta Was this translation helpful? Give feedback.
All reactions