Skip to content

Commit d88cf70

Browse files
authored
[ENH] experiments: uniform call signature and terminology (#178)
In `BaseExperiment` descendants, makes the following consistent: * `__call__` signature is now `__call__(params)`, instead of `__call__(**params)` - for consistency with `evaluate` and the expected function/callable interface * the second return of `score` and `evaluate` is now consistently called "metadata" (instead of `add_info`), as referred to in the docstrings Minor additional changes: * removed some unused imports
1 parent 4eeea90 commit d88cf70

15 files changed

Lines changed: 23 additions & 33 deletions

examples/optuna/gp_sampler_example.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
- Can handle constraints and noisy observations
1515
"""
1616

17-
import numpy as np
1817
from sklearn.datasets import load_breast_cancer
1918
from sklearn.svm import SVC
20-
from sklearn.model_selection import cross_val_score
2119

2220
from hyperactive.experiment.integrations import SklearnCvExperiment
2321
from hyperactive.opt.optuna import GPOptimizer

examples/optuna/grid_sampler_example.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
- Interpretable and deterministic results
1515
"""
1616

17-
import numpy as np
1817
from sklearn.datasets import load_iris
1918
from sklearn.neighbors import KNeighborsClassifier
20-
from sklearn.model_selection import cross_val_score
2119

2220
from hyperactive.experiment.integrations import SklearnCvExperiment
2321
from hyperactive.opt.optuna import GridOptimizer

examples/optuna/nsga_ii_sampler_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self, X, y):
3333
self.X = X
3434
self.y = y
3535

36-
def __call__(self, **params):
36+
def __call__(self, params):
3737
# Create model with parameters
3838
model = RandomForestClassifier(random_state=42, **params)
3939

examples/optuna/nsga_iii_sampler_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(self, X, y):
3434
self.X = X
3535
self.y = y
3636

37-
def __call__(self, **params):
37+
def __call__(self, params):
3838
# Create model with parameters
3939
model = DecisionTreeClassifier(random_state=42, **params)
4040

examples/optuna/qmc_sampler_example.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919
- Baseline optimization comparisons
2020
"""
2121

22-
import numpy as np
2322
from sklearn.datasets import load_wine
2423
from sklearn.linear_model import LogisticRegression
25-
from sklearn.model_selection import cross_val_score
2624

2725
from hyperactive.experiment.integrations import SklearnCvExperiment
2826
from hyperactive.opt.optuna import QMCOptimizer

examples/optuna/random_sampler_example.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515
- Good when objective function is noisy
1616
"""
1717

18-
import numpy as np
1918
from sklearn.datasets import load_digits
2019
from sklearn.svm import SVC
21-
from sklearn.model_selection import cross_val_score
2220

2321
from hyperactive.experiment.integrations import SklearnCvExperiment
2422
from hyperactive.opt.optuna import RandomOptimizer

examples/optuna/tpe_sampler_example.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
- Default choice for most hyperparameter optimization tasks
1414
"""
1515

16-
import numpy as np
1716
from sklearn.datasets import load_wine
1817
from sklearn.ensemble import RandomForestClassifier
19-
from sklearn.model_selection import cross_val_score
2018

2119
from hyperactive.experiment.integrations import SklearnCvExperiment
2220
from hyperactive.opt.optuna import TPEOptimizer

src/hyperactive/base/_experiment.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ class BaseExperiment(BaseObject):
2121
def __init__(self):
2222
super().__init__()
2323

24-
def __call__(self, **kwargs):
25-
"""Score parameters, with kwargs call. Same as score call."""
26-
score, _ = self.score(kwargs)
24+
def __call__(self, params):
25+
"""Score parameters. Same as score call, returns only only a first element."""
26+
score, _ = self.score(params)
2727
return score
2828

2929
@property

src/hyperactive/experiment/bench/_ackley.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ class Ackley(BaseExperiment):
3939
>>> from hyperactive.experiment.bench import Ackley
4040
>>> ackley = Ackley(a=20)
4141
>>> params = {"x0": 1, "x1": 2}
42-
>>> score, add_info = ackley.score(params)
42+
>>> score, metadata = ackley.score(params)
4343
4444
Quick call without metadata return or dictionary:
45-
>>> score = ackley(x0=1, x1=2)
45+
>>> score = ackley({"x0": 1, "x1": 2})
4646
""" # noqa: E501
4747

4848
_tags = {

src/hyperactive/experiment/bench/_parabola.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ class Parabola(BaseExperiment):
3333
>>> from hyperactive.experiment.bench import Parabola
3434
>>> parabola = Parabola(a=1.0, b=0.0, c=0.0)
3535
>>> params = {"x": 1, "y": 2}
36-
>>> score, add_info = parabola.score(params)
36+
>>> score, metadata = parabola.score(params)
3737
3838
Quick call without metadata return or dictionary:
39-
>>> score = parabola(x=1, y=2)
39+
>>> score = parabola({"x": 1, "y": 2})
4040
"""
4141

4242
_tags = {

0 commit comments

Comments
 (0)