-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain_laba.asv
294 lines (252 loc) · 8.83 KB
/
Main_laba.asv
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
%-------------------Lab A -------------------------------------------%
% Author : Awabullah Syed
% Date : 21th May 2021
% Description : Explore the design space for the problem - revealing the
% relationships that exist between design variables and performance
% criteria and communicating these relathiships clearly through
% visualisation methods
clc; clear;
ts = 1;
z = tf('z',ts);
% Gains (compare with stable and unstable system - if deemed necessary)
k = 2; %No. of design variables
n = 100; % No. of desired points
Kp = [0.1];
Ki = [0.2];
KpMin = 0.01; KpMax = 0.9; %0.9
KiMin = 0.02; KiMax = 0.4; % 0.4
K = [Kp Ki];
for i = 1:100
Z(i,:) = evaluateControlSystem(K);
end
num = ((1-exp(-1))*(Kp + Ki)*z - Kp);
den = z^2*(z-exp(-1))*(z-1);
sys = num / den;
% Sobol Sampling
p = sobolset(k);
p.Skip = 1; %Skip first row
X_sobol = net(p,100); % Sobol Sampling
design_space = fullfactorial ([10 10],1); %Fulll Factorial [2 50]
design_space1 = rlh(n,k); % Latin
pert_fac = perturb(design_space,25); % Pertubed full fac by 25 numbers
% best_latin = bestlh(n,k, 100, 250); [save Morrison_Sampling.mat]
load Morrison_Sampling.mat % To avoid running everytime
% design_space2 = screeningplan(2,[10 10],1,1);
% screeningplot(space2,sys,[0m.1 0.2 ; 0.8 0.5],
space(:,1) = rescale(design_space(:,1),KpMin,KpMax); % Full Factorial
space(:,2) = rescale(design_space(:,2),KiMin,KiMax);
space1(:,1) = rescale(design_space1(:,1),KpMin,KpMax); % Latin
space1(:,2) = rescale(design_space1(:,2),KiMin,KiMax);
space2(:,1) = rescale(X_sobol(:,1),KpMin,KpMax);
space2(:,2) = rescale(X_sobol(:,2),KiMin,KiMax); % Sobol
space3(:,1) = rescale(pert_fac(:,1),KpMin,KpMax);
space3(:,2) = rescale(pert_fac(:,2),KiMin,KiMax);
space4(:,1) = rescale(best_latin(:,1),KpMin,KpMax);
space4(:,2) = rescale(best_latin(:,2),KiMin,KiMax);
phiq_fac = mmphi(space,1,2); % Full factorial [Euclidean Distance]
phiq_latin = mmphi(space1,1,2); % Latin Hypercube design
phiq_sobol = mmphi(space2,1,2); % Sobol Sampling
phiq_pert = mmphi(space3,1,2); % Full Fac Perturbed
phiq_opt = mmphi(space4,1,2); % Best Optimal latin
disp(phiq_fac)
disp(phiq_latin)
disp(phiq_sobol)
disp(phiq_pert)
disp(phiq_opt);
%%
figure (1) % Scatter Plot with Latin Hypercube sampling plan
Z1 = evaluateControlSystem(space1);
gplotmatrix(Z1)
title('Scatter Plot: Latin Hypercube Sampling Plan')
figure(2) % Scatter Plot with Full Factorial sampling plan
Z2 = evaluateControlSystem(space);
gplotmatrix(Z2)
title('Scatter Plot: Full Factorial Sampling Plan')
figure (3) % Scatter Plot with Sobol Sampling Plan
Z3 = evaluateControlSystem(space2);
gplotmatrix(Z3)
title('Scatter Plot: Sobol Sampling Plan')
figure (31) % Morrison Hypercube
Z4 = evaluateControlSystem(space2);
gplotmatrix(Z4)
title('Scatter Plot: Morris Latin Hypercube')
figure(4) % with Initial system (Kp & Ki)
for i = 1:9
gplotmatrix(Z,[],Z(:,i))
end
title('Initial System [Without Sampling Plan]')
figure(5)
plot(1:100,clusterdata(Z4,1),'o') % Latin
hold on
plot(1:100,clusterdata(Z2,1),'o') % full factorial
hold on
plot(1:100,clusterdata(Z3,1),'o') % sobol
legend('Latin Hyper','Full !','Sobol')
figure (6) % Star Plot with different sampling plan
glyphplot(Z4,'glyph','face','features',[1:9]);
title('Chernoff Face Plot of 100 Candidate Design')
print('-clipboard','-dmeta')
% subplot(1,3,1)
% glyphplot(Z4,'glyph','face','features',[1:9],'standardize','PCA')
% glyphplot(Z1)
% title('Star Plot: Latin Hypercube Sampling Plan')
% subplot(1,3,2)
% glyphplot(Z2)
% title('Star Plot: Full Factorial Sampling Plan')
% subplot(1,3,3)
% glyphplot(Z3)
% title('Star Plot: Sobol Sampling Plan')
figure (7) % x-axis = performance critera , y-axis = Kp(top) & Ki(bottom)
group = []; % Sobol Scatter Sobol Scatter
for i = 1:100
group(i,:) = [1, 2];
end
gplotmatrix(Z3,space2,group)
title('Scatter Plot with Sobol Sampling Plan')
figure (8) % Full Factorial Sampling Plan Scatter
group = [];
for i = 1:100
group(i,:) = [1, 2];
end
gplotmatrix(Z2,space,group)
title('Scatter Plot with Full Factorial Sampling Plan')
figure (9) % Latin Hyper Cube
group = [];
for i = 1:100
group(i,:) = [1, 2];
end
gplotmatrix(Z1,space1,group)
title('Scatter Plot with Latin Hypercube Sampling Plan')
%--------------------Space Filling Plots--------------------------------%
% Visually Compare Phi metric value
figure (10)
plot(space(:,1),space(:,2),'o')
title('Space Filling of Full Factorial')
xlabel('Design Variable, x_1 (K_p)')
ylabel('Deisgn Variable, x_2 (K_i)')
figure (21)
plot(space3(:,1),space3(:,2),'o')
title('Space Filling of Perturbed Full Factorial')
xlabel('Design Variable, x_1 (K_p)')
ylabel('Deisgn Variable, x_2 (K_i)')
figure(22)
plot(space1(:,1),space1(:,2),'o')
title('Space Filling of Random Latin Hypercube')
xlabel('Design Variable, x_1 (K_p)')
ylabel('Deisgn Variable, x_2 (K_i)')
figure (23) % Optimal Latin Hyper
plot(space4(:,1),space4(:,2),'o')
title('Space Filling of Morris-Mitchell optimum plan q =50')
xlabel('Design Variable, x_1 (K_p)')
ylabel('Deisgn Variable, x_2 (K_i)')
figure (12)
plot(space2(:,1),space2(:,2),'o')
title('Space Filling of Sobol Plan')
xlabel('Design Variable, x_1 (K_p)')
ylabel('Deisgn Variable, x_2 (K_i)')
%-----------------------------Parallel Coordinates---------------------%
% Select the optimal sampling plan & then only used that to plot the
% parallel coordinates plot
figure (13)
parallelcoords(Z4)
xlabel ('Performance Criteria')
title('Correlation between Designs and Performance Criteria')
Relationship between Design Variables and Performance Criteria')
save Sobol_Space_Sampling.mat space2 % To be used in lab B
save Latin_Space_Sampling.mat space1 % To be used in Lab B
save Full_Space_Sampling.mat space % % To be used in Lab B
save Morrison_Latin_Space_Sampling.mat space4
%%
% Previous
%---------------------Sampling Plan------------------------------%
% Full Factorial Sampling Plan
q = [2,50];
edge = 2;
fac_sampl = fullfactorial(q,edge); % full factorial sampling plan
% Latin Hypercube Design Sampling Plan
latin_hyper = rlh(n,k,edge); % Latin hypercube design
%---------------------------------Phi Metric-----------------------%
phiq_fac = mmphi(fac_sampl,1,2); % Full factorial [Euclidean Distance]
phiq_latin = mmphi(latin_hyper,1,2); % Latin Hypercube design
phiq_sobol = mmphi(X_sobol,1,2); % Sobol Sampling
disp(phiq_fac)
disp(phiq_latin)
disp(phiq_sobol)
%%
%------------------------------Plot--------------------------------------%
figure (1) % Scatter Plot with Latin Hypercube sampling plan
Z1 = evaluateControlSystem(latin_hyper);
gplotmatrix(Z1)
title('Scatter Plot: Latin Hypercube Sampling Plan')
figure(2) % Scatter Plot with Full Factorial sampling plan
Z2 = evaluateControlSystem(fac_sampl);
gplotmatrix(Z2)
title('Scatter Plot: Full Factorial Sampling Plan')
figure (3) % Scatter Plot with Sobol Sampling Plan
Z3 = evaluateControlSystem(X_sobol);
gplotmatrix(Z3)
title('Scatter Plot: Sobol Sampling Plan')
figure(4) % with Initial system (Kp & Ki)
for i = 1:9
gplotmatrix(Z,[],Z(:,i))
end
title('Initial System [Without Sampling Plan]')
figure(5)
plot(1:100,clusterdata(Z1,1),'o') % Latin
hold on
plot(1:100,clusterdata(Z2,1),'o') % full factorial
hold on
plot(1:100,clusterdata(Z3,1),'o') % sobol
legend('Latin Hyper','Full !','Sobol')
figure (6) % Star Plot with different sampling plan
subplot(1,3,1)
glyphplot(Z1)
title('Star Plot: Latin Hypercube Sampling Plan')
subplot(1,3,2)
glyphplot(Z2)
title('Star Plot: Full Factorial Sampling Plan')
subplot(1,3,3)
glyphplot(Z3)
title('Star Plot: Sobol Sampling Plan')
figure (7) % x-axis = performance critera , y-axis = Kp(top) & Ki(bottom)
group = []; % Sobol Scatter Sobol Scatter
for i = 1:100
group(i,:) = [1, 2];
end
gplotmatrix(Z3,X_sobol,group)
title('Scatter Plot with Sobol Sampling Plan')
figure (8) % Full Factorial Sampling Plan Scatter
group = [];
for i = 1:100
group(i,:) = [1, 2];
end
gplotmatrix(Z2,fac_sampl,group)
title('Scatter Plot with Full Factorial Sampling Plan')
figure (9) % Latin Hyper Cube
group = [];
for i = 1:100
group(i,:) = [1, 2];
end
gplotmatrix(Z1,latin_hyper,group)
title('Scatter Plot with Latin Hypercube Sampling Plan')
%--------------------Space Filling Plots--------------------------------%
% Visually Compare Phi metric value
figure (10)
plot(fac_sampl(:,1),fac_sampl(:,2),'o')
title('Space Filling of Full Factorial')
figure(11)
plot(latin_hyper(:,1),latin_hyper(:,2),'o')
title('Space Filling of Latin Hypercube')
figure (12)
plot(X_sobol(:,1),X_sobol(:,2),'o')
title('Space Filling of Sobol Plan')
%-----------------------------Parallel Coordinates---------------------%
% Select the optimal sampling plan & then only used that to plot the
% parallel coordinates plot
figure (13)
parallelcoords(Z1)
xlabel ('Performance Criteria')
title('Latin Hypercube sampling')
save Sobol_Sampling.mat X_sobol % To be used in lab B
save Latin_Sampling.mat latin_hyper % To be used in Lab B
save Full_Sampling.mat fac_sampl % % To be used in Lab B