forked from francopestilli/life_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
s_fe_fit.m
87 lines (74 loc) · 2.73 KB
/
s_fe_fit.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
function fe = s_fe_fit()
%
% This function:
% - Identifies al the fibers between two ROIs from a whole-brain conenctome
% - Combines them with fibers tracted between the two ROIs
% - Generates an optimized connectome from a candidate connectome using
% LIFE method
% - Performs a virtual lesion
%
% fe = s_fe_fit()
%
% INPUTS: none
% OUTPUTS: fe structure the optimized life structure
%
% Copyright Franco Pestilli (2014) Stanford University.
%% Get the base directory for the data
datapath = pestilliDataPath;
% Build the file names for the diffusion data, the anatomical MR, the fiber
% group containing the connectome and the
dwiFile = fullfile(datapath,'diffusion','subject1_scan1_2mm_150dir_b2000.nii.gz');
dwiFileRepeat = fullfile(datapath,'diffusion','subject1_scan2_2mm_150dir_b2000.nii.gz');
t1File = fullfile(datapath,'anatomy','subject1_t1_anatomy.nii.gz');
fgFileName = fullfile(datapath,'connectomes','subject1_fibers_unculled_2mm_150dir_b2000_probabilistic_lmax8.mat');
savedir = datapath;
% The final connectome and dat astructure will be saved with this name:
feFileName = 'fe_culled_subject1_scan1_2mm_150dir_b2000';
% Intialize a local matlab cluster if the parallel toolbox is available.
feOpenLocalCluster;
%% Initialize the Connectome
fe = feConnectomeInit(dwiFile,fgFileName,feFileName,savedir,dwiFileRepeat,t1File);
%% Fit the model and cull. This will take some time...
fe = feConnectomeCull(fe);
%% Save it
feConnectomeSave(fe);
%% Make a plot of the weights:
w = feGet(fe,'fiber weights');
figName = sprintf('Fascicle weights');
mrvNewGraphWin(figName);
[y,x] = hist(w(w>0),logspace(-4,-.3,50));
semilogx(x,y)
set(gca,'tickdir','out','fontsize',16,'box','off')
title('fascicle weights','fontsize',16)
ylabel('number of fascicles','fontsize',16)
xlabel('fascicle weight','fontsize',16)
%% Make a plot of the RMSE:
rmse = feGet(fe,'vox rmse');
rmsexv = feGetRep(fe,'vox rmse');
figName = sprintf('RMSE');
mrvNewGraphWin(figName);
% Non-cross-validated
[y,x] = hist(rmse,50);
plot(x,y,'k-')
hold on
% Cross-validated
[y,x] = hist(rmsexv,50);
plot(x,y,'r-')
set(gca,'tickdir','out','fontsize',16,'box','off')
title('Root-mean squared error distribution across voxels','fontsize',16)
ylabel('number of voxels','fontsize',16)
xlabel('rmse','fontsize',16)
legend({'RMSE fitted data set','RMSE cross-validated'},'fontsize',16)
%% Make a plot of the RMSE Ratio:
R = feGetRep(fe,'voxrmseratio');
figName = sprintf('RMSE RATIO');
mrvNewGraphWin(figName);
[y,x] = hist(R,linspace(.5,2,50));
plot(x,y,'k-')
hold on
plot([1 1],[0 450],'k--')
set(gca,'tickdir','out','fontsize',16,'box','off')
title('Root-mean squared error Ratio','fontsize',16)
ylabel('number of voxels','fontsize',16)
xlabel('R_{rmse}','fontsize',16)
return