-
Notifications
You must be signed in to change notification settings - Fork 1
/
spm_ADEM_set.m
81 lines (68 loc) · 2.37 KB
/
spm_ADEM_set.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
function [DEM] = spm_ADEM_set(DEM)
% Perform checks on DEM structures for active inversion
% FORMAT [DEM] = spm_ADEM_set(DEM)
%
% DEM.G - generative model
% DEM.M - recognition model
% DEM.C - exogenous causes
% DEM.U - prior expectation of causes
%__________________________________________________________________________
% Copyright (C) 2008-2014 Wellcome Trust Centre for Neuroimaging
% Karl Friston
% $Id: spm_ADEM_set.m 5962 2014-04-17 12:47:43Z spm $
% check recognition model
% -------------------------------------------------------------------------
try
DEM.M = spm_DEM_M_set(DEM.M);
catch
errordlg('please check your generative model')
end
try
DEM.G = spm_ADEM_M_set(DEM.G);
catch
errordlg('please check your generative process')
end
% check data or generative model
% -------------------------------------------------------------------------
try
N = length(DEM.C);
catch
errordlg('please specify causes (e.g., sparse(0,N)')
end
try
DEM.class;
catch
DEM.class = 'active';
end
% Default priors
% -------------------------------------------------------------------------
if ~isfield(DEM,'U')
DEM.U = sparse(DEM.M(end).l,N);
end
% transpose causes and confounds, if specified in conventional fashion
%--------------------------------------------------------------------------
try, if size(DEM.U,2) < N, DEM.U = DEM.U'; end, end
try, if size(DEM.C,2) < N, DEM.C = DEM.C'; end, end
% ensure model and input dimensions check
% -------------------------------------------------------------------------
if size(DEM.C,1) ~= DEM.G(end).l
errordlg('model (G) and causes (C) are incompatible')
end
if size(DEM.U,1) ~= DEM.M(end).l
errordlg('model (M) and priors (U) are incompatible')
end
% check prior expectation of causes (at level n) and confounds
%--------------------------------------------------------------------------
if ~nnz(DEM.U), DEM.U = sparse(DEM.M(end).l,N); end
if ~nnz(DEM.C), DEM.C = sparse(DEM.G(end).l,N); end
% ensure causes and data dimensions check
% -------------------------------------------------------------------------
if size(DEM.U,2) < N
errordlg('priors (U) and causes (C) have different lengths')
end
% check length of time-series
%--------------------------------------------------------------------------
if N < DEM.M(1).E.n
errordlg('Please ensure time-series is longer than embedding order')
return
end