-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplotter.m
More file actions
194 lines (190 loc) · 5.85 KB
/
plotter.m
File metadata and controls
194 lines (190 loc) · 5.85 KB
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
clc
clear all
close all
%%
% Seting the example-specific hyper-parameters
num_points = 20; % number of points for plotting
beta = .01; % confidence = 1-beta
eps =.01; % this constant affects the level of conservativeness
eta_x = .2; % state discretization size
eta_u = .3; % input discretization size
w_bar = .01; % upper-bound on the value of disturbance vector
dim_x = 3; % dimension of the state space
dim_u = 2; % dimension of the state space
L_d = 1.46; % upper-bound over the Lipschitz constant
is_adaptive = 0; % set this binary variable to True for using the adaptive GB
dist_presence = 1; % set this binary variable to True for sampling the disturbance space
if dist_presence
n = dim_x*2; % sample both the state and disturbance spaces
else
n = dim_x; % only sample the state space
end
if is_adaptive
n = n*2; % sample both the state and disturbance spaces TWICE
end
N_x = ceil(10/eta_x)*ceil(10/eta_x)*ceil((2*pi+.8)/eta_x); % number of discrete states (for examples other than unicycle pls change it)
N_u = ceil(1/eta_u)*ceil(1/eta_u); % number of discrete states (for examples other than unicycle pls change it)
conf_per_cell = beta; %/N_x*N_u; % modify the overall confidence (1-conf_per_cell) based on number of cells
%%
% plot effect of changing epsilon on sample complexity
figure()
N=zeros(num_points,1);
epss =zeros(num_points,1);
for i=1:1:num_points
epss(i)= eps*i;
N(i) = n-1; % initializing sample numbers
lhs =lhs_computer(N(i),n,epss(i));
while lhs>conf_per_cell
N(i) =N(i)+1;
lhs =lhs_computer(N(i),n,epss(i));
end
if i ==1
N_max=N(i);
else
N_max=max(N(i),N_max);
end
end
plot(epss, N,'-*','color', 'r', 'LineWidth',2)
hold on
N1=max(N);
N=zeros(num_points,1);
epss =zeros(num_points,1);
for i=1:1:num_points
epss(i)= eps*i;
N(i) = dim_x-1; % initializing sample numbers
lhs =lhs_computer(N(i),dim_x,epss(i));
while lhs>conf_per_cell
N(i) =N(i)+1;
lhs =lhs_computer(N(i),dim_x,epss(i));
end
if i ==1
N_max=N(i);
else
N_max=max(N(i),N_max);
end
end
plot(epss, N,'-*','color', 'b', 'LineWidth',2)
N2=max(N);
legend('With disturbance','Without disturbance', 'interpreter','latex', 'FontSize', 20)
%legend('Variations of $N$ with $\varepsilon$ when $W\neq\{0\}$','Sample number in the absence of disturbance', 'interpreter','latex', 'FontSize', 15)
xlabel('$\varepsilon$','interpreter','latex', 'FontSize', 20)
ylabel('$N$','interpreter','latex', 'FontSize', 20)
xlim([eps,1.01*eps*num_points])
ylim([0,1.01*max(N1,N2)])
%title('Effect of Variations in required ')
grid
set(gca,'FontSize',20)
axis tight
%%
% plot effect of changing beta on sample complexity
N=zeros(num_points,1);
conf_per_celll =zeros(num_points,1);
figure()
for i=1:1:num_points
conf_per_celll(i) = beta*i;
N(i) = n-1; % initializing sample numbers
lhs =lhs_computer(N(i),n,eps);
while lhs>conf_per_celll(i)
N(i) =N(i)+1;
lhs =lhs_computer(N(i),n,eps);
end
if i ==1
N_max=N(i);
else
N_max=max(N(i),N_max);
end
end
plot(conf_per_celll, N,'-*','color', 'r', 'LineWidth',2)
hold on
N1=max(N);
for i=1:1:num_points
conf_per_celll(i) = beta*i;
N(i) = dim_x-1; % initializing sample numbers
lhs =lhs_computer(N(i),dim_x,eps);
while lhs>conf_per_celll(i)
N(i) =N(i)+1;
lhs =lhs_computer(N(i),dim_x,eps);
end
if i ==1
N_max=N(i);
else
N_max=max(N(i),N_max);
end
end
plot(conf_per_celll, N,'-*','color', 'b', 'LineWidth',2)
N2=max(N);
legend('With disturbance','Without disturbance', 'FontSize', 20)
xlabel('$\beta$','interpreter','latex', 'FontSize', 20)
ylabel('$N$','interpreter','latex', 'FontSize', 20)
xlim([beta,1.01*beta*num_points])
ylim([0,1.01*max(N1,N2)])
grid
set(gca,'FontSize',20)
axis tight
%%
% plot effect of changing epsilon on bias value
bias=zeros(num_points,1);
epss =zeros(num_points,1);
figure()
for i=1:1:num_points
epss(i)= eps*i;
%L_d = max(eta_x/2,1); % the value of Lipschitz constant in theta
bias(i) = L_d*(((eta_x/2)^dim_x)*((2*w_bar)^dim_x)*epss(i))^(1/n); % the bias
end
plot(epss, bias, '-*', 'color', 'r', 'LineWidth',2)
hold on
b1=max(bias);
for i=1:1:num_points
epss(i)= eps*i;
%L_d = max(eta_x/2,1); % the value of Lipschitz constant in theta
bias(i) = L_d*(((eta_x/2)^dim_x)*epss(i))^(1/dim_x); % the bias
end
plot(epss, bias, '-*', 'color', 'b', 'LineWidth',2)
b2=max(bias);
legend('With disturbance','Without disturbance', 'FontSize', 20)
xlabel('$\varepsilon$','interpreter','latex', 'FontSize', 20)
ylabel('$\gamma$','interpreter','latex','FontSize', 20)
xlim([eps,1.01*eps*num_points])
ylim([0,1.01*max(b1,b2)])
grid
set(gca,'FontSize',20)
axis tight
%%
% plot effect of changing eta_x on bias value...ETA_X HAS NO EFFECT ON THE
% BIAS VALUE
% bias=zeros(num_points,1);
% eta_xx =zeros(num_points,1);
% figure()
% for i=1:1:num_points
% eta_xx(i)= eta_x*i;
% L_d = max(eta_xx(i)/2,1); % the value of Lipschitz constant in theta
% bias(i) = L_d*((((eta_xx(i)/2)^dim_x)*((2*w_bar)^dim_x)*eps)^(1/n)); % the bias
% end
% plot(eta_xx, bias, '-*', 'color', 'r', 'LineWidth',2)
% hold on
% b1 = max(bias);
% for i=1:1:num_points
% eta_xx(i)= eta_x*i;
% L_d = max(eta_xx(i)/2,1); % the value of Lipschitz constant in theta
% bias(i) = L_d*(((eta_xx(i)/2)^dim_x)^(1/dim_x)); % the bias
% end
% plot(eta_xx, bias, '-*', 'color', 'b', 'LineWidth',2)
% hold on
% b2 = max(bias);
% legend('With disturbance','Without disturbance', 'FontSize', 20)
% xlabel('$\eta_x$','interpreter','latex', 'FontSize', 20)
% ylabel('$\gamma$','interpreter','latex','FontSize', 20)
% xlim([eta_x,1.01*eta_x*num_points])
% ylim([0,1.01*max(b1,b2)])
% grid
%
% set(gca,'FontSize',20)
% axis tight
%%
% defining the necessary functions
function lhs = lhs_computer(N,n,eps)
lhs = 0;
for i=0:1:n-1
lhs = lhs+nchoosek(N,i)*eps^i*(1-eps)^(N-i);
end
end