Home > data-import > generate_learning_score_variables.m

generate_learning_score_variables

PURPOSE ^

This function reads stimulus_table.txt and TestInforExpXX.txt under

SYNOPSIS ^

function [sub_list_score, result_mat_score_counts] = generate_learning_score_variables(exp_id)

DESCRIPTION ^

 This function reads stimulus_table.txt and TestInforExpXX.txt under
 multidir root with each experiment, and for every subject that has
 learning test scores, learning score variables will be generated.
 
 TestInforExpXX.txt is recorded in this format:
 Subject    Subject_ID      Dodi    Kookle    Mobit    Wawa    Riffy    Tema
 __20140627_16579    7106    1    0    2    0    0    1
 __20140717_16710    7107    1    1    1    1    0    0
 
 Output: 4 learning score variables: 
 One overall score variable
 1 - 'cevent_speech_naming_test-score', ...
 
 For the first  'cevent_speech_naming_test-score', the first two columns 
 will be the same with 'cevent_speech_naming_local-id', and the categorical 
 value column will be 0, 1, 2, indicating the learning score.
 
 Three separated learning score variables:
 2 - 'cevent_speech_naming_learn-score-0_parent', ...
 3 - 'cevent_speech_naming_learn-score-1_parent', ...
 4 - 'cevent_speech_naming_learn-score-2_parent', ...
 
 Each will only contain variables that are scored 0/1/2 according to title, and 
 the 3rd column will be the local naming object id. Some of them will be
 empty, when a particular subject didn't have objects learned with that
 score.
 
 Each cevent corresponds to one naming instance.
 Warning: there are utterances containing 2 object names; as a result,
 certain naming cevent has two learning scores.
 
 Last updated by Linger, txu@indiana.edu on 07/21/2016
 
 The script was ran for experiments 14, 32, 34, 43, 44, 71, 72 on
 07/21/2016 by Linger, txu@indiana.edu.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [sub_list_score, result_mat_score_counts] = generate_learning_score_variables(exp_id)
