Skip to content
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

Derivatives of max and min #68

Open
amrods opened this issue Oct 21, 2021 · 2 comments
Open

Derivatives of max and min #68

amrods opened this issue Oct 21, 2021 · 2 comments

Comments

@amrods
Copy link

amrods commented Oct 21, 2021

Should we enforce that the derivatives of max(x, y) and min(x, y) are undefined when x == y?

@mcabbott
Copy link
Member

I think the more useful result is to pick a something like a sub-gradient. The use case to imagine is some optimisation problem, where equality might be the best or worst point. We'd like gradient descent to be able to end up there, or not to get stuck there, both of which want a finite gradient.

You could argue that these should pick a symmetric convention, though:

julia> ForwardDiff.gradient(x -> max(x...), [1,1])
2-element Vector{Int64}:
 0
 1

julia> ForwardDiff.derivative(x -> clamp(x, 1, 2), 1)
1

julia> ForwardDiff.derivative(x -> clamp(x, 1, 2), 2)
1

@amrods
Copy link
Author

amrods commented Nov 1, 2021

Yes, the problem I had was encountered when optimizing a function with max(x, y) inside it. I was checking the gradients using ForwardDiff and realized that problem of no symmetry. Worse, though, is FiniteDiff:

julia> FiniteDiff.finite_difference_gradient(x -> max(x...), [1.0, 1.0])
2-element Vector{Float64}:
 0.4999999999934427
 0.4999999999934427

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants