Skip to content
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

MovingTimeWindow #210

Open
JoaoAparicio opened this issue Jul 5, 2020 · 3 comments
Open

MovingTimeWindow #210

JoaoAparicio opened this issue Jul 5, 2020 · 3 comments

Comments

@JoaoAparicio
Copy link
Contributor

This[1] could be more efficient if the timestamps are assumed to be ordered. TimeSeries.jl enforces this. Do you think it would make sense to have some interop?

[1]

cutoff = maximum(first, o.values) - o.window
filter!(x -> x[1] >= cutoff, o.values)

@joshday
Copy link
Owner

joshday commented Jul 5, 2020

That seems like a fair assumption. The _merge! method would need to change to handle the timestamp ordering.

What kind of interop are you thinking of?

@JoaoAparicio
Copy link
Contributor Author

Currently we have function _fit!(o::MovingTimeWindow, y). In addition we could implement function _fit!(o::MovingTimeWindow, y::TimeArray). What is currently done is push all values of y into o, then filter. When the new _fit! method is called, timestamps in MovingTimeWindow are guaranteed to be sorted because timestamps in TimeArray are guaranteed to be sorted. So first compute the cutoff point, and then to determine what is kept and what is dropped, use searchsorted (if this point is in y, this is what from(y, cutoff) does, see [1]).

I'm sure this code can be made faster when we know the input array is time-sorted, I just don't know if the cleanest way to implement this is by adding function _fit!(o::MovingTimeWindow, y::TimeArray). Because then that would add TImeSeries.jl as a dependency to OnlineStats.jl, which is annoying.

[1] https://juliastats.org/TimeSeries.jl/latest/split/#from-1

@joshday
Copy link
Owner

joshday commented Jul 12, 2020

Sorry for the slow response! I'd be happy with changing MovingTimeWindow to assume all of the inputs are sorted. I agree with wanting to avoid a new dependency.

Is this something you'd like to implement? I'm about to have a baby (wife is due today!), so I'll be out of commission for a bit.

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

No branches or pull requests

2 participants