-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprt_getFeatureModel.m
More file actions
151 lines (125 loc) · 4.84 KB
/
Copy pathprt_getFeatureModel.m
File metadata and controls
151 lines (125 loc) · 4.84 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
function [Phi_all,ID,fid] = prt_getFeatureModel(PRT,mid)
% 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
% mid : index of model in the data structure/ PRT.mat
%
% Output:
% --------
% Phi_all : cell array with one feature set per 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_getFeatureModel.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
nfid = numel(PRT.model(mid).input.fs);
Phi_all=[];
for ifid = 1:nfid
fid = prt_init_fs(PRT, PRT.model(mid).input.fs(ifid));
ID_all = PRT.fs(fid).id_mat;
ID = PRT.fs(fid).id_mat(samp_idx,:); % Reduce ID mat to selected samples
% Check that all feature sets have the same ID matrix
if ifid==1
ID1 = ID;
else
cols = [1,2,4,5];
if any(any(ID1(:,cols)~=ID(:,cols)))
error('prt_get_FeatureModel:CannotCombineFS',...
'Multiple feature sets selected but they do not have the same ID matrix')
end
end
% Find modality/modalities in feature set and corresponding file arrays
mods = [PRT.fs(fid).modality(:).mod_name];
modnames = {PRT.fas(:).mod_name};
fas = zeros(1,numel(modnames));
mm=zeros(length(mods),numel(modnames));
for i = 1:numel(modnames)
for j = 1:length(mods)
if strcmpi(PRT.fas(i).mod_name,mods{j})
fas(i) = 1;
mm(i,j)= 1;
end
end
end
fas_idx = find(fas);
if ~ isempty(PRT.fs(fid).modality(1).idfeat_fas)
ifeat = numel(PRT.fs(fid).modality(1).idfeat_fas); %all concatenated modalities have the same size
else
ifeat = PRT.fas(fas_idx(1)).dat.dim(2);
end
% Averaging of the feature on onr or more dimensions?
if isfield(PRT.fs(fid).modality(1),'aver') && ...
any(PRT.fs(fid).modality(1).aver)
ndim = numel(PRT.fs(fid).modality(1).dim_m);
fin_dim = ones(1,ndim);
for idim = 1:ndim
fin_dim(idim) = length(PRT.fs(fid).modality(1).dim_m{idim});
end
dimav = fin_dim;
dimav(find(PRT.fs(fid).modality(1).aver)) = 1;
ifeat = prod(dimav);
end
d.datamat = zeros(length(samp_idx), ifeat);
for i = 1:length(fas_idx)
mf = find(mm(fas_idx(i),:));
if ~ isempty(PRT.fs(fid).modality(mf(1)).idfeat_fas)
feats = PRT.fs(fid).modality(mf(1)).idfeat_fas; %all concatenated modalities have the same size
else
feats = 1:PRT.fas(fas_idx(i)).dat.dim(2);
end
indm = ID(:,3) == fas_idx(i);
samp_all = zeros(size(ID_all,1),1);
samp_all(samp_idx) = 1;
inds = find(samp_all(ID_all(:,3)==fas_idx(i)));
if isempty(inds) %Modality not selected in this model
continue;
else
ifa = PRT.fs(fid).fas.ifa(inds);
end
% Average data matrix along specified dimensions
if isfield(PRT.fs(fid).modality(mf(1)),'aver') && ...
any(PRT.fs(fid).modality(mf(1)).aver)
tmp = PRT.fas(fas_idx(i)).dat(ifa,feats)';
ndim = numel(PRT.fs(fid).modality(mf(1)).dim_m);
fin_dim = ones(1,ndim);
for idim = 1:ndim
fin_dim(idim) = length(PRT.fs(fid).modality(mf(1)).dim_m{idim});
end
tmp = reshape(tmp,[fin_dim length(ifa)]);
dimta = find(PRT.fs(fid).modality(mf(1)).aver); %dimensions to average
for iav = 1:length(dimta)
tmp = mean(tmp, dimta(iav));
end
dimav = fin_dim;
dimav(find(PRT.fs(fid).modality(mf(1)).aver)) = 1;
tmp = reshape(tmp,prod(dimav),length(ifa));
d.datamat(indm,:) = tmp';
else
% index for the target data matrix
d.datamat(indm,:) = PRT.fas(fas_idx(i)).dat(ifa,feats);
end
end
try
Phi_all = [Phi_all, d.datamat];
catch
error('prt_get_KernelFeature:CannotCombineFS',...
'Could not combine feature sets, potentially too large data set')
end
clear d
end
% Gather outputs
%-----------------
fid = prt_init_fs(PRT, PRT.model(mid).input.fs(1)); %As everything is based on 1st feature set
ID = ID1;
Phi_all = {Phi_all};