Passed
Push — master ( 61a8e6...a7d091 )
by Simon
03:21
created

hyperactive.util.util   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 25
dl 0
loc 45
rs 10
c 0
b 0
f 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A sort_for_best() 0 11 1
A init_eval() 0 7 1
A merge_dicts() 0 7 3
A init_candidate() 0 5 1
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