Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifying behaviour of special derivatives #50

Closed
Crown421 opened this issue Sep 22, 2023 · 4 comments
Closed

Modifying behaviour of special derivatives #50

Crown421 opened this issue Sep 22, 2023 · 4 comments

Comments

@Crown421
Copy link

I recently learned of about this package in the SciML slack channel, and I like it a lot. However, I have one question:
The documentation states that the derivative of $u/|u|$ is deliberately set to NaN.

I am coming to a similar problem from the perspective of RBF kernels, in which case it is necessary to consider this from the "right side" derivative perspective, such that $\tfrac{d^2}{dxdy} \sqrt{(x-y)^2}^2 = -2$ and $\tfrac{d^2}{dxdy} \sqrt{(x-y)^2} = 0$. Due to the mentioned behaviour, this returns NaN when using this package.

I was wondering if there was an option to deliberately modify this behaviour?

@brianguenter
Copy link
Owner

I am open to adding such an option. Let me look at the code to see what would be the best way to allow users to define this.

@brianguenter
Copy link
Owner

Maybe you could do this by wrapping the function in a conditional

ifelse x-y == 0 ? -2 : $\tfrac{d^2}{dxdy} \sqrt{(x-y)^2}^2$

FD doesn't support conditionals yet and it will be a while before it does.

@Crown421
Copy link
Author

Crown421 commented Sep 23, 2023

Interesting, that could certainly be a way to do it (not just with FD, but probably with any choice of AD framework). It at least lets me do something on my end now.

However, using the conditional approach might need a lot of special casing or type piracy. For added context, the problem appears when using the Euclidean distance from Distances.jl (which is exactly $\sqrt((x-y)^2)$) in some of the stationary kernels. This came up in JuliaGaussianProcesses/KernelFunctions.jl#517
KernelFunctions already defines a special ChainRules.jl rule for this distances, but also making it possible to use more recent/ faster AD frameworks would be fantastic.

I will play around with the idea above, and beyond that, happy to try to help on this package, if I can.

@brianguenter
Copy link
Owner

It seems that allowing users to define custom derivative rules would increase the range of problems FD can be applied to. If you have any insight about how to do this then let's continue this discussion.

Repository owner locked and limited conversation to collaborators Nov 28, 2023
@brianguenter brianguenter converted this issue into discussion #55 Nov 28, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants