Questions tagged [sliding-window]

In data analysis, sliding windows are advancing sub-lists inside lists which allow, e.g., computation of a record's change from the previous record or next record. In networking, a sliding window may refer to a flow control technique that maintains windows of sequential frames sent or received without a corresponding acknowledgement.

In data analysis, sliding windows are advancing sub-lists inside lists which allow, e.g., computation of a record's change from the previous record or next record. In SQL in particular, the analytic functions LEAD(), LAG(), and computations OVER() a changing subset of query results involve sliding windows.

In networking, a sliding window may refer to a flow control technique that maintains windows of sequential frames sent or received without a corresponding acknowledgement.

441 questions
95
votes
4 answers

What is Sliding Window Algorithm? Examples?

While solving a geometry problem, I came across an approach called Sliding Window Algorithm. Couldn't really find any study material/details on it. What is the algorithm about?
Silvester
  • 1,643
  • 2
  • 18
  • 23
49
votes
8 answers

Sliding window of M-by-N shape numpy.ndarray

I have a Numpy array of shape (6,2): [[ 0, 1], [10,11], [20,21], [30,31], [40,41], [50,51]] I need a sliding window with step size 1 and window size 3 like this: [[ 0, 1,10,11,20,21], [10,11,20,21,30,31], [20,21,30,31,40,41], …
siamii
  • 20,540
  • 26
  • 86
  • 136
49
votes
4 answers

R data.table sliding window

What is the best (fastest) way to implement a sliding window function with the data.table package? I'm trying to calculate a rolling median but have multiple rows per date (due to 2 additional factors), which I think means that the zoo rollapply…
alan
  • 3,717
  • 6
  • 31
  • 48
38
votes
3 answers

Simulate lag function in MySQL

| time | company | quote | +---------------------+---------+-------+ | 0000-00-00 00:00:00 | GOOGLE | 40 | | 2012-07-02 21:28:05 | GOOGLE | 60 | | 2012-07-02 21:28:51 | SAP | 60 | | 2012-07-02 21:29:05 | SAP | 20…
javanx
  • 648
  • 1
  • 5
  • 13
26
votes
5 answers

Does reactive extensions support rolling buffers?

I'm using reactive extensions to collate data into buffers of 100ms: this.subscription = this.dataService .Where(x => !string.Equals("FOO", x.Key.Source)) .Buffer(TimeSpan.FromMilliseconds(100)) .ObserveOn(this.dispatcherService) …
Kent Boogaart
  • 165,446
  • 34
  • 376
  • 376
20
votes
3 answers

How can I simply calculate the rolling/moving variance of a time series in python?

I have a simple time series and I am struggling to estimate the variance within a moving window. More specifically, I cannot figure some issues out relating to the way of implementing a sliding window function. For example, when using NumPy and…
Barry
  • 347
  • 2
  • 4
  • 7
15
votes
2 answers

Evaluate a function in a sliding window with Keras

I'm trying to extend a matching matching algorithm across a sequence. My matches are 20 units long and have 4 channels at each timepoint. I have built a model that encapsulates the matching, I just can't figure out how to use that in a sliding…
JudoWill
  • 4,433
  • 1
  • 31
  • 45
14
votes
9 answers

How to aggregate (counting distinct items) over a sliding window in SQL Server?

I am currently using this query (in SQL Server) to count the number of unique item each day: SELECT Date, COUNT(DISTINCT item) FROM myTable GROUP BY Date ORDER BY Date How can I transform this to get for each date the number of unique item over…
RockScience
  • 15,586
  • 22
  • 74
  • 117
12
votes
5 answers

Implementing an efficient sliding-window algorithm in Haskell

I needed an efficient sliding window function in Haskell, so I wrote the following: windows n xz@(x:xs) | length v < n = [] | otherwise = v : windows n xs where v = take n xz My problem with this is that I think the complexity is O(n*m)…
Ana
  • 11,726
  • 5
  • 49
  • 101
12
votes
1 answer

Implementing a "Kurtosis filter" using scipys generic_filter

I have a 5000*5000 numpy array on which I want to calculate the Kurtosis for windows of size 25. I tried putting scipys own kurtosis function in the generic_filter found in ndimage.filters like so: import numpy as np from scipy.stats import…
JEquihua
  • 1,168
  • 2
  • 19
  • 38
11
votes
3 answers

BigQuery SQL for 28-day sliding window aggregate (without writing 28 lines of SQL)

I'm trying to compute a 28 day moving sum in BigQuery using the LAG function. The top answer to this question Bigquery SQL for sliding window aggregate from Felipe Hoffa indicates that that you can use the LAG function. An example of this would…
alan
  • 3,717
  • 6
  • 31
  • 48
10
votes
1 answer

SQL Server: Lead/Lag analytic function across groups (and not within groups)

Sorry for the long post, but I have provided copy & paste sample data and a possible solution approach below. The relevant part of the question is in the upper part of the post (above the horizontal rule). I have the following table Dt …
cryo111
  • 4,174
  • 1
  • 13
  • 32
9
votes
2 answers

How do I lag columns in MySQL?

Consider the following table: SELECT id, value FROM table ORDER BY id ASC; +-----+---------+ | id | value | +-----+---------+ | 12 | 158 | | 15 | 346 | | 27 | 334 | | 84 | 378 | | 85 | 546 | +-----+---------+ The id…
knorv
  • 45,461
  • 71
  • 205
  • 289
9
votes
5 answers

R: Rolling window function with adjustable window and step-size for irregularly spaced observations

Say there is a 2-column data frame with a time or distance column which sequentially increases and an observation column which may have NAs here and there. How can I efficiently use a sliding window function to get some statistic, say a mean, for…
Jota
  • 16,103
  • 7
  • 54
  • 89
9
votes
1 answer

Sliding Window over Time - Data Structure and Garbage Collection

I am trying to implement something along the lines of a Moving Average. In this system, there are no guarantees of a quantity of Integers per time period. I do need to calculate the Average for each period. Therefore, I cannot simply slide over the…
Kurtis
  • 1,509
  • 1
  • 16
  • 29
1
2 3
29 30