Higher order derivatives return wrong results
See original GitHub issueWhen trying to compute higher order derivatives of a very simple function:
def inv(x):
return 1/X
print(grad(grad(grad(grad(grad(grad(inv))))))(4.))
It prints -1.9560547
instead of the correct 0.0439453125
.
It starts returning incorrect results at 4. It still gets it right with 3.999
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Higher Order Derivatives - YouTube
This calculus video tutorial provides a basic introduction into higher order derivatives. it explains how to find the second derivative of a ...
Read more >Understanding higher order derivative result
1 Answer 1 ... I can reproduce the error with version 12.0.0 ; however, it has been fixed, and with either version 12.1.1...
Read more >Difficulties in understanding higher order derivatives for tf ...
Based on what I played with some examples, I believe you are correct. The official doc is somehow ambiguous (or incorrect). The second_order_ ......
Read more >1.7: Higher Order Derivatives - Mathematics LibreTexts
Now f′(x) is once again a function. So we can differentiate it again, assuming that it is differentiable, to create a third function,...
Read more >6. Higher order derivatives, functions and matrix formulation
Using finite differences, we can construct derivatives up to any order. Before we discuss this, we first explicitly describe in detail the second-order...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If we look at what’s going on, this appears to be a case where the higher order gradient calculation is unstable and also rather inefficient:
The source of the issue is that
grad(inv)
turns into-1/(x*x)
instead of-1/x**2
:The later is much more efficient for higher order differentiation:
It seems like we should consider defining the gradient derivative rule for division in terms of
pow
rather thansquare
(which should perhaps also be written in terms ofpow
). Thepow
primitive in turn would also probably need to be rewritten to include special case logic for efficient integer powers.Yes, an
integer_power
primitive could work well. Possibly restricted to statically known powers?