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

Discrepancies Between Different Modes #109

Open
julmb opened this issue Mar 8, 2024 · 1 comment
Open

Discrepancies Between Different Modes #109

julmb opened this issue Mar 8, 2024 · 1 comment

Comments

@julmb
Copy link
Contributor

julmb commented Mar 8, 2024

While investigating #108, I came across some more discrepancies between differentiation modes.

>>> import Numeric.AD.Mode.Forward as F
>>> import Numeric.AD.Mode.Reverse as R
>>> F.diff cos 0
>>> R.diff cos 0
-0.0
0.0
>>> import Numeric.AD.Mode.Forward as F
>>> import Numeric.AD.Mode.Reverse as R
>>> let f x = log (1 - exp x)
>>> F.diff (F.diff f) 0
>>> R.diff (R.diff f) 0
-Infinity
NaN

These examples may be somewhat contrived, but given the nature of algebra, I feel like any discrepancy could probably be amplified to yield significantly different results given the right circumstances.

@julmb
Copy link
Contributor Author

julmb commented Mar 11, 2024

It seems like Numeric.AD.Mode.Forward and Numeric.AD.Mode.Forward.Double also yield different results sometimes:

>>> import Numeric.AD.Mode.Forward as F
>>> import Numeric.AD.Mode.Forward.Double as FD
>>> f [x, y] = x ** y
>>> xs = [0, 2]
>>> F.grad f xs
>>> FD.grad f xs
[0.0,NaN]
[0.0,0.0]

I have not looked into this too much, but I have a hunch there are some simplification rules in Forward.Double that rely on the identity forall a. 0 * a = 0, which unfortunately does not hold in the presence of IEEE floating point special values (angry).

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