cds2.bayesopt
Gaussian Process and Bayesian optimization.
Bayesian optimization with Gaussian-process surrogate and acquisition functions.
GaussianProcess
Gaussian-process regressor with RBF kernel.
Uses the squared-exponential kernel
k(x, x') = sigma_f^2 * exp(-0.5 * ||x-x'||^2 / length_scale^2)
with a small observation noise added to the diagonal.
Source code in src/cds2/bayesopt.py
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 | |
fit(x_train, y_train)
Fit the GP to training data.
Source code in src/cds2/bayesopt.py
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 | |
predict(x_star)
Predict mean and standard deviation at new points.
Source code in src/cds2/bayesopt.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
OptimizeResult
dataclass
Outcome of Bayesian optimization.
Source code in src/cds2/bayesopt.py
209 210 211 212 213 214 215 216 217 218 219 | |
expected_improvement(mu, sigma, best_f, xi=0.01)
Expected Improvement for minimization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu
|
object
|
Predicted mean(s) at candidate points. |
required |
sigma
|
object
|
Predicted standard deviation(s). |
required |
best_f
|
float
|
Best observed objective value so far (minimum). |
required |
xi
|
float
|
Exploration-exploitation trade-off. |
0.01
|
Source code in src/cds2/bayesopt.py
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 | |
upper_confidence_bound(mu, sigma, kappa=2.0)
Upper confidence bound acquisition.
ucb = mu + kappa * sigma. For maximization, maximise this
quantity; for minimization the optimizer uses -mu + kappa*sigma
(i.e. upper_confidence_bound(-mu, sigma)).
Source code in src/cds2/bayesopt.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
bayes_opt(objective, bounds, n_init=5, n_iter=20, acquisition='ei', seed=None)
Bayesian optimization over a box-constrained domain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
objective
|
Callable[[FloatArray], float]
|
Function to minimize; takes a 1-D array of shape |
required |
bounds
|
Sequence[tuple[float, float]] | FloatArray
|
Sequence of |
required |
n_init
|
int
|
Number of random initial evaluations. |
5
|
n_iter
|
int
|
Number of Bayesian optimization steps. |
20
|
acquisition
|
str
|
Acquisition function: |
'ei'
|
seed
|
int | None
|
Random seed for reproducibility. |
None
|
Source code in src/cds2/bayesopt.py
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 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | |