-
Notifications
You must be signed in to change notification settings - Fork 1
/
Uniform_PDFs.m
138 lines (110 loc) · 3.67 KB
/
Uniform_PDFs.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
%% Symbolic calculation and numeric simulation for uniform distriutions with no pruning
clear all
close all
%% Parameters
N = 10000000; %number of pair connections
%% Plotting parameters
numericFontSize = 25;
axesFontSize = 30;
lineThickness = 2;
markLine = 1;
markSize = 12;
n_bins = 200; %bins for the histogram
%% Parameters and variables for symbolic calculation
syms u;
%% Simulation samples
x = rand(N,1);
y = rand(N,1);
%% Single distributions
sum_var = x + y;
abs_diff_var = abs(x-y);
%% Plots
% Initial Distribution
bin_dim = 1 / n_bins;
[counts,bin_location] = hist(x, n_bins); %Note: bin_location==sample
figure(1);
bar(bin_location, counts/(sum(bin_dim*counts)));
hold on
x_ax = 0:0.001:1;
y_ax = ones(1, size(x_ax,2));
h = plot(x_ax,y_ax);
set(h, 'color', 'k', 'LineWidth', lineThickness);
set(gca,'fontsize',numericFontSize);
xlabel('w','fontsize',axesFontSize);
ylabel('f(w)','fontsize',axesFontSize);
axis([-0.2 1.2 0 1.2]);
colormap(gray);
caxis([-1 1.4]);
title('');
print(gcf, '-depsc2', '-loose', 'Uniform_initialPDF_noprune'); % Print the figure in eps (first option) and uncropped (second object)
% Sum
bin_dim = 2 / n_bins;
[counts,bin_location] = hist(sum_var, n_bins); %Note: bin_location==sample
figure(2);
bar(bin_location, counts/(sum(bin_dim*counts)));
hold on
h1 = ezplot(u,[0,1]);
set(h1,'color', 'k', 'LineWidth', lineThickness);
hold on
h2 = ezplot(-u+2,[1,2]);
set(h2,'color','k', 'LineWidth', lineThickness);
set(gca,'fontsize',numericFontSize);
xlabel('Z_2','fontsize',axesFontSize);
ylabel('f(Z_2)','fontsize',axesFontSize);
axis([-0.2 2.2 0 1.5]);
colormap(gray);
caxis([-1 1.4]);
title('');
print(gcf, '-depsc2', '-loose', 'Uniform_sumPDF_noprune'); % Print the figure in eps (first option) and uncropped (second object)
% Difference
bin_dim = 2 / n_bins;
[counts,bin_location] = hist(x-y, n_bins); %Note: bin_location==sample
figure(3);
bar(bin_location, counts/(sum(bin_dim*counts)));
hold on
h1 = ezplot(u+1,[-1,0]);
set(h1,'color', 'k', 'LineWidth', lineThickness);
hold on
h2 = ezplot(-u+1,[0,1]);
set(h2,'color', 'k', 'LineWidth', lineThickness);
set(gca,'fontsize',numericFontSize);
xlabel('diff','fontsize',axesFontSize);
ylabel('f(diff)','fontsize',axesFontSize);
axis([-1.2 1.2 0 1.5]);
colormap(gray);
caxis([-1 1.4]);
title('');
% Absolute difference
bin_dim = 1 / n_bins;
[counts,bin_location] = hist(abs_diff_var, n_bins); %Note: bin_location==sample
figure(4);
bar(bin_location, counts/(sum(bin_dim*counts)));
hold on
h = ezplot(-2*u+2,[0,1]);
set(h,'color','k', 'LineWidth', lineThickness);
set(gca,'fontsize',numericFontSize);
xlabel('Z_1','fontsize',axesFontSize);
ylabel('f(Z_1)','fontsize',axesFontSize);
axis([-0.2 1.2 0 2.5]);
colormap(gray);
caxis([-1 1.4]);
title('');
print(gcf, '-depsc2', '-loose', 'Uniform_absdiffPDF_noprune'); % Print the figure in eps (first option) and uncropped (second object)
% Joint Distribution
bin_dim_x = 1 / n_bins;
bin_dim_y = 2 / n_bins;
[bidim_counts,Cell_location] = hist3([sum_var, abs_diff_var], [n_bins,n_bins]);
figure(5);
mesh(Cell_location{1},Cell_location{2},bidim_counts'/(sum(sum(bin_dim_x*bin_dim_y*bidim_counts)))) %simulation
%hold on
%surf(Cell_location{1},Cell_location{2}, ones(size(Cell_location{1},2),size(Cell_location{2},2))')
set(gca,'fontsize',numericFontSize);
axis on
% xlabel('Z_2','fontsize',axesFontSize);
% ylabel('Z_1','fontsize',axesFontSize);
% zlabel('f(Z_1,Z_2)','fontsize',axesFontSize);
colormap(gray);
caxis([-1.5 4]);
view([145 45]);
title('');
print(gcf, '-depsc2', '-loose', 'Uniform_jointPDF_noprune'); % Print the figure in eps (first option) and uncropped (second object)