MilesCranmer / PySR

High-Performance Symbolic Regression in Python and Julia
https://ai.damtp.cam.ac.uk/pysr
Apache License 2.0
2.44k stars 217 forks source link

[Feature]: Unary operator to pick an item at index from current X #629

Open sentialx opened 6 months ago

sentialx commented 6 months ago

Feature Request

Is there a way to define a custom unary operator getXAt that takes an integer i as a parameter and returns X_i? This could possibly allow creating a similar mechanism to attention.

MilesCranmer commented 6 months ago

Not yet but all we need to do is make SymbolicRegression.jl compatible with GenericOperatorEnum – see https://github.com/SymbolicML/DynamicExpressions.jl?tab=readme-ov-file#tensors. Then the operators could do anything at all – even operations on non-numerical data.

Right now it is fixed to only use OperatorEnum by this line: https://github.com/MilesCranmer/SymbolicRegression.jl/blob/71447ee7bee18fc836a7d7bb4c8ce5d249bc0e7c/src/Options.jl#L718-L722.

We would need to change that to allow the user to specify the AbstractOperatorEnum type, and then basically fix up all the error messages that will show up. But I feel like it wouldn't be too bad.

(There are also n-ary operators planned which someone is working on, those could be useful here as well)