Comments (5)
Does it make sense to take a derivative with respect to an integer-valued argument? I could treat it as a float, but then the derivatives would be incorrect if the function contained integer-specific behavior like integer division. I also like the idea that the type of the derivative (float, array, list etc) is always the same as the type of the variable with respect to which the function is differentiated.
from autograd.
One perspective is that you should be able to take the derivative of any (numeric) function. There's no barrier in principle to integers, e.g., you can consider polynomials over the integers with integer coefficients, these are nicely closed under differentiation.
In Math, and Scheme, you'd regard the integers as a subset of the reals so this isn't an issue. But in Python, I dunno, I can see it both ways.
If you take a differential geometry perspective, where reverse mode is a pull-back and thus defined by a dual construction over the push-forward, then even if the primal quantities are integers the tangent and co-tangent spaces are vector spaces over the reals. So derivatives would be float even when primals are real.
Anyway, a second perspective is that when f(2.0) and f(2) are "the same" then their derivatives should both be defined, and both be "the same" in the same sense of sameness.
from autograd.
Ok, I can see both sides. The problem is that Python treats integers and floats differently, so that f(2)
and f(2.0)
are not the same in general (consider f = lambda x : x / 4
). What should the result of grad(lambda x : x /4)(2)
be? 0? 0.25?
from autograd.
I'd say 0, but there are two different 0s it might be.
One being the real number 0.
The other being the zero element of a zero-dimensional vector space, which is of course the only element of that vector space, aka ().
I guess the bottom line is the Python is a mess? Because this wouldn't be an issue in Scheme or Haskell.
from autograd.
I think @dougalm fixed this in 1d5375d. The above example seems to work!
In [2]: grad(lambda x:x*x)(2)
autograd/core.py:209: UserWarning: Casting int to float to handle differentiation.
warnings.warn("Casting int to float to handle differentiation.")
Out[2]: 4.0
from autograd.
Related Issues (20)
- support for Jax-like custom forward pass definition? HOT 1
- Gradient become Nan for 0 value test HOT 1
- Is it possible to see gradient function? HOT 1
- Four scipy tests are failing HOT 6
- Add np.float128,np.complex256 dtypes to vspaces and boxes registers HOT 2
- unsafe URL HOT 1
- Numpy 1.25 breaks a few linalg functions HOT 1
- `autograd` 1.6 breaks Apple M-series macOS and Windows builds (module `numpy` has no attribute `float128`) HOT 3
- Can I differentiate this function?
- Python 2 and dependency on future HOT 2
- `'ArrayBox' object has no attribute 'dot'` when differentiating function containing `x.dot(y)` HOT 1
- How do I create a scalar value that does not depend on the independent variables ?
- AttributeError: module 'autograd.numpy' has no attribute 'numpy_extra'
- Autograd for quantum circuits
- [BUG] Differentiating `autograd.numpy.linalg.norm` gives incorrect results
- Support for advanced library based on autograd HOT 4
- Release new version 1.6.3 on PyPI
- autograd return nan with to norm function
- Saving `ArrayBox` to hdf5 file
- Incompatibility with numpy 2.0.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autograd.