Compute the winning vector by Euclidean distance >>> SelfOrganizingMap().get_winner([[1, 2, 3], [4, 5, 6]], [1, 2, 3]) 1
(self, weights: list[list[float]], sample: list[int])
| 7 | |
| 8 | class SelfOrganizingMap: |
| 9 | def get_winner(self, weights: list[list[float]], sample: list[int]) -> int: |
| 10 | """ |
| 11 | Compute the winning vector by Euclidean distance |
| 12 | |
| 13 | >>> SelfOrganizingMap().get_winner([[1, 2, 3], [4, 5, 6]], [1, 2, 3]) |
| 14 | 1 |
| 15 | """ |
| 16 | d0 = 0.0 |
| 17 | d1 = 0.0 |
| 18 | for i in range(len(sample)): |
| 19 | d0 += math.pow((sample[i] - weights[0][i]), 2) |
| 20 | d1 += math.pow((sample[i] - weights[1][i]), 2) |
| 21 | return 0 if d0 > d1 else 1 |
| 22 | return 0 |
| 23 | |
| 24 | def update( |
| 25 | self, weights: list[list[int | float]], sample: list[int], j: int, alpha: float |