-
Notifications
You must be signed in to change notification settings - Fork 1
/
NewRunVisGam_2023.m
144 lines (121 loc) · 5.75 KB
/
NewRunVisGam_2023.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
function NewRunVisGam_2023(i)
% Top level script showing how to apply the thalamo-cortical neural mass
% model decribed in Shaw et al 2020 NeuroImage, to M/EEG data.
%
% Requires atcm (thalamo cortical modelling package) and aoptim
% (optimisation package)
%
% atcm: https://github.com/alexandershaw4/atcm
% aoptim: https://github.com/alexandershaw4/aoptim
%
% Overview of contents
%--------------------------------------------------
% - atcm. contains:
% - the equations of motion for an 8 pop thalamo-cortical
% model described by parameterised Morris-Lecar/Hodgkin-Hux
% conductance ODEs
% - numerical integration (Euler, RK, Newton-Cotes +) and spectral
% response functions
% - lots of helper functions (integration, differentiation,
% continuation, decomposition methods etc)
% - aoptim contains:
% - a second order gradient descent optimisation routine that
% includes both free energy and orther objective functions
% - n-th order numerical differentiation functions (parallelised)
%
%
% AS2020/21/22 {alexandershaw4[@]gmail.com}
% EXAMPLE ONE NODE SETUP:
%==========================================================================
clear global;
% Data & Design
%--------------------------------------------------------------------------
Data.Datasets = 'MeanSZDatasets.txt';
Data.Design.X = []; % design matrix
Data.Design.name = {'undefined'}; % condition names
Data.Design.tCode = [1]; % condition codes in SPM
Data.Design.Ic = [1]; % channel indices
Data.Design.Sname = {'V1'}; % channel (node) names
Data.Prefix = 'nfinalTCM_'; % outputted DCM prefix
Data.Datasets = atcm.fun.ReadDatasets(Data.Datasets);
% Model space - T = ns x ns, where 1 = Fwd, 2 = Bkw
%--------------------------------------------------------------------------
T = [... % this is a 1-node model; nothing to put here...
0];
F = (T==1);
B = (T==2);
C = [1]'; % input(s)
L = sparse(1,1);
% Set up, over subjects
%--------------------------------------------------------------------------
for s = i;%1:length(Data.Datasets)
% Data Naming & Design Matrix
%----------------------------------------------------------------------
DCM = [];
[fp fn fe] = fileparts(Data.Datasets{s});
DCM.name = [Data.Prefix fn fe];
DCM.xY.Dfile = Data.Datasets{s}; % original spm datafile
Ns = length(F); % number of regions / modes
DCM.xU.X = Data.Design.X; % design matrix
DCM.xU.name = Data.Design.name; % condition names
tCode = Data.Design.tCode; % condition index (in SPM)
DCM.xY.Ic = Data.Design.Ic; % channel indices
DCM.Sname = Data.Design.Sname; % channel names
if exist(DCM.name);
fprintf('Skipping model %d/%d - already exists!\n( %s )\n',i,length(Data.Datasets),DCM.name);
continue;
end
% Extrinsic Connectivity - Model Space
%----------------------------------------------------------------------
DCM.A{1} = F;
DCM.A{2} = B;
DCM.A{3} = L;
DCM.B{1} = DCM.A{1} | DCM.A{2};
DCM.B(2:length(DCM.xU.X)) = DCM.B;
DCM.C = C;
% Function Handles
%---------------------------------------------------------------------
DCM.M.f = @atcm.experimental_models.spm_fx_tcm; % model function handle
DCM.M.IS = 'spm_csd_mtf'; % Alex integrator/transfer function
DCM.options.SpecFun = @atcm.fun.Afft; % fft function for IS
% Print Progress
%----------------------------------------------------------------------
fprintf('Running Dataset %d / %d\n',s,length(Data.Datasets));
% Frequency range of interest
fq = [3 90];
% Prepare Data
%----------------------------------------------------------------------
DCM.M.U = sparse(diag(ones(Ns,1))); %... ignore [modes]
DCM.options.trials = tCode; %... trial code [GroupDataLocs]
DCM.options.Tdcm = [300 1300]; %... peristimulus time
DCM.options.Fdcm = fq; %... frequency window
DCM.options.D = 1; %... downsample
DCM.options.han = 1; %... apply hanning window
DCM.options.h = 4; %... number of confounds (DCT)
DCM.options.DoData = 1; %... leave on [custom]
%DCM.options.baseTdcm = [-200 0]; %... baseline times [new!]
DCM.options.Fltdcm = fq; %... bp filter [new!]
DCM.options.analysis = 'CSD'; %... analyse type
DCM.xY.modality = 'LFP'; %... ECD or LFP data? [LFP]
DCM.options.spatial = 'LFP'; %... spatial model [LFP]
DCM.options.model = 'tc6'; %... neural model
DCM.options.Nmodes = length(DCM.M.U); %... number of modes
% 1010 == use atcm.fun.AFFT.m
DCM.options.UseWelch = 1010;
DCM.options.FFTSmooth = 3;
%DCM.options.UseButterband = fq;
DCM.options.BeRobust = 0;
DCM.options.FrequencyStep = 1;
DCM.xY.name = DCM.Sname;
DCM = atcm.fun.prepcsd(DCM);
DCM.options.DATA = 1 ;
% Subfunctions and default priors
%----------------------------------------------------------------------
DCM = atcm.parameters(DCM,Ns);
% If using DCM inversion, select whether to block graph or not
DCM.M.nograph = 0;
% Feature function for the integrator [NOT USED]
%----------------------------------------------------------------------
DCM = atcm.complete(DCM);
atcm.optim.dcminvert(DCM)
end