Completed
Push — 0.7.dev ( 20409b...5de18e )
by
unknown
02:36
created

genetic_algorithm_observer.get_global_best()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
2
3
import numpy as np
0 ignored issues
show
Configuration introduced by
The import numpy could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
4
5
6
class genetic_algorithm_observer:
7
    """!
8
9
    """
10
11
    def __init__(self, need_global_best=False, need_population_best=False, need_mean_ff=False):
12
        """ """
13
14
        # Global best chromosome and fitness function for each population
15
        self.global_best_result = {'chromosome': [], 'fitness_function': []}
16
17
        # Best chromosome and fitness function on a population
18
        self.best_population_result = {'chromosome': [], 'fitness_function': []}
19
20
        # Mean fitness function on each population
21
        self.mean_ff_result = []
22
23
        # Flags to collect
24
        self.need_global_best = need_global_best
25
        self.need_population_best = need_population_best
26
        self.need_mean_ff = need_mean_ff
27
28
    def collect_global_best(self, best_chromosome, best_fitness_function):
29
        """ """
30
31
        if not self.need_global_best:
32
            return
33
34
        self.global_best_result['chromosome'].append(best_chromosome)
35
        self.global_best_result['fitness_function'].append(best_fitness_function)
36
37
    def collect_population_best(self, best_chromosome, best_fitness_function):
38
        """ """
39
40
        if not self.need_population_best:
41
            return
42
43
        self.best_population_result['chromosome'].append(best_chromosome)
44
        self.best_population_result['fitness_function'].append(best_fitness_function)
45
46
    def collect_mean(self, fitness_functions):
47
        """ """
48
49
        if not self.need_mean_ff:
50
            return
51
52
        self.mean_ff_result.append(np.mean(fitness_functions))
53
54
    def get_global_best(self):
55
        return self.global_best_result
56
57
    def get_population_best(self):
58
        return self.best_population_result
59
60
    def get_mean_fitness_function(self):
61
        return self.mean_ff_result
62
63
64