Home > data-analysis > manip > cevent > cevent_query_subsequence.m

cevent_query_subsequence

PURPOSE ^

this function searches through the whole cevent and finds those

SYNOPSIS ^

function [sequences] = cevent_query_subsequence(cevent, pattern)

DESCRIPTION ^

 this function searches through the whole cevent and finds those
 subsequences that matches with the sequential sequences defined in 
 PATTERN

 Usage:
 cevent_query_subsequence(CEVENT, PATTERN)
 Input: cevent
        PATTERN: Nx3. [minDuration category maxGap] 

 Output: sequences is a cell array. Each entry is a "small" cevent -- the
 subsequence that matches with the sequence query 
 
 this functins will match a pattern defined by durations, categories, and
 gaps in a cevent variable. the output list has all the subsequences.
 e.g.
 %  cevent = [  1.7410    2.1410   64.0000
     2.8810    4.6010   64.0000
     5.4410    5.8210   64.0000
     6.8010    7.3210   64.0000
     7.4610    7.7810   64.0000
     7.9610    8.4010   64.0000
     9.2010    9.8810   64.0000
    13.7610   14.0610   96.0000
    32.7610   33.0810   32.0000
    33.3610   34.5210   64.0000
    34.7410   35.2210   32.0000
    35.2410   35.6210   32.0000
    36.1610   36.5010   32.0000
    44.1210   44.8210   64.0000
    55.5210   58.7610   64.0000
    58.8410   59.5610   32.0000
    60.7610   61.1410   32.0000
    68.6810   69.0210   64.0000]
    
    case 1: pattern =  [ 0.2 64 1; 0.3 64 0];
    output: 6 subsequences 
     ans =
 
     1.7410    2.1410   64.0000
     2.8810    4.6010   64.0000
 
 
 ans =
 
     2.8810    4.6010   64.0000
     5.4410    5.8210   64.0000
 
 
 ans =
 
     5.4410    5.8210   64.0000
     6.8010    7.3210   64.0000
 
 
 ans =
 
     6.8010    7.3210   64.0000
     7.4610    7.7810   64.0000
 
 
 ans =
 
     7.4610    7.7810   64.0000
     7.9610    8.4010   64.0000
 
 
 ans =
 
     7.9610    8.4010   64.0000
     9.2010    9.8810   64.0000  
 
 
 case 2: pattern = [ 0.2 64 1.2; 0.2 32 0];   
 results: 2 subsequences 
 
 ans =
 
    33.3610   34.5210   64.0000
    34.7410   35.2210   32.0000
 
 
 ans =
 
    55.5210   58.7610   64.0000
    58.8410   59.5610   32.0000
 
    case 3: pattern = [ 0.2 32 1.2; 0.2 64 0];
     results:
     ans =
 
    32.7610   33.0810   32.0000
    33.3610   34.5210   64.0000

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [sequences] = cevent_query_subsequence(cevent, pattern)
0002 % this function searches through the whole cevent and finds those
0003 % subsequences that matches with the sequential sequences defined in
0004 % PATTERN
0005 %
0006 % Usage:
0007 % cevent_query_subsequence(CEVENT, PATTERN)
0008 % Input: cevent
0009 %        PATTERN: Nx3. [minDuration category maxGap]
0010 %
0011 % Output: sequences is a cell array. Each entry is a "small" cevent -- the
0012 % subsequence that matches with the sequence query
0013 %
0014 % this functins will match a pattern defined by durations, categories, and
0015 % gaps in a cevent variable. the output list has all the subsequences.
0016 % e.g.
0017 % %  cevent = [  1.7410    2.1410   64.0000
0018 %     2.8810    4.6010   64.0000
0019 %     5.4410    5.8210   64.0000
0020 %     6.8010    7.3210   64.0000
0021 %     7.4610    7.7810   64.0000
0022 %     7.9610    8.4010   64.0000
0023 %     9.2010    9.8810   64.0000
0024 %    13.7610   14.0610   96.0000
0025 %    32.7610   33.0810   32.0000
0026 %    33.3610   34.5210   64.0000
0027 %    34.7410   35.2210   32.0000
0028 %    35.2410   35.6210   32.0000
0029 %    36.1610   36.5010   32.0000
0030 %    44.1210   44.8210   64.0000
0031 %    55.5210   58.7610   64.0000
0032 %    58.8410   59.5610   32.0000
0033 %    60.7610   61.1410   32.0000
0034 %    68.6810   69.0210   64.0000]
0035 %
0036 %    case 1: pattern =  [ 0.2 64 1; 0.3 64 0];
0037 %    output: 6 subsequences
0038 %     ans =
0039 %
0040 %     1.7410    2.1410   64.0000
0041 %     2.8810    4.6010   64.0000
0042 %
0043 %
0044 % ans =
0045 %
0046 %     2.8810    4.6010   64.0000
0047 %     5.4410    5.8210   64.0000
0048 %
0049 %
0050 % ans =
0051 %
0052 %     5.4410    5.8210   64.0000
0053 %     6.8010    7.3210   64.0000
0054 %
0055 %
0056 % ans =
0057 %
0058 %     6.8010    7.3210   64.0000
0059 %     7.4610    7.7810   64.0000
0060 %
0061 %
0062 % ans =
0063 %
0064 %     7.4610    7.7810   64.0000
0065 %     7.9610    8.4010   64.0000
0066 %
0067 %
0068 % ans =
0069 %
0070 %     7.9610    8.4010   64.0000
0071 %     9.2010    9.8810   64.0000
0072 %
0073 %
0074 % case 2: pattern = [ 0.2 64 1.2; 0.2 32 0];
0075 % results: 2 subsequences
0076 %
0077 % ans =
0078 %
0079 %    33.3610   34.5210   64.0000
0080 %    34.7410   35.2210   32.0000
0081 %
0082 %
0083 % ans =
0084 %
0085 %    55.5210   58.7610   64.0000
0086 %    58.8410   59.5610   32.0000
0087 %
0088 %    case 3: pattern = [ 0.2 32 1.2; 0.2 64 0];
0089 %     results:
0090 %     ans =
0091 %
0092 %    32.7610   33.0810   32.0000
0093 %    33.3610   34.5210   64.0000
0094 
0095 cp = 1; % a pointer to the current symbol in the sequence
0096 isGap = 0; % 0 -- gap is small enough
0097 nSq = 0; 
0098 nEvent = size(cevent, 1); 
0099 nSymbol = size(pattern, 1);
0100 sequences = []; 
0101 
0102 i = 0; 
0103 while (i < nEvent)
0104     i = i + 1; 
0105     if (cp > 1) 
0106         if ((cevent(i,1) - cevent(i-1,2))<=pattern(cp-1,3)) % check the PREVIOUS gap
0107             isGap = 0;
0108         else
0109             isGap = 1; 
0110         end;
0111     end;
0112     if ((pattern(cp,2) == cevent(i,3)) && ((cevent(i,2) - cevent(i,1) >= pattern(cp,1))) && (isGap == 0))
0113         if (cp == nSymbol) % found one!
0114             % save it
0115             nSq = nSq + 1;
0116             sequences{nSq} =  cevent(i-cp+1:i,:);
0117             i = i - cp + 1; % also set the loop back to cover overallapped patterns
0118             cp = 1; % go back to the first symbol in the sequence
0119             isGap = 0; 
0120 
0121         else
0122             cp = cp + 1; 
0123         end;
0124     else 
0125         i = i - cp + 1; % go back to recheck overlapped items
0126         cp = 1; % go back to the first symbol
0127         isGap = 0; 
0128     end;
0129 end;
0130

Generated on Tue 23-May-2017 20:00:55 by m2html © 2005