Home > data-utility > cevent_pattern_query > demo_cevent_query_patterns.m

demo_cevent_query_patterns

PURPOSE ^

This is the example script for function: cevent_query_miner

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 This is the example script for function: cevent_query_miner
 [results_final chunked_data] = cevent_query_miner(query,data,relation)
 The description is embeded between the codes

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % This is the example script for function: cevent_query_miner
0002 % [results_final chunked_data] = cevent_query_miner(query,data,relation)
0003 % The description is embeded between the codes
0004 
0005 clear all;
0006 
0007 exp_id = 70;
0008 sub_list = list_subjects(exp_id);
0009 
0010 %   query: a struct that includes the overall information about this query.
0011 %       required fields:
0012 %       sub_list: the subject list
0013 %       grouping: the way how data should be extracted, for example, based
0014 %       on subjects or based on trials. By default, it is set to 'subject'.
0015 %       See GET_VARIABLE_BY_GROUPING.
0016 query.sub_list = sub_list;
0017 query.grouping = 'trial_cat'; 
0018 
0019 %   data: a list of structs that contains the information of the cevent
0020 %       variables. The cevent data that can be fed into the miner function
0021 %       can be two forms: 1. variable name; 2. cell of cevents;
0022 %   For example, if user specify the variable name of the cevent, the field
0023 %   VAR_NAME needs to be set:
0024 %       data(1).var_name = 'cevent_inhand_parent';
0025 %     optional fields are:
0026 %       merge_thresh: the parameter for merging cevents if two consecutive
0027 %       cevents have the same cevent value and are close together (the gap
0028 %       between two cevents <= merge_thresh)
0029 %       dur_range: the duration range of cevents.
0030 %   If the user wants to specify the actual cevent data, then the field
0031 %   CHUNKS must be set:
0032 %       data(1).chunks =
0033 %           [26x3 double]    [37x3 double]    [17x3 double]    [35x3 double]
0034 %     optional fields are: dur_range
0035 data(1).var_name = 'cevent_inhand_parent';
0036 data(1).merge_thresh = 0.2;
0037 data(1).dur_range = [0.2 inf];
0038 
0039 data(2).var_name = 'cevent_inhand_child';
0040 data(2).merge_thresh = 0.2;
0041 data(2).dur_range = [0.2 inf];
0042 
0043 data(3).var_name = 'cevent_vision_dominant-obj_cam1_4';
0044 data(3).merge_thresh = 0.2;
0045 data(3).dur_range = [0.2 inf];
0046 
0047 %   relation: a list of structs that contains the information of the actual
0048 %   queries. User can define arbitrary number of relations on any two data
0049 %   variable.
0050 %   required fields:
0051 %     data_list: 1*2 matrix, indicating the data chunk targets, the query
0052 %       defined by this relation will be performed on these two data.
0053 %       For example:
0054 %       relation(1).data_list = [2 1];
0055 %       The above code means that the query will be performed on data(2)
0056 %       and data(1), and data(2) will serve as base cevents for searching:
0057 %       the function will go through every cevent in data(2) to search for
0058 %       a following cevent in data(1).
0059 %     type: the relation type between two data chunks, the value can be set
0060 %       to 'following', 'leading', 'within', 'overlap'.
0061 %     whence_list: indicating the relationship is between the start or end
0062 %       time point of the two cevents.
0063 %     interval: the interval limit on the relationship.
0064 %     roi_list: if user want to extract patterns with specified cevent
0065 %       values, this field needs to be set.
0066 %       For example:
0067 %       relation(1).roi_list = [1 2 3 4 5];
0068 %       Then the function will extract event pairs with the same cevent value,
0069 %       but the cevent value has to be in the list of [1 2 3 4 5];
0070 %       relation(1).roi_list = {[1] [2 3]; [2] [1 3]; [3] [1 2]};
0071 %       Then the function will extract event pairs with the following
0072 %       cevent value pairs: [1 2], [1 3], [2 1], [2 3], [3 1], [3 2];
0073 %     mapping_arg: this field can only be set when TYPE is 'following',
0074 %       'leading' or 'within'.
0075 %       it is usually the case that within an interval, there
0076 %       are more than one pair that will meet the criteria, so user has to
0077 %       specify that whether only the nearest pair is extracted or all the
0078 %       pairs can be considered as candidates.
0079 %       The value can be 'many2many', 'many2one', 'one2one'.
0080 %     overlap_arg: this field can only be set when TYPE is 'overlap'.
0081 %       The value can be:
0082 %           start: cevents that overlap with the onsets of base cevents
0083 %               (starts before base cevent, ends before base cevent);
0084 %           startend: cevents that overlap with the onsets and the offsets
0085 %               of base cevents (starts before base cevent, ends after base cevent);
0086 %           within: cevents that start later than onset and ends earlier
0087 %               than the offsets of base cevents.
0088 %           end: cevents that overlap with the offsets of base cevents;
0089 %           all: all the overlapping cevents;
0090 %           equal: identical overlapping cevents (starts at the same time,
0091 %               ends at the same time)
0092 %     Please see functions
0093 %       CEVENT_GET_FOLLOWING_CEVENTS, CEVENT_GET_LEADING_CEVENTS,
0094 %       CEVENTS_GET_CEVENTS_WITHIN_INTERVAL, CEVENT_GET_OVERLAP_CEVENTS
0095 %     For further information.
0096 relation(1).data_list = [1 2]; % ORDER MATTERS data_list(1) means the base events and data_list(2) means the search events
0097 relation(1).type = 'following'; %'following', 'leading' or 'overlap'
0098 relation(1).mapping_arg = 'many2many';
0099 relation(1).whence_list = {'start'; 'start'};
0100 relation(1).interval = [0 5];
0101 relation(1).roi_list = [1 2 3 4 5];
0102 
0103 relation(2).data_list = [2 3];
0104 relation(2).type = 'overlap'; %'following', 'leading' or 'overlap'
0105 relation(2).whence_list = {'start'; 'start'};
0106 relation(2).overlap_arg = 'all';
0107 relation(2).roi_list = [1 2 3 4 5];
0108 
0109 relation(3).data_list = [1 3];
0110 relation(3).type = 'following'; %'following', 'leading' or 'overlap'
0111 relation(3).mapping_arg = 'many2many';
0112 relation(3).whence_list = {'start'; 'start'};
0113 relation(3).interval = [0 5];
0114 
0115 %   query: a struct that includes the overall information about this query.
0116 %   optional fields for input query, only set when user want to extract continue
0117 %   variables based on the ranges of the cevent query results:
0118 %     chunking_var_name: the list of cont variable names;
0119 %     chunking_ref_column: the time ranges that will be used to extract
0120 %       continue variables. [1 2] means that the ranges are set using first column from
0121 %       the cevent query results as the onset of events, and the second column as the
0122 %       offset of event ranges.
0123 %     chunking_whence & chunking_interval: parameters that are used to produce
0124 %       user specified intervals based on the the event ranges that were extracted based
0125 %       on chunking_ref_column. The value of chunking_whence can be 'start'/'end'/'startend'.
0126 % query.chunking_var_name = {'cont_vision_size_obj1_child'; ...
0127 %     'cont_vision_size_obj2_child'; ...
0128 %     'cont_vision_size_obj3_child'; ...
0129 %     'cont_vision_size_obj4_child'; ...
0130 %     'cont_vision_size_obj5_child'};
0131 % query.chunking_ref_column = [1 2];
0132 % query.chunking_whence = 'startend';
0133 % query.chunking_interval = [-1 5];
0134 
0135 % Call the actual function:
0136 % Output:
0137 %   results_final: contains the query result that meets all the
0138 %   requirements that were defined by the user in the RELATION structure.
0139 %   It is a list of cells, one cell for each subject or trial;
0140 %   For example:
0141 %   results_final =
0142 %     [ 4x9 double]
0143 %     [ 6x9 double]
0144 %     [ 0x9 double]
0145 %     [ 3x9 double]
0146 %     [10x9 double]
0147 %     [ 5x9 double]
0148 %     [ 4x9 double]
0149 %     [ 1x9 double]
0150 %     [ 3x9 double]
0151 %     [ 5x9 double]
0152 %     [ 0x9 double]
0153 %     [ 4x9 double]
0154 %     [ 6x9 double]
0155 %   chunked_data: this will only has value when the field 'chunking_var_name'
0156 %   of QUERY is set. It will be a matrix of cells, the number of row will
0157 %   be equal to the number of subjects or trials, the number of columns
0158 %   will be equal to the list of continue variables that were set by the
0159 %   user.
0160 %   For example:
0161 % chunked_data =
0162 %     { 4x1 cell}    { 4x1 cell}    { 4x1 cell}    { 4x1 cell}    { 4x1 cell}
0163 %     { 6x1 cell}    { 6x1 cell}    { 6x1 cell}    { 6x1 cell}    { 6x1 cell}
0164 %              {}             {}             {}             {}             {}
0165 %     { 3x1 cell}    { 3x1 cell}    { 3x1 cell}    { 3x1 cell}    { 3x1 cell}
0166 %     {10x1 cell}    {10x1 cell}    {10x1 cell}    {10x1 cell}    {10x1 cell}
0167 %     { 5x1 cell}    { 5x1 cell}    { 5x1 cell}    { 5x1 cell}    { 5x1 cell}
0168 %     { 4x1 cell}    { 4x1 cell}    { 4x1 cell}    { 4x1 cell}    { 4x1 cell}
0169 %     { 1x1 cell}    { 1x1 cell}    { 1x1 cell}    { 1x1 cell}    { 1x1 cell}
0170 %     { 3x1 cell}    { 3x1 cell}    { 3x1 cell}    { 3x1 cell}    { 3x1 cell}
0171 %     { 5x1 cell}    { 5x1 cell}    { 5x1 cell}    { 5x1 cell}    { 5x1 cell}
0172 %              {}             {}             {}             {}             {}
0173 %     { 4x1 cell}    { 4x1 cell}    { 4x1 cell}    { 4x1 cell}    { 4x1 cell}
0174 %     { 6x1 cell}    { 6x1 cell}    { 6x1 cell}    { 6x1 cell}    { 6x1 cell}
0175 % [results_final chunked_data] = cevent_query_patterns(query, data, relation);
0176 results_final = cevent_query_patterns(query, data, relation);
0177 
0178 %% to calculate the statistics of the patterns
0179 % stats_results = cevent_cal_stats(results_final(:,1));
0180 %
0181 
0182 % pause
0183 
0184 %% start plotting
0185 plotting_example_id = 1;
0186 % you need to vertcat the results before plotting, for example:
0187 %   cevent_data: a 51 * 9 matrix, one row represents one pattern
0188 %   cont_data: a 51 * 5 cells
0189 %
0190 % For example:
0191 % cevent_data =
0192 %    90.6000   93.1000    1.0000   92.2000  108.9000    1.0000   94.1000   94.4000    1.0000
0193 %   303.9000  304.4000    3.0000  308.2000  310.8000    3.0000  308.8000  311.1000    3.0000
0194 %   335.9000  341.4000    2.0000  340.5000  349.6000    2.0000  340.9000  344.4000    2.0000
0195 %   350.4000  351.3000    2.0000  351.7000  354.0000    2.0000  350.8000  352.6000    2.0000
0196 %    72.4000   81.1000    3.0000   73.4000   75.4000    3.0000   73.2000   74.0000    3.0000
0197 %    72.4000   81.1000    3.0000   73.4000   75.4000    3.0000   74.2000   75.3000    3.0000
0198 %
0199 % cont_data =
0200 %     [ 85x2 double]    [ 85x2 double]    [ 85x2 double]    [ 85x2 double]    [ 85x2 double]
0201 %     [ 65x2 double]    [ 65x2 double]    [ 65x2 double]    [ 65x2 double]    [ 65x2 double]
0202 %     [115x2 double]    [115x2 double]    [115x2 double]    [115x2 double]    [115x2 double]
0203 %     [ 69x2 double]    [ 69x2 double]    [ 69x2 double]    [ 69x2 double]    [ 69x2 double]
0204 %     [147x2 double]    [147x2 double]    [147x2 double]    [147x2 double]    [147x2 double]
0205 %     [147x2 double]    [147x2 double]    [147x2 double]    [147x2 double]    [147x2 double]
0206 %
0207 cevent_data = cell2mat(results_final);
0208 if plotting_example_id ~= 1
0209     for cdi = 1:size(chunked_data, 2)
0210         cont_data{1,cdi} = vertcat(chunked_data{:,cdi});
0211     end
0212     cont_data = horzcat(cont_data{:});
0213 end
0214 
0215 %
0216 colormap = { ...
0217     [0 0 1]; ... % blue
0218     [0 1 0]; ... % green
0219     [1 0 0]; ... % red
0220     [1 1 0]; ... % yellow
0221     [1 0 1]; ... % pink
0222     }; 
0223 
0224 % 'MAX_ROWS':
0225 %   The number of instances that will appear in one figure
0226 args.MAX_ROWS = 30;
0227 % 'legend'
0228 args.legend = {data(1).var_name; data(2).var_name; data(3).var_name};
0229 % User can specify the color code for each pattern. By default, the color
0230 % will be extracted according to a rainbow color spectrum.
0231 args.colormap = colormap;
0232 % 'ForceZero' & 'ref_column':
0233 %   The timing for cevents in each query is globally different, user can set
0234 %   'ForceZero' to true and define a relative 0 for each pattern by setting
0235 %   the field of 'ref_column' - which column in the pattern matrix is set to
0236 %   be relative 0 time point.
0237 %   For example, for matrix
0238 %   cevent_data =
0239 %    90.6000   93.1000    1.0000   92.2000  108.9000    1.0000   94.1000   94.4000    1.0000
0240 %   303.9000  304.4000    3.0000  308.2000  310.8000    3.0000  308.8000  311.1000    3.0000
0241 %   335.9000  341.4000    2.0000  340.5000  349.6000    2.0000  340.9000  344.4000    2.0000
0242 %   350.4000  351.3000    2.0000  351.7000  354.0000    2.0000  350.8000  352.6000    2.0000
0243 %    72.4000   81.1000    3.0000   73.4000   75.4000    3.0000   73.2000   74.0000    3.0000
0244 %    72.4000   81.1000    3.0000   73.4000   75.4000    3.0000   74.2000   75.3000    3.0000
0245 %   If args.ref_column = 2, then the matrix will become:
0246 %   cevent_data =
0247 %    -2.5000         0    1.0000   -0.9000   15.8000    1.0000    1.0000    1.3000    1.0000
0248 %    -0.5000         0    3.0000    3.8000    6.4000    3.0000    4.4000    6.7000    3.0000
0249 %    -5.5000         0    2.0000   -0.9000    8.2000    2.0000   -0.5000    3.0000    2.0000
0250 %    -0.9000         0    2.0000    0.4000    2.7000    2.0000   -0.5000    1.3000    2.0000
0251 %    -8.7000         0    3.0000   -7.7000   -5.7000    3.0000   -7.9000   -7.1000    3.0000
0252 %    -8.7000         0    3.0000   -7.7000   -5.7000    3.0000   -6.9000   -5.8000    3.0000
0253 args.ForceZero = 1;
0254 args.ref_column = 8;
0255 % 'color_code':
0256 %   User can set color for the cevent instances in patterns in two ways:
0257 %   'cevent_type': all the cevents from the same variable source (the first
0258 %   three columns in the pattern matrix) will be getting the same color
0259 %   disregard the cevent value.
0260 %   'cevent_value': all the cevents with the same cevent value will be
0261 %   getting the same color, disregard the variable type.
0262 args.color_code = 'cevent_type';
0263 % 'transparency':
0264 %   Sometimes, cevents will have overlaps, by setting the 'transparency'
0265 %   field to a value smaller than 1 the overlapping segments will be shown
0266 %   with a mixture of colors from the overlapping cevents.
0267 % args.transparency = 0.5;
0268 % 'stream_position':
0269 %   In the pattern matrix, the first three column will be considered as
0270 %   cevents from one variable source, and ...
0271 %   When one pattern is consisting of multiple cevents, the field of
0272 %   STREAM_POSITION indicates the position that each cevent will be plotted
0273 %   on.
0274 %   For example, if
0275 %   args.stream_position = [1 1 1]
0276 %   which means that in each pattern, there are three cevents, and all
0277 %   three cevents will be plotted in the same y space.
0278 %   and if
0279 %   args.stream_position = [1 2 3]
0280 %   The space for plotting each pattern instance will be first devided into
0281 %   three parts on y scale, and the first cevent will be plotted on the top
0282 %   part, the second cevent will be plotted on the middle part, and the
0283 %   third cevent will be plotted on the bottom part.
0284 args.stream_position = [1 2 3];
0285 % 'vert_line':
0286 %   Setting this field allows you to draw red verticle lines on the plot.
0287 args.vert_line = [0 5]; 
0288 % 'save_name':
0289 %   By setting this field, all the figures will be automatically closed
0290 %   and saved.
0291 if plotting_example_id == 1
0292     args.save_name = 'pattern_plotting_example1';
0293     plot_temp_patterns(cevent_data, args);
0294 end
0295 
0296 % If user wants to have a figure side by side with the cevent pattern
0297 % plotting figure for continue variables, these field can be set:
0298 % 'legend'
0299 cont_args.legend = {'obj1'; 'obj2'; 'obj3'; 'obj4'; 'obj5'};
0300 % 'colormap': same as describe above
0301 cont_args.colormap = colormap;
0302 % 'vert_line': same as describe above
0303 cont_args.vert_line = [0 5];
0304 % 'target_value_ref_column':
0305 %   This field indicates which continue variable should be plotted
0306 %   according to cevent value column in the cevent pattern matrix.
0307 %   If this field is not set, then all the continue variables will be
0308 %   plotted.
0309 if plotting_example_id == 2
0310     args.save_name = 'pattern_plotting_example2';
0311     plot_temp_patterns(cevent_data, args, cont_data, cont_args);
0312 end
0313 
0314 cont_args.target_value_ref_column = 3;
0315 if plotting_example_id == 3
0316     args.save_name = 'pattern_plotting_example3';
0317     plot_temp_patterns(cevent_data, args, cont_data, cont_args);
0318 end

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