You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed that the file SymbolicRegression.jl/ext/SymbolicRegressionSymbolicUtilsExt.jl defines the functions node_to_symbolic and symbolic_to_node as follows:
function node_to_symbolic(tree::Union{AbstractExpressionNode,AbstractExpression}, options::Options; kws...)
return node_to_symbolic(get_tree(tree), get_operators(tree, options); kws...)
end
function node_to_symbolic(tree::Union{AbstractExpressionNode,AbstractExpression}, m::AbstractSymbolicRegressor; kws...)
return node_to_symbolic(tree, get_options(m); kws...)
end
function symbolic_to_node(eqn::Symbolic, options::Options; kws...)
return symbolic_to_node(eqn, options.operators; kws...)
end
function symbolic_to_node(eqn::Symbolic, m::AbstractSymbolicRegressor; kws...)
return symbolic_to_node(eqn, get_options(m); kws...)
end
However, I'm encountering an error when trying to use symbolic_to_node, and I can't figure out why.
What I'm trying to do is:
During symbolic regression training, I want to obtain the first derivative of the expression tree (which is of type Node{Float64}), and find the root of that derivative. Since differentiating the expression requires converting it into an Expression type using DynamicExpressions.jl, I started by manually constructing an Expression to validate the pipeline before applying it to actual training trees.
using DynamicDiff: D
binary_ops = (+, -, *, /)
unary_ops = (sin, exp)
operators = OperatorEnum(binary_operators=binary_ops, unary_operators=unary_ops)
x = Expression(Node{Float64}(feature=1); operators, variable_names=["x"])
expr_f = exp(exp(x / x))
println(expr_f) # result: exp(exp(x / x))
expr_dfdx = D(expr_f, 1)
println(expr_dfdx) # result: exp(exp(x / x)) * (exp(x / x) * (∂₁[/](x, x) + ∂₂[/](x, x)))
expr_str_dfdx = string(expr_dfdx)
using Symbolics
@variables x
symbolics_expr_dfdx = eval(Meta.parse(expr_str_dfdx))
# UndefVarError: `∂₁` not defined in `Main`
# Suggestion: check for spelling errors or missing imports.
#
# Stacktrace:
# [1] top-level scope
# @ none:1
# [2] eval
# @ ./boot.jl:430 [inlined]
# [3] eval(x::Expr)
# @ Main ./sysimg.jl:48
# [4] top-level scope
# @ In[10]:4
But even when I try a simple example, I run into issues calling symbolic_to_node. I thought the above method could handle this conversion instead, but I'm not sure what's wrong.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi @MilesCranmer,
I noticed that the file
SymbolicRegression.jl/ext/SymbolicRegressionSymbolicUtilsExt.jl
defines the functionsnode_to_symbolic
andsymbolic_to_node
as follows:However, I'm encountering an error when trying to use symbolic_to_node, and I can't figure out why.
What I'm trying to do is:
During symbolic regression training, I want to obtain the first derivative of the expression tree (which is of type Node{Float64}), and find the root of that derivative. Since differentiating the expression requires converting it into an Expression type using DynamicExpressions.jl, I started by manually constructing an Expression to validate the pipeline before applying it to actual training trees.
But even when I try a simple example, I run into issues calling
symbolic_to_node
. I thought the above method could handle this conversion instead, but I'm not sure what's wrong.Any ideas on what might be causing this?
Beta Was this translation helpful? Give feedback.
All reactions