Home > GVSToolbox > getLeave1OutLabels.m

getLeave1OutLabels

PURPOSE ^

get a struct for specifying folds of leave one out cross validation

SYNOPSIS ^

function trainTesTLabels = getLeave1OutLabels( numSamples, numPer1Subj )

DESCRIPTION ^

 get a struct for specifying folds of leave one out cross validation
 notes: return an array of the train/testing indices for leave 1 subject
 out cross validation.  It wassumes samples from 1 subject are stored 
 adjacent to each other
 
 syntax: trainTesTLabels = getLeave1OutLabels( numSamples, numPer1Subj )

 Input:
   numSamples: total number of data samples
   numPer1Subj: vector of number of consecutive samples for each subject.
       If it is a constant amount of each subject, then you can just
       specify that constant integer
 
 Outputs:
   trainTesTLabels: struct array of train/test indices,
       trainTesTLabels(1).test, or trainTesTLabels(1).train

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % get a struct for specifying folds of leave one out cross validation
0002 % notes: return an array of the train/testing indices for leave 1 subject
0003 % out cross validation.  It wassumes samples from 1 subject are stored
0004 % adjacent to each other
0005 %
0006 % syntax: trainTesTLabels = getLeave1OutLabels( numSamples, numPer1Subj )
0007 %
0008 % Input:
0009 %   numSamples: total number of data samples
0010 %   numPer1Subj: vector of number of consecutive samples for each subject.
0011 %       If it is a constant amount of each subject, then you can just
0012 %       specify that constant integer
0013 %
0014 % Outputs:
0015 %   trainTesTLabels: struct array of train/test indices,
0016 %       trainTesTLabels(1).test, or trainTesTLabels(1).train
0017 
0018 function trainTesTLabels = getLeave1OutLabels( numSamples, numPer1Subj )
0019 
0020 if length(numPer1Subj) == 1  %if fixed number
0021     numTrials = numSamples/numPer1Subj;
0022     for i1 = 1:numTrials
0023         i1_test = i1*numPer1Subj - [numPer1Subj-1:-1:0];    
0024         trainTesTLabels(i1).test = i1_test;
0025         trainTesTLabels(i1).train = 1:numSamples;
0026         trainTesTLabels(i1).train(i1_test) = [];           
0027     end
0028     
0029 else        %different number in each block, the case for infants
0030     numTrials = length(numPer1Subj);    
0031     trainTesTLabels(1).test =1:numPer1Subj(1);
0032     trainTesTLabels(1).train =  (numPer1Subj(1)+1):numSamples;
0033     for i1 = 2:numTrials        
0034         i1_test = (sum(numPer1Subj(1:i1-1))+1):sum(numPer1Subj(1:i1));
0035         trainTesTLabels(i1).test =i1_test;
0036         trainTesTLabels(i1).train = 1:numSamples;
0037         trainTesTLabels(i1).train(i1_test) = [];           
0038     end
0039     
0040     
0041 end

Generated on Tue 01-Jul-2014 12:35:04 by m2html © 2005