sliding-window

Fast rolling-sum for list of data vectors (2d matrix)

孤者浪人 提交于 2019-12-03 14:42:32
I am looking for a fast way to compute a rolling-sum, possibly using Numpy. Here is my first approach: def func1(M, w): Rtn = np.zeros((M.shape[0], M.shape[1]-w+1)) for i in range(M.shape[1]-w+1): Rtn[:,i] = np.sum(M[:, i:w+i], axis=1) return Rtn M = np.array([[0., 0., 0., 0., 0., 1., 1., 0., 1., 1., 1., 0., 0.], [0., 0., 1., 0., 1., 0., 0., 0., 0., 0., 0., 1., 1.], [1., 1., 0., 1., 0., 0., 0., 1., 0., 0., 0., 0., 0.]]) window_size = 4 print func1(M, window_size) [[ 0. 0. 1. 2. 2. 3. 3. 3. 3. 2.] [ 1. 2. 2. 1. 1. 0. 0. 0. 1. 2.] [ 3. 2. 1. 1. 1. 1. 1. 1. 0. 0.]] I wanted to prevent the window

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

主宰稳场 提交于 2019-12-03 11:18:13
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 window size = 20: def rolling_window(a, window): shape = a.shape[:-1] + (a.shape[-1] - window + 1, window) strides = a.strides + (a.strides[-1],) return np.lib.stride_tricks.as_strided(a, shape=shape, strides=strides) rolling_window(data, 20) np.var(rolling_window(data, 20), -1) datavar=np.var(rolling_window(data, 20), -1) Perhaps I am mistaken

how to make Sliding window model for data stream mining?

冷暖自知 提交于 2019-12-03 04:01:05
we have a situation that a stream (data from sensor or click stream data at server) is coming with sliding window algorithm we have to store the last (say) 500 samples of data in memory. These samples are then used to create histograms, aggregations & capture information about anomalies in the input data stream. please tell me how to make such sliding window. If you are asking how to store and maintain these values in a sliding-window manner, consider this simple example which keep tracks of the running mean of the last 10 values of some random stream of data: WINDOW_SIZE = 10; x = nan(WINDOW

Numpy summation with sliding window is really slow

时间秒杀一切 提交于 2019-12-02 18:15:43
问题 Code: shape = np.array([6, 6]) grid = np.array([x.ravel() for x in np.meshgrid(*[np.arange(x) for i, x in enumerate(shape)], indexing='ij')]).T slices = [tuple(slice(box[i], box[i] + 2) for i in range(len(box))) for box in grid] score = np.zeros((7,7,3)) column = np.random.randn(36, 12) #just for example column >> array([[ 0, 1, 2, 3, ... 425, 426, 427, 428, 429, 430, 431]]) column = column.reshape((16, 3, 3, 3)) for i, window in enumerate(slices): score[window] += column[i] score >> array([[

Create overlapping and non-overlapping sliding windows in MATLAB

南笙酒味 提交于 2019-12-02 09:38:07
问题 I am trying to create overlapping and non-overlapping blocks of data from an array Data containing N elements. How can I correctly form sub-arrays of Data for any N and any blksze ? The following code is for non-overlapping blocks throws error because of the number of elements exceed when creating sub-blocks. For example, let Data = [1,2,3,4,5,6] , then for overlapping case I should get : block size blksze = 2 , I would get block1 = [1,2], block2 = [2,3], block3 = [3,4], block4 = [4,5],

Numpy summation with sliding window is really slow

不羁岁月 提交于 2019-12-02 09:37:41
Code: shape = np.array([6, 6]) grid = np.array([x.ravel() for x in np.meshgrid(*[np.arange(x) for i, x in enumerate(shape)], indexing='ij')]).T slices = [tuple(slice(box[i], box[i] + 2) for i in range(len(box))) for box in grid] score = np.zeros((7,7,3)) column = np.random.randn(36, 12) #just for example column >> array([[ 0, 1, 2, 3, ... 425, 426, 427, 428, 429, 430, 431]]) column = column.reshape((16, 3, 3, 3)) for i, window in enumerate(slices): score[window] += column[i] score >> array([[[0.000e+00, 1.000e+00, 2.000e+00], [3.000e+01, 3.200e+01, 3.400e+01], [9.000e+01, 9.300e+01, 9.600e+01]

Create overlapping and non-overlapping sliding windows in MATLAB

北城以北 提交于 2019-12-02 05:49:52
I am trying to create overlapping and non-overlapping blocks of data from an array Data containing N elements. How can I correctly form sub-arrays of Data for any N and any blksze ? The following code is for non-overlapping blocks throws error because of the number of elements exceed when creating sub-blocks. For example, let Data = [1,2,3,4,5,6] , then for overlapping case I should get : block size blksze = 2 , I would get block1 = [1,2], block2 = [2,3], block3 = [3,4], block4 = [4,5], block5 = [5,6] for non-overlapping : block size blksze = 2 , I would get block1 = [1,2], block2 = [3,4],

How do I select n elements of a sequence in windows of m ? (matlab)

大憨熊 提交于 2019-12-01 21:34:02
问题 Quick MATLAB question. What would be the best/most efficient way to select a certain number of elements, 'n' in windows of 'm'. In other words, I want to select the first 50 elements of a sequence, then elements 10-60, then elements 20-70 ect. Right now, my sequence is in vector format(but this can easily be changed). EDIT: The sequences that I am dealing with are too long to be stored in my RAM. I need to be able to create the windows, and then call upon the window that I want to analyze

How do I select n elements of a sequence in windows of m ? (matlab)

蓝咒 提交于 2019-12-01 20:01:26
Quick MATLAB question. What would be the best/most efficient way to select a certain number of elements, 'n' in windows of 'm'. In other words, I want to select the first 50 elements of a sequence, then elements 10-60, then elements 20-70 ect. Right now, my sequence is in vector format(but this can easily be changed). EDIT: The sequences that I am dealing with are too long to be stored in my RAM. I need to be able to create the windows, and then call upon the window that I want to analyze/preform another command on. Do you have enough RAM to store a 50-by-nWindow array in memory? In that case,

Sliding window - how to get window location on image?

旧巷老猫 提交于 2019-12-01 14:20:11
Referring to this great sliding window implementation in python: https://github.com/keepitsimple/ocrtest/blob/master/sliding_window.py#blob_contributors_box , my question is - where in the code can I actually see the location of the current window on the image? Or how can I grab its location? On lines 72 and after line 85, I tried printing out shape and newstrides , but I'm clearly not getting anywhere here. In the norm_shape function, I printed out tuple but the output was only the window dimensions (if I understood that right, too). But I need not just the dimensions, such as width and