[RFC, ANN] WindowMap.jl

Regularly I need to apply a function to a series of y[i] in a windowed (rolling) way, where the window is defined by values of another series x[i] instead of the indices i themselves. E.g. x represents timestamps, y are some measurements, and the target result is a rolling average of measurements wrt time. I could not find any existing library that can perform this kind of mapping, neither in Julia nor in Python. For quite some time I wrote ad-hoc implementations with different hardcoded assumptions in different projects of mine, but recently I decided to format this as a reasonably reusable package.

The package can be installed from https://github.com/aplavin/WindowMap.jl, and there is a jupyter notebook with simple usage examples: https://github.com/aplavin/WindowMap.jl/blob/master/examples.ipynb. For now it is not general enough for my usage: only univariate and bivariate applications are supported, and in the bivariate case the window can only be a product of two univariate windows; I’m planning to extend the package in this direction.

As I’m not experienced in writing general and reusable Julia code and packages, I would be really thankful for any comments and suggestions regarding the overall design of this package. The whole source code is only one file with 120 lines now: https://github.com/aplavin/WindowMap.jl/blob/master/src/WindowMap.jl. I’m also curious of how you think performance could be improved while keeping the generality.

6 Likes

Looks nice. I took a brief look at the code, but it wasn’t obvious to me: what happens to points that fall at a boundary between windows? Are they not included in any window? Also, is it possible for windows to overlap?

Another approach that I find useful for time series: https://code.kx.com/q/ref/wj/

Yes, if any point falls outside a window it is not included anywhere. But the main usecase, as illustrated in the examples, has highly overlapping windows: the step to shift the window is significantly smaller than the window width. I mainly use it for plotting, and in this scenario only steps much smaller than the window width make sense.

Another approach that I find useful for time series: https://code.kx.com/q/ref/wj/

Oh, that’s quite an obscure syntax :slight_smile: Looks like that function solves a different problem involving joining two tables, but maybe I misunderstood it.