-
Notifications
You must be signed in to change notification settings - Fork 9
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
Default axis of differentiation is axis 1, rather than axis 0 or -1 #51
Comments
Also in the object method FWIW in pysindy we explicitly set the axis when calling |
Originally, derivative was written with "snapshot matrices" in mind, so X = [x_1 x_2 ... x_T] was the shape to use, and anything else was out of scope. Perhaps this is too restrictive now. As long as downstream is safe, there is no reason to prefer the old way if a new approach enables additional features. |
If I change the default to 0 in |
It seems like the assumption was we'd never work with greater than 2D data. Is this right? |
Yes, that's exactly right (see previous post about snapshot matrix assumption). |
#41 added It's odd that changing the default in |
So even if the data is 3D or greater, we reshape to 2D, differentiate along axis 1, and shape back. I'm trying to picture how that works mathematically. I guess as long as the axis of interest is kept in tact, then all the vectors along it can be stacked into a big matrix, and then you can reshape back. This may or may not be easier than leaving it as is and trying to do whatever smoothing or differentiation operations along whichever dimension. The tradeoff is this extra reshaping code so that various methods can consistently expect axis 1. I don't hate it. But I'm adding a docstring, and my preference would be to reshape such that differentiation always happens along axis 0. |
Alternative view: what we consider an n-dimensional numpy array is really a contiguous list of memory locations along with information what size strides to take when indexing each of the n-dimensions. Reshape, moveaxis, and flatten don't really have great mathematical analogues. Moving an axis is just a swap of two elements in the metadata tuple. Flattening several axes is just forgetting some metadata, which is why
Changing the default value in the public API is easy; changing the backend convention, less so. |
In
differentiation.py
, theaxis
parameter defaults to 1 and is used to index things likeX.shape[1]
. I think it's more intuitive for the default direction of differentiation to be the first or last dimension, not the 2nd, especially for 3D or higher-dimensional data.The text was updated successfully, but these errors were encountered: