-
Notifications
You must be signed in to change notification settings - Fork 26
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
gradient of non-smooth functions #129
Comments
Hi Carlo, Glad to hear that you're using FiniteDifferences in NNlib :) @wesselb is the best qualified person to help with the issue of custom grids etc, but I have a couple of thoughts. In particular regarding singularities in the derivatives, we've also struggled with that. My usual strategy in the case of scalar functions is to try and make sure that I don't cross them either by using Regarding the |
Hi @CarloLucibello, Here a simple example of using julia> central_fdm(5, 1)(log, 1e-3)
ERROR: DomainError with -0.004694116537609249:
log will only return a complex result if called with a complex argument. Try log(Complex(x)). This fails, because julia> forward_fdm(5, 1)(log, 1e-3)
999.9999999746666 If the case isn't so clear cut and you just want to evaluate the function near the derivative, I would recommend to turn off adaptation and limit the step size to something appropriately small: julia> central_fdm(12, 1, adapt=0)(log, 1e-3, max_step=1e-5)
1000.0000000000076 I notice that, currently, adaptation doesn't respect |
Thank you both for the quick responses. |
Hmm, what I can come up with right now is something like the following: julia> grad((f, x) -> central_fdm(8, 1)(f, x, 1e-4), sum, ones(2))
([0.9999999999990572, 0.9999999999990572],) This fixes the step size to You're right that keyword arguments cannot be passed to |
@CarloLucibello Once #130 is merged, you can limit how far the function is evaluated away from julia> m = central_fdm(5, 1, max_range=1e-4);
julia> grad(m, sum, ones(5))
([1.0000000000004334, 1.0000000000004334, 1.0000000000004334, 1.0000000000004334, 1.0000000000004334],) |
that's great, thanks! For the grad case, |
@CarloLucibello Yes, that's exactly right. |
Hi,
we are using FiniteDifferences in NNlib.jl to validate the automatic derivative compute through Zygote of some operators, like ReLU and maxpool, that contain a few singularities.
Since we test on a few random inputs, if FD evaluates the function in a small neighborhood of the input the FD estimate should be correct and not affected by the singularities with high probability. What we see instead is that sometimes the estimate is off.
I couldn't figure out from the docs how to select a small grid spacing or something along the lines, I tried with
but with no observable improvement (even worse, I get some cholesky factorization errors If I remember correctly).
Any help with this would be appreciated.
Best,
Carlo
The text was updated successfully, but these errors were encountered: