added multidimensional functionality to rtsdiff#189
added multidimensional functionality to rtsdiff#189mariaprot wants to merge 1 commit intoflorisvb:masterfrom
Conversation
| except ImportError: pass | ||
|
|
||
| from pynumdiff.utils.utility import huber_const | ||
|
|
There was a problem hiding this comment.
I think what happened is Windows replaced all the newline characters in this file. The thing to do is probably to save your few lines of changes elsewhere, use git reset to pull the original copy of this file from the master branch (git checkout master -- path/to/file), and copy back in your changes.
Or, you can replace the newlines directly. Here I've asked Chat what to do:
| return xhat_smooth if not compute_P_smooth else (xhat_smooth, P_smooth) | ||
|
|
||
|
|
||
| def rtsdiff(x, dt_or_t, order, log_qr_ratio, forwardbackward, axis=0, _recurse=True): |
There was a problem hiding this comment.
We should be able to accomplish this without the addition of an argument. More arguments mean more potential confusion for users, because there are already a lot.
| # each 1D slice along the given axis, and then stack the results back together. | ||
| # The _recurse flag is to avoid infinite recursion. | ||
| if x.ndim > 1 and _recurse: | ||
| packed = np.apply_along_axis( |
There was a problem hiding this comment.
I think apply_along_axis isn't taking full advantage of the structure here. See below where the A matrix is formed. That work is repeated for each vector if you naively apply along axis, but that matrix can be reused. It's even more extreme if dt_or_t is vector instead of scalar, meaning it encodes timestamps of data points instead of a set time-gap between data: In that case, the kalman filter will compute a new A matrix for each gap within each vector, which compounds the work even more.
To avert that extra work in the latter case will require some mild restructuring of the code, because right now the kalman_filter function takes a continuous-time A if a series of times are given, computing the many discrete-time A itself. If it needs to be re-called for many vectors, maybe it should be given either a single discrete-time A or a list or array of all the discrete-time A matrices stacked, so they can be computed only once up here in the caller. Or, kalman_filter could be made to take multidimensional data itself and given an axis parameter of its own, although that seems a touch more complicated/nonstandard to me, since Kalman filters are usually described as working on a single state vector at a time.
No description provided.