-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathgrid_search_sk.py
More file actions
33 lines (27 loc) · 956 Bytes
/
grid_search_sk.py
File metadata and controls
33 lines (27 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
GridSearchSk Optimizer Example
This example demonstrates how to use the GridSearchSk optimizer with
loky backend for parallel execution.
"""
import numpy as np
from hyperactive.opt import GridSearchSk
from hyperactive.experiment.toy import Sphere
# Define the optimization problem using a toy sphere function
# The sphere function f(x,y) = x² + y² has its minimum at (0,0)
sphere_experiment = Sphere(n_dim=2)
# Define parameter grid - creates a 9x9 = 81 point grid
param_grid = {
"x0": np.linspace(-2, 2, 9),
"x1": np.linspace(-2, 2, 9),
}
# Grid search with parallel execution using loky backend
grid_search = GridSearchSk(
param_grid=param_grid,
backend="loky", # Use loky backend for parallelization
backend_params={
"n_jobs": -1, # Use all available CPU cores
},
experiment=sphere_experiment,
)
best_params = grid_search.run()
print(f"Best params: {best_params}, Score: {grid_search.best_score_:.6f}")