-
Notifications
You must be signed in to change notification settings - Fork 2
/
spm_DEM_set.m
108 lines (95 loc) · 3.02 KB
/
spm_DEM_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
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
function [varargout] = spm_DEM_set(DEM)
% Performs checks on DEM structures
% FORMAT [DEM] = spm_DEM_set(DEM)
%
% DEM.M - hierarchical model
% DEM.Y - response varaible, output or data
% DEM.U - explanatory variables, inputs or prior expectation of causes
% DEM.X - confounds
%__________________________________________________________________________
% Copyright (C) 2005 Wellcome Department of Imaging Neuroscience
% Karl Friston
% $Id$
% check recognition model
% -------------------------------------------------------------------------
try
DEM.M = spm_DEM_M_set(DEM.M);
catch
errordlg('please check your model')
end
% check data or generative model
% -------------------------------------------------------------------------
try
N = size(DEM.Y,2);
catch
try
DEM.G = spm_DEM_M_set(DEM.G);
N = size(DEM.C,2);
catch
errordlg('please specify data or inputs')
end
end
try
DEM.class;
catch
DEM.class = 'unknown';
end
% ensure model and data dimensions check
% -------------------------------------------------------------------------
try
if size(DEM.Y,1) ~= DEM.M(1).l
errordlg('DCM and data are incompatible')
end
catch
if size(DEM.C,1) ~= DEM.M(end).l
errordlg('DCM and causes are incompatible')
end
end
% Default priors and confounds
% -------------------------------------------------------------------------
n = DEM.M(end).l;
if ~isfield(DEM,'U')
DEM.U = sparse(n,N);
end
if ~isfield(DEM,'X')
DEM.X = sparse(0,N);
end
% transpose causes and confounds, if specified in conventional fashion
%--------------------------------------------------------------------------
if size(DEM.U,2) < N, DEM.U = DEM.U'; end
if size(DEM.X,2) < N, DEM.X = DEM.X'; end
% check prior expectation of causes (at level n) and confounds
%--------------------------------------------------------------------------
if ~nnz(DEM.U), DEM.U = sparse(n,N); end
if ~nnz(DEM.X), DEM.X = sparse(0,N); end
% ensure inputs and cause dimensions check
% -------------------------------------------------------------------------
if size(DEM.U,1) ~= DEM.M(end).l
errordlg('DCM inputs and priors are not compatible')
end
% ensure causes and data dimensions check
% -------------------------------------------------------------------------
if size(DEM.U,2) < N
errordlg('priors and data have different lengths')
end
% ensure confounds and data dimensions check
% -------------------------------------------------------------------------
if size(DEM.X,2) < N
errordlg('confounds and data 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
% unpack DEM if necessary
% -------------------------------------------------------------------------
if nargout == 4
varargout{1} = DEM.M;
varargout{2} = DEM.Y;
varargout{3} = DEM.U;
varargout{4} = DEM.X;
else
varargout{1} = DEM;
end