Replies: 2 comments
-
Initial tips: I ran your loss function through julia> using SymbolicRegression
julia> X = randn(Float32, 5, 256); y = randn(Float32, 256);
julia> dataset = Dataset(X, y);
julia> tree = Node{Float32}(val=0.1);
julia> options = Options();
julia> @code_warntype my_custom_objective(tree, dataset, options) This will highlight type instabilities in red which can hurt performance. In particular it looks like it can't figure out the type of penalty_term::Any
should::Vector
should_nt::Vector and there are also various types that are It looks like this means the inferred return value of the custom objective is |
Beta Was this translation helpful? Give feedback.
-
Now, for passing a constant dataset, you could set a constant global variable in Julia, and then access those from your loss function? For example: from pysr import jl
# ^jl is the Julia runtime
create_const = jl.seval("(const_name, ar) -> @eval const $(Symbol(const_name)) = convert(Array, $ar)") This is a function in Julia, callable from Python, that creates constants with name Make sure to convert the numpy array you pass this to the right type using e.g., create_const("my_constant", np.random.randn(100).astype(np.float32))
jl.my_constant # Now accessible within Julia
# Including within functions:
jl.seval("""
function my_fnc()
return my_constant
end
""")
jl.my_fnc() Therefore, you can use " Just make sure your loss function creates a copy of the constant globals so it doesn't modify them. e.g., |
Beta Was this translation helpful? Give feedback.
-
Hello everyone,
I need the 4 trees in the following objective function to be functions of only variables 3, 4, and 8. However, my objective function requires 18 inputs. Searching between 18 variables requires more iterations. Is there an option for a custom objective function to be of the form my_custom_objective(tree, dataset::Dataset{T,L}, options, constant_dataset::Dataset{T,L}) where {T,L}, where dataset contains only variables 3, 4, and 8 that the trees use, and constant_dataset contains the remaining variables used for calculating the objective function? This will speed up the training.
Beta Was this translation helpful? Give feedback.
All reactions