|
10 | 10 | from multiprocessing.managers import DictProxy |
11 | 11 |
|
12 | 12 | from ._objective_adapter import ObjectiveAdapter |
| 13 | +from ._result import Result |
13 | 14 |
|
14 | 15 |
|
15 | 16 | class CachedObjectiveAdapter(ObjectiveAdapter): |
16 | | - memory_dict = {} |
17 | | - memory_dict_new = {} |
18 | | - |
19 | 17 | def __init__(self, conv, objective): |
20 | 18 | super().__init__(conv, objective) |
21 | 19 |
|
| 20 | + self.memory_dict = {} |
| 21 | + self.memory_dict_new = {} |
| 22 | + |
22 | 23 | def memory(self, warm_start: pd.DataFrame, memory: Any = None): |
23 | 24 | if isinstance(memory, DictProxy): |
24 | 25 | self.memory_dict = memory |
@@ -50,21 +51,3 @@ def __call__(self, pos): |
50 | 51 | self.memory_dict[pos_t] = result |
51 | 52 | self.memory_dict_new[pos_t] = result |
52 | 53 | return result, params |
53 | | - |
54 | | - def _memory( |
55 | | - self, objective_function: Callable[[List[float]], float] |
56 | | - ) -> Callable[[List[float]], float]: |
57 | | - def wrapper(para: List[float]) -> float: |
58 | | - value = self._conv.para2value(para) |
59 | | - position = self._conv.value2position(value) |
60 | | - pos_tuple = tuple(position) |
61 | | - |
62 | | - if pos_tuple in self.memory_dict: |
63 | | - return self.memory_dict[pos_tuple] |
64 | | - else: |
65 | | - score = objective_function(para) |
66 | | - self.memory_dict[pos_tuple] = score |
67 | | - self.memory_dict_new[pos_tuple] = score |
68 | | - return score |
69 | | - |
70 | | - return wrapper |
0 commit comments