Total Complexity | 6 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # Author: Simon Blanke |
||
2 | # Email: [email protected] |
||
3 | # License: MIT License |
||
4 | |||
5 | |||
6 | import numpy as np |
||
7 | |||
8 | |||
9 | def init_candidate(_core_, nth_process, Candidate): |
||
10 | _core_._set_random_seed(nth_process) |
||
11 | _cand_ = Candidate(nth_process, _core_) |
||
12 | |||
13 | return _cand_ |
||
14 | |||
15 | |||
16 | def init_eval(_cand_, nth_process, X, y): |
||
17 | pos = _cand_._init_._set_start_pos(nth_process, X, y) |
||
18 | score = _cand_.eval_pos(pos, X, y) |
||
19 | _cand_.score_best = score |
||
20 | _cand_.pos_best = pos |
||
21 | |||
22 | return _cand_ |
||
23 | |||
24 | |||
25 | def merge_dicts(base_dict, added_dict): |
||
26 | # overwrite default values |
||
27 | for key in base_dict.keys(): |
||
28 | if key in list(added_dict.keys()): |
||
29 | base_dict[key] = added_dict[key] |
||
30 | |||
31 | return base_dict |
||
32 | |||
33 | |||
34 | def sort_for_best(sort, sort_by): |
||
35 | # Returns two lists sorted by the second |
||
36 | sort = np.array(sort) |
||
37 | sort_by = np.array(sort_by) |
||
38 | |||
39 | index_best = list(sort_by.argsort()[::-1]) |
||
40 | |||
41 | sort_sorted = sort[index_best] |
||
42 | sort_by_sorted = sort_by[index_best] |
||
43 | |||
44 | return sort_sorted, sort_by_sorted |
||
45 |