Custom loss with partial derivatives for 2 inputs and 2 outputs function. #1174
Unanswered
NiccoloAntonelliDziri
asked this question in
Q&A
Replies: 1 comment 4 replies
-
|
I think you could try doing this with TemplateExpressionSpec and I'll do some digging for relevant issues... (@MilesCranmerBot can you please read through discussions/issues over the past year and point to the most relevant ones? Ideally it would be nice if you could find a discussion that shows how to use |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I am currently trying to use PySR for finding an approximant for the inverse of a function. I apologize if there is something trivial that I missed but I haven't been able to find a discussion or an issue for something similar.
I want to find two functions, f1 and f2, such that:
I also have a custom condition on their partial derivatives that I want to enforce during the optimization process:
My hope is that this condition will help steer the algorithm toward solutions that are physically meaningful.
I have X and y of shape (241127, 2), where:
X contains the inputs [P, h]
y contains the targets [d, T]
I used a custom loss function in PySR to combine the standard MSE loss with the derivative condition.
When I tried to implement the custom loss, I got a BoundsError:
BoundsError: attempt to access 2×241127 Matrix{Float32} at index [1:2, 1, 2]This suggests that eval_grad_tree_array only returns a (2, N) matrix (2 variables × N data points), not the full Jacobian for both outputs.
My attempts to extract four derivatives
(df1/dP, df1/dh, df2/dP, df2/dh)failed because PySR appears to call the loss function separately for each output (or at least it's my guess).Is it possible to enforce such a condition in PySR with a single loss function for two outputs?
If not, is there a recommended way to achieve this ?
Beta Was this translation helpful? Give feedback.
All reactions