


Function to load the kernels according to the samples considered in a given model Inputs: ------- PRT: data structure prt_dir: path for PRT.mat (string) mid : index of model in the data structure/ PRT.mat Output: -------- Phi_all : cell array with one kernel per cell (in case of multiple kernels) or a single cell with the samples considered in the specified model, as defined by the class selection. ID : the ID matrix for the considered samples fid : index of feature set in data structure / PRT.mat __________________________________________________________________________ Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory


0001 function [Phi_all,ID,fid] = prt_getKernelModel (PRT,prt_dir,mid) 0002 0003 % Function to load the kernels according to the samples considered in a 0004 %given model 0005 % 0006 % Inputs: 0007 % ------- 0008 % PRT: data structure 0009 % prt_dir: path for PRT.mat (string) 0010 % mid : index of model in the data structure/ PRT.mat 0011 % 0012 % Output: 0013 % -------- 0014 % Phi_all : cell array with one kernel per cell (in case of 0015 % multiple kernels) or a single cell with the samples considered in the 0016 % specified model, as defined by the class selection. 0017 % ID : the ID matrix for the considered samples 0018 % fid : index of feature set in data structure / PRT.mat 0019 % 0020 %__________________________________________________________________________ 0021 % Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory 0022 0023 % Written by J Schrouff 0024 % $Id: prt_getKernelModel.m 855 2014-05-27 09:35:15Z schrouff $ 0025 0026 % load data files and configure ID matrix 0027 disp('Loading data files.....>>'); 0028 0029 samp_idx = PRT.model(mid).input.samp_idx; % which samples are in the model 0030 0031 for i = 1:length(PRT.model(mid).input.fs) 0032 %Backwards compatibility with v0 and v1: transform kernel into cell if needed 0033 if PRT.model(mid).input.use_kernel 0034 fid = prt_init_fs(PRT, PRT.model(mid).input.fs(i)); 0035 load(fullfile(prt_dir, PRT.fs(fid).k_file)); 0036 if ~iscell(Phi) 0037 Phi = {Phi}; 0038 end 0039 end 0040 0041 %first case: combine feature sets 0042 if length(PRT.model(mid).input.fs)>1 0043 Phi_all=[]; 0044 0045 if i == 1 0046 ID = PRT.fs(fid).id_mat(samp_idx,:); 0047 end 0048 0049 if PRT.model(mid).input.use_kernel 0050 for j = 1:length(Phi) 0051 Phi_all = [Phi_all, {Phi{j}(samp_idx,samp_idx)}]; % in case one feature set comprises multiple kernels already 0052 end 0053 else 0054 error('training with features not implemented yet'); 0055 %vname = whos('-file', [prt_dir,PRT.fs(fid).fs_file]); 0056 %eval(['Phi_all{',num2str(i),'}=',vname,'(samp_idx,:);']); 0057 end 0058 else 0059 %If only one feature set, load kernel to see which case 0060 if PRT.model(mid).input.use_kernel 0061 ID = PRT.fs(fid).id_mat(samp_idx,:); 0062 if length(Phi)==1 0063 Phi_all{1} = Phi{1}(samp_idx,samp_idx); 0064 else 0065 %Check that if multiple kernels, MKL was selected, 0066 %otherwise kernels will be added when calling prt_machine 0067 if isempty(strfind(PRT.model(mid).input.machine.function,'MKL')) 0068 warning('prt_cv_model:AddKernels',... 0069 'Multiple kernels but machine cannot deal with them, adding the kernels'); 0070 % Phi_tmp = zeros(length(samp_idx)); 0071 % for j=1:length(Phi) 0072 % try 0073 % %add kernels 0074 % tp = Phi{j}(samp_idx,samp_idx); 0075 % Phi_tmp=Phi_tmp + tp; 0076 % catch 0077 % error('prt_cv_model:KernelsWithDifferentDimensions', ... 0078 % 'Kernels cannot be added since they have different dimensions') 0079 % end 0080 % end 0081 % Phi_all{1} = Phi_tmp; 0082 % clear Phi_tmp 0083 end 0084 Phi_all=cell(1,length(Phi)); 0085 for j=1:length(Phi) 0086 Phi_all{j}=Phi{j}(samp_idx,samp_idx); 0087 end 0088 end 0089 else 0090 error('training with features not implemented yet'); 0091 %vname = whos('-file', [prt_dir,PRT.fs(fid).fs_file]); 0092 %eval(['Phi_all{',num2str(i),'}=',vname,'(samp_idx,:);']); 0093 end 0094 end 0095 end 0096 clear Phi