0002 % This function reads stimulus_table.txt and TestInforExpXX.txt under
0003 % multidir root with each experiment, and for every subject that has
0004 % learning test scores, learning score variables will be generated.
0005 %
0006 % TestInforExpXX.txt is recorded in this format:
0007 % Subject    Subject_ID      Dodi    Kookle    Mobit    Wawa    Riffy    Tema
0008 % __20140627_16579    7106    1    0    2    0    0    1
0009 % __20140717_16710    7107    1    1    1    1    0    0
0010 %
0011 % Output: 4 learning score variables:
0012 % One overall score variable
0013 % 1 - 'cevent_speech_naming_test-score', ...
0014 %
0015 % For the first  'cevent_speech_naming_test-score', the first two columns
0016 % will be the same with 'cevent_speech_naming_local-id', and the categorical
0017 % value column will be 0, 1, 2, indicating the learning score.
0018 %
0019 % Three separated learning score variables:
0020 % 2 - 'cevent_speech_naming_learn-score-0_parent', ...
0021 % 3 - 'cevent_speech_naming_learn-score-1_parent', ...
0022 % 4 - 'cevent_speech_naming_learn-score-2_parent', ...
0023 %
0024 % Each will only contain variables that are scored 0/1/2 according to title, and
0025 % the 3rd column will be the local naming object id. Some of them will be
0026 % empty, when a particular subject didn't have objects learned with that
0027 % score.
0028 %
0029 % Each cevent corresponds to one naming instance.
0030 % Warning: there are utterances containing 2 object names; as a result,
0031 % certain naming cevent has two learning scores.
0032 %
0033 % Last updated by Linger, txu@indiana.edu on 07/21/2016
0034 %
0035 % The script was ran for experiments 14, 32, 34, 43, 44, 71, 72 on
0036 % 07/21/2016 by Linger, txu@indiana.edu.
0037 
0038 % clear all;
0039 % exp_id = 44;
0040 
0041 % Two boolean variables for debugging purposes.
0042 is_visual_examine = false;
0043 is_record_variable = true;
0044 
0045 multidir = get_multidir_root();
0046 
0047 % STEP 1: parse the stimulus table to get vocal id and object trial info
0048 filename_stimulus = 'stimulus_table.txt';
0049 fname_stimulus = fullfile(multidir, filename_stimulus);
0050 [exp_num_in_obj_rec,local_id,trial,color,labelme_name, object_id, word,vocab_id] = ...
0051     textread(fname_stimulus,'%d%d%d%s%s%d%s%d','delimiter',',','headerlines',1);
0052 
0053 mask_exp = exp_num_in_obj_rec == exp_id;
0054 local_id = local_id(mask_exp);
0055 trial = trial(mask_exp);
0056 % object_id = object_id(mask_exp);
0057 word = word(mask_exp);
0058 vocab_id = vocab_id(mask_exp);
0059 
0060 fname_testinfo = sprintf('TestInfoExp%d.txt', exp_id);
0061 fname_testinfo = fullfile(multidir, fname_testinfo);
0062 sub_list = list_subjects(exp_id);
0063 
0064 % STEP 2: parse the test score file
0065 % Subject    Subject_ID      Dodi    Kookle    Mobit    Wawa    Riffy    Tema
0066 % __20140627_16579    7106    1    0    2    0    0    1
0067 % __20140717_16710    7107    1    1    1    1    0    0
0068 % __20140701_16824    7109    1    1    1    1    0    1
0069 % __20140710_16646    7110    1    0    1    0    0    0
0070 % __20140904_16729    7116    1    1    1    2    0    0
0071 % __20141004_16869    7121    2    0    1    2    0    0
0072 % __20141024_17095    7122    2    1    1    0    1    1
0073 % __20150306_17062    7129    1    1    2    1    1    1
0074 % __20150225_17049    7131    2    0    0    2    2    0
0075 % __20150324_17332    7132    2    1    1    0    0    0
0076 % __20150609_17282    7127    1    1    1    1    0    0
0077 % __20150708_17154    7135    1    1    1    1    1    1
0078 
0079 fid = fopen(fname_testinfo);
0080 object_list = fgets(fid);
0081 sub_dir_list = {};
0082 score_mat = [];
0083 score_sub_mat = [];
0084 
0085 obj_name_list = strsplit(object_list);
0086 obj_name_list = obj_name_list(3:end-1);
0087 tline = fgets(fid);
0088 while ischar(tline)
0089     tmp_split = strsplit(tline);
0090     score_subid = str2double(tmp_split{2});
0091     if score_subid == 1425
0092         tline = fgets(fid);
0093         continue
0094     end
0095     sub_dir_list = [sub_dir_list; tmp_split(1)];
0096     tmp_line = [];
0097     for tmpi = 2:length(tmp_split)
0098         tmp_char = tmp_split{tmpi};
0099         if length(tmp_char) == 1
0100             tmp_line = [tmp_line str2num(tmp_char)];
0101         end
0102     end
0103     score_sub_mat = [score_sub_mat; score_subid];
0104     score_mat = [score_mat; tmp_line];
0105     tline = fgets(fid);
0106 end
0107 
0108 fclose(fid);
0109 
0110 if is_visual_examine
0111     args.sample_rate = 0.03334;
0112     main_module = sprintf('naming_score');
0113 
0114     var_name_list = {
0115         'cevent_speech_naming_learn-score-0_parent'
0116         'cevent_speech_naming_learn-score-1_parent'
0117         'cevent_speech_naming_learn-score-2_parent'
0118         'cevent_speech_naming_local-id'
0119         'cevent_speech_naming_test-score'
0120         };
0121     args.var_text = get_vis_vartext(var_name_list);
0122 
0123     args.legend = {'blue object'; 'green object'; 'red object'; 'nan'; 'nan'; 'nan'; 'nan'; 'nan'; 'nan'; ...
0124         'score0'; 'score1'; 'score2'};
0125     args.row_text_type = 'time'; % or it can be label such as shown below
0126     save_path = '.';
0127     args.set_position = [50 50 1800 (280+30*length(var_name_list))];
0128     args.var_name_list = var_name_list;
0129     
0130     input.sub_list = sub_list;
0131     input.grouping = 'trial';
0132     input.check_var_exist = 1;
0133     title_str = main_module;
0134     
0135     args.colormap = [...
0136         [0 0 1]; ... % blue 1
0137         [0 1 0]; ... % green 2
0138         [1 0 0]; ... % red 3
0139         [0.4 0.4 0.4]; ... % grey 5
0140         [0.4 0.4 0.4]; ... % grey 5
0141         [0.4 0.4 0.4]; ... % grey 6
0142         [0.4 0.4 0.4]; ... % grey 7
0143         [0.4 0.4 0.4]; ... % grey 8
0144         [0.4 0.4 0.4]; ... % grey 9
0145         [1 0.5 0.2]; ... % orange 10
0146         [0.7 0 0.7]; ... % purple 11
0147         [0 1 1]; ... % cran 12
0148         ];
0149     args.ForceZero = false;
0150     args.ref_column = 1;
0151     args.color_code = 'cevent_value';
0152     % args.transparency = 0.3;
0153     args.xlabel = 'time';
0154     args.row_text = {'T1', 'T2', 'T3', 'T4'};
0155 end
0156 
0157 % STEP 3: Generate the 4 naming variable files
0158 varname = 'cevent_speech_naming';
0159 varname_type = get_data_type(varname);
0160 
0161 mask_sub_has_score = false(size(sub_list));
0162 result_mat_score_items = nan(length(sub_list), 6);
0163 result_mat_score_counts = nan(length(sub_list), 3);
0164 
0165 for sidx = 1:length(sub_list)
0166     sub_id = sub_list(sidx);
0167     
0168     trials_one = get_trial_times(sub_id);
0169     
0170     if is_visual_examine
0171         title = sprintf('subject %d data vis: ', sub_id);
0172         args.title = [title title_str];
0173         args.sub_id = sub_id;
0174         input.sub_list = sub_id;
0175         args.time_ref = trials_one(:,1);
0176         args.trial_times = trials_one;
0177         data = cell(size(trials_one, 1), length(var_name_list));
0178         var_type = 'cevent';
0179     end
0180     
0181     if ~has_variable(sub_id, 'cevent_speech_naming_local-id')
0182         fprintf('Subject %d does not have variable %s', sub_id, 'cevent_speech_naming_local-id');
0183         continue
0184     end
0185     
0186     sub_dir_str = get_subject_dir(sub_id);
0187     sub_dir_str = strsplit(sub_dir_str, {'/', '\'});
0188     sub_dir_str = sub_dir_str{end};
0189     mask_subdir = ismember(sub_dir_list, sub_dir_str);
0190     
0191     if sum(mask_subdir) > 0
0192         mask_sub_has_score(sidx) = true;
0193         cevents_naming = get_variable(sub_id, varname);
0194         cevents_namelocal = get_variable(sub_id, 'cevent_speech_naming_local-id');
0195         cevents_score = cevents_naming;
0196         score_per_sub = score_mat(mask_subdir, :);
0197         result_mat_score_items(sidx, :) = score_per_sub;
0198 
0199         for objidx = 1:length(obj_name_list)
0200             obj_score = obj_name_list{objidx};
0201             mask_obj_sore = strcmpi(word, obj_score);
0202             vid = vocab_id(mask_obj_sore);
0203             score_oneword = score_per_sub(objidx);
0204             mask_vid = ismember(cevents_naming(:,3), vid);
0205             cevents_score(mask_vid, 3) = score_oneword;
0206         end
0207         
0208         if is_visual_examine
0209             data(:,4) = extract_ranges(cevents_namelocal, var_type, trials_one);
0210             cevents_tmp = cevents_score;
0211             cevents_tmp(:,3) = cevents_tmp(:,3) + 10;
0212             data(:,5) = extract_ranges(cevents_tmp, var_type, trials_one);
0213         end
0214         
0215         if is_record_variable
0216             record_variable(sub_id, 'cevent_speech_naming_test-score', cevents_score);
0217         end
0218 
0219         scorename_list = {'cevent_speech_naming_learn-score-0_parent', ...
0220             'cevent_speech_naming_learn-score-1_parent', ...
0221             'cevent_speech_naming_learn-score-2_parent'};
0222         
0223         score_list = 0:2;
0224         for scoreidx = 1:length(score_list)
0225             score_one = score_list(scoreidx);
0226             mask_score = ismember(cevents_score(:, 3), score_one);
0227             cevents_one = cevents_namelocal(mask_score, :);
0228             if is_visual_examine
0229                 chunks_one = extract_ranges(cevents_one, var_type, trials_one);
0230                 chunks_len_one = cellfun(@length, chunks_one);
0231                 if sum(chunks_len_one > 0) < 1
0232                     fprintf('The variable %s exist for subject %d, but is completely empty.\n', scorename_list{scoreidx}, sub_id);
0233                     for tidx = 1:size(trials_one, 1)
0234                         data{tidx, scoreidx} = nan(1,3);
0235                     end
0236                 else
0237                     data(:,scoreidx) = chunks_one;
0238                 end
0239             end
0240             
0241             if is_record_variable
0242                 record_variable(sub_id, scorename_list{scoreidx}, cevents_one);
0243             end
0244             result_mat_score_counts(sidx, scoreidx) = sum(score_per_sub == score_one);
0245         end
0246         if is_visual_examine
0247             save_name = sprintf('%s_all_vis_across_modules', main_module);
0248             args.save_name = sprintf('%d_%s', sub_id, save_name);
0249             visualize_cevent_patterns(data, args);
0250         end
0251     end
0252 end
0253 
0254 sub_list_score = sub_list(mask_sub_has_score);
0255 % result_mat_score_items = score_mat(mask_sub_has_score, :);
0256 result_mat_score_counts = result_mat_score_counts(mask_sub_has_score, :);
0257 
0258 mask_incomplete_objs = sum(result_mat_score_counts, 2) ~= 6;
0259 if sum(mask_incomplete_objs) > 0
0260     sub_error_list = sub_list_score(mask_incomplete_objs)';
0261     error('These subjects %d do not have scores for every object, please check file %s', ...
0262         sub_error_list, fname_testinfo);
0263 end

Generated on Tue 23-May-2017 03:00:58 by m2html © 2005