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.

583 questions
208
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
  • 2,819
  • 5
  • 22
  • 23
61
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
  • 23,374
  • 28
  • 93
  • 143
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
  • 4,247
  • 7
  • 37
  • 49
41
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
  • 678
  • 1
  • 5
  • 13
27
votes
6 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
  • 175,602
  • 35
  • 392
  • 393
22
votes
7 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
  • 377
  • 2
  • 4
  • 7
21
votes
6 answers

Sum values in a rolling/sliding window

I have the following vector: x = c(1, 2, 3, 10, 20, 30) At each index, 3 consecutive elements are summed, resulting in the following vector: c(6, 15, 33, 60) Thus, first element is 1 + 2 + 3 = 6, the second element is 2 + 3 + 10 = 15, et.c
user2834313
  • 213
  • 1
  • 2
  • 6
17
votes
3 answers

Sliding window over seq

In Clojure, what would be the nicest way to have a sliding window over a (finite, not too large) seq? Should I just use drop and take and keep track of the current index or is there a nicer way I'm missing?
pmf
  • 7,619
  • 4
  • 47
  • 77
16
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,741
  • 2
  • 36
  • 48
16
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)…
user1002430
16
votes
4 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
  • 4,247
  • 7
  • 37
  • 49
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
  • 17,932
  • 26
  • 89
  • 125
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,217
  • 3
  • 20
  • 40
12
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,444
  • 1
  • 15
  • 37
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
  • 49,059
  • 74
  • 210
  • 294
1
2 3
38 39