forked from JoramSoch/MACS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbatch_MS_BMS_group_auto.m
119 lines (102 loc) · 4.26 KB
/
batch_MS_BMS_group_auto.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
function module = batch_MS_BMS_group_auto
% _
% Configure MATLAB Batch for "MS: perform BMS (automatic)"
%
% Author: Joram Soch, BCCN Berlin
% E-Mail: joram.soch@bccn-berlin.de
%
% First edit: 17/03/2017, 07:15 (V0.99/V15)
% Last edit: 09/03/2018, 10:25 (V1.2/V18)
%=========================================================================%
% F I E L D S %
%=========================================================================%
% Select MS.mat
%-------------------------------------------------------------------------%
MS_mat = cfg_files;
MS_mat.tag = 'MS_mat';
MS_mat.name = 'Select MS.mat';
MS_mat.help = {'Select the MS.mat file describing a model space of GLMs.'};
MS_mat.filter = 'mat';
MS_mat.ufilter = '^MS\.mat$';
MS_mat.num = [1 1];
% Enter LME map
%-------------------------------------------------------------------------%
LME_map = cfg_entry;
LME_map.tag = 'LME_map';
LME_map.name = 'Enter LME map';
LME_map.help = {'Enter the name of the log model evidence map that you want to use.'
'In the SPM.mat, LME maps will then be accessed via "SPM.MACS.[input].fname".'
'If you are unsure what this means, just leave this variable at its default value.'};
LME_map.strtype = 's';
LME_map.num = [1 Inf];
LME_map.val = {'cvLME'};
% Inference method
%--------------------------------------------------------------------------
inf_meth = cfg_menu;
inf_meth.tag = 'inf_meth';
inf_meth.name = 'Inference method';
inf_meth.help = {'Select inference method using which Bayesian model selection should be performed.'};
inf_meth.labels = {'Fixed Effects (FFX)', ...
'Random Effects with Variational Bayes (RFX-VB)', ...
'Random Effects with Gibbs Sampling (RFX-GS)'};
inf_meth.values = {'FFX', 'RFX-VB', 'RFX-GS'};
inf_meth.val = {'RFX-VB'};
% Exceedance probabilities
%-------------------------------------------------------------------------%
EPs = cfg_menu;
EPs.tag = 'EPs';
EPs.name = 'Exceedance probabilities';
EPs.help = {'Choose whether exceedance probabilities are calculated in addition to expected and likeliest frequencies.'};
EPs.labels = {'No', 'Yes'};
EPs.values = {0, 1};
EPs.val = {0};
%=========================================================================%
% M O D U L E %
%=========================================================================%
% MS: BMS group (auto)
%-------------------------------------------------------------------------%
module = cfg_exbranch;
module.tag = 'MS_BMS_group_auto';
module.name = 'MS: perform BMS (automatic)';
module.val = {MS_mat LME_map inf_meth EPs};
module.help = {'Bayesian Model Selection for General Linear Models'
'Type "help MS_BMS_group" or "help ME_BMS_RFX_VB" for help.'};
module.prog = @run_module;
module.vout = @vout_module;
%=========================================================================%
% F U N C T I O N S %
%=========================================================================%
% Run batch
%-------------------------------------------------------------------------%
function out = run_module(job)
% get input variables
load(job.MS_mat{1});
method = job.inf_meth;
EPs = logical(job.EPs);
job = rmfield(job,{'inf_meth','EPs'});
% execute operation
[N,M] = size(MS.SPMs);
job.dir{1} = MS.swd;
job.names = MS.GLMs;
job.models = cell(1,N);
for i = 1:N
job.models{i} = cell(1,M);
for j = 1:M
load(MS.SPMs{i,j});
eval(strcat('H = SPM.MACS.',job.LME_map,';'));
job.models{i}{j} = cellstr(strcat(SPM.swd,'/',H.fname));
end;
end;
job = rmfield(job,{'MS_mat','LME_map'});
MS_BMS_group(job,method,[],EPs);
% set output files
load(strcat(job.dir{1},'/','MS.mat'));
out.BMS_mat = cellstr(strcat(MS.swd,'/','BMS.mat'));
% Dependencies
%-------------------------------------------------------------------------%
function dep = vout_module(job)
% define dependencies
dep(1) = cfg_dep;
dep(1).sname = 'BMS results (BMS.mat file)';
dep(1).src_output = substruct('.','BMS_mat');
dep(1).tgt_spec = cfg_findspec({{'filter','mat','strtype','e'}});