Passed
Push — master ( 44bd28...268666 )
by Simon
03:57
created

gradient_free_optimizers.results_manager   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A ResultsManager.__init__() 0 6 1
A ResultsManager.score() 0 8 1
A ResultsManager._obj_func_results() 0 13 2
1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
6
class ResultsManager:
7
    def __init__(self, objective_function, conv):
8
        super().__init__()
9
        self.objective_function = objective_function
10
        self.conv = conv
11
12
        self.results_list = []
13
14
    def _obj_func_results(self, para):
15
        results = self.objective_function(para)
16
17
        if isinstance(results, tuple):
18
            score = results[0]
19
            results_dict = results[1]
20
        else:
21
            score = results
22
            results_dict = {}
23
24
        results_dict["score"] = score
25
26
        return results_dict
27
28
    def score(self, pos):
29
        value = self.conv.position2value(pos)
30
        para = self.conv.value2para(value)
31
        results_dict = self._obj_func_results(para)
32
33
        self.results_list.append({**results_dict, **para})
34
35
        return results_dict["score"]
36
37