forked from KamitaniLab/GenericObjectDecoding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalysis_CategoryIdentification.m
161 lines (116 loc) · 5.42 KB
/
analysis_CategoryIdentification.m
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
% analysis_CategoryIdentification Run object category identification
%
% Author: Tomoyasu Horikawa <[email protected]>, Shuntaro C. Aoki <[email protected]>
%
clear all;
%% Initial settings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Data settings
% subjectList : List of subject IDs [cell array]
% featureList : List of image features [cell array]
% roiList : List of RoiList [cell array]
subjectList = {'Subject1', 'Subject2', 'Subject3', 'Subject4', 'Subject5'};
featureList = {'cnn1', 'cnn2', 'cnn3', 'cnn4', ...
'cnn5', 'cnn6', 'cnn7', 'cnn8', ...
'hmax1', 'hmax2', 'hmax3', 'gist', 'sift'};
roiList = {'V1', 'V2', 'V3', 'V4', 'FFA', 'LOC', 'PPA', 'LVC', 'HVC', 'VC'};
% Image feature data
imageFeatureFile = 'ImageFeatures.mat';
%% Directory settings
workDir = pwd;
dataDir = fullfile(workDir, 'data'); % Directory containing brain and image feature data
resultsDir = fullfile(workDir, 'results'); % Directory to save analysis results
%% File name settings
predResultFile = fullfile(resultsDir, 'FeaturePrediction.mat');
resultFile = fullfile(resultsDir, 'CategoryIdentification.mat');
%% Analysis Main %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fprintf('%s started\n', mfilename);
%%----------------------------------------------------------------------
%% Initialization
%%----------------------------------------------------------------------
addpath(genpath('./lib'));
if ~exist(resultsDir, 'dir'), mkdir(resultsDir); end;
%%----------------------------------------------------------------------
%% Load data
%%----------------------------------------------------------------------
%% Load image features
fprintf('Loading image feature data...\n');
[feat.dataSet, feat.metaData] = load_data(fullfile(dataDir, imageFeatureFile));
%%----------------------------------------------------------------------
%% Create analysis parameter matrix (analysisParam)
%%----------------------------------------------------------------------
analysisParam = uint16(zeros(length(subjectList) * length(roiList) * length(featureList), 3));
c = 1;
for iSbj = 1:length(subjectList)
for iRoi = 1:length(roiList)
for iFeat = 1:length(featureList)
analysisParam(c, :) = [ iSbj, iRoi, iFeat ];
c = c + 1;
end
end
end
%%----------------------------------------------------------------------
%% Analysis loop
%%----------------------------------------------------------------------
featpred = load(predResultFile);
results = [];
for n = 1:size(analysisParam, 1)
%% Initialization --------------------------------------------------
% Get data index in the current analysis
iSbj = analysisParam(n, 1);
iRoi = analysisParam(n, 2);
iFeat = analysisParam(n, 3);
% Set analysis ID and a result file name
analysisId = sprintf('%s-%s-%s-%s', ...
mfilename, ...
subjectList{iSbj}, ...
roiList{iRoi}, ...
featureList{iFeat});
% Check or double-running
if checkfiles(resultFile)
% Analysis result already exists
fprintf('The analysis is already done and skipped\n');
continue;
end
fprintf('Start %s\n', analysisId);
%% Get image features ----------------------------------------------
layerFeat = select_feature(feat.dataSet, feat.metaData, ...
sprintf('%s = 1', featureList{iFeat}));
catIds = get_dataset(feat.dataSet, feat.metaData, 'CatID');
featType = get_dataset(feat.dataSet, feat.metaData, 'FeatureType');
%% Load data (unit_all) --------------------------------------------
ind = strcmp({featpred.results(:).subject}, subjectList{iSbj}) ...
& strcmp({featpred.results(:).roi}, roiList{iRoi}) ...
& strcmp({featpred.results(:).feature}, featureList{iFeat});
% TODO: add index check
predPercept = featpred.results(ind).predictPercept;
predImagine = featpred.results(ind).predictImagery;
categoryPercept = featpred.results(ind).categoryTestPercept;
%% Object category identification analysis -------------------------
%% Get category features
featCatTest = layerFeat(featType == 3, :);
catIdsCatTest = catIds(featType == 3, :);
featCatTest = get_refdata(featCatTest, catIdsCatTest, categoryPercept);
featCatOther = layerFeat(featType == 4, :);
catIdCatOther = catIds(featType == 4, :);
%% Pairwise identification
labels = 1:size(featCatTest, 1);
candidate = [featCatTest; featCatOther];
% Seen categories
simmat = fastcorr(predPercept', candidate');
correctRate.perception = pwidentification(simmat, labels);
% Imagined catgories
simmat = fastcorr(predImagine', candidate');
correctRate.imagery = pwidentification(simmat, labels);
fprintf('Correct rate (seen) = %.f%%\n', mean(correctRate.perception) * 100);
fprintf('Correct rate (imagined) = %.f%%\n', mean(correctRate.imagery) * 100);
results(n).subject = subjectList{iSbj};
results(n).roi = roiList{iRoi};
results(n).feature = featureList{iFeat};
results(n).correctRatePercept = correctRate.perception;
results(n).correctRateImagery = correctRate.imagery;
results(n).correctRatePerceptAve = mean(correctRate.perception);
results(n).correctRateImageryAve = mean(correctRate.imagery);
end
%% Save data -----------------------------------------------------------
save(resultFile, 'results', '-v7.3');
fprintf('%s done\n', mfilename);