0001 function [F,opt] = preproc_triplets(Xtr, Xte, varargin)
0002
0003
0004 [Xtr,opt]=preproc_scalecenter(Xtr,varargin{:});
0005 Xte=preproc_scalecenter(Xte,opt);
0006
0007
0008 for ii=1:length(Xtr), Xtr{ii}=Xtr{ii}(1,:); end
0009 for ii=1:length(Xte), Xte{ii}=Xte{ii}(1,:); end
0010
0011 Xtr=cell2mat(Xtr);
0012 Xte=cell2mat(Xte);
0013
0014 nn=size(Xtr,2);
0015 if nn~=size(Xte,2)
0016 error('Size of Xtr and Xte are different.');
0017 end
0018
0019 if isfield(opt,'ixtr') && length(opt.ixtr)>0
0020 ncomb = length(opt.ixtr);
0021 else
0022 ncomb=nn*(nn-1)*(nn-2)/6;
0023 opt.ixtr=[];
0024 end
0025
0026
0027 if ~isfield(opt,'polyorder')
0028 opt.polyorder=2;
0029 end
0030 if ~isfield(opt,'tr')
0031 if ~isequal(Xtr,Xte)
0032 error('Xtr and Xte seems to be different but no opt.tr given.');
0033 end
0034 opt.tr=zeros(1,ncomb);
0035 end
0036
0037 if length(opt.ixtr)>0
0038 F=zeros(size(Xte,1),size(Xtr,1), ncomb);
0039 for ii=1:ncomb
0040 F(:,:,ii)=(1+Xte(:,opt.ixtr{ii})*Xtr(:,opt.ixtr{ii})').^opt.polyorder;
0041
0042 if opt.tr(ii)==0
0043 opt.tr(ii)=trace(F(:,:,ii));
0044 end
0045
0046 F(:,:,ii)=F(:,:,ii)/opt.tr(ii);
0047 end
0048 else
0049 F=zeros(size(Xte,1),size(Xtr,1), ncomb);
0050 opt.ixtr=cell(1,ncomb);
0051
0052 ind=1;
0053 for kk=1:nn
0054 for jj=kk+1:nn
0055 for ii=jj+1:nn
0056 F(:,:,ind)=(1+Xte(:,[kk,jj,ii])*Xtr(:,[kk,jj,ii])').^opt.polyorder;
0057
0058 if opt.tr(ind)==0
0059 opt.tr(ind)=trace(F(:,:,ind));
0060 end
0061 F(:,:,ind)=F(:,:,ind)/opt.tr(ind);
0062
0063 opt.ixtr{ind}=[kk,jj,ii];
0064
0065 ind=ind+1;
0066 end
0067 end
0068 end
0069 end
0070
0071
0072