Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sliding window algorithm for activity recognition

I want to write a sliding window algorithm for use in activity recognition.

The training data is <1xN> so I'm thinking I just need to take (say window_size=3) the window_size of data and train that. I also later want to use this algorithm on a matrix .

I'm new to matlab so i need any advice/directions on how to implement this correctly.

like image 244
csc Avatar asked Feb 04 '10 19:02

csc


People also ask

Which algorithms use human activity recognition?

Hidden Markov Model plays a major role in activity recognition system. It is used to recognize the gesture, speech and pattern recognition.

What is sliding window in machine learning?

The use of prior time steps to predict the next time step is called the sliding window method. For short, it may be called the window method in some literature. In statistics and time series analysis, this is called a lag or lag method. The number of previous time steps is called the window width or size of the lag.

Is activity recognition a computer vision task?

Human activity recognition (HAR) is a widely studied computer vision problem. Applications of HAR include video surveillance, health care, and human-computer interaction. As the imaging technique advances and the camera device upgrades, novel approaches for HAR constantly emerge.

What is feature extraction in human activity recognition?

Abstract: An online recognition system must analyze the changes in the sensing data and at any significant detection; it has to decide if there is a change in the activity performed by the person.


1 Answers

The short answer:

%# nx = length(x)
%# nwind = window_size
idx = bsxfun(@plus, (1:nwind)', 1+(0:(fix(nx/nwind)-1))*nwind)-1;

idx will be a matrix of size nwind-by-K where K is the number of sliding windows (ie each column contains the indices of one sliding window).

Note that in the code above, if the last window's length is less than the desired one, it is dropped. Also the sliding windows are non-overlapping.

An example to illustrate:

%# lets create a sin signal
t = linspace(0,1,200);
x = sin(2*pi*5*t);

%# compute indices
nx = length(x);
nwind = 8;
idx = bsxfun(@plus, (1:nwind)', 1+(0:(fix(nx/nwind)-1))*nwind)-1;

%'# loop over sliding windows
for k=1:size(idx,2)
    slidingWindow = x( idx(:,k) );
    %# do something with it ..
end

%# or more concisely as
slidingWindows = x(idx);

EDIT:

For overlapping windows, let:

noverlap = number of overlapping elements

then the above is simply changed to:

idx = bsxfun(@plus, (1:nwind)', 1+(0:(fix((nx-noverlap)/(nwind-noverlap))-1))*(nwind-noverlap))-1;


An example to show the result:

>> nx = 100; nwind = 10; noverlap = 2;
>> idx = bsxfun(@plus, (1:nwind)', 1+(0:(fix((nx-noverlap)/(nwind-noverlap))-1))*(nwind-noverlap))-1
idx =
     1     9    17    25    33    41    49    57    65    73    81    89
     2    10    18    26    34    42    50    58    66    74    82    90
     3    11    19    27    35    43    51    59    67    75    83    91
     4    12    20    28    36    44    52    60    68    76    84    92
     5    13    21    29    37    45    53    61    69    77    85    93
     6    14    22    30    38    46    54    62    70    78    86    94
     7    15    23    31    39    47    55    63    71    79    87    95
     8    16    24    32    40    48    56    64    72    80    88    96
     9    17    25    33    41    49    57    65    73    81    89    97
    10    18    26    34    42    50    58    66    74    82    90    98
like image 158
Amro Avatar answered Oct 19 '22 23:10

Amro