1
|
|
|
# Author: Simon Blanke |
2
|
|
|
# Email: [email protected] |
3
|
|
|
# License: MIT License |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
import numpy as np |
7
|
|
|
import pandas as pd |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
class HyperactiveResults: |
11
|
|
|
def __init__(*args, **kwargs): |
12
|
|
|
pass |
13
|
|
|
|
14
|
|
|
def _sort_results_objFunc(self, objective_function): |
15
|
|
|
best_score = -np.inf |
16
|
|
|
best_para = None |
17
|
|
|
search_data = None |
18
|
|
|
|
19
|
|
|
results_list = [] |
20
|
|
|
|
21
|
|
|
for results_ in self.results_list: |
22
|
|
|
nth_process = results_["nth_process"] |
23
|
|
|
|
24
|
|
|
process_infos = self.process_infos[nth_process] |
25
|
|
|
objective_function_ = process_infos["objective_function"] |
26
|
|
|
|
27
|
|
|
if objective_function_ != objective_function: |
28
|
|
|
continue |
29
|
|
|
|
30
|
|
|
if results_["best_score"] > best_score: |
31
|
|
|
best_score = results_["best_score"] |
32
|
|
|
best_para = results_["best_para"] |
33
|
|
|
|
34
|
|
|
results_list.append(results_["results"]) |
35
|
|
|
|
36
|
|
|
if len(results_list) > 0: |
37
|
|
|
search_data = pd.concat(results_list) |
38
|
|
|
|
39
|
|
|
self.objFunc2results[objective_function] = { |
40
|
|
|
"best_para": best_para, |
41
|
|
|
"best_score": best_score, |
42
|
|
|
"search_data": search_data, |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
def _sort_results_search_id(self, search_id): |
46
|
|
|
for results_ in self.results_list: |
47
|
|
|
nth_process = results_["nth_process"] |
48
|
|
|
search_id_ = self.process_infos[nth_process]["search_id"] |
49
|
|
|
|
50
|
|
|
if search_id_ != search_id: |
51
|
|
|
continue |
52
|
|
|
|
53
|
|
|
best_score = results_["best_score"] |
54
|
|
|
best_para = results_["best_para"] |
55
|
|
|
search_data = results_["results"] |
56
|
|
|
|
57
|
|
|
self.search_id2results[search_id] = { |
58
|
|
|
"best_para": best_para, |
59
|
|
|
"best_score": best_score, |
60
|
|
|
"search_data": search_data, |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
def _get_one_result(self, id_, result_name): |
64
|
|
|
if isinstance(id_, str): |
65
|
|
|
if id_ not in self.search_id2results: |
66
|
|
|
self._sort_results_search_id(id_) |
67
|
|
|
|
68
|
|
|
return self.search_id2results[id_][result_name] |
69
|
|
|
|
70
|
|
|
else: |
71
|
|
|
if id_ not in self.objFunc2results: |
72
|
|
|
self._sort_results_objFunc(id_) |
73
|
|
|
|
74
|
|
|
return self.objFunc2results[id_][result_name] |
75
|
|
|
|
76
|
|
|
def best_para(self, id_): |
77
|
|
|
return self._get_one_result(id_, "best_para") |
78
|
|
|
|
79
|
|
|
def best_score(self, id_): |
80
|
|
|
return self._get_one_result(id_, "best_score") |
81
|
|
|
|
82
|
|
|
def results(self, id_): |
83
|
|
|
return self._get_one_result(id_, "search_data") |
84
|
|
|
|