-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunBrainExp.m
More file actions
112 lines (95 loc) · 2.83 KB
/
runBrainExp.m
File metadata and controls
112 lines (95 loc) · 2.83 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
subjects = 'ABCD';
load ../brainData/semantic_data.mat;
% load ../brainData/C_matrices.mat;
% addpath ./spg_package/SPG_singletask/
% install_mex;
if false
%% Coordinate Descent Code - Training
objFunc = @fusedObjective;
coordFuncs = {@fusedFusedUpdate; @fusedFusedSlack1Update; @fusedFusedSlack2Update; @fusedFusedSlack3Update};
paramOrder = [1 0 0 0 1]; %merrrh
betas = cell(length(subjects), 1);
for s = 1:length(subjects)
load(['../brainData/' subjects(s) '_data.mat']);
betas{s} = coordDescReg(X(:,1:3:end), Y(:,1:218), coordFuncs, objFunc, Psi(1:3:end, 1:3:end), Theta(1:218, 1:218), paramOrder);
fprintf('Subject %s complete\n', subjects(s));
end
save ../brainData/betasCoord.mat betas;
%% Coordinate Descent Code - Testing and Plotting
if ~exist('betas', 'var')
load ../brainData/betasCoord.mat;
end
N = size(Y,1);
S = length(subjects);
scores = zeros(S, S);
for s = 1:S
subplot(S/2, S/2, s);
imagesc(betas{s});
colorbar;
xlabel('Semantic Features');
ylabel('MEG Sources');
title(subjects(s));
for ss = 1:S
if ss ~= s
load(['../brainData/' subjects(ss) '_data.mat']);
Yhat = X(:, 1:3:306)*betas{s};
for n = 1:N
d = pdist([Yhat(n,:); Y(:,1:218)], 'cosine');
[~,ind] = sort(d(1:N));
ranks(n) = find(n==ind);
end
scores(s, ss) = mean(1 - (ranks - 1)./(N -1));
end
end
end
suptitle('Weight maps for individual subjects');
figure;
imagesc(scores);
colorbar;
xlabel('Testing Subject');
ylabel('Training Subject');
title('Rank Accuracy Scores Across Subjects');
end
%% SPG Code - Training
penFlag = 'fused';
betas = cell(length(subjects), 1);
for s = 1:length(subjects)
load(['../brainData/' subjects(s) '_data.mat']);
betas{s} = graph_siol_spg_reg(X(:, 1:3:end), Y(:, 1:218), C{s}, C_out, penFlag);
fprintf('Subject %s complete\n', subjects(s));
end
save ../brainData/betasSPG.mat betas;
%% Coordinate Descent Code - Testing and Plotting
if ~exist('betas', 'var')
load ../brainData/betasSPG.mat;
end
N = size(Y,1);
S = length(subjects);
scores = zeros(S, S);
for s = 1:S
subplot(S/2, S/2, s);
imagesc(betas{s});
colorbar;
xlabel('Semantic Features');
ylabel('MEG Sources');
title(subjects(s));
for ss = 1:S
if ss ~= s
load(['../brainData/' subjects(ss) '_data.mat']);
Yhat = X*betas{s};
for n = 1:N
d = pdist([Yhat(n,:); Y], 'cosine');
[~,ind] = sort(d(1:N));
ranks(n) = find(n==ind);
end
scores(s, ss) = mean(1 - (ranks - 1)./(N -1));
end
end
end
suptitle('Weight maps for individual subjects');
figure;
imagesc(scores);
colorbar;
xlabel('Testing Subject');
ylabel('Training Subject');
title('Rank Accuracy Scores Across Subjects');