Total Complexity | 3 |
Total Lines | 27 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | import numpy as np |
||
4 | class VelocityCalculator: |
||
5 | """Calculate Velocity fo single stage. |
||
6 | |||
7 | Attributes: |
||
8 | current_velocity (list) : list of coordinates of speed for current stage |
||
9 | """ |
||
10 | |||
11 | def __init__(self, stage): |
||
12 | self.stage = stage |
||
13 | self.C1 = 0.5 |
||
14 | self.C2 = 0.5 |
||
15 | self.w = 0.8 |
||
16 | self.current_velocity = None |
||
17 | |||
18 | def calculate_initial_velocity(self): |
||
19 | velocity = 0.02 * np.random.rand(len(self.stage.control_params)) - 0.01 |
||
20 | self.current_velocity = velocity |
||
21 | return velocity |
||
22 | |||
23 | def calculate(self, particle_best_position, leader_best_position): |
||
24 | velocity = self.w * self.current_velocity |
||
25 | + self.C1 * np.random.rand(len(self.stage.control_params)) * ( |
||
26 | leader_best_position - self.stage.control_params) |
||
27 | + self.C2 * np.random.rand(len(self.stage.control_params)) * ( |
||
28 | particle_best_position - self.stage.control_params) |
||
29 | self.current_velocity = velocity |
||
30 | return velocity |
||
31 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.