This repository has been archived by the owner on Feb 28, 2024. It is now read-only.
Benchmark functions were locked into one of the tests #29
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"""A collection of benchmark problems""" | ||
|
||
import numpy as np | ||
|
||
|
||
def branin(x, a=1, b=5.1 / (4 * np.pi**2), c=5. / np.pi, | ||
r=6, s=10, t=1. / (8 * np.pi)): | ||
"""Branin-Hoo function is defined on the square x1 ∈ [-5, 10], x2 ∈ [0, 15]. | ||
|
||
It has three minima with f(x*) = 0.397887 at x* = (-pi, 12.275), | ||
(+pi, 2.275), and (9.42478, 2.475). | ||
|
||
More details: <http://www.sfu.ca/~ssurjano/branin.html> | ||
""" | ||
return (a * (x[1] - b * x[0]**2 + c * x[0] - r)**2 + | ||
s * (1 - t) * np.cos(x[0]) + s) | ||
|
||
def hartmann_6(x, | ||
alpha=np.asarray([1.0, 1.2, 3.0, 3.2]), | ||
P=10**-4 * np.asarray([[1312, 1696, 5569, 124, 8283, 5886], | ||
[2329, 4135, 8307, 3736, 1004, 9991], | ||
[2348, 1451, 3522, 2883, 3047, 6650], | ||
[4047, 8828, 8732, 5743, 1091, 381]]), | ||
A=np.asarray([[10, 3, 17, 3.50, 1.7, 8], | ||
[0.05, 10, 17, 0.1, 8, 14], | ||
[3, 3.5, 1.7, 10, 17, 8], | ||
[17, 8, 0.05, 10, 0.1, 14]])): | ||
"""The six dimensional Hartmann function is defined on the unit hypercube. | ||
|
||
It has six local minima and one global minimum f(x*) = -3.32237 at | ||
x* = (0.20169, 0.15001, 0.476874, 0.275332, 0.311652, 0.6573). | ||
|
||
More details: <http://www.sfu.ca/~ssurjano/hart6.html> | ||
""" | ||
return -np.sum(alpha * np.exp(-np.sum(A * (x - P)**2, axis=1))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import numpy as np | ||
from sklearn.utils.testing import assert_array_almost_equal | ||
from sklearn.utils.testing import assert_almost_equal | ||
|
||
from skopt.benchmarks import branin, hartmann_6 | ||
|
||
|
||
def test_branin(): | ||
xstars = np.asarray([(-np.pi, 12.275), (+np.pi, 2.275), (9.42478, 2.475)]) | ||
f_at_xstars = np.asarray([branin(xstar) for xstar in xstars]) | ||
branin_min = np.array([0.397887] * xstars.shape[0]) | ||
assert_array_almost_equal(f_at_xstars, branin_min) | ||
|
||
|
||
def test_hartmann6(): | ||
assert_almost_equal(hartmann_6((0.20169, 0.15001, 0.476874, | ||
0.275332, 0.311652, 0.6573)), | ||
-3.32237, | ||
decimal=5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,25 +3,7 @@ | |
from sklearn.utils.testing import assert_less | ||
|
||
from skopt.gp_opt import gp_minimize | ||
|
||
|
||
def branin(x, a=1, b=5.1 / (4 * pi ** 2), c=5. / pi, | ||
r=6, s=10, t=1. / (8 * pi)): | ||
return (a * (x[1] - b * x[0] ** 2 + c * x[0] - r) ** 2 + | ||
s * (1 - t) * cos(x[0]) + s) | ||
|
||
|
||
def hartmann_6(x, | ||
alpha=np.asarray([1.0, 1.2, 3.0, 3.2]), | ||
P=10**-4 * np.asarray([[1312, 1696, 5569, 124, 8283, 5886], | ||
[2329, 4135, 8307, 3736, 1004, 9991], | ||
[2348, 1451, 3522, 2883, 3047, 6650], | ||
[4047, 8828, 8732, 5743, 1091, 381]]), | ||
A=np.asarray([[10, 3, 17, 3.50, 1.7, 8], | ||
[0.05, 10, 17, 0.1, 8, 14], | ||
[3, 3.5, 1.7, 10, 17, 8], | ||
[17, 8, 0.05, 10, 0.1, 14]])): | ||
return -np.sum(alpha * np.exp(-np.sum(A * (x - P)**2, axis=1))) | ||
from skopt.benchmarks import branin, hartmann_6 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one import per line |
||
|
||
|
||
def check_branin(search): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here