Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/source/user_guide/search_spaces.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,29 @@ The spacing between values matters. Choose based on how the parameter affects yo

----

Union Grids and Array-Like Inputs (GFO)
---------------------------------------

GFO optimizers accept array-like values (for example lists or tuples) and
sklearn-style union grids.

.. code-block:: python

from hyperactive.opt.gfo import GridSearch

# array-like values are coerced internally
search_space = {"x": [0, 1], "y": (0, 1)}

# union grids: list of dicts, each dict is a separate grid
search_space = [
{"x": [0], "y": [0]},
{"x": [1], "y": [2]},
]

optimizer = GridSearch(search_space=search_space, n_iter=5, experiment=exp)

----

Granularity and Size
--------------------

Expand Down
1 change: 1 addition & 0 deletions examples/gfo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ python bayesian_optimization_example.py
| [BayesianOptimizer](bayesian_optimization_example.py) | Probabilistic | Expensive evaluations | Gaussian Process |
| [TreeStructuredParzenEstimators](tree_structured_parzen_estimators_example.py) | Bayesian | Mixed parameters | TPE algorithm |
| [ForestOptimizer](forest_optimizer_example.py) | Surrogate-based | Non-linear problems | Random Forest surrogates |
| [Union Grid Search Space Example](search_space_union_example.py) | Utility | Grid unions | Union grids + array-like values |

## Algorithm Categories

Expand Down
35 changes: 35 additions & 0 deletions examples/gfo/search_space_union_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Union Grid Search Space Example

Demonstrates GFO optimizers accepting:
- array-like values (lists/tuples coerced to numpy arrays)
- union grids (list of dicts)
"""

from hyperactive.experiment.func import FunctionExperiment
from hyperactive.opt.gfo import GridSearch


def objective(params):
return params["x"] + params["y"]


experiment = FunctionExperiment(objective)

# Array-like values are coerced internally (list + tuple shown here)
grid_a = {"x": [0, 1], "y": (0, 1)}

# Union grids: each dict is a separate grid; the optimizer runs all and keeps best
search_space = [
grid_a,
{"x": [2], "y": [3]},
]

optimizer = GridSearch(
search_space=search_space,
n_iter=5,
experiment=experiment,
)

best_params = optimizer.solve()
print("Best params:", best_params)