Home > data-analysis > extraction > get_chunks_target.m

get_chunks_target

PURPOSE ^

out = get_chunks_target(chunks, targets, label_matrix, operation)

SYNOPSIS ^

function [out, targets] = get_chunks_target(chunks, targets, label_matrix, datatype)

DESCRIPTION ^

 out = get_chunks_target(chunks, targets, label_matrix, operation)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [out, targets] = get_chunks_target(chunks, targets, label_matrix, datatype)
0002 % out = get_chunks_target(chunks, targets, label_matrix, operation)
0003 
0004 if iscell(targets)
0005     out = cell(numel(targets),1);
0006     for o = 1:numel(targets)
0007         out{o,1} = get_chunks_target(chunks{o}, targets{o}, label_matrix, datatype);
0008     end
0009     return
0010 end
0011 
0012 if ~iscell(chunks)
0013     error('chunks must be cell array when targets is not');
0014 end
0015 %continuous data types
0016 if size(chunks, 2) > 1
0017     %get rid of targets that have categories outside of range of
0018     %label_matrix
0019     log = targets(:,end) > size(label_matrix, 1);
0020     targets(log, :) = [];
0021     chunks(log, :) = [];
0022     %get rid of chunks that have categories outside of range of
0023     %label_matrix
0024     minwidth = min([size(chunks, 2) size(label_matrix, 2)]);
0025     chunks = chunks(:,1:minwidth);
0026     un = unique(label_matrix);
0027     label_matrix = label_matrix(:,1:minwidth);
0028     grouped = cell(1, numel(un));
0029     for k = 1:size(targets,1)
0030         target = targets(k,end);
0031         chunk = chunks(k,:);
0032 %         chunk = chunks(k,1:size(label_matrix,2));
0033         lmrow = label_matrix(target,:);
0034         time = chunk{1}(:,1);
0035         for i = 1:numel(un)
0036             tmp = chunk(lmrow == un(i));
0037             if ~isempty(tmp)
0038                 switch datatype
0039                     case 'cont'
0040                         tmp = cellfun(@(a) a(:,end), tmp, 'un', 0);
0041                         tmp = horzcat(tmp{:});
0042                         tmp = nanmean(tmp,2);
0043                         grouped{1,i}{k,1} = [time tmp];
0044                     case 'cevent'
0045                         tmp = vertcat(tmp{:});
0046                         grouped{1,i}{k,1} = tmp;
0047                     case 'cstream'
0048                         tmp = cellfun(@(a) a(:,end), tmp, 'un', 0);
0049                         tmp = horzcat(tmp{:});
0050                         tmp = sum(tmp,2);
0051                         grouped{1,i}{k,1} = [time tmp];
0052                 end
0053             else
0054                 grouped{1,i}{k,1} = [];
0055             end
0056         end
0057     end
0058     chunks = horzcat(grouped{:});
0059 %cevents
0060 else
0061     log = targets(:,end) > size(label_matrix, 1);
0062     targets(log, :) = [];
0063     chunks(log, :) = [];
0064     for k = 1:numel(chunks)
0065         chunk = chunks{k};
0066         log = chunk(:,end) > size(label_matrix, 2);
0067         chunk(log, :) = [];
0068         fchunk = chunk;
0069         target = targets(k,end);
0070         lmrow = label_matrix(target,:);
0071         for l = 1:numel(lmrow)
0072             log = chunk(:,end) == l;
0073             fchunk(log,end) = lmrow(l);
0074         end
0075         chunks{k} = fchunk;
0076     end
0077 end
0078 
0079 out = chunks;
0080 
0081 end

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