From 01851d9c6507e915bdfd925806013fd25555172a Mon Sep 17 00:00:00 2001 From: Simon Blanke Date: Wed, 3 Sep 2025 18:45:33 +0200 Subject: [PATCH 1/4] fix paths to examples; fix examples within readme --- README.md | 117 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 76 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 3f1960d6..f7288c05 100644 --- a/README.md +++ b/README.md @@ -46,29 +46,29 @@ pip install hyperactive import numpy as np # function to be maximized -def problem(opt): - x = opt["x"] - y = opt["y"] +def problem(params): + x = params["x"] + y = params["y"] return - x ** 2 + - y ** 2 # discrete search space: dict of iterable, scikit-learn like grid space # (valid search space types depends on optimizer) -grid = { +search_space = { "x": np.arange(-1, 1, 0.01), "y": np.arange(-1, 2, 0.1), } -from hyperactive.opt import HillClimbing +from hyperactive.opt.gfo import HillClimbing hillclimbing = HillClimbing( - experiment=problem, - search_space=grid, + search_space=search_space, n_iter=100, + experiment=problem, ) # running the hill climbing search: -best_params = hillclimbing.run() +best_params = hillclimbing.solve() ``` ### experiment abstraction - example: scikit-learn CV experiment @@ -79,6 +79,7 @@ best_params = hillclimbing.run() `scikit-learn` cross-validation experiments: ```python +import numpy as np from hyperactive.experiment.integrations import SklearnCvExperiment from sklearn.datasets import load_iris from sklearn.svm import SVC @@ -96,23 +97,25 @@ sklearn_exp = SklearnCvExperiment( y=y, ) -# experiments can be evaluated via "score +# experiments can be evaluated via "score" params = {"C": 1.0, "kernel": "linear"} score, add_info = sklearn_exp.score(params) # they can be used in optimizers like above -from hyperactive.opt import HillClimbing +from hyperactive.opt.gfo import HillClimbing + +search_space = { + "C": np.logspace(0.01, 100, num=10), + "kernel": ["linear", "rbf"], +} hillclimbing = HillClimbing( - experiment=problem, - search_space={ - "C": np.logspace(0.01, 100, num=10), - "kernel": ["linear", "rbf"], - } + search_space=search_space, n_iter=100, + experiment=sklearn_exp, ) -best_params = hillclimbing.run() +best_params = hillclimbing.solve() ``` ### full ML toolbox integration - example: scikit-learn @@ -125,10 +128,11 @@ Any `hyperactive` optimizer can be combined with the ML toolbox integrations! # 1. defining the tuned estimator: from sklearn.svm import SVC from hyperactive.integrations.sklearn import OptCV -from hyperactive.opt import HillClimbing +from hyperactive.opt.gfo import HillClimbing -param_grid = {"kernel": ["linear", "rbf"], "C": [1, 10]} -tuned_svc = OptCV(SVC(), HillClimbing(param_grid)) +search_space = {"kernel": ["linear", "rbf"], "C": [1, 10]} +optimizer = HillClimbing(search_space=search_space, n_iter=20) +tuned_svc = OptCV(SVC(), optimizer) # 2. fitting the tuned estimator: from sklearn.datasets import load_iris @@ -145,6 +149,26 @@ best_params = tuned_svc.best_params_ best_estimator = tuned_svc.best_estimator_ ``` +## :bulb: Key Concepts + +### Experiment-Based Architecture + +Hyperactive v5 introduces a clean separation between optimization algorithms and optimization problems through the **experiment abstraction**: + +- **Experiments** define *what* to optimize (the objective function and evaluation logic) +- **Optimizers** define *how* to optimize (the search strategy and algorithm) + +This design allows you to: +- Mix and match any optimizer with any experiment type +- Create reusable experiment definitions for common ML tasks +- Easily switch between different optimization strategies +- Build complex optimization workflows with consistent interfaces + +**Built-in experiments include:** +- `SklearnCvExperiment` - Cross-validation for sklearn estimators +- `SktimeForecastingExperiment` - Time series forecasting optimization +- Custom function experiments (pass any callable as experiment) + ## Overview @@ -177,43 +201,54 @@ Hyperactive features a collection of optimization algorithms that can be used fo Local Search:
Global Search:
Population Methods:
Sequential Methods:
+ Optuna Backend: + Machine Learning: