Home > . > showClasses.m

showClasses

PURPOSE ^

%% classes = showClasses(CV.msf,nbins)

SYNOPSIS ^

function [classes,binned] = showClasses(cv,nbins)

DESCRIPTION ^

%% classes = showClasses(CV.msf,nbins)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [classes,binned] = showClasses(cv,nbins)
0002 %%% classes = showClasses(CV.msf,nbins)
0003 
0004 figure;
0005 [nTasks,nTrials] = size(cv.classes);
0006 for ttrial = 1:nTrials
0007   c = cv.testResults{ttrial}{5};
0008   npertask = length(c)/nTrials; %assumes each trial has same number samples
0009   correct = repmat(1:nTasks,npertask,1);
0010   classes{ttrial} = [correct(:) c'];
0011 
0012   subplot(nTrials,1,ttrial);
0013   adj = [classes{ttrial}(:,1)-0.2 classes{ttrial}(:,2)];
0014   plot(adj,'k');
0015   title(['Test Trial ' num2str(ttrial)]);
0016   if ttrial == nTrials,   xlabel('Sample'); end
0017   ylabel('Task Index');
0018   childs = get(gca,'Children');
0019   set(childs(2),'LineStyle','--');
0020 end
0021 
0022 figure;
0023 [nTasks,nTrials] = size(cv.classes);
0024 for ttrial = 1:nTrials
0025   subplot(nTrials,1,ttrial);
0026   binned{ttrial} = bins(classes{ttrial},nbins);
0027   adj = [binned{ttrial}(:,1)-0.2 binned{ttrial}(:,2)];
0028   plot(adj,'k');
0029   title(['Test Trial ' num2str(ttrial)]);
0030   if ttrial == nTrials,   xlabel('Sample'); end
0031   ylabel('Task Index');
0032   childs = get(gca,'Children');
0033   set(childs(2),'LineStyle','--');
0034 
0035   percent = sum(classes{ttrial}(:,1) == classes{ttrial}(:,2)) / ...
0036       size(classes{ttrial},1) * 100;
0037   percentbinned = sum(binned{ttrial}(:,1) == binned{ttrial}(:,2)) / ...
0038       size(binned{ttrial},1) * 100;
0039   fprintf(1,'Test Trial %d Percent correct %5.1f, %d bins Percent Correct %5.1f\n',...
0040             ttrial,percent,nbins,percentbinned);
0041 end
0042 
0043 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0044 % function binned = binsAvg(cv,nbins)
0045 %
0046 % reps = showTestRep(cv);
0047 %
0048 % [nTasks,nTrials] = size(cv.classes);
0049 % for ttrial = 1:nTrials
0050 %   w = cv.testResults{ttrial}{2}.weights;
0051 %   w = w - repmat(mean(w,2),1,nTasks);
0052 %   b = cv.testResults{ttrial}{2}.bias;
0053 %   funcs = reps{ttrial}' * w + repmat(b',size(reps{ttrial},2),1);
0054 %   n = size(funcs,1);
0055 %   for r = 1:n-nbins+1
0056 %     v = mean(funcs(r:r+nbins-1,:));
0057 %     [junk,maxi] = max(v);
0058 %     binned(r,:) = [cv.classes{maxi;
0059 %   end
0060 % end
0061 %
0062 % end
0063 %
0064 % for r = 1:n-nbins+1
0065 %   for c = 1:size(data,2)
0066 %     v = data(r:r+nbins-1,c);
0067 %     uniq = unique(v)';
0068 %     most = 0;
0069 %     for u = uniq
0070 %       count = sum(v==u);
0071 %       if count > most
0072 %     most = count;
0073 %     majority = u;
0074 %       end
0075 %     end
0076 %     binnedMaj(r,c) = majority;
0077 %   end
0078 % end
0079 %
0080 %
0081 
0082 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0083 function binnedMaj = bins(data,nbins)
0084 % data has sequences in columns
0085 
0086 n = size(data,1);
0087 binnedMaj = zeros(n-nbins+1,size(data,2));
0088 for r = 1:n-nbins+1
0089   for c = 1:size(data,2)
0090     v = data(r:r+nbins-1,c);
0091     uniq = unique(v)';
0092     most = 0;
0093     for u = uniq
0094       count = sum(v==u);
0095       if count > most
0096     most = count;
0097     majority = u;
0098       end
0099     end
0100     binnedMaj(r,c) = majority;
0101   end
0102 end
0103 
0104

Generated on Tue 07-Feb-2006 12:02:57 by m2html © 2003