| 1 |  |  | """Represents swarm.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 | 1 |  | import numpy as np | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 | 1 |  | from grortir.main.pso.particle import Particle | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 | 1 |  | class Swarm(object): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |     """Class which represent swarm.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 | 1 |  |     def __init__(self, process, stages, number_of_particles): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 | 1 |  |         self.stages = stages | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 | 1 |  |         self.process = process | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 | 1 |  |         self.number_of_particles = number_of_particles | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 | 1 |  |         self.particles = [Particle(stages, self.process, i) for i in | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |                           range(number_of_particles)] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 | 1 |  |         self.best_particle_quality = np.inf | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 | 1 |  |         self.best_particle = self.particles[0] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 | 1 |  |     def initialize(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         """Initialize all particles in swarm.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 | 1 |  |         for particle in self.particles: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 | 1 |  |             particle.initialize() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 | 1 |  |     def do_single_iteration(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         """Iterate one time.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 | 1 |  |         for particle in self.particles: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 | 1 |  |             particle.update_values() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 | 1 |  |         self._update_best_particle() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 | 1 |  |         self._update_velocieties() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 | 1 |  |         for particle in self.particles: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 1 |  |             particle.move() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 | 1 |  |     def _update_best_particle(self): | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 | 1 |  |         for particle in self.particles: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 1 |  |             if particle.best_quality < self.best_particle_quality: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 1 |  |                 self.best_particle = particle | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 1 |  |                 self.best_particle_quality = particle.best_quality | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 39 | 1 |  |     def _update_velocieties(self): | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 40 | 1 |  |         for particle in self.particles: | 
            
                                                                        
                            
            
                                    
            
            
                | 41 | 1 |  |             particle.update_velocities(self.best_particle) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 1 |  |     def post_processing(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         """Method which should be done after all iterations.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 1 |  |         best_control_params = self.best_particle.best_positions | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         # calculate output: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 1 |  |         for stage in self.stages: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 1 |  |             current_output = stage.get_output_of_stage( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |                 stage.input_vector, best_control_params[stage]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 1 |  |             successors = self.process.successors(stage) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 1 |  |             for successor in successors: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 1 |  |                 successor.input_vector = current_output | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 1 |  |             stage.final_output = current_output | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 1 |  |             stage.final_cost = stage.get_cost() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 1 |  |             stage.final_quality = stage.get_quality( | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 56 |  |  |                 stage.input_vector, best_control_params[stage]) | 
            
                                                        
            
                                    
            
            
                | 57 |  |  |  | 
            
                        
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.
2. Missing __init__.py files
This error could also result from missing
__init__.pyfiles in your module folders. Make sure that you place one file in each sub-folder.