Skip to content

Commit 60019e6

Browse files
committed
add stochastic hill climbing example
1 parent bf1b06e commit 60019e6

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import numpy as np
2+
3+
from hyperactive import Hyperactive
4+
from hyperactive.optimizers import StochasticHillClimbingOptimizer
5+
6+
7+
def sphere_function(para):
8+
x = para["x"]
9+
y = para["y"]
10+
11+
return -(x * x + y * y)
12+
13+
14+
search_space = {
15+
"x": list(np.arange(-10, 10, 0.1)),
16+
"y": list(np.arange(-10, 10, 0.1)),
17+
}
18+
19+
opt = StochasticHillClimbingOptimizer(
20+
epsilon=0.01,
21+
n_neighbours=5,
22+
distribution="laplace",
23+
p_accept=0.05,
24+
)
25+
26+
hyper = Hyperactive()
27+
hyper.add_search(sphere_function, search_space, n_iter=1500, optimizer=opt)
28+
hyper.run()

0 commit comments

Comments
 (0)