-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcreate_figs_and_tables.m
146 lines (110 loc) · 3.72 KB
/
create_figs_and_tables.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
%% create figures and tables
% scken, 2021
% Copyright (C) 2021 Chair of Automation Technology / TU Chemnitz
clear all
close all
n_dim = [512 1024 2048];
scale = [2 4 6 8];
encoding_dim = [20 40 60 80 100];
HDC_network = 'True';
dataset = 'full';
f1_tensor = zeros([3 3 3]);
%% iterate over all results of hyper-parameter analysis (table 3)
for d=1:numel(n_dim)
for s=1:numel(scale)
for e=1:numel(encoding_dim)
% load file
load(['results/' dataset '/results_HDC_' num2str(n_dim(d)) '_' num2str(scale(s)) '_' num2str(encoding_dim(e)) '_1.0.mat'])
f1_tensor(d,s,e) = round(report.accuracy,2);
end
end
end
% create result table
subtable = {};
% create Rownames
rownames = {};
for s=1:numel(scale)
rownames{end +1} = ['scale = ' num2str(scale(s))];
end
% variable names
varnames = {};
for e=1:numel(encoding_dim)
varnames{end+1} = [num2str(encoding_dim(e))];
end
for d=1:numel(n_dim)
subtable{d} = array2table(squeeze(f1_tensor(d,:,:)), ...
'VariableNames',varnames);
end
tab = table(subtable{:},'VariableNames',{'\# Dimensions = 512', '\# Dimensions = 1024', '\# Dimensions = 2048'},'RowNames',rownames)
table2latex(tab,[3 2],0.5,'tables/results_vsa.tex')
%% evaluate model size (table 4)
param_array = zeros([numel(n_dim) numel(encoding_dim)]);
for d=1:numel(n_dim)
for e=1:numel(encoding_dim)
% load file
load(['results/' dataset '/results_HDC_' num2str(n_dim(d)) '_8_' num2str(encoding_dim(e)) '_1.0.mat'])
start_idx = findstr(model_summary,'Trainable params: ');
start_idx = start_idx + 18;
end_idx = findstr(model_summary,'Non-trainable');
n_params = str2num(replace(model_summary(start_idx:end_idx-1),',',''));
param_array(d,e) = n_params;
end
end
%% plot different scales of fractional binding (fig. 2)
vsa = 'FHRR';
dim = 2048;
VSA = vsa_env('vsa',vsa,'dim',dim);
init_vector = VSA.add_vector();
values = -1.5:0.01:1.5;
line_type = {':';'-';'--';'-.'};
sim_values = zeros([numel(scale) numel(values)]);
leg = {};
for s=1:numel(scale)
encoded_values = VSA.frac_binding(init_vector,values * scale(s));
ref_value = VSA.frac_binding(init_vector,0);
sim_values(s,:) = VSA.sim(ref_value, encoded_values);
plot(values,sim_values(s,:),line_type{s})
hold on
leg{end+1} = ['scaling = ' num2str(scale(s))];
end
grid on
title('Similarity of encoded scalar value 0 to neighboring values')
xlabel('scalar value')
ylabel('similarity to encoded value 0')
legend(leg)
set(gcf,'color','w')
saveas(gcf,'images/similarity_plot_frac_binding.png')
export_fig('images/similarity_plot_frac_binding.pdf','-dpdf')
%% plot data efficiency (fig. 6)
figure()
n_dim = 2048;
scale = 10;
encoding_dim = 40;
dataset = 'full';
training_volume = {'0.2'; '0.4'; '0.6'; '0.8'; '1.0'};
f1_array_orig = [];
f1_array_VSA = [];
% original network
for t=1:numel(training_volume)
% load file
load(['results/' dataset '/results_origNet_' training_volume{t} '.mat'])
f1_array_orig(end+1) = report.accuracy;
end
% VSA network
for t=1:numel(training_volume)
% load file
load(['results/' dataset '/results_HDC_' num2str(n_dim) '_' num2str(scale) '_' num2str(encoding_dim) '_' training_volume{t} '.mat'])
f1_array_VSA(end+1) = report.accuracy;
end
plot(str2num(cell2mat(training_volume)), f1_array_orig,'--','LineWidth',2)
hold on
plot(str2num(cell2mat(training_volume)), f1_array_VSA,'-.','LineWidth',2)
grid on
xlabel('training volume')
ylabel('F_1 Score')
title('Data efficiency')
set(gcf,'color','w')
set(gcf,'Position',[100 100 500 200])
legend({'LSTM-ANN'; 'HDC-ANN'},'Location','SouthEast')
saveas(gcf,'images/data_efficiency.png')
export_fig('images/data_efficiency.pdf','-dpdf')