1
|
|
|
# Author: Simon Blanke |
2
|
|
|
# Email: [email protected] |
3
|
|
|
# License: MIT License |
4
|
|
|
|
5
|
|
|
from ..search_space import SearchSpace |
6
|
|
|
from ..model import Model |
7
|
|
|
from ..init_position import InitSearchPosition |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
class Candidate: |
11
|
|
|
def __init__(self, nth_process, _core_): |
12
|
|
|
self.iter = 0 |
13
|
|
|
self.search_config = _core_.search_config |
14
|
|
|
self.memory = _core_.memory |
15
|
|
|
|
16
|
|
|
self._score_best = -1000 |
17
|
|
|
self.pos_best = None |
18
|
|
|
|
19
|
|
|
self.model = None |
20
|
|
|
|
21
|
|
|
self.nth_process = nth_process |
22
|
|
|
|
23
|
|
|
model_nr = nth_process % _core_.n_models |
24
|
|
|
self.func_ = list(_core_.search_config.keys())[model_nr] |
25
|
|
|
self._space_ = SearchSpace(_core_, model_nr) |
26
|
|
|
|
27
|
|
|
self.func_name = str(self.func_).split(" ")[1] |
28
|
|
|
|
29
|
|
|
self._space_.create_searchspace() |
30
|
|
|
self._model_ = Model(self.func_, nth_process) |
31
|
|
|
|
32
|
|
|
self._init_ = InitSearchPosition( |
33
|
|
|
self._space_, self._model_, _core_.warm_start, _core_.scatter_init |
34
|
|
|
) |
35
|
|
|
|
36
|
|
|
self.eval_time_sum = 0 |
37
|
|
|
|
38
|
|
|
def _get_warm_start(self): |
39
|
|
|
return self._space_.pos2para(self.pos_best) |
40
|
|
|
|
41
|
|
|
@property |
42
|
|
|
def score_best(self): |
43
|
|
|
return self._score_best |
44
|
|
|
|
45
|
|
|
@score_best.setter |
46
|
|
|
def score_best(self, value): |
47
|
|
|
self.model_best = self.model |
48
|
|
|
self._score_best = value |
49
|
|
|
|
50
|
|
|
def eval_pos(self, pos, X, y, force_eval=False): |
51
|
|
|
pos_str = pos.tostring() |
52
|
|
|
|
53
|
|
|
if pos_str in self._space_.memory and self.memory and not force_eval: |
54
|
|
|
return self._space_.memory[pos_str] |
55
|
|
|
else: |
56
|
|
|
para = self._space_.pos2para(pos) |
57
|
|
|
score, eval_time, self.model = self._model_.train_model(para, X, y) |
58
|
|
|
self._space_.memory[pos_str] = score |
59
|
|
|
self.eval_time_sum = self.eval_time_sum + eval_time |
60
|
|
|
|
61
|
|
|
return score |
62
|
|
|
|