How to get the equations for TemplateExpressionSpec and how to use it to define a custom objective function #865
Replies: 3 comments 2 replies
-
beta_1 = 1.0 # SET ME
beta_2 = 2.0 # SET ME
template = TemplateExpressionSpec(
expressions=["f", "g"],
variable_names=["x1", "x2", "x3", "x4", "y_real", "f_real", "g_real"]
parameters={"p": 2},
combine=f"""
f_predicted = f(x1, x2)
g_predicted = g(x1, x3, x4)
y_predicted = p[1] * f_predicted + p[2] * g_predicted
(y_real - y_predicted)^2 + {beta_1} * (f_real - f_predicted)^2 + {beta_2} * (g_real - g_predicted)^2
""",
)
model = PySRRegressor(expression_spec=template, elementwise_loss="L1DistLoss()", **kwargs)
# Set the target to be 0:
model.fit(X, np.zeros(X.shape[0])) I'm assuming you want to take the mean-squared error (?) which is why I wrote these out as I use Note that we would need to pass The tricky thing about a loss like this is that you can't use Thanks for the kind message! |
Beta Was this translation helpful? Give feedback.
-
Btw, for 1, you can just do |
Beta Was this translation helpful? Give feedback.
-
Hi Miles! 1 - I was just wondering if the LaTeX export was being developed, but it’s totally fine if it’s not. I’ll manage with model.equations_. |
Beta Was this translation helpful? Give feedback.
-
Hi!!
$$y=\alpha_1 * f(x_1, x_2) + \alpha_2 * g(x_1, x_2, x_3)$$
I am new to PySR and am trying to use it to create symbolic equations within a larger predefined expression:
Here is the code I am using:
I have two questions regarding the implementation of this problem:
Also, I am using Spyder and cannot visualize the variable I saved with the equations as: equations = model.equations_.
where
P.S. I want to thank Miles for his work on the development of PySR. It is an excellent tool, very well documented, and a pleasure to use so far.
Beta Was this translation helpful? Give feedback.
All reactions