-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvalidation_split_half.m
131 lines (109 loc) · 3.9 KB
/
validation_split_half.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
function validation_split_half(PWD,ROI,SUB_LIST,METHOD,VOX_SIZE,MAX_CL_NUM,N_ITER,POOLSIZE,GROUP_THRES,MPM_THRES,LorR)
% split half strategy
if LorR == 1
LR='L';
elseif LorR == 0
LR='R';
end
sub=textread(SUB_LIST,'%s');
sub_num=length(sub);
if ~exist('N_ITER','var') | isempty(N_ITER)
N_ITER=100;
end
if ~exist('MPM_THRES','var') | isempty(MPM_THRES)
MPM_THRES=0.25;
end
GROUP_THRES=GROUP_THRES*100;
MASK_FILE=strcat(PWD,'/group_',num2str(sub_num),'_',num2str(VOX_SIZE),'mm/',ROI,'_',LR,'_roimask_thr',num2str(GROUP_THRES),'.nii.gz');
MASK_NII=load_untouch_nii(MASK_FILE);
MASK=double(MASK_NII.img);
MASK(isnan(MASK))=0;
half=floor(sub_num/2);
dice=zeros(N_ITER,MAX_CL_NUM);
nminfo=zeros(N_ITER,MAX_CL_NUM);
vi=zeros(N_ITER,MAX_CL_NUM);
cv=zeros(N_ITER,MAX_CL_NUM);
% Parallel Computing Toolbox settings
% 2014a removed findResource, replaced by parcluster
% 2016b removed matlabpool, replaced by parpool
% modify temporary dir
temp_dir=tempname();
mkdir(temp_dir);
if exist('parcluster')
pc=parcluster('local');
pc.JobStorageLocation=temp_dir;
else
sched=findResource('scheduler','type','local');
sched.DataLocation=temp_dir;
end
% open pool
if exist('parpool')
pcp=gcp('nocreate');
if isempty(pcp)
p=parpool('local',POOLSIZE);
end
else
if matlabpool('size')==0
matlabpool('local',POOLSIZE);
end
end
parfor ti=1:N_ITER
tmp=randperm(sub_num);
list1_sub={sub{tmp(1:half)}}';
list2_sub={sub{tmp(half+1:sub_num)}}';
temp_dice=zeros(1,MAX_CL_NUM);
temp_nmi=zeros(1,MAX_CL_NUM);
temp_vi=zeros(1,MAX_CL_NUM);
temp_cv=zeros(1,MAX_CL_NUM);
for kc=2:MAX_CL_NUM
disp(['split_half: ',ROI,'_',LR,' kc=',num2str(kc),' ',num2str(ti),'/',num2str(N_ITER)]);
mpm_cluster1=cluster_mpm_validation(PWD,ROI,list1_sub,METHOD,VOX_SIZE,kc,MPM_THRES,LorR);
mpm_cluster2=cluster_mpm_validation(PWD,ROI,list2_sub,METHOD,VOX_SIZE,kc,MPM_THRES,LorR);
mpm_cluster1=mpm_cluster1.*MASK;
mpm_cluster2=mpm_cluster2.*MASK;
%compute dice coefficent
temp_dice(kc)=v_dice(mpm_cluster1,mpm_cluster2,kc);
%compute the normalized mutual information and variation of information
[temp_nmi(kc),temp_vi(kc)]=v_nmi(mpm_cluster1,mpm_cluster2);
%compute cramer V
temp_cv(kc)=v_cramerv(mpm_cluster1,mpm_cluster2);
end
dice(ti,:)=temp_dice;
nminfo(ti,:)=temp_nmi;
vi(ti,:)=temp_vi;
cv(ti,:)=temp_cv;
end
if ~exist(strcat(PWD,'/validation_',num2str(sub_num),'_',num2str(VOX_SIZE),'mm'))
mkdir(strcat(PWD,'/validation_',num2str(sub_num),'_',num2str(VOX_SIZE),'mm'));
end
save(strcat(PWD,'/validation_',num2str(sub_num),'_',num2str(VOX_SIZE),'mm/',ROI,'_',LR,'_index_split_half.mat'),'dice','nminfo','cv','vi');
fp=fopen(strcat(PWD,'/validation_',num2str(sub_num),'_',num2str(VOX_SIZE),'mm/',ROI,'_',LR,'_index_split_half.txt'),'at');
if fp
for kc=2:MAX_CL_NUM
fprintf(fp,'%s','cluster num = ');
fprintf(fp,'%d',kc);
fprintf(fp,'\n');
fprintf(fp,'%s',' dice: mean = ');
fprintf(fp,'%f %f',nanmean(dice(:,kc)));
fprintf(fp,'%s',' , std = ');
fprintf(fp,'%f %f',nanstd(dice(:,kc)));
fprintf(fp,'\n');
fprintf(fp,'%s',' normalized mutual info: mean = ');
fprintf(fp,'%f %f',nanmean(nminfo(:,kc)));
fprintf(fp,'%s',' , std = ');
fprintf(fp,'%f %f',nanstd(nminfo(:,kc)));
fprintf(fp,'\n');
fprintf(fp,'%s',' variation of info: mean = ');
fprintf(fp,'%f %f',nanmean(vi(:,kc)));
fprintf(fp,'%s',' , std = ');
fprintf(fp,'%f %f',nanstd(vi(:,kc)));
fprintf(fp,'\n');
fprintf(fp,'%s',' cramer V: mean = ');
fprintf(fp,'%f %f',nanmean(cv(:,kc)));
fprintf(fp,'%s',' , std = ');
fprintf(fp,'%f %f',nanstd(cv(:,kc)));
fprintf(fp,'\n');
fprintf(fp,'\n');
end
end
fclose(fp);