MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / get_winner

Method get_winner

machine_learning/self_organizing_map.py:9–22  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

7
8class 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

Callers 1

mainFunction · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected