Skip to content

Commit 209d20f

Browse files
committed
Pushing the docs to 0.9/ for branch: 0.9.X, commit a2369ddbc332d16d8ff173b12404b03fea472492
1 parent 49e1e84 commit 209d20f

File tree

472 files changed

+103057
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

472 files changed

+103057
-0
lines changed

Diff for: 0.9/.buildinfo

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Sphinx build info version 1
2+
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
3+
config: 8775eac5e78fff9d3a8c75b300e84394
4+
tags: 645f666f9bcd5a90fca523b33c5a78b7

Diff for: 0.9/.nojekyll

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": false
8+
},
9+
"outputs": [],
10+
"source": [
11+
"%matplotlib inline"
12+
]
13+
},
14+
{
15+
"cell_type": "markdown",
16+
"metadata": {},
17+
"source": [
18+
"\n# Parallel optimization\n\nIaroslav Shcherbatyi, May 2017.\nReviewed by Manoj Kumar and Tim Head.\nReformatted by Holger Nahrstaedt 2020\n\n.. currentmodule:: skopt\n\n## Introduction\n\nFor many practical black box optimization problems expensive objective can be\nevaluated in parallel at multiple points. This allows to get more objective\nevaluations per unit of time, which reduces the time necessary to reach good\nobjective values when appropriate optimization algorithms are used, see for\nexample results in [1]_ and the references therein.\n\n\nOne such example task is a selection of number and activation function of a\nneural network which results in highest accuracy for some machine learning\nproblem. For such task, multiple neural networks with different combinations\nof number of neurons and activation function type can be evaluated at the same\ntime in parallel on different cpu cores / computational nodes.\n\nThe \u201cask and tell\u201d API of scikit-optimize exposes functionality that allows to\nobtain multiple points for evaluation in parallel. Intended usage of this\ninterface is as follows:\n\n1. Initialize instance of the `Optimizer` class from skopt\n2. Obtain n points for evaluation in parallel by calling the `ask` method of an optimizer instance with the `n_points` argument set to n > 0\n3. Evaluate points\n4. Provide points and corresponding objectives using the `tell` method of an optimizer instance\n5. Continue from step 2 until eg maximum number of evaluations reached\n"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": null,
24+
"metadata": {
25+
"collapsed": false
26+
},
27+
"outputs": [],
28+
"source": [
29+
"print(__doc__)\nimport numpy as np"
30+
]
31+
},
32+
{
33+
"cell_type": "markdown",
34+
"metadata": {},
35+
"source": [
36+
"## Example\n\nA minimalistic example that uses joblib to parallelize evaluation of the\nobjective function is given below.\n\n"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": null,
42+
"metadata": {
43+
"collapsed": false
44+
},
45+
"outputs": [],
46+
"source": [
47+
"from skopt import Optimizer\nfrom skopt.space import Real\nfrom joblib import Parallel, delayed\n# example objective taken from skopt\nfrom skopt.benchmarks import branin\n\noptimizer = Optimizer(\n dimensions=[Real(-5.0, 10.0), Real(0.0, 15.0)],\n random_state=1,\n base_estimator='gp'\n)\n\nfor i in range(10):\n x = optimizer.ask(n_points=4) # x is a list of n_points points\n y = Parallel(n_jobs=4)(delayed(branin)(v) for v in x) # evaluate points in parallel\n optimizer.tell(x, y)\n\n# takes ~ 20 sec to get here\nprint(min(optimizer.yi)) # print the best objective found"
48+
]
49+
},
50+
{
51+
"cell_type": "markdown",
52+
"metadata": {},
53+
"source": [
54+
"Note that if `n_points` is set to some integer > 0 for the `ask` method, the\nresult will be a list of points, even for `n_points` = 1. If the argument is\nset to `None` (default value) then a single point (but not a list of points)\nwill be returned.\n\nThe default \"minimum constant liar\" [1]_ parallelization strategy is used in\nthe example, which allows to obtain multiple points for evaluation with a\nsingle call to the `ask` method with any surrogate or acquisition function.\nParallelization strategy can be set using the \"strategy\" argument of `ask`.\nFor supported parallelization strategies see the documentation of\nscikit-optimize.\n\n.. [1] `<https://hal.archives-ouvertes.fr/hal-00732512/document>`_\n"
55+
]
56+
}
57+
],
58+
"metadata": {
59+
"kernelspec": {
60+
"display_name": "Python 3",
61+
"language": "python",
62+
"name": "python3"
63+
},
64+
"language_info": {
65+
"codemirror_mode": {
66+
"name": "ipython",
67+
"version": 3
68+
},
69+
"file_extension": ".py",
70+
"mimetype": "text/x-python",
71+
"name": "python",
72+
"nbconvert_exporter": "python",
73+
"pygments_lexer": "ipython3",
74+
"version": "3.9.7"
75+
}
76+
},
77+
"nbformat": 4,
78+
"nbformat_minor": 0
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
"""
2+
==========================
3+
Comparing surrogate models
4+
==========================
5+
6+
Tim Head, July 2016.
7+
Reformatted by Holger Nahrstaedt 2020
8+
9+
.. currentmodule:: skopt
10+
11+
Bayesian optimization or sequential model-based optimization uses a surrogate
12+
model to model the expensive to evaluate function `func`. There are several
13+
choices for what kind of surrogate model to use. This notebook compares the
14+
performance of:
15+
16+
* gaussian processes,
17+
* extra trees, and
18+
* random forests
19+
20+
as surrogate models. A purely random optimization strategy is also used as
21+
a baseline.
22+
"""
23+
24+
print(__doc__)
25+
import numpy as np
26+
np.random.seed(123)
27+
import matplotlib.pyplot as plt
28+
29+
#############################################################################
30+
# Toy model
31+
# =========
32+
#
33+
# We will use the :class:`benchmarks.branin` function as toy model for the expensive function.
34+
# In a real world application this function would be unknown and expensive
35+
# to evaluate.
36+
37+
from skopt.benchmarks import branin as _branin
38+
39+
def branin(x, noise_level=0.):
40+
return _branin(x) + noise_level * np.random.randn()
41+
42+
#############################################################################
43+
44+
from matplotlib.colors import LogNorm
45+
46+
47+
def plot_branin():
48+
fig, ax = plt.subplots()
49+
50+
x1_values = np.linspace(-5, 10, 100)
51+
x2_values = np.linspace(0, 15, 100)
52+
x_ax, y_ax = np.meshgrid(x1_values, x2_values)
53+
vals = np.c_[x_ax.ravel(), y_ax.ravel()]
54+
fx = np.reshape([branin(val) for val in vals], (100, 100))
55+
56+
cm = ax.pcolormesh(x_ax, y_ax, fx,
57+
norm=LogNorm(vmin=fx.min(),
58+
vmax=fx.max()),
59+
cmap='viridis_r')
60+
61+
minima = np.array([[-np.pi, 12.275], [+np.pi, 2.275], [9.42478, 2.475]])
62+
ax.plot(minima[:, 0], minima[:, 1], "r.", markersize=14,
63+
lw=0, label="Minima")
64+
65+
cb = fig.colorbar(cm)
66+
cb.set_label("f(x)")
67+
68+
ax.legend(loc="best", numpoints=1)
69+
70+
ax.set_xlabel("X1")
71+
ax.set_xlim([-5, 10])
72+
ax.set_ylabel("X2")
73+
ax.set_ylim([0, 15])
74+
75+
76+
plot_branin()
77+
78+
#############################################################################
79+
# This shows the value of the two-dimensional branin function and
80+
# the three minima.
81+
#
82+
#
83+
# Objective
84+
# =========
85+
#
86+
# The objective of this example is to find one of these minima in as
87+
# few iterations as possible. One iteration is defined as one call
88+
# to the :class:`benchmarks.branin` function.
89+
#
90+
# We will evaluate each model several times using a different seed for the
91+
# random number generator. Then compare the average performance of these
92+
# models. This makes the comparison more robust against models that get
93+
# "lucky".
94+
95+
from functools import partial
96+
from skopt import gp_minimize, forest_minimize, dummy_minimize
97+
98+
func = partial(branin, noise_level=2.0)
99+
bounds = [(-5.0, 10.0), (0.0, 15.0)]
100+
n_calls = 60
101+
102+
#############################################################################
103+
104+
105+
def run(minimizer, n_iter=5):
106+
return [minimizer(func, bounds, n_calls=n_calls, random_state=n)
107+
for n in range(n_iter)]
108+
109+
# Random search
110+
dummy_res = run(dummy_minimize)
111+
112+
# Gaussian processes
113+
gp_res = run(gp_minimize)
114+
115+
# Random forest
116+
rf_res = run(partial(forest_minimize, base_estimator="RF"))
117+
118+
# Extra trees
119+
et_res = run(partial(forest_minimize, base_estimator="ET"))
120+
121+
#############################################################################
122+
# Note that this can take a few minutes.
123+
124+
from skopt.plots import plot_convergence
125+
126+
plot = plot_convergence(("dummy_minimize", dummy_res),
127+
("gp_minimize", gp_res),
128+
("forest_minimize('rf')", rf_res),
129+
("forest_minimize('et)", et_res),
130+
true_minimum=0.397887, yscale="log")
131+
132+
plot.legend(loc="best", prop={'size': 6}, numpoints=1)
133+
134+
#############################################################################
135+
# This plot shows the value of the minimum found (y axis) as a function
136+
# of the number of iterations performed so far (x axis). The dashed red line
137+
# indicates the true value of the minimum of the :class:`benchmarks.branin` function.
138+
#
139+
# For the first ten iterations all methods perform equally well as they all
140+
# start by creating ten random samples before fitting their respective model
141+
# for the first time. After iteration ten the next point at which
142+
# to evaluate :class:`benchmarks.branin` is guided by the model, which is where differences
143+
# start to appear.
144+
#
145+
# Each minimizer only has access to noisy observations of the objective
146+
# function, so as time passes (more iterations) it will start observing
147+
# values that are below the true value simply because they are fluctuations.

0 commit comments

Comments
 (0)