| Total Complexity | 6 |
| Total Lines | 39 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
| 1 | """Contains things related to calculating velocity.""" |
||
| 6 | 1 | class VelocityCalculator: |
|
| 7 | """Calculate Velocity for single stage. |
||
| 8 | |||
| 9 | Attributes: |
||
| 10 | current_velocity (list) : list of coordinates of speed for current stage |
||
| 11 | """ |
||
| 12 | |||
| 13 | 1 | def __init__(self, stage): |
|
| 14 | 1 | self.stage = stage |
|
| 15 | 1 | self.c_1 = 0.5 |
|
| 16 | 1 | self.c_2 = 0.5 |
|
| 17 | 1 | self.w_factor = 0.8 |
|
| 18 | 1 | self.current_velocity = None |
|
| 19 | |||
| 20 | 1 | def calculate_initial_velocity(self): |
|
| 21 | """Calculate initial velocity.""" |
||
| 22 | 1 | velocity = 0.02 * np.random.rand(len(self.stage.control_params)) - 0.01 |
|
| 23 | 1 | self.current_velocity = velocity |
|
| 24 | 1 | return velocity |
|
| 25 | |||
| 26 | 1 | def calculate(self, particle_best_position, leader_best_position): |
|
| 27 | """Calculate velocity.""" |
||
| 28 | 1 | velocity = self._s0() + self.c_1 * self._s1( |
|
| 29 | leader_best_position) + self.c_2 * self._s2(particle_best_position) |
||
| 30 | 1 | self.current_velocity = velocity |
|
| 31 | 1 | return velocity |
|
| 32 | |||
| 33 | 1 | def _s2(self, particle_best_position): |
|
| 34 | 1 | return np.random.rand(len(self.stage.control_params)) * ( |
|
| 35 | np.asarray(particle_best_position) - np.asarray( |
||
| 36 | self.stage.control_params)) |
||
| 37 | |||
| 38 | 1 | def _s1(self, leader_best_position): |
|
| 39 | 1 | return np.random.rand(len(self.stage.control_params)) * ( |
|
| 40 | np.asarray(leader_best_position) - np.asarray( |
||
| 41 | self.stage.control_params)) |
||
| 42 | |||
| 43 | 1 | def _s0(self): |
|
| 44 | return self.w_factor * self.current_velocity |
||
| 45 |
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.