|
1
|
|
|
# Author: Simon Blanke |
|
2
|
|
|
# Email: [email protected] |
|
3
|
|
|
# License: MIT License |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
from .core import Core |
|
7
|
|
|
from .opt_args import Arguments |
|
8
|
|
|
from . import ( |
|
9
|
|
|
HillClimbingOptimizer, |
|
10
|
|
|
StochasticHillClimbingOptimizer, |
|
11
|
|
|
TabuOptimizer, |
|
12
|
|
|
RandomSearchOptimizer, |
|
13
|
|
|
RandomRestartHillClimbingOptimizer, |
|
14
|
|
|
RandomAnnealingOptimizer, |
|
15
|
|
|
SimulatedAnnealingOptimizer, |
|
16
|
|
|
StochasticTunnelingOptimizer, |
|
17
|
|
|
ParallelTemperingOptimizer, |
|
18
|
|
|
ParticleSwarmOptimizer, |
|
19
|
|
|
EvolutionStrategyOptimizer, |
|
20
|
|
|
BayesianOptimizer, |
|
21
|
|
|
) |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
class Hyperactive: |
|
25
|
|
|
def __init__(self, *args, **kwargs): |
|
26
|
|
|
|
|
27
|
|
|
""" |
|
28
|
|
|
|
|
29
|
|
|
Parameters |
|
30
|
|
|
---------- |
|
31
|
|
|
|
|
32
|
|
|
search_config: dict |
|
33
|
|
|
A dictionary providing the model and hyperparameter search space for the |
|
34
|
|
|
optimization process. |
|
35
|
|
|
n_iter: int |
|
36
|
|
|
The number of iterations the optimizer performs. |
|
37
|
|
|
metric: string, optional (default: "accuracy") |
|
38
|
|
|
The metric the model is evaluated by. |
|
39
|
|
|
n_jobs: int, optional (default: 1) |
|
40
|
|
|
The number of searches to run in parallel. |
|
41
|
|
|
cv: int, optional (default: 3) |
|
42
|
|
|
The number of folds for the cross validation. |
|
43
|
|
|
verbosity: int, optional (default: 1) |
|
44
|
|
|
Verbosity level. 1 prints out warm_start points and their scores. |
|
45
|
|
|
random_state: int, optional (default: None) |
|
46
|
|
|
Sets the random seed. |
|
47
|
|
|
warm_start: dict, optional (default: False) |
|
48
|
|
|
Dictionary that definies a start point for the optimizer. |
|
49
|
|
|
memory: bool, optional (default: True) |
|
50
|
|
|
A memory, that saves the evaluation during the optimization to save time when |
|
51
|
|
|
optimizer returns to position. |
|
52
|
|
|
scatter_init: int, optional (default: False) |
|
53
|
|
|
Defines the number n of random positions that should be evaluated with 1/n the |
|
54
|
|
|
training data, to find a better initial position. |
|
55
|
|
|
|
|
56
|
|
|
Returns |
|
57
|
|
|
------- |
|
58
|
|
|
None |
|
59
|
|
|
|
|
60
|
|
|
""" |
|
61
|
|
|
|
|
62
|
|
|
optimizer_dict = { |
|
63
|
|
|
"HillClimbing": HillClimbingOptimizer, |
|
64
|
|
|
"StochasticHillClimbing": StochasticHillClimbingOptimizer, |
|
65
|
|
|
"TabuSearch": TabuOptimizer, |
|
66
|
|
|
"RandomSearch": RandomSearchOptimizer, |
|
67
|
|
|
"RandomRestartHillClimbing": RandomRestartHillClimbingOptimizer, |
|
68
|
|
|
"RandomAnnealing": RandomAnnealingOptimizer, |
|
69
|
|
|
"SimulatedAnnealing": SimulatedAnnealingOptimizer, |
|
70
|
|
|
"StochasticTunneling": StochasticTunnelingOptimizer, |
|
71
|
|
|
"ParallelTempering": ParallelTemperingOptimizer, |
|
72
|
|
|
"ParticleSwarm": ParticleSwarmOptimizer, |
|
73
|
|
|
"EvolutionStrategy": EvolutionStrategyOptimizer, |
|
74
|
|
|
"Bayesian": BayesianOptimizer, |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
_core_ = Core(*args, **kwargs) |
|
78
|
|
|
_arg_ = Arguments(**_core_.opt_para) |
|
79
|
|
|
|
|
80
|
|
|
optimizer_class = optimizer_dict[_core_.optimizer] |
|
81
|
|
|
self._optimizer_ = optimizer_class(_core_, _arg_) |
|
82
|
|
|
|
|
83
|
|
|
self.pos_list = self._optimizer_.pos_list |
|
84
|
|
|
self.score_list = self._optimizer_.score_list |
|
85
|
|
|
|
|
86
|
|
|
def search(self, X, y): |
|
87
|
|
|
"""Public method for starting the search with the training data (X, y) |
|
88
|
|
|
|
|
89
|
|
|
Parameters |
|
90
|
|
|
---------- |
|
91
|
|
|
X : array-like or sparse matrix of shape = [n_samples, n_features] |
|
92
|
|
|
|
|
93
|
|
|
y : array-like, shape = [n_samples] or [n_samples, n_outputs] |
|
94
|
|
|
|
|
95
|
|
|
Returns |
|
96
|
|
|
------- |
|
97
|
|
|
None |
|
98
|
|
|
""" |
|
99
|
|
|
self._optimizer_._fit(X, y) |
|
100
|
|
|
self.score_best = self._optimizer_.score_best |
|
101
|
|
|
|
|
102
|
|
|
def get_results(self): |
|
103
|
|
|
return self._optimizer_.results |
|
104
|
|
|
|
|
105
|
|
|
def save_report(self): |
|
106
|
|
|
pass |
|
107
|
|
|
|