diff --git a/README.md b/README.md index 3f1960d6..7059b9ad 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,10 @@ **A unified interface for optimization algorithms and problems.** -* [easy sklearn-like interface](#hyperactive-is-very-easy-to-use), [versatile and configurable](./examples/optimization_applications/search_space_example.py) -- collection of [optimization algorithms](#overview), integrates with major [ML frameworks](#overview) such as `scikit-learn` -- [memory-efficient](./examples/optimization_applications/memory.py) native implementations of [gradient-free optimizers](https://github.com/SimonBlanke/Gradient-Free-Optimizers) -- unified API to popular optimization packages such as `optuna` +Hyperactive implements a collection of optimization algorithms, accessible through a unified experiment-based +interface that separates optimization problems from algorithms. The library provides native implementations of algorithms from the Gradient-Free-Optimizers +package alongside direct interfaces to Optuna and scikit-learn optimizers, supporting discrete, continuous, and mixed parameter spaces. +
@@ -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: