-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprt_getKernelModel.m
More file actions
96 lines (82 loc) · 3.4 KB
/
Copy pathprt_getKernelModel.m
File metadata and controls
96 lines (82 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
function [Phi_all,ID,fid] = prt_getKernelModel (PRT,prt_dir,mid,flag)
% Function to load the kernels according to the samples considered in a
%given model. These kernels will be added if the machine is a single kernel
%technique.
%
% Inputs:
% -------
% PRT: data structure
% prt_dir: path for PRT.mat (string)
% mid : index of model in the data structure/ PRT.mat
% flag: 1 to compute one model for each kernel, 0 otherwise (def)
%
% Output:
% --------
% Phi_all : cell array with one kernel per cell or a single cell
% with the samples considered in the
% specified model, as defined by the class/regression 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
% Written by J Schrouff
% $Id: prt_getKernelModel.m 855 2014-05-27 09:35:15Z schrouff $
% load data files and configure ID matrix
disp('Loading data files.....>>');
samp_idx = PRT.model(mid).input.samp_idx; % which samples are in the model
Phi_all=[];
if nargin<4 || isempty(flag)
flag = 0;
end
for i = 1:length(PRT.model(mid).input.fs)
%Backwards compatibility with v0 and v1: transform kernel into cell if needed
fid = prt_init_fs(PRT, PRT.model(mid).input.fs(i));
load(fullfile(prt_dir, PRT.fs(fid).k_file));
if ~iscell(Phi)
Phi = {Phi};
end
%first case: combine feature sets
if length(PRT.model(mid).input.fs)>1
if i == 1
ID = PRT.fs(fid).id_mat(samp_idx,:);
end
for j = 1:length(Phi)
Phi_all = [Phi_all, {Phi{j}(samp_idx,samp_idx)}]; % in case one feature set comprises multiple kernels already
end
else
%If only one feature set, load kernel to see which case
ID = PRT.fs(fid).id_mat(samp_idx,:);
if length(Phi)==1
Phi_all{1} = Phi{1}(samp_idx,samp_idx);
else
Phi_all=cell(1,length(Phi));
for j=1:length(Phi)
Phi_all{j}=Phi{j}(samp_idx,samp_idx);
end
end
end
%Check that if multiple kernels, MKL was selected,
%otherwise kernels will be added when calling prt_machine
if length(Phi_all)>1 &&... %Multiple kernels
isempty(strfind(PRT.model(mid).input.machine.function,'MKL')) &&... %not simpleMKL
isempty(strfind(PRT.model(mid).input.machine.function,'wip')) &&... %not wip
~flag %not independent models
warning('prt_getKernelModel:AddKernels',...
'Multiple kernels but machine cannot deal with them, adding the kernels');
Phi_tmp = zeros(length(samp_idx));
for j=1:length(Phi_all)
try
%add kernels
tp = Phi_all{j};
Phi_tmp=Phi_tmp + tp;
catch
error('prt_cv_model:KernelsWithDifferentDimensions', ...
'Kernels cannot be added since they have different dimensions')
end
end
Phi_all = {Phi_tmp};
clear Phi_tmp
end
end
clear Phi