-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMeta_NBC.m
99 lines (70 loc) · 2.56 KB
/
Meta_NBC.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
function [nbc, data, group_data] = Meta_NBC(MC_Setup, terms, test_images)
% [nbc, data, group_data] = Meta_NBC(MC_Setup, terms, test_images)
%
% You will need:
% Inputs: a folder of text files with term labels
%
% MC_Setup = a database saved from an MKDA meta-analysis
% terms = {'pain', 'working.memory', 'emotion'};
% test_images = 'pain_test_data.img'
%
% Load group data up front, so we know if OK...
% --------------------------------------------------
if nargin > 2
group_data = load_test_data(MC_Setup, test_images);
else
group_data = [];
end
% Set up data object with default parameters
% --------------------------------------------------
data = meta_dataset('MC_Setup', MC_Setup);
clear MC_Setup
% Choose terms and restrict dataset
% --------------------------------------------------
data = setup_data(data, terms);
% Train classifier on all data
% --------------------------------------------------
nbc = train(meta_nbc, data);
% Test on same data to get apparent misclass rate
% --------------------------------------------------
nbc = test(nbc, data.dat);
nbc = get_error(nbc, data.classes);
% Display apparent correct classification rate
fprintf('\nApparent classification accuracy:\n---------------------------------------------\n')
nbc = report(nbc);
% Cross-validate and get cv error rate
% --------------------------------------------------
nbc = cv(nbc, data);
fprintf('\nCross-validated accuracy for meta-analysis dataset:\n---------------------------------------------\n')
nbc = report(nbc);
% Test on new image data -- if entered
% --------------------------------------------------
if nargin > 2
nbc = test(nbc, group_data.dat(:, data.include_vox)', 1);
test_class = ones(size(group_data.dat, 1), 1);
nbc = get_error(nbc, test_class);
fprintf('\nAccuracy for test data:\n---------------------------------------------\n')
nbc = report(nbc);
end
end % main function
function group_data = load_test_data(MC_Setup, test_images)
t1 = tic;
disp('Loading mask from MC_Setup')
[discard, maskname, ee] = fileparts(MC_Setup.volInfo.fname);
maskname = [maskname ee];
if exist(maskname, 'file')
mask = fmri_mask_image(which(maskname));
else
error('Mask %s is not on path.', maskname);
end
disp('Reading data in mask space')
group_data = fmri_data(test_images, mask, 'sample2mask');
fprintf('Loaded in %3.0f sec\n', toc(t1));
end
% methods(group_data)
% plot(group_data);
% % RESAMPLE TEST DATA TO NEW SPACE
%
% group_data = resample_space(group_data, volInfo);
%
% fprintf('Resampled in %3.0f sec\n', toc(t1)); t1 = tic;