-
Notifications
You must be signed in to change notification settings - Fork 0
/
greedy_cont.m
149 lines (147 loc) · 5.97 KB
/
greedy_cont.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
143
144
145
146
147
148
149
function [pick] = greedy_cont(NC, NB, Rcc,hnum,n_cont,n_neck, mode)
% greedy picking algorithm for picking a required number of points from a
% lagre set of points:
% Input:
% NB: binary dimension, NC: continuous dimension, Rcc: large matrix
% contains coordinates of points, mode = 0: using the l_2 norm to compute
% the energy criterion, mode = 1: d_mixed = l_2 + d_neck, else dmix=l2+dH
% hnum (= nDOE): number of point requiring (e.g., NB+NC+1 points)
% Return: a matrix contains the set of picking points (hnum*(NB+NC))
% hnum = NB+NC+1;
NC_tune = 50;
NB_tune = 2;
[n_points, n_dim] = size(Rcc);
mdsdim = n_dim - NC;
%% Energycrit
ret = zeros(n_points,1);
if mode == 0% (energycrit) energy is computed according to Eucleadian distance only
for i = 1:n_points
runcrit = 0;
for j = 1:n_points
runcrittmp = 0;
for k = 1:n_dim
runcrittmp = runcrittmp + (abs(Rcc(i,k) - Rcc(j,k)))^2;
end
runcrit = runcrit + (sqrt(runcrittmp));
end
ret(i) = runcrit/n_points;
end
%% Herdingeff
id = zeros(hnum,1);
currentsum = zeros(n_points,1);
pick = zeros(hnum, n_dim);
[~,id(1)] = min(ret);
pick(1,:) = Rcc(id(1),:);
for i = 2:hnum
for j = 1:n_points
runcrit = 0;
for k = 1:n_dim
runcrit = runcrit + (abs(Rcc(j,k) - pick(i-1,k)))^2;
end
currentsum(j) = currentsum(j) + (sqrt(runcrit) );
end
crit = ret - (currentsum/(i-1));
[~, id(i)] = min((crit));
pick(i,:) = Rcc(id(i),:);
end
elseif mode == 1 % mode = 1: mixed distance: d = d_cont + d_neck
%% energycrit
for i = 1:n_points
runcrit = 0;
for j = 1:n_points
runcrittmp = 0;
for k = NB+1:n_dim
runcrittmp = runcrittmp + (abs(Rcc(i,k) - Rcc(j,k)))^2;
end
runcrit = runcrit + (exp(-NC_tune*runcrittmp)*exp(-sqrt(exp(-NB_tune*(d_neck(Rcc(i,1:NB),Rcc(i,1:NB))))+exp(-NB_tune*(d_neck(Rcc(j,1:NB),Rcc(j,1:NB))))-2*exp(-NB_tune*(d_neck(Rcc(i,1:NB),Rcc(j,1:NB))))))); %(exp(-NB_tune*d_neck(Rcc(i,1:NB), Rcc(j,1:NB)))));
% runcrit = runcrit + (1/2*(sqrt(norm(Rcc(i,NB+1:n_dim),2))+sqrt(norm(Rcc(i,NB+1:n_dim),2))-sqrt(runcrittmp))*(exp(-1.5*d_neck(Rcc(i,1:NB), Rcc(j,1:NB)))));
% runcrit = runcrit + (sqrt(runcrittmp)+sqrt(exp(-NB*(d_neck(Rcc(i,1:NB),Rcc(i,1:NB))))+exp(-NB*(d_neck(Rcc(j,1:NB),Rcc(j,1:NB))))-2*exp(-NB*(d_neck(Rcc(i,1:NB),Rcc(j,1:NB))))));
end
ret(i) = runcrit/n_points;
end
%% Herdingeff
id = zeros(hnum,1);
currentsum = zeros(n_points,1);
pick = zeros(hnum, n_dim);
[~,id(1)] = min(ret);
pick(1,:) = Rcc(id(1),:);
neck_pen = zeros(n_cont*n_neck,1);
for i = 2:hnum
for j = 1:n_points
runcrit = 0;
for k = NB+1:n_dim
runcrit = runcrit + (abs(Rcc(j,k) - pick(i-1,k)))^2;
end
currentsum(j) = currentsum(j) + (exp(-NC_tune*runcrit)*exp(-(sqrt(exp(-NB_tune*(d_neck(Rcc(j,1:NB),Rcc(j,1:NB))))+exp(-NB_tune*(d_neck(pick(i-1,1:NB),pick(i-1,1:NB))))-2*exp(-NB_tune*(d_neck(Rcc(j,1:NB),pick(i-1,1:NB))))))));%(exp(-NB_tune*d_neck(Rcc(j,1:NB), pick(i-1,1:NB)))));
% currentsum(j) = currentsum(j) + (1/2*(sqrt(norm(Rcc(i,NB+1:n_dim),2))+sqrt(norm(pick(i-1,NB+1:n_dim),2))-sqrt(runcrit))*(exp(-1.5*d_neck(Rcc(j,1:NB), pick(i-1,1:NB)))));
% currentsum(j) = currentsum(j) + (sqrt(runcrit)+sqrt(exp(-NB*(d_neck(Rcc(j,1:NB),Rcc(j,1:NB))))+exp(-NB*(d_neck(pick(i-1,1:NB),pick(i-1,1:NB))))-2*exp(-NB*(d_neck(Rcc(j,1:NB),pick(i-1,1:NB))))));
end
crit = 2*ret - (currentsum/(i-1));
[~, id(i)] = max((crit));
pick(i,:) = Rcc(id(i),:);
end
else % For mixed dneck (no pen) (commented the part of hamming distance and L2 norm)
for i = 1:n_points
runcrit = 0;
for j = 1:n_points
runcrittmp = 0;
for k = NB+1:n_dim
runcrittmp = runcrittmp + (abs(Rcc(i,k) - Rcc(j,k)))^2;
end
runcrit = runcrit + (sqrt(runcrittmp)+d_neck(Rcc(i,1:NB), Rcc(j,1:NB)));
end
ret(i) = runcrit/n_points;
end
%% Herdingeff
id = zeros(hnum,1);
val = id;
currentsum = zeros(n_points,1);
pick = zeros(hnum, n_dim);
[~,id(1)] = min(ret);
pick(1,:) = Rcc(id(1),:);
neck_pen = zeros(n_cont*n_neck,1);
for i = 2:hnum
for j = 1:n_points
runcrit = 0;
for k = NB+1:n_dim
runcrit = runcrit + (abs(Rcc(j,k) - pick(i-1,k)))^2;
end
currentsum(j) = currentsum(j) + (sqrt(runcrit)+ d_neck(Rcc(j,1:NB), pick(i-1,1:NB)));
end
crit = ret - (currentsum/(i-1));
[~, id(i)] = min((crit));
pick(i,:) = Rcc(id(i),:);
end
%% Energycrit
% for i = 1:n_points
% runcrit = 0;
% for j = 1:n_points
% runcrittmp = 0;
% for k = NB+1:n_dim
% runcrittmp = runcrittmp + (abs(Rcc(i,k) - Rcc(j,k)))^2;
% end
% runcrit = runcrit + sqrt(runcrittmp)+sum(abs((Rcc(i,1:NB)- Rcc(j,1:NB))));
% end
% ret(i) = runcrit/n_points;
% end
% %% Herdingeff
% id = zeros(hnum,1);
% currentsum = zeros(n_points,1);
% pick = zeros(hnum, n_dim);
% [~,id(1)] = min(ret);
% pick(1,:) = Rcc(id(1),:);
% for i = 2:hnum
% crit = zeros(n_points, 1);
% for j = 1:n_points
% runcrit = 0;
% for k = NB+1:n_dim
% runcrit = runcrit + (abs(Rcc(j,k) - pick(i-1,k)))^2;
% end
% currentsum(j) = currentsum(j) + sqrt(runcrit)+sum(abs((Rcc(i,1:NB)- Rcc(j,1:NB)))) ;
% end
% crit = ret - (currentsum/(i-1));
% [val(i), id(i)] = min(crit);
% pick(i,:) = Rcc(id(i),:);
% end
end
end