Skip to content

Commit bc35a76

Browse files
committed
Update examples to be more like those covered in tests
Refs: sambo-optimization/sambo#4
1 parent 251a65b commit bc35a76

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

index.html

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,9 @@ <h4>Use case №1: Find global minimium of an objective/cost function</h4>
366366
from scipy.optimize import rosen
367367

368368
result = sambo.minimize(
369-
rosen, bounds=[(-2, 2)]*2, method='shgo',
370-
constraints=lambda x: sum(x**2) &lt;= 2**len(x))
369+
rosen, bounds=[(-2., 2.)] * 2, # Mind the dots
370+
constraints=lambda x: sum(x**2) &lt;= 2**len(x),
371+
max_iter=50, method='shgo')
371372

372373
plot_convergence(result)
373374
plot_objective(result) # Partial dependence
@@ -427,17 +428,21 @@ <h4>Use case №2: Sequential surrogate model-based "Ask-and-Tell" optimization<
427428
... # Abstract long and laborious process
428429
return rosen(x)
429430

431+
bounds = [(-2., 2.)] * 4 # 4D
430432
optimizer = Optimizer(
431-
fun=None, # Implies ask-and-tell interface
432-
bounds=[(-2, 2)]*2,
433+
fun=None, # Implies Ask-And-Tell interface
434+
bounds=bounds,
433435
estimator='gp', # or bring your own
434436
)
435437

436-
for i in range(100):
438+
n_iter = 50
439+
for i in range(n_iter):
437440
suggested_x = optimizer.ask(1)
438441
y = [evaluate(x) for x in suggested_x]
439442
optimizer.tell(y)
440443

444+
best_x, best_fvals = optimizer.top_k()
445+
# Continue the optimization ...
441446
result: OptimizeResult = optimizer.run()
442447
</code></pre>
443448
<div class="snippet snippet-plot" data-plot="- SMBO estimators">

0 commit comments

Comments
 (0)