-
Notifications
You must be signed in to change notification settings - Fork 1
/
PlotEntropies.m
136 lines (103 loc) · 3.18 KB
/
PlotEntropies.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
% Plot entropy simulations
%
% mikael.mieskolainen@cern.ch, 2018
clear; close all;
addpath src
STEPS = 250; % Not too high, otherwise pdf turned to .png
mu_values = logspace(-1.5,log10(200),STEPS);
alpha_values = [0.01 0.1 0.2 1.0];
REALIZATIONS = 20; % Number of MC realizations
N_values = [2,4,8];
% mean and variance
f1 = {};
f2 = {};
for i = 1:length(alpha_values)
f1{end+1} = figure;
f2{end+1} = figure;
end
tic;
% Loop over dimensionality
for N = N_values
% Loop over dirichtlet distribution concentration parameters
for k = 1:length(alpha_values)
% Save entropy trajectories here
entropies = zeros(REALIZATIONS, STEPS);
% Loop over realizations
for a = 1:REALIZATIONS
% Dirichlet distribution input
alpha = ones(1,2^N-1) * alpha_values(k);
input = dirnd(alpha,1)';
% Create Möbius matrices
LAMBDA = amat(N);
LAMBDAINV = inv(LAMBDA);
y_values = zeros(length(input),STEPS);
p_values = zeros(length(input),STEPS);
entropy = zeros(1,STEPS);
% Loop over mu-values
for i = 1:length(mu_values)
mu = mu_values(i);
% Forward
%
y = LAMBDAINV*((exp(-mu*LAMBDA*input) - 1)/(exp(-mu)-1));
y_values(:,i) = y;
%}
% Inverse
%{
p = LAMBDAINV*(log((exp(-mu) - 1)*LAMBDA*input + 1)) / (-mu);
p_values(:,i) = p;
%}
entropies(a, i) = shannonentropy(y); % Shannon entropy in bits
end
end % Realizations loop
%
f3 = figure;
figure(f3);
plot(mu_values, entropies');
xlabel('$\mu$','interpreter','latex');
ylabel('$S(\mathbf{y})$','interpreter','latex');
title(sprintf('$N=%d, \\alpha = %0.2f$', N, alpha_values(k)), 'interpreter','latex');
set(gca,'xscale','log');
axis([min(mu_values) max(mu_values) 0 N]);
axis square;
filename = sprintf('../figs/DIRrealizationsN%dk%d.pdf', N, k);
print(f3, filename, '-dpdf');
system(sprintf('pdfcrop --margins 10 %s %s', filename, filename));
close(f3);
%}
% Calculate point statistics
figure(f1{k});
plot(mu_values, mean(entropies)); hold on;
set(gca,'xscale','log');
xlabel('$\mu$','interpreter','latex');
ylabel('$\langle S(\mathbf{y})\rangle$','interpreter','latex');
title(sprintf('$\\alpha = %0.2f$', alpha_values(k)), 'interpreter','latex');
axis square;
axis([min(mu_values) max(mu_values) 0 max(N_values)]);
figure(f2{k});
plot(mu_values, var(entropies)); hold on;
set(gca,'xscale','log');
xlabel('$\mu$','interpreter','latex');
ylabel('$\langle S(\mathbf{y})^2 \rangle - \langle S(\mathbf{y}) \rangle^2$','interpreter','latex');
title(sprintf('$\\alpha = %0.2f$', alpha_values(k)), 'interpreter','latex');
axis square;
axis([min(mu_values) max(mu_values) 0 inf]);
end % Alpha-values loop
end % N-loop
toc;
%% Make legends
legs = {};
for i = 1:length(N_values)
legs{i} = sprintf('$N = %d$', N_values(i));
end
for k = 1:length(alpha_values)
figure(f1{k});
legend(legs,'interpreter','latex'); legend('boxoff');
filename = sprintf('../figs/DIRmean%d.pdf', k);
print(f1{k}, filename, '-dpdf');
system(sprintf('pdfcrop --margins 10 %s %s', filename, filename));
figure(f2{k});
legend(legs,'interpreter','latex'); legend('boxoff');
filename = sprintf('../figs/DIRvar%d.pdf', k);
print(f1{k}, filename, '-dpdf');
system(sprintf('pdfcrop --margins 10 %s %s', filename, filename));
end