Skip to content

added multidimensional functionality to rtsdiff#189

Open
mariaprot wants to merge 1 commit intoflorisvb:masterfrom
mariaprot:rtsdiff
Open

added multidimensional functionality to rtsdiff#189
mariaprot wants to merge 1 commit intoflorisvb:masterfrom
mariaprot:rtsdiff

Conversation

@mariaprot
Copy link

No description provided.

except ImportError: pass

from pynumdiff.utils.utility import huber_const

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Image Image

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):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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

Successfully merging this pull request may close these issues.

2 participants