MilesCranmer / PySR

High-Performance Symbolic Regression in Python and Julia
https://astroautomata.com/PySR
Apache License 2.0
2.32k stars 211 forks source link

[Feature]: Add priori of equation form #494

Open zhuyi-bjut opened 9 months ago

zhuyi-bjut commented 9 months ago

Feature Request

Hi!When I want to find some expressions from my data, I want his form to be specific. For example, I hope that the equation form obtained by pysr is C1 x1 + ( C2 x2 / F ), where F is the term to be found, C1 and C2 are constants to be found. This is equivalent to the form of a constrained expression tree, that is, adding a priori. Is it possible for today 's pysr to implement this function ? Thanks!

MilesCranmer commented 9 months ago

Hi @prozhuyi,

The current method for doing this is exemplified here: https://astroautomata.com/PySR/examples/#9-custom-objectives. An easier way to do this is being discussed here: https://github.com/MilesCranmer/SymbolicRegression.jl/issues/193. (Help is always appreciated!)

Cheers, Miles

zhuyi-bjut commented 3 months ago

@MilesCranmer Can SymbolicRegression.jl/issues/193 be used in pysr ? Is there this module in PySRRegressor ? Since I want to add constraints like F = f ( x1, x2, x3 ) + g ( x4, x5 ) / f ( x1, x2, x6 ), examples/ # 9-custom-objectives does not seem to work. Thanks!

MilesCranmer commented 3 months ago

@zhuyi-bjut this is something in development at the moment. It likely won’t be ready for at the very least a few months. In the meantime I would try the custom objectives and post on the discussions page with any issues you are running into.

zhuyi-bjut commented 2 months ago

Hi Miles @MilesCranmer , When I implement constraints such as F = f ( x1, x2, x3 ) / g ( x4, x5 ), the regularization term is constructed to constrain the child nodes. However, when I deal with symbolic nodes, I construct constraints according to PySR/examples/#9-custom-objectives : it actually forces prediction to be equal to f1 / g1, but does not pass ' / ' to loss. Therefore, in subsequent processing, it may be necessary to manually replace other symbols with ' / '. I wonder whether it is possible to constrain the symbol node to be equal to a certain symbol, such as tree.l = = ' / ', just like using the regularization term to constrain the child node. Can similar functions be implemented in the loss item ? looking forward to your reply. Thanks!

MilesCranmer commented 2 months ago

Assuming that / is the 4th operator you pass, you can add a constraint that tree.degree == 2 && tree.op == 4, otherwise return some large number.