MilesCranmer / PySR

High-Performance Symbolic Regression in Python and Julia

Home Page:https://astroautomata.com/PySR

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature] Nested operator constraint

MilesCranmer opened this issue · comments

Just as the constraints argument can specify per-operator max-size (see https://astroautomata.com/PySR/#/options?id=constraining-operator-complexity), it would be very useful to have a constraint that specifies the number of times an operator can be nested.

For example, sometimes PySR tends to nest power operations, and these can be extremely difficult to interpret. It would be very useful to specify that a power operator cannot appear in the argument of another power operator. (or give some limit to the number of occurrences within an operator's argument).

For example:

nested_constraints = {
    "exp": -1,  # (any number of nested uses)
    "pow": 0,  # (nested use is not allowed.)
    "sin": 1,  # (only one nested use is allowed.)
}

It might even be good to have some defaults on the built-in operators.

Actually, if we simply disallow the nesting of sin, then it would nest cos with sin.

Perhaps a more general solution is to specify what operators are allowed to be nested. For example:

nested_constraints = {
  "exp": {
    "+": -1 # (any number of uses inside; this is also the default)
    "exp": 0 # (nested use of self is disallowed)
    "sin": 1 # (can only use a single sin operation inside an exp)
  }
  "sin": {"sin": 0, "exp": 0} # use of these operators inside a sin.
}

This would be awesome... I think with this kind of prior, one could achieve more comprehensible results and control a little bit better the convergence of the results

This was added on v0.8.0, so closing.