@@ -135,31 +135,32 @@ function (s::ZeroOrderGPSurrogate)(x)
135
135
return Interval .(y, y)
136
136
else
137
137
if eltype (s. y) <: Real
138
- _m, _v = mean_and_var (posterior (
139
- s. gps[1 ](s. X, s. noise), s. y,
140
- ), [x])
141
- m, v = _m[1 ], _v[1 ]
138
+ return _call_gp (s. gps[1 ], x, s. X, s. y, s. noise, s. std_multiple)
142
139
else
143
- ms_vs = map (1 : s. N) do i
144
- _gp = s. gps[i](s. X, s. noise)
145
- mean_and_var (posterior (_gp, getindex .(s. y, i)), [x])
146
- end
147
- m = reduce (vcat, getindex .(ms_vs, 1 ))
148
- v = reduce (vcat, getindex .(ms_vs, 2 ))
140
+ return map (i -> _call_gp (s. gps[i], x, s. X, getindex .(s. y, i), s. noise, s. std_multiple), 1 : length (s. gps))
149
141
end
150
- r = s. std_multiple .* sqrt .(v)
151
- return Interval .(m .- r, m .+ r)
152
142
end
153
143
end
154
144
145
+ function _call_gp (gp, x, X, y, noise, std_multiple)
146
+ _m, _v = mean_and_var (posterior (
147
+ gp (X, noise), y,
148
+ ), [x])
149
+ m, v = _m[1 ], _v[1 ]
150
+ r = std_multiple * sqrt (v)
151
+ return Interval (m - r, m + r)
152
+ end
153
+
155
154
function surrogate (f, x; kwargs... )
156
155
s = ZeroOrderGPSurrogate (f, x; mode = :exact , kwargs... )
157
156
s (x)
158
157
s. mode = :interval
159
158
return s
160
159
end
161
160
162
- _lower_f (s) = x -> getproperty .(s (x), :lo )
161
+ get_lo (x) = x. lo
162
+ get_lo (x:: AbstractVector ) = map (get_lo, x)
163
+ _lower_f (s) = get_lo ∘ s
163
164
_equality_f (s) = x -> begin
164
165
t = s (x)
165
166
return [getproperty .(t, :lo ); .- getproperty (t, :hi )]
@@ -187,14 +188,14 @@ function surrogate_model(vecmodel::VecModel; kwargs...)
187
188
! (:expensive in c. flags)
188
189
end
189
190
eq_constraints = VectorOfFunctions (cheap_eq_constraints)
190
- ineq_constraints1 = mapreduce (vcat, expensive_eq_constraints; init = Union{}[]) do c
191
+ ineq_constraints1 = Tuple ( mapreduce (vcat, expensive_eq_constraints; init = Union{}[]) do c
191
192
@assert c isa EqConstraint
192
193
s = surrogate (c, copy (x0); kwargs... )
193
194
push! (surrogates, s)
194
195
return IneqConstraint (
195
196
_equality_f (s), [zero .(c. rhs); zero .(c. rhs)], c. dim * 2 , c. flags,
196
197
)
197
- end
198
+ end )
198
199
ineq_constraints2 = map (vecmodel. ineq_constraints. fs) do c
199
200
@assert c isa IneqConstraint
200
201
if :expensive in c. flags
@@ -208,11 +209,11 @@ function surrogate_model(vecmodel::VecModel; kwargs...)
208
209
end
209
210
end
210
211
ineq_constraints = VectorOfFunctions (
211
- vcat (ineq_constraints1, ineq_constraints2),
212
+ (ineq_constraints1... , ineq_constraints2... ),
212
213
)
213
214
return VecModel (
214
215
obj, eq_constraints, ineq_constraints, vecmodel. sd_constraints, vecmodel. box_min, vecmodel. box_max, vecmodel. init, vecmodel. integer,
215
- ), surrogates
216
+ ), Tuple ( surrogates)
216
217
end
217
218
218
219
function update_surrogates! (model, surrogates, x)
@@ -228,15 +229,15 @@ function update_surrogates!(model, surrogates, x)
228
229
return o, i, e
229
230
end
230
231
231
- @params struct BayesOptOptions
232
- sub_options
232
+ struct BayesOptOptions{S, N <: NamedTuple }
233
+ sub_options:: S
233
234
maxiter:: Int
234
235
initialize:: Bool
235
236
ninit:: Int
236
237
ctol:: Float64
237
238
ftol:: Float64
238
239
postoptimize:: Bool
239
- nt:: NamedTuple
240
+ nt:: N
240
241
end
241
242
function BayesOptOptions (;
242
243
sub_options = IpoptOptions (),
@@ -276,20 +277,20 @@ function BayesOptOptions(;
276
277
)
277
278
end
278
279
279
- @params mutable struct BayesOptWorkspace <: Workspace
280
- model:: VecModel
281
- sub_workspace
282
- x0:: AbstractVector
283
- options:: BayesOptOptions
284
- surrogates:: AbstractVector
280
+ mutable struct BayesOptWorkspace{M <: VecModel , S1, X <: AbstractVector , O <: BayesOptOptions , S2 <: Union{Tuple, AbstractVector} } <: Workspace
281
+ model:: M
282
+ sub_workspace:: S1
283
+ x0:: X
284
+ options:: O
285
+ surrogates:: S2
285
286
end
286
287
287
- @params struct BayesOptResult <: AbstractResult
288
- minimizer
289
- minimum
288
+ struct BayesOptResult{M1, M2, S1 <: AbstractResult , S2} <: AbstractResult
289
+ minimizer:: M1
290
+ minimum:: M2
290
291
niters:: Int
291
- sub_result:: AbstractResult
292
- surrogates
292
+ sub_result:: S1
293
+ surrogates:: S2
293
294
end
294
295
295
296
# ScaledSobolIterator adapted from BayesianOptimization.jl
0 commit comments