Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow y to be vector-valued? #35

Closed
patrick-kidger opened this issue Mar 4, 2021 · 7 comments · Fixed by #46
Closed

Allow y to be vector-valued? #35

patrick-kidger opened this issue Mar 4, 2021 · 7 comments · Fixed by #46
Labels
enhancement New feature or request

Comments

@patrick-kidger
Copy link

patrick-kidger commented Mar 4, 2021

It would be nice to allow y to be vector valued, essentially as a (parallelised?) shortcut for something like the following:

expressions = []
for index in range(y.shape[-1]):
    yi = y[:, index]
    expression_i = pysr.pysr(x, yi)
    expressions.append(expression_i)

This links to (and is actually motivated by) my suggestion in #32: as_pytorch could then return a single SymPyModule wrapping a list of all expressions, rather than returning several SymPyModules for each one, which would then have to be composed together in the above for loop.

@MilesCranmer
Copy link
Owner

Definitely agree. Actually it could be even nicer to just have the SymbolicRegression.jl backend loop over each y-component and return a list of equations at each complexity. Will think more about this.

@MilesCranmer MilesCranmer added the enhancement New feature or request label Mar 4, 2021
@MilesCranmer
Copy link
Owner

Just added capabilities for multi-output (and multiple equations returned). SymbolicRegression.jl will now return a list of equations for each output.

This should be simple enough to set up for just importing into PySR. The trickier part is the JAX and PyTorch backend! I'm not sure how to approach - whether to continue outputting a different Torch/JAX model for each equation, or try to merge? It's probably overcomplicated to merge...

@patrick-kidger
Copy link
Author

Is the PyTorch backend (you mean exporting via sympytorch?) actually available? I don't see it based on a quick glance through the code.

For sympytorch at least it's possible to pass multiple equations to the SymPyModule, i.e. vector values are automatically supported.

@MilesCranmer
Copy link
Owner

The PyTorch backend hasn't been implemented yet; it's next on my todo list!

That is nice that vector equations are supported! It doesn't assume the equations are all the same, but for different parameter choices, right? They can be completely different equations?

@patrick-kidger
Copy link
Author

Yep, completely different equations.

@MilesCranmer
Copy link
Owner

MilesCranmer commented May 30, 2021

Actually on second thought I'm not sure it will work due to the API of PySR: it will output a list of equations for each feature of y. When JAX/Torch export is turned on, it will generate a separate function/module for each expression. But I think the user will want to filter equations for each feature of y separately before making a choice of equation, and then fusing them.
I don't see an easy way to do this otherwise? I also don't know if there'd be a speedup since the expressions are assumed to be different, and no operations are re-used?

@patrick-kidger
Copy link
Author

Hmm. I see your point. Perhaps only offer an export as SymPy, and just document that there are external libraries to convert SymPy into PyTorch/JAX. Then the end user can do whatever they like to select their sympy expression from the various possibilities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants