Skip to content

Commit e0a5fdd

Browse files
committed
Added paper wrapper.
1 parent f8297e0 commit e0a5fdd

13 files changed

+176
-105
lines changed

fig4_get_params.m

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
%% get parameters for intero and extero
88

9-
clear all
109
evparam =[0.5:.1:1];
1110
ivparam =[0.5:.1:1];
1211

@@ -16,8 +15,8 @@
1615
for ev = 1:numel(evparam)
1716

1817

19-
filestr = sprintf(['/MDPfiles/MDP_90vol_%dip_%dep.mat'],ivparam(iv)*100, evparam(ev)*100);
20-
filename = [pwd filestr];
18+
filestr = sprintf(['/MDP_files/MDP_90vol_%dip_%dep.mat'],ivparam(iv)*100, evparam(ev)*100);
19+
filename = [datpath filestr];
2120
load(filename, 'MDP')
2221

2322
param_mat_extero(iv, ev) = sum(calc_h_extero(MDP)); % exteroceptive confidence/entropy

figure_3_plots.m

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
%% initialize
66
clear h1 h2 spiderprob1 spiderprob2 mdp1 mdp2
77
close all
8-
load MDP_30n_100t_healthy.mat
9-
load MDP_30n_100t_lesion.mat
108

11-
figdir = [pwd '\figures\'];
9+
load(fullfile(datpath, 'MDP_30n_100t_healthy.mat'), 'mdp1')
10+
load(fullfile(datpath, 'MDP_30n_100t_lesion.mat'), 'mdp2')
11+
12+
13+
figdir = [pwd '\Figures\'];
1214

1315
if ~exist(figdir)
1416
mkdir(figdir)
@@ -61,7 +63,7 @@
6163
xlim([0 40])
6264
box off
6365
fname = [figdir 'FearExpectation.pdf'];
64-
print(fname, '-dpdf', '-r600')
66+
% print(fname, '-dpdf', '-r600') % uncomment to save figure to disk
6567

6668
%% figure 3A - binned beats
6769

@@ -192,4 +194,4 @@
192194
set(gca, 'FontSize', 12)
193195
box off
194196
fname = [figdir 'cardiac_response.pdf'];
195-
print(fname, '-dpdf', '-r600')
197+
%print(fname, '-dpdf', '-r600') % uncomment to save figure to disk

figure_3_simulations.m

+42-37
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
%% script to run the simulations in figure 3
22
% runs MDP simulation with the first 15 trials as fixed inputs.
33

4-
%% get canonical variables for each cardiac phase
5-
close all
6-
clear all
7-
8-
% path to code repository - change this
9-
addpath('C:\Users\Micah Allen\Google Drive\FEP_Heartbeat\code\cbrewer')
10-
11-
% path to SPM 12 - change this
12-
addpath('C:\Users\Micah Allen\Dropbox\toolboxes\MatlabToolboxes\SPM12_latest')
13-
14-
% intialize and close spm - need MDP functions on path
15-
spm fmri -nogui
16-
spm quit
174

185
%% run model 1 - healthy control
196
% healthy interoception
@@ -39,28 +26,37 @@
3926
input.T = 100; % specify number of total trials to simulate
4027

4128
%% simulate 30 healthy subjects in a parfor loop
42-
nsubjects = 30;
43-
44-
parfor n = 1:nsubjects
45-
46-
47-
48-
tic
49-
fprintf('\nSubject %d/%d Started\n', n, nsubjects)
50-
mdp1(n)= run_mdp_simulation(input);
51-
t=toc;
52-
fprintf('\nSubject %d/%d Simulated in %02f seconds \n'...
53-
, n,nsubjects, t)
54-
55-
56-
29+
% if you do not have parallel computing toolbox, just change to a for loop
30+
% and it should run. It may take a while.
31+
if ~exist(fullfile(datpath, 'MDP_30n_100t_healthy.mat'), 'file')
32+
nsubjects = 30;
33+
34+
parfor n = 1:nsubjects
35+
36+
37+
38+
tic
39+
fprintf('\nSubject %d/%d Started\n', n, nsubjects)
40+
mdp1(n)= run_mdp_simulation(input);
41+
t=toc;
42+
fprintf('\nSubject %d/%d Simulated in %02f seconds \n'...
43+
, n,nsubjects, t)
44+
45+
46+
47+
end
48+
49+
save(fullfile(datpath, 'MDP_30n_100t_healthy.mat'), 'mdp1')
50+
51+
else
52+
53+
load(fullfile(datpath, 'MDP_30n_100t_healthy.mat'), 'mdp1')
54+
5755
end
5856

59-
save MDP_30n_100t_healthy mdp1
60-
61-
%% optional plotting
62-
spm_figure('GetWin','Figure 1');
63-
spm_MDP_VB_trial(mdp1(end))
57+
%% optional plotting of state trajectories
58+
% spm_figure('GetWin','Figure 1');
59+
% spm_MDP_VB_trial(mdp1(end))
6460

6561
%% simulation #2 - lesioned interoceptive precision
6662

@@ -80,6 +76,7 @@
8076
input.s = [repmat([1 2 3], 1, length(input.s)./3); input.s];
8177
input.T = 100;
8278

79+
if ~exist(fullfile(datpath, 'MDP_30n_100t_lesion.mat'), 'file')
8380

8481
nsubjects = 30;
8582

@@ -98,13 +95,21 @@
9895

9996
end
10097

98+
save(fullfile(datpath, 'MDP_30n_100t_lesion.mat'), 'mdp2')
99+
100+
else
101+
101102

103+
load(fullfile(datpath, 'MDP_30n_100t_lesion.mat'), 'mdp2')
104+
105+
106+
end
102107

103-
save MDP_30n_100t_lesion mdp2
108+
104109

105-
%% optional plotting
106-
spm_figure('GetWin','Figure 1');
107-
spm_MDP_VB_trial(mdp2(end))
110+
%% optional plotting of state trajectories
111+
% spm_figure('GetWin','Figure 1');
112+
% spm_MDP_VB_trial(mdp2(end))
108113

109114

110115

figure_4_cardiac_cycle_plots.m

+4-21
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,7 @@
11
%% wrapper script to run simulations and
22
%% get canonical variables for each cardiac phase
33
%% reproduces Figure 4B and 4D
4-
close all
5-
clear all
64

7-
% path to code repository - must be run from inside code repo dir
8-
addpath(genpath(pwd))
9-
% path to SPM 12 - change this
10-
addpath('C:\Users\Micah Allen\Dropbox\toolboxes\MatlabToolboxes\SPM12_latest')
11-
12-
% intialize and close spm - need MDP functions on path
13-
spm fmri -nogui
14-
spm quit
15-
16-
17-
figdir = [pwd '\figures\'];
18-
19-
if ~exist(figdir)
20-
mkdir(figdir)
21-
end
225

236
%% run model 1 - healthy extero
247

@@ -72,7 +55,7 @@
7255
[h1_3, h2_3, h3_3] = split_h_cardiac_extero(MDP3);
7356

7457
figure;
75-
cmap = cbrewer('seq', 'PuRd', 3);
58+
cmap = cbrewer2('seq', 'PuRd', 3);
7659
y = [h1_1 h2_1 h3_1; h1_2 h2_2 h3_2; h1_3 h2_3 h3_3];%; h1_4 h2_4 h3_4];
7760
b = bar(y,'FaceColor','flat');
7861

@@ -88,15 +71,15 @@
8871
title('Cardiac Cycle and Exteroceptive Uncertainty')
8972

9073
fname = [figdir 'fig4b_barplot_cardiac_cycle_extero.pdf'];
91-
print(fname, '-dpdf', '-r600')
74+
%print(fname, '-dpdf', '-r600')
9275

9376
%% figure 3D
9477
[h1_1, h2_1, h3_1] = split_h_cardiac_intero(MDP1);
9578
[h1_2, h2_2, h3_2] = split_h_cardiac_intero(MDP2);
9679
[h1_3, h2_3, h3_3] = split_h_cardiac_intero(MDP3);
9780

9881
figure;
99-
cmap = cbrewer('seq', 'PuRd', 3);
82+
cmap = cbrewer2('seq', 'PuRd', 3);
10083
y = [h1_1 h2_1 h3_1; h1_2 h2_2 h3_2; h1_3 h2_3 h3_3];%; h1_4 h2_4 h3_4];
10184
b = bar(y,'FaceColor','flat');
10285

@@ -112,4 +95,4 @@
11295
title('Cardiac Cycle and Interoceptive Uncertainty')
11396

11497
fname = [figdir 'fig4D_barplot_cardiac_cycle_intero.pdf'];
115-
print(fname, '-dpdf', '-r600')
98+
%print(fname, '-dpdf', '-r600')

figure_4_plot_params.m

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
%% initialize
22

33

4-
figdir = [pwd '\figures\'];
4+
figdir = [pwd '\Figures\'];
55

66
if ~exist(figdir)
77
mkdir(figdir)
@@ -23,7 +23,7 @@
2323
%% figure
2424

2525
figure
26-
cmap = cbrewer('div', 'Spectral', 50);
26+
cmap = cbrewer2('div', 'Spectral', 50);
2727

2828
s=surf(tickparam, tickparam, param_mat_in); zlabel(zlab), xlabel(xlab),ylabel(ylab); colormap(cmap)
2929
set(gca, 'XTickLabel', tickparam, 'XTick',tickparam, 'YTickLabel', tickparam, 'YTick', tickparam)
@@ -36,7 +36,7 @@
3636

3737
fname = [figdir 'fig4A_extero.pdf'];
3838
title('Exteroceptive Uncertainty')
39-
print(fname, '-dpdf', '-r600');
39+
%print(fname, '-dpdf', '-r600');
4040

4141

4242
%% parameters - intero
@@ -53,7 +53,7 @@
5353
%% figure
5454

5555
figure
56-
cmap = cbrewer('div', 'Spectral', 50);
56+
cmap = cbrewer2('div', 'Spectral', 50);
5757

5858
s=surf(tickparam, tickparam, param_mat_in); zlabel(zlab), xlabel(xlab),ylabel(ylab); colormap(cmap)
5959
set(gca, 'XTickLabel', tickparam, 'XTick',tickparam, 'YTickLabel', tickparam, 'YTick', tickparam)
@@ -65,4 +65,4 @@
6565
pbaspect([1 1 1])
6666
title('Interoceptive Uncertainty')
6767
fname = [figdir 'fig4C_intero.pdf'];
68-
print(fname, '-dpdf', '-r600');
68+
%print(fname, '-dpdf', '-r600');

figure_4_plots_wrapper.m

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
%% wrapper script to generate the plots in figure 4
22

33
%% first, run the simulations for panels A & C
4-
% note this will take a *long* time
54

65
figure_4_simulations_wrapper;
76

figure_4_simulations.m

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
%% script to run many simulations in parallel,
2+
% for figure 4A and 4C.
3+
4+
5+
if ~isdir(fullfile(datpath, '/MDP_files'))
6+
mkdir(fullfile(datpath, '/MDP_files'))
7+
addpath(fullfile(datpath, '/MDP_files'))
8+
end
9+
10+
%% this will run *many* simulations in parallel and
11+
% save them. Will take at least a day to run!
12+
eparam =[0.5:0.1:1];
13+
iparam =[0.5:0.1:1];
14+
15+
for ev = 1:numel(eparam)
16+
17+
18+
parfor iv = 1:numel(iparam)
19+
% run sim
20+
MDP = sim_save(iparam(iv), eparam(ev),datpath);
21+
22+
23+
end
24+
25+
end

figure_4_simulations_wrapper.m

+7-21
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,23 @@
1-
%% wrapper script to run many simulations in parallel,
1+
%% script to run many simulations in parallel,
22
% for figure 4A and 4C.
33

4-
close all
5-
clear all
64

7-
% path to code repository - must be run from inside code repo dir
8-
addpath(genpath(pwd))
9-
% path to SPM 12 - change this
10-
addpath('C:\Users\Micah Allen\Dropbox\toolboxes\MatlabToolboxes\SPM12_latest')
11-
12-
% intialize and close spm - need MDP functions on path
13-
spm fmri -nogui
14-
spm quit
15-
16-
% parameters to loop over - here the full range from
17-
% lesioned precision to hyper-precision in steps of 10%
18-
19-
eparam =[0.5:0.1:1];
20-
iparam =[0.5:0.1:1];
21-
22-
if ~isdir('MDP_files')
23-
mkdir('MDP_files')
5+
if ~isdir(fullfile(datpath, '/MDP_files'))
6+
mkdir(fullfile(datpath, '/MDP_files'))
7+
addpath(fullfile(datpath, '/MDP_files'))
248
end
259

2610
%% this will run *many* simulations in parallel and
2711
% save them. Will take at least a day to run!
12+
eparam =[0.5:0.1:1];
13+
iparam =[0.5:0.1:1];
2814

2915
for ev = 1:numel(eparam)
3016

3117

3218
parfor iv = 1:numel(iparam)
3319
% run sim
34-
MDP = sim_save(iparam(iv), eparam(ev));
20+
MDP = sim_save(iparam(iv), eparam(ev),datpath);
3521

3622

3723
end

figure_5_hrv_plots.m

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
load MDP_hrv_models.mat
2+
33

44

55
%% healthy model
@@ -12,15 +12,15 @@
1212
plot_data(1).data = [summary_data.pLF summary_data.pHF]; % output data for final barplot
1313

1414
hrv_rr_plot % rr
15-
print([figdir 'rr_plot_healthy.pdf'], '-dpdf', '-r600')
15+
%print([figdir 'rr_plot_healthy.pdf'], '-dpdf', '-r600')
1616

1717
hrv_trace_plot % trace
1818

19-
print([figdir 'hrv_traceplot_healthy.pdf'], '-dpdf', '-r600')
19+
%print([figdir 'hrv_traceplot_healthy.pdf'], '-dpdf', '-r600')
2020

2121
psd_plot_hrv % spectral frequency
2222

23-
print([figdir 'hrv_spectral_healthy.pdf'], '-dpdf', '-r600')
23+
%print([figdir 'hrv_spectral_healthy.pdf'], '-dpdf', '-r600')
2424

2525

2626
%% visceral hyper precision model
@@ -34,7 +34,7 @@
3434

3535
psd_plot_hrv % spectral frequency
3636

37-
print([figdir 'hrv_spectral_hyper.pdf'], '-dpdf', '-r600')
37+
%print([figdir 'hrv_spectral_hyper.pdf'], '-dpdf', '-r600')
3838

3939
%% visceral hyper arousal prior model
4040

@@ -47,4 +47,4 @@
4747

4848
psd_plot_hrv % spectral frequency
4949

50-
print([figdir 'hrv_spectral_arousalprior.pdf'], '-dpdf', '-r600')
50+
%print([figdir 'hrv_spectral_arousalprior.pdf'], '-dpdf', '-r600')

0 commit comments

Comments
 (0)