(self, init_position, H, max_iter=400, epsilon=0.001, dt=2.0)
| 28 | self.damping_factor = damping_factor |
| 29 | |
| 30 | def simulate(self, init_position, H, max_iter=400, epsilon=0.001, dt=2.0) -> None: |
| 31 | import numpy as np |
| 32 | |
| 33 | """ |
| 34 | Simulate the force-directed layout algorithm. |
| 35 | """ |
| 36 | position = init_position.copy() |
| 37 | velocity = np.zeros_like(position) |
| 38 | damping = 1.0 |
| 39 | for it in range(max_iter): |
| 40 | position, velocity, stop = self._step( |
| 41 | position, velocity, H, epsilon, damping, dt |
| 42 | ) |
| 43 | # np.save("./tmp/position_{}.npy".format(it), position) |
| 44 | # np.save("./tmp/velocity_{}.npy".format(it), velocity) |
| 45 | if stop: |
| 46 | break |
| 47 | damping *= self.damping_factor |
| 48 | return position |
| 49 | |
| 50 | def _step(self, position, velocity, H, epsilon, damping, dt): |
| 51 | import numpy as np |
no test coverage detected