Passed
Push — master ( 9ff666...1a4396 )
by Simon
03:24
created

hyperactive.util.util   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 19
dl 0
loc 36
rs 10
c 0
b 0
f 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A init_candidate() 0 5 1
A sort_for_best() 0 11 1
A merge_dicts() 0 7 3
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(_main_args_, nth_process, Candidate):
10
    _main_args_._set_random_seed(nth_process)
11
    _cand_ = Candidate(nth_process, _main_args_)
12
13
    return _cand_
14
15
16
def merge_dicts(base_dict, added_dict):
17
    # overwrite default values
18
    for key in base_dict.keys():
19
        if key in list(added_dict.keys()):
20
            base_dict[key] = added_dict[key]
21
22
    return base_dict
23
24
25
def sort_for_best(sort, sort_by):
26
    # Returns two lists sorted by the second
27
    sort = np.array(sort)
28
    sort_by = np.array(sort_by)
29
30
    index_best = list(sort_by.argsort()[::-1])
31
32
    sort_sorted = sort[index_best]
33
    sort_by_sorted = sort_by[index_best]
34
35
    return sort_sorted, sort_by_sorted
36