Skip to content

Commit 9d5fba4

Browse files
committed
add smac backend to docs
1 parent 667ec6f commit 9d5fba4

7 files changed

Lines changed: 385 additions & 4 deletions

File tree

docs/source/_snippets/user_guide/optimizers.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,60 @@ def objective(params):
225225
# [end:optuna_tpe]
226226

227227

228+
# ============================================================================
229+
# SMAC Backend
230+
# ============================================================================
231+
232+
# [start:smac_imports]
233+
from hyperactive.opt.smac import (
234+
SmacRandomForest, # Random Forest surrogate
235+
SmacGaussianProcess, # Gaussian Process surrogate
236+
SmacRandomSearch, # Random sampling baseline
237+
)
238+
# [end:smac_imports]
239+
240+
241+
# [start:smac_random_forest]
242+
from hyperactive.opt.smac import SmacRandomForest
243+
244+
# Define search space with continuous parameters
245+
smac_param_space = {
246+
"x": (-5.0, 5.0),
247+
"y": (-5.0, 5.0),
248+
}
249+
250+
optimizer = SmacRandomForest(
251+
param_space=smac_param_space,
252+
n_iter=50,
253+
n_initial_points=10,
254+
experiment=objective,
255+
)
256+
# [end:smac_random_forest]
257+
258+
259+
# [start:smac_gaussian_process]
260+
from hyperactive.opt.smac import SmacGaussianProcess
261+
262+
# Best for continuous parameter spaces
263+
optimizer = SmacGaussianProcess(
264+
param_space=smac_param_space,
265+
n_iter=50,
266+
experiment=objective,
267+
)
268+
# [end:smac_gaussian_process]
269+
270+
271+
# [start:smac_random_search]
272+
from hyperactive.opt.smac import SmacRandomSearch
273+
274+
optimizer = SmacRandomSearch(
275+
param_space=smac_param_space,
276+
n_iter=100,
277+
experiment=objective,
278+
)
279+
# [end:smac_random_search]
280+
281+
228282
# ============================================================================
229283
# Configuration Examples
230284
# ============================================================================

docs/source/api_reference/optimizers/index.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The :mod:`hyperactive.opt` module contains optimization algorithms for hyperpara
88
All optimizers inherit from :class:`~hyperactive.base.BaseOptimizer` and share the same interface:
99
the ``solve()`` method to run optimization, and configuration via the ``experiment`` and ``search_space`` parameters.
1010

11-
Hyperactive provides optimizers from three backends:
11+
Hyperactive provides optimizers from four backends:
1212

1313
.. list-table::
1414
:widths: 25 75
@@ -20,6 +20,8 @@ Hyperactive provides optimizers from three backends:
2020
- Native gradient-free optimization algorithms (21 optimizers)
2121
* - :doc:`optuna`
2222
- Interface to Optuna's samplers (8 optimizers)
23+
* - :doc:`smac`
24+
- Interface to SMAC3's Bayesian optimization (3 optimizers)
2325
* - :doc:`sklearn`
2426
- sklearn-compatible search interfaces (2 optimizers)
2527

@@ -28,4 +30,5 @@ Hyperactive provides optimizers from three backends:
2830

2931
gfo
3032
optuna
33+
smac
3134
sklearn
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.. _optimizers_smac_ref:
2+
3+
SMAC
4+
====
5+
6+
.. currentmodule:: hyperactive.opt
7+
8+
The SMAC backend provides an interface to `SMAC3 <https://automl.github.io/SMAC3/main/>`_
9+
(Sequential Model-based Algorithm Configuration) optimization algorithms.
10+
These optimizers use Bayesian optimization with different surrogate models.
11+
12+
.. autosummary::
13+
:toctree: ../auto_generated/
14+
:template: class.rst
15+
16+
SmacRandomForest
17+
SmacGaussianProcess
18+
SmacRandomSearch

docs/source/examples.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ on GitHub.
1818
examples/population_based
1919
examples/sequential_model_based
2020
examples/optuna_backend
21+
examples/smac_backend
2122
examples/sklearn_backend
2223
examples/integrations
2324
examples/other
@@ -61,6 +62,10 @@ Backend Examples
6162
Examples using Optuna's samplers including TPE, CMA-ES, NSGA-II/III,
6263
and Gaussian Process optimization.
6364

65+
:ref:`examples_smac_backend`
66+
State-of-the-art Bayesian optimization using SMAC3 with Random Forest
67+
and Gaussian Process surrogate models.
68+
6469
:ref:`examples_sklearn_backend`
6570
Scikit-learn compatible interfaces as drop-in replacements for
6671
GridSearchCV and RandomizedSearchCV.
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
.. _examples_smac_backend:
2+
3+
============
4+
SMAC Backend
5+
============
6+
7+
Hyperactive provides wrappers for SMAC3's (Sequential Model-based Algorithm
8+
Configuration) optimization algorithms, enabling state-of-the-art Bayesian
9+
optimization with Random Forest and Gaussian Process surrogate models.
10+
11+
.. note::
12+
13+
SMAC must be installed separately:
14+
15+
.. code-block:: bash
16+
17+
pip install hyperactive[smac]
18+
# or
19+
pip install hyperactive[all_extras]
20+
21+
22+
Available Optimizers
23+
--------------------
24+
25+
SMAC provides three optimization strategies with different surrogate models:
26+
27+
.. list-table::
28+
:header-rows: 1
29+
:widths: 25 35 40
30+
31+
* - Optimizer
32+
- Surrogate Model
33+
- Best For
34+
* - ``SmacRandomForest``
35+
- Random Forest
36+
- Mixed parameter spaces (continuous, categorical, integer)
37+
* - ``SmacGaussianProcess``
38+
- Gaussian Process
39+
- Continuous parameter spaces, small to moderate budgets
40+
* - ``SmacRandomSearch``
41+
- None (random sampling)
42+
- Baseline comparison, high-dimensional spaces
43+
44+
45+
SmacRandomForest
46+
----------------
47+
48+
The flagship SMAC optimizer. Uses a Random Forest surrogate model with
49+
Expected Improvement acquisition function. Handles mixed parameter types natively.
50+
51+
.. code-block:: python
52+
53+
from hyperactive.opt.smac import SmacRandomForest
54+
55+
param_space = {
56+
"C": (0.01, 100.0), # Float range
57+
"gamma": (0.0001, 1.0), # Float range
58+
"kernel": ["rbf", "linear"], # Categorical
59+
}
60+
61+
optimizer = SmacRandomForest(
62+
param_space=param_space,
63+
n_iter=100,
64+
n_initial_points=10, # Random points before model-based search
65+
random_state=42,
66+
experiment=objective,
67+
)
68+
best_params = optimizer.solve()
69+
70+
71+
SmacGaussianProcess
72+
-------------------
73+
74+
Uses a Gaussian Process surrogate model (Matern 5/2 kernel) for sample-efficient
75+
optimization. Best suited for continuous parameter spaces.
76+
77+
.. warning::
78+
79+
Gaussian Processes scale O(n^3) with observations. Not recommended for
80+
budgets exceeding 100 evaluations. For mixed or categorical spaces,
81+
use ``SmacRandomForest`` instead.
82+
83+
.. code-block:: python
84+
85+
from hyperactive.opt.smac import SmacGaussianProcess
86+
87+
# Continuous parameters work best with GP
88+
param_space = {
89+
"learning_rate": (0.0001, 0.1),
90+
"weight_decay": (0.0, 0.1),
91+
}
92+
93+
optimizer = SmacGaussianProcess(
94+
param_space=param_space,
95+
n_iter=50, # GP is sample-efficient
96+
random_state=42,
97+
experiment=objective,
98+
)
99+
best_params = optimizer.solve()
100+
101+
102+
SmacRandomSearch
103+
----------------
104+
105+
Pure random search without surrogate modeling. Useful as a baseline or for
106+
high-dimensional spaces where model-based methods struggle.
107+
108+
.. code-block:: python
109+
110+
from hyperactive.opt.smac import SmacRandomSearch
111+
112+
optimizer = SmacRandomSearch(
113+
param_space=param_space,
114+
n_iter=100,
115+
random_state=42,
116+
experiment=objective,
117+
)
118+
best_params = optimizer.solve()
119+
120+
121+
Common Parameters
122+
-----------------
123+
124+
All SMAC optimizers share these parameters:
125+
126+
.. list-table::
127+
:header-rows: 1
128+
:widths: 25 15 60
129+
130+
* - Parameter
131+
- Default
132+
- Description
133+
* - ``param_space``
134+
- Required
135+
- Search space dictionary with parameter ranges
136+
* - ``n_iter``
137+
- 100
138+
- Number of optimization iterations
139+
* - ``max_time``
140+
- None
141+
- Optional time limit in seconds
142+
* - ``random_state``
143+
- None
144+
- Random seed for reproducibility
145+
* - ``deterministic``
146+
- True
147+
- Whether objective function is deterministic
148+
* - ``initialize``
149+
- None
150+
- Warm start configuration (see below)
151+
152+
153+
Parameter Space Definition
154+
--------------------------
155+
156+
SMAC optimizers support three parameter types:
157+
158+
.. code-block:: python
159+
160+
param_space = {
161+
# Float range: both bounds must be float
162+
"learning_rate": (0.001, 0.1),
163+
164+
# Integer range: both bounds must be int
165+
"n_estimators": (10, 500),
166+
167+
# Categorical: list of choices
168+
"kernel": ["rbf", "linear", "poly"],
169+
}
170+
171+
.. note::
172+
173+
For ambiguous tuples like ``(1, 10)``, Python type determines the parameter
174+
type. Use ``(1, 10)`` for integer range and ``(1.0, 10.0)`` for float range.
175+
176+
177+
Warm Starting
178+
-------------
179+
180+
Use warm starting to seed optimization with known good configurations:
181+
182+
.. code-block:: python
183+
184+
optimizer = SmacRandomForest(
185+
param_space=param_space,
186+
n_iter=100,
187+
initialize={
188+
"warm_start": [
189+
{"C": 1.0, "gamma": 0.1, "kernel": "rbf"},
190+
{"C": 10.0, "gamma": 0.01, "kernel": "linear"},
191+
]
192+
},
193+
experiment=objective,
194+
)
195+
196+
197+
When to Use SMAC Backend
198+
------------------------
199+
200+
The SMAC backend is useful when you need:
201+
202+
- **State-of-the-art Bayesian optimization** with proven surrogate models
203+
- **Native handling of mixed parameter spaces** (Random Forest handles categorical parameters well)
204+
- **Sample-efficient optimization** for expensive function evaluations
205+
- **Hyperparameter optimization** following AutoML best practices
206+
- **Reproducible results** in scientific experiments
207+
208+
Choose ``SmacRandomForest`` when:
209+
210+
- Your search space has mixed parameter types
211+
- You have 50+ evaluations budget
212+
- Parameters interact in complex ways
213+
214+
Choose ``SmacGaussianProcess`` when:
215+
216+
- All parameters are continuous
217+
- Budget is small (10-50 evaluations)
218+
- You need uncertainty estimates
219+
220+
Choose ``SmacRandomSearch`` when:
221+
222+
- You need a baseline for comparison
223+
- Search space is high-dimensional (>20 parameters)
224+
- Evaluations are cheap and parallelizable
225+
226+
227+
References
228+
----------
229+
230+
- `SMAC3 Documentation <https://automl.github.io/SMAC3/main/>`_
231+
- Lindauer, M., et al. (2022). SMAC3: A Versatile Bayesian Optimization
232+
Package for Hyperparameter Optimization. JMLR.

0 commit comments

Comments
 (0)