% crtrset   divides given data into training set and test set
%			recognition of sex using set of features  
% 
% [trsets,testset] = crt(Data,NumTrset)
% Inputs:
% Data [Nx7] ... N is the number of records
%                7 is the number of features
%                Data(:,1)=1 for Male
%                Data(:,1)=0 for Female
% NumTrset   ... Number of records to be in training set 
%                (power of training set)
%
% Returns
% trsets ... field of structs 1-Male, 2-Female 
% trsets(i).X [inum x 7]      ... data matrices
% trsets(i).idxClasses [inum] ... indexes to Data
% trsets(i).NumClass          ... equal to inum 
%
% Power of each class in training set is derived from its occurence 
% in Data. In other words, prior probabilities of classes in training
% set are equal to prior probabilities in Data
%
% Tomas Svoboda, CTU Prague

function [trsets,testset] = crttrset(Data,NumTrset)

%%%
% Data analysis
%%%
data.TotalNum	 = size(Data,1);
data.idxClass{1} = find(Data(:,1)==1);	% Male
data.idxClass{2} = find(Data(:,1)==0);	% Female

for i = 1:2,
  trset(i).NumClass = round(NumTrset*(size(data.idxClass{i},1)/data.TotalNum));
  permvec			= randperm(size(data.idxClass{i},1));
  trset(i).idxClass = data.idxClass{i}(permvec(1:trset(i).NumClass));
  trset(i).X		= Data(trset(i).idxClass,:);
end

testset.idx = getoff([1:data.TotalNum]',[trset(1).idxClass;trset(2).idxClass]);
testset.X	= Data(testset.idx,:);

trsets = trset;

