-
Notifications
You must be signed in to change notification settings - Fork 3
/
tabulateVARmissingvalues.m
200 lines (157 loc) · 8.37 KB
/
tabulateVARmissingvalues.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
%% tabulate performance times for VAR's with missing value
% coded by Elmar Mertens em@elmarmertens.com
%% clean workspace
clear
clc
close all
%% load toolboxes
path(pathdef)
addpath matlabtoolbox/emtools/
addpath matlabtoolbox/emtexbox/
addpath matlabtoolbox/emgibbsbox/
addpath matlabtoolbox/emeconometrics/
addpath matlabtoolbox/emstatespace/
%#ok<*UNRCH>
%#ok<*NOPTS>
%% prepare latex wrapper
initwrap
matfiledir = 'matfilesJEDCR1';
%% load results
for BRANDS = {'MacOSIntel', 'WindowsXeon'}
thisBrand = BRANDS{:};
switch thisBrand
case 'WindowsXeon'
thisComputerShort = 'Intel Xeon w/Windows';
thisComputer = 'Intel(R) Xeon(R) Gold 6320 CPU @ 2.1 GHz (Windows)';
availableThreads = 32;
case 'MacOSIntel'
thisComputerShort = 'Intel i7 w/macOS';
thisComputer = 'Intel(R) Core(TM) i7-5775R CPU @ 3.30GHz (macOS)';
availableThreads = 4;
case 'AppleSilicon'
thisComputerShort = 'Apple Silicon';
thisComputer = 'Apple M1 Pro (macOS, Rosetta 2)';
availableThreads = 8;
case 'IntelUbuntu'
thisComputerShort = 'Intel Xeon w/Ubuntu';
thisComputer = 'Intel(R) Xeon(R) CPU E5-1680 v4 @ 3.40GHz';
availableThreads = 8;
otherwise
error('brand <<%s>> not known.', thisBrand)
end
for usedThreads = [1 availableThreads]
if usedThreads == 1
threadLabel = sprintf('%d thread', usedThreads);
else
threadLabel = sprintf('%d threads', usedThreads);
end
for missValShare = [.01 .05 .1 .2 .3 .5 .7 .9]
if strcmp(thisBrand, 'IntelUbuntu') && missValShare > .01
continue % skip other cases, since matfiles for IntelUbuntu are missing
end
matname = sprintf('VARmissingvaluesPStimes%sThreads%dof%dmissValShare%02d', thisBrand, usedThreads, availableThreads, floor(missValShare * 100));
mat = matfile(fullfile(matfiledir, matname));
if mat.missValShare ~= missValShare
error('missValShare mismatch in matfile')
end
thisVer = mat.thisVer; % MatFile object does not support indexing into struct arrays
ndx = arrayfun(@(x) strcmp(x.Name, 'MATLAB'), thisVer);
thisMatlab = sprintf('%s %s', thisVer(ndx).Name, thisVer(ndx).Release);
gridNy = mat.gridNy;
gridT = mat.gridT;
gridP = mat.gridP;
% [PStimes, PS0times, DKtimes] = deal(NaN(length(gridP), length(gridNy), length(gridT)));
PStimes = mat.PStimes;
PS0times = mat.PS0times;
DKtimes = mat.DKtimes;
DKMisstimes = mat.DKMisstimes;
if length(gridT) ~= 2
error('expecting gridT to have only 2 elements');
end
% PStimes ./ DKtimes
% PS0times ./ DKtimes
%% create latex table
panellabel = {'A', 'B', 'C', 'D'};
panelcaption = {'ABC-PS (excl. QR) as percentage of DK', 'ABC-PS (incl. QR) as percentage of DK', 'missing-variables DK as percentage of DK', 'DK in seconds'};
Npanel = length(panellabel);
tabname = sprintf('VARmissingvaluesPStimes%sThreads%dof%dmissValShare%02d.tex', thisBrand, usedThreads, availableThreads, floor(missValShare * 100));
% tabcaption = sprintf('Execution times for sampling missing values of a VAR');
tabcaption = sprintf('Missing-value VAR on %s (%s) with %d\\%% of observations missing', thisComputerShort, threadLabel, floor(missValShare * 100));
tabdir = wrap.dir;
latexwrapper(wrap, 'add', 'tab', tabname, tabcaption)
% collect table data
tableData = NaN(length(gridP), length(gridNy) * 2, Npanel);
iterPanel = 1;
thisPanel = PStimes ./ DKtimes * 100;
tableData(:,:,iterPanel) = reshape(thisPanel, [length(gridP), length(gridNy) * 2]);
iterPanel = 2;
thisPanel = PS0times ./ DKtimes * 100;
tableData(:,:,iterPanel) = reshape(thisPanel, [length(gridP), length(gridNy) * 2]);
iterPanel = 3;
thisPanel = DKMisstimes ./ DKtimes * 100;
tableData(:,:,iterPanel) = reshape(thisPanel, [length(gridP), length(gridNy) * 2]);
iterPanel = 4;
thisPanel = DKtimes;
tableData(:,:,iterPanel) = reshape(thisPanel, [length(gridP), length(gridNy) * 2]);
% tabulate
fid = fopen(fullfile(tabdir, tabname), 'wt');
fprintf(fid, '\\begin{center}\n');
Ncols = 1 + 2 * length(gridNy);
fprintf(fid, '\\begin{tabular}{r%s}\n', repmat('.2', 1, 2 * length(gridNy)));
fprintf(fid, '\\toprule\n');
% column headers
fprintf(fid, ' & ');
fprintf(fid, '\\multicolumn{%d}{c}{$N_y$} ', 2 * length(gridNy));
fprintf(fid, '\\\\\n');
fprintf(fid, '\\cmidrule(lr){%d-%d}\n',2,Ncols);
iterT = 1;
fprintf(fid, '& \\multicolumn{%d}{c}{$T = %d$} ', length(gridNy), gridT(iterT));
iterT = 2;
fprintf(fid, '& \\multicolumn{%d}{c}{$T = %d$} ', length(gridNy), gridT(iterT));
fprintf(fid, '\\\\\n');
fprintf(fid, '\\cmidrule(lr){%d-%d}\n',2,1 + length(gridNy));
fprintf(fid, '\\cmidrule(lr){%d-%d}\n',2 + length(gridNy), Ncols);
fprintf(fid, '$p$ ');
fprintf(fid, '& \\multicolumn{1}{c}{\\quad$%d$\\quad} ', gridNy);
fprintf(fid, '& \\multicolumn{1}{c}{\\quad$%d$\\quad} ', gridNy);
fprintf(fid, '\\\\\n');
for iterPanel = 1 : Npanel
fprintf(fid, '\\midrule\n');
fprintf(fid, '\\multicolumn{%d}{c}{\\textbf{PANEL %s: %s}} ', Ncols, panellabel{iterPanel}, panelcaption{iterPanel});
fprintf(fid, '\\\\\n');
fprintf(fid, '\\midrule\n');
for iterP = 1 : length(gridP)
fprintf(fid, '$%d$ ', gridP(iterP));
if iterPanel < Npanel
fprintf(fid, '& \\multicolumn{1}{r}{%4.0f} ', tableData(iterP,:,iterPanel));
else
fprintf(fid, '& %8.2f ', tableData(iterP,:,iterPanel));
end
fprintf(fid, '\\\\\n');
end
end
fprintf(fid, '\\bottomrule\n');
fprintf(fid, '\\end{tabular}\n');
fprintf(fid, '\\end{center}\n');
fprintf(fid, '\n');
fprintf(fid, 'Notes: ');
fprintf(fid, 'Based on simulated data with %d\\%% of all observations missing.\n', floor(missValShare * 100));
fprintf(fid, 'Panels~A and~B report the execution time of a typical call to the precision-based sampler (PS) for different choices of lag length ($p$), number of VAR variables ($N_y$) and observations ($T$) as percentage of the execution time of the Durbin-Koopmann''s disturbance smoothing sampler (DK) whose execution time (in seconds) is reported in Panel~D.\n');
fprintf(fid, 'Execution times for the precision-based sampler reported in Panel A reflect the use of prepared one-off computations (incl. the QR decomposition of measurement loadings $\\boldsymbol{C}$) outside the measured times. These time are relevant for MCMC applications where $\\boldsymbol{C}$ does not change between sampling steps.\n');
fprintf(fid, 'Panel~B considers calls to the precision-based sampler that encompass all computations.\n');
fprintf(fid, 'Panel~C considers a version of the DK sampler that is specialized to the missing-value case (where the sampler processes only the relevant rows of the state equation when updating the Kalman filter).\n');
fprintf(fid, 'All times were measured in %s with the \\texttt{timeit} function on an %s ', thisMatlab, thisComputer);
if usedThreads == 1
fprintf(fid, ' in single-threaded mode.\n');
else
fprintf(fid, ' in multi-threaded mode (for matrix operations) using %d threads.\n', usedThreads);
end
fprintf(fid, '\n');
fclose(fid);
type(fullfile(tabdir, tabname))
end % missValShare
end % usedThreads
end % thisBrand
%% finish
finishwrap
finishscript