-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGeneralAttentionModel.m
52 lines (40 loc) · 2.41 KB
/
GeneralAttentionModel.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
%% Variables
% behav_all: z-scored behavior performances of individuals (in rows) and three tasks (in columns)
% mat_all: vectorized connectomes of individuals for five states in 3-dim (edge x subject x states)
% five states: task 1, task 2, task 3, rest, and movie
% nFold: 10 for 10-fold.
% thr: 0.05 for a feature selction threshold in CPM modeling
% permList: 1000 iterations x shuffled subjects in 2-dim (iteration x shuffling label)
% subjKlist: 10 x 2 matrix, defining the first and last subjects number in 10 folds. (fold x subject number)
% subjKnum: 10 x 1 matrix, defining the number of subjects in each fold (should agree with subjKlist)
% CPMpred*: individuals' predicted scores (1st dim) with training data (2nd dim) and testing data (3rd dim)
%% General attention connectome lookup table
for e = 1:size(mat_all,1)
[~, temp_idx] = max(abs(mean(squeeze(mat_all(e,:,1:3)))));
aa5(e,1) = temp_idx;
mat_task(e,:) =mat_all(e,:,temp_idx); clear temp_idx
end
%% General attention modeling
nPerm = size(permList,1);
meanPCA = 0; nPCA = 50; nPLS = 10; thr = 0.05;
for np = 1:nPerm
for nf = 1:nFold
fprintf('\t%d/%d fold %d/%d iteration \n', nf, nFold, np, nPerm)
subjTest = permList(np,[subjKlist(nf,1):subjKlist(nf,2)]);
subjTrain = setdiff([1:size(behav_all,1)],subjTest);
matPred(:,subjTest) = c2c_2sets(mat_all(:,subjTrain, 4)', mat_task(:,subjTrain)', mat_all(:,subjTest, 4)', nCompPCA, nCompPLS, meanPCA)';
[~, CPMpred_general(subjTest,1)] = cpm_lr_D1D2_union(mat_task(:,subjTrain), matPred(:,subjTest), mean(behav_all(subjTrain, :), 2), behav_all(subjTest, 1), thr, behav_all(subjTrain, :) );
end
% performance: correlation
[temp_R temp_P] = corr(behav_all, squeeze(CPMpred_general));
predCorr_general.R(:,:,np) = temp_R; predCorr_general.P(:,:,np) = temp_P; clear temp*
% performance: Prediction q^2
for nf = 1:nFold
subjTest = permList(np,[subjKlist(nf,1):subjKlist(nf,2)]);
subjTrain = setdiff([1:size(behav_all,1)],subjTest);
deno(subjTest,:) = behav_all(subjTest, :) - mean(behav_all(subjTrain, :));
nume(subjTest,:) = behav_all(subjTest, :) - CPMpred_general(subjTest);
end
predMSE_general(:, np) = 1 - ( mean(nume.^2) ./mean(deno.^2)); clear deno nume
end; clear s t1 t2
% save matPred, CPMpred_general, and pred*_general files