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

[Feature]: ternary operators #227

Closed
ericphanson opened this issue Jul 4, 2023 · 3 comments
Closed

[Feature]: ternary operators #227

ericphanson opened this issue Jul 4, 2023 · 3 comments

Comments

@ericphanson
Copy link

Feature Request

This might not be feasible, but I think it would be interesting to be able to model piecewise functions. I think this would basically need something like choice(x, y, z) = ifelse(x > 0, y, z).

@ericphanson
Copy link
Author

Actually thinking a bit more, this could be expressed as (x > 0)*y + (x <= 0)*z so I don’t think ternary operators are strictly necessary.

@MilesCranmer
Copy link
Owner

MilesCranmer commented Jul 4, 2023

Also see #102 but yeah I agree with you – generally it's surprisingly rare to need an operator that can't be expressed as a binary operator. Though it could be true that ifelse(x, y, z) may be more simple for some expressions than stacking binary operators like (>=)(x, y) and (*).

The only true ternary operators – which are not reducible – I've run into are weird basis functions used to solve some PDEs, where the operator has multiple parameters.

If needed we would first need to generalize https://github.com/SymbolicML/DynamicExpressions.jl/'s node type to have some MAX_DEGREE type parameter.

@MilesCranmer
Copy link
Owner

There's actually very few functions that need to be rewritten in the core type: https://github.com/SymbolicML/DynamicExpressions.jl/blob/6be88b78dca76013086f29f2ff22f6a532d20460/src/base.jl#L68-L136.

Though there are some other mutation functions in SymbolicRegression.jl that would need to re-weight their mutation probabilities based on the max degree.

MilesCranmer added a commit that referenced this issue Jul 6, 2023
[Diff since v0.19.1](v0.19.1...v0.20.0)

**Closed issues:**
- [Feature]: MLJ integration (#225)
- [Feature]: ternary operators  (#227)

**Merged pull requests:**
- MLJ Integration (#226) (@MilesCranmer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants