-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathKMS_36_drawpoints.m
180 lines (158 loc) · 6 KB
/
KMS_36_drawpoints.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
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
function [theta_keep,EI_keep] = KMS_36_drawpoints(theta_hash,q,r_max,r_min,f_ineq,f_eq,f_ineq_keep,f_eq_keep,f_stdev_ineq,f_stdev_eq,dmodel,LB,UB,A,b,KMSoptions)
%% Code description
% This code draws initial points theta near theta_hash. It checks that at
% these draws satisfy EI>0.
%
% Method 1: Draw points from a box:
% A = { theta : p'theta >= theta_hash, d(theta,theta_hash) < r}
% for some tuning parameter r, where the distance metric in the infinity
% norm. We start with r = r_max and add, say, 2 points and check expected
% improvement of these two points. If EI > 0 we add them, otherwise
% we continue. We reduce the size of the box: r = r/2, and add more
% points. We continue until we have either, say, 10 points or r<r_min.
%
% Method 2: Draw points from a slice:
% Draw points from
% B = { theta : p'theta >= theta_hash, and |theta(component) -theta_hash(component)| < r}.
% Again, we continue drawing until we have a
% sufficient number of points satisfying EI>0.
%
% Method 3: Draw some points uniformly from the parameter space
%% Extract Parameters
dim_p = KMSoptions.dim_p;
component = KMSoptions.component;
unif_points = KMSoptions.unif_points;
EI_points = KMSoptions.EI_points;
EI_points_start = KMSoptions.EI_points_start;
parallel = KMSoptions.parallel;
sample_method = KMSoptions.sample_method;
options_linprog = KMSoptions.options_linprog;
% Check to make sure r_max is biggest
r_max = max(r_max, r_min);
% Initiate:
r = r_max;
theta_keep = [];
EI_keep = [];
LB2 = LB;
UB2 = UB;
A1 = A;
b1 = b;
A2 = A;
b2 = b;
%% Draw points
flag_while = true;
while flag_while
if sample_method == 0 % Latin hypercube sampling
% Method 1: Draw points from a box around theta#
if max(q) > 0
LB1 = LB;
UB1 = min(theta_hash + r,UB);
else
LB1 = max(theta_hash - r,LB);
UB1 = UB;
end
theta_draw1 = KMS_AUX2_drawpoints(EI_points_start,dim_p,LB1,UB1,KMSoptions);
% Method 2: Draw points from slice around theta#
if max(q) > 0
LB2 = LB;
UB2 = UB;
UB2(component) = min(theta_hash(component) + r,UB(component));
else
LB2 = LB;
LB2(component) = max(theta_hash(component) - r,LB(component));
UB2 = UB;
end
theta_draw2 = KMS_AUX2_drawpoints(EI_points_start,dim_p,LB2,UB2,KMSoptions);
elseif sample_method == 1 || sample_method == 2
% Hit-and-run sampling
% Method 1: Draw points from a box around theta#
A1 = A;
A1 = [A1; eye(dim_p); -eye(dim_p)];
b1 = b;
b1 = [b1 ; theta_hash+r; -theta_hash+r];
theta_draw1 = KMS_AUX2_drawpoints(EI_points_start,dim_p,LB,UB,KMSoptions,A1,b1,theta_hash);
% Method 2: Draw points from a slice around theta#
A2 = A;
A2 = [A2; q.'];
b2 = b;
b2 = [b2 ; q.'*theta_hash + r*abs(q.'*ones(dim_p,1))];
theta_draw2 = KMS_AUX2_drawpoints(EI_points_start,dim_p,LB,UB,KMSoptions,A2,b2,theta_hash);
elseif sample_method == 3
% Method 1: Draw points from a box around theta#
if max(q) > 0
LB1 = LB;
UB1 = min(theta_hash + r,UB);
else
LB1 = max(theta_hash - r,LB);
UB1 = UB;
end
% Bound transform if draw-and-discard method is used
[LB1,UB1] = bound_transform(LB1,UB1,KMSoptions);
theta_draw1 = KMS_AUX2_drawpoints(EI_points_start,dim_p,LB1,UB1,KMSoptions,A,b,theta_hash);
% Method 2: Draw points from slice around theta#
component = find(abs(q) ==1);
if max(q) > 0
LB2 = LB;
UB2 = UB;
UB2(component) = min(theta_hash(component) + r,UB(component));
else
LB2 = LB;
LB2(component) = max(theta_hash(component) - r,LB(component));
UB2 = UB;
end
% Bound transform if draw-and-discard method is used
[LB2,UB2] = bound_transform(LB2,UB2,KMSoptions);
theta_draw2 = KMS_AUX2_drawpoints(EI_points_start,dim_p,LB2,UB2,KMSoptions,A,b,theta_hash);
end
% Concatenate theta_draw1,draw2
theta_draw = [theta_draw1;theta_draw2];
size_draw = size(theta_draw,1);
% Find theta's that have positive EI
Eimprovement = @(theta)KMS_37_EI_value(theta,q,theta_hash,f_ineq,f_eq,f_ineq_keep,f_eq_keep,f_stdev_ineq,f_stdev_eq,dmodel,KMSoptions);
EI = zeros(size_draw,1);
if parallel
parfor jj = 1:size_draw
try
EI(jj,1) = -(max(Eimprovement( theta_draw(jj,:).')));
catch
EI(jj,1) = -1;
end
end
else
for jj = 1:size_draw
try
EI(jj,1) = -(max(Eimprovement( theta_draw(jj,:).')));
catch
EI(jj,1) = -1;
end
end
end
% Sort theta from best, and pick those that have positive EI.
[EI,I] = sort(EI,'descend');
theta_draw = theta_draw(I,:);
ind = find(EI>1e-10);
% Keep those with positive EI
theta_keep = [theta_keep ; theta_draw(ind,:)];
EI_keep = [EI_keep ;EI(ind)];
% Update r
r = r/2;
% If r < r_min or if we have sufficient number of points, break.
if r < r_min || size(theta_keep,1) > EI_points
flag_while = false;
end
end
% We also draw some points uniformly from
% {theta : p'theta >= p'theta#}
if sample_method == 0 % Latin hypercube sampling
theta_draw = KMS_AUX2_drawpoints(unif_points,dim_p,LB,UB,KMSoptions);
else
theta_draw = KMS_AUX2_drawpoints(unif_points,dim_p,LB,UB,KMSoptions,A,b,theta_hash);
end
% Set uniformly drawn EI to zero (this might not be true, but we do not
% require EI to be positive for these points so there is no need to
% calculate it.
EI = zeros(size(theta_draw,1),1);
% Concatenate
theta_keep = [theta_keep;theta_draw];
EI_keep =[EI_keep ; EI];
end