Closed sairus7 closed 5 years ago
@sairus7 Thanks for the PR, these look like pretty solid improvements! Could you try to work on getting the build tests to pass? If those get handled then I wouldn't mind merging.
That error is because of NaNs at the front of the result array.
I can fix it in different ways:
1) Initialize sum with the first point, multiplied by window length n
- result will start smoothly from the first point.
2) Compute sum with narrower window at the front (window
= 1, 2, 3, ... n
) - result will be more noisy at the front.
3) Repeat first valid sum (1:n
) at first n-1
points of the output - there will be constant level at the front.
Also, I can update main loop to safely treat NaNs, e.g. for every NaN it can reset its state and output nans, and then initialize with abovementioned options 1, 2 or 3. If we choose option 2, I can discard any NaNs from the running sum, so it will output running sums over n
or less points, and if n' == 0
, it will output NaN. (More options here - we can even wish to output NaNs if current n'
is less than a given value depending on the window size n
.)
What do you think?
Fixed to be consistent with original version, any single NaN that is encountered within a moving window leads to NaN output. Since the code became less clear, I left the old version in comments.
@sairus7 Nice! Thanks for working on this, seems like a solid improvement.
See also my newly published package: https://discourse.julialang.org/t/ann-maxminfilters-jl-fast-streaming-maximum-minimum-within-moving-window/30151
Though I'm not sure about floating point error accumulation. The same thing could be done for runvar, runsd, runcov, etc.