TemplateExpressionSpec for finding constants #841
-
|
I am trying to predict 2 constants in a function of the form: where a and b are constants that I want to determine. However, my current implementation treats a, b, and x as constants, even though x is meant to be a variable. Additionally, the training process only finds a single equation in the Hall of Fame, without exploring other possible solutions. I am aware that linear regression works well for this case, but I specifically want to use PySR to perform the fitting. Below is my code for my TemplateExpressionSpec: Does anybody know how this can be fixed and why it doesn't search for more numbers to fit this? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
|
With the new syntax on PySR 1.5.0 I would write it like this: FunctionTemplate = TemplateExpressionSpec(
expressions=["f"],
variable_names=["x"],
parameters={"a": 1, "b": 1},
combine="abs(a[1]) + abs(b[1]) / sqrt(f(x))
) |
Beta Was this translation helpful? Give feedback.
I mean if you want, you could just force it with something like:
Note the
0 * f(x)term, which will kill the contribution fromf.Obviously it will still do a redundant search over the space of symbolic expressions for
f, but this would indeed let you use it.Basically the backend is set up to assume there is always SOME symbolic expression that is being optimized. i.e., it's just not written with the assumption that anybody would use it for regular constant fitting. But I guess you could hack it in like this!