Git Product home page Git Product logo

MethodError: Cannot `convert` an object of type SymbolicUtils.Term{Number, Nothing} to an object of type SymbolicUtils.Pow{Number, SymbolicUtils.Term{Number, Nothing}, Float32, Nothing} about symbolicregression.jl HOT 3 CLOSED

milescranmer avatar milescranmer commented on May 18, 2024
MethodError: Cannot `convert` an object of type SymbolicUtils.Term{Number, Nothing} to an object of type SymbolicUtils.Pow{Number, SymbolicUtils.Term{Number, Nothing}, Float32, Nothing}

from symbolicregression.jl.

Comments (3)

MilesCranmer avatar MilesCranmer commented on May 18, 2024 1

On 0.6.14 (once it uploads)

from symbolicregression.jl.

MilesCranmer avatar MilesCranmer commented on May 18, 2024

Thanks, I'm looking at this now.

I found an simpler way to reproduce it:

julia> options = SymbolicRegression.Options(
    binary_operators=(+, *, /, -, ^),
    unary_operators=(sqrt,),
    npopulations=100,
);
julia> tree = Node(1, Node(1) ^ 1.3 + Node(2) * 3.2 ^ Node(3));
julia> printTree(tree, options)
sqrt_abs(pow(x1, 1.3) + (x2 * pow(3.2, x3)))

julia> eqn = node_to_symbolic(tree, options)
ERROR: MethodError: Cannot `convert` an object of type SymbolicUtils.Term{Number, Nothing} to an object of type SymbolicUtils.Add{Number, Int64, Dict{Any, Number}, Nothing}
Closest candidates are:
  convert(::DataType, ::SymbolicUtils.Symbolic, ::Options; varMap) at /Users/mcranmer/SymbolicRegression.jl/src/InterfaceSymbolicUtils.jl:78
  convert(::Type{var"#s16"} where var"#s16"<:Union{Number, T}, ::MultivariatePolynomials.AbstractPolynomialLike{T}) where T at /Users/mcranmer/.julia/packages/MultivariatePolynomials/vqcb5/src/conversion.jl:65
  convert(::DataType, ::Symbol, ::Options; varMap) at /Users/mcranmer/SymbolicRegression.jl/src/InterfaceSymbolicUtils.jl:73
  ...
Stacktrace:
 [1] sqrt_abs(x::SymbolicUtils.Add{Number, Int64, Dict{Any, Number}, Nothing})
   @ SymbolicRegression.../Operators.jl ~/SymbolicRegression.jl/src/Operators.jl:74
 [2] parse_tree_to_eqs(tree::Node, options::Options{Tuple{typeof(+), typeof(*), typeof(/), typeof(-), typeof(pow)}, Tuple{typeof(sqrt_abs)}, L2DistLoss}, index_functions::Bool, evaluate_functions::Bool)
   @ SymbolicRegression.../InterfaceSymbolicUtils.jl ~/SymbolicRegression.jl/src/InterfaceSymbolicUtils.jl:30
 [3] node_to_symbolic(tree::Node, options::Options{Tuple{typeof(+), typeof(*), typeof(/), typeof(-), typeof(pow)}, Tuple{typeof(sqrt_abs)}, L2DistLoss}; varMap::Nothing, evaluate_functions::Bool, index_functions::Bool)
   @ SymbolicRegression.../InterfaceSymbolicUtils.jl ~/SymbolicRegression.jl/src/InterfaceSymbolicUtils.jl:119
 [4] node_to_symbolic(tree::Node, options::Options{Tuple{typeof(+), typeof(*), typeof(/), typeof(-), typeof(pow)}, Tuple{typeof(sqrt_abs)}, L2DistLoss})
   @ SymbolicRegression.../InterfaceSymbolicUtils.jl ~/SymbolicRegression.jl/src/InterfaceSymbolicUtils.jl:119
 [5] top-level scope
   @ REPL[17]:1

from symbolicregression.jl.

MilesCranmer avatar MilesCranmer commented on May 18, 2024

Found it!

When you call node_to_symbolic with a custom function, you need to pass index_functions=true. Technically sqrt is a custom function, because it is redefined as sqrt(abs(x)) inside SymbolicRegression.jl.

I will make index_functions=true the default to avoid this issue coming up again. It is already the default when called internally to the search, so this isn't an issue for the main loop.

from symbolicregression.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.