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

max when values agree? #53

Open
tawheeler opened this issue Apr 9, 2017 · 0 comments
Open

max when values agree? #53

tawheeler opened this issue Apr 9, 2017 · 0 comments

Comments

@tawheeler
Copy link

tawheeler commented Apr 9, 2017

The partial derivative of max currently uses the Julia Base implementation:

max(x,y) = ifelse(y < x, x, y)

Unfortunately, this may cause incorrect results when the Dual values agree but the partials do not:

max(Dual(3,1), Dual(3,-1))

Here, the values are both 3 but the partials have opposite signs. I think the partial here may be undefined.

Maybe something like:

function Base.max(a::Dual, b::Dual)
    if value(a) > value(b)
        return a
    elseif value(a) < value(b)
        return b
    else # value(a) == value(b)
        return ifelse(epsilon(a) == epsilon(b), a, Dual(value(a), NaN))
    end
end
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

1 participant