import math
class     lowerCAmelCase_     :







							def  UpperCamelCase_						(   self      :     Dict ,			_A      :     list[list[float]] ,			_A      :     list[int]		):
												_UpperCamelCase			     =     0.0
												_UpperCamelCase			     =     0.0
												for i in range(len(_A		)		):
																	da += math.pow((sample[i] - weights[0][i]) ,			2		)
																	da += math.pow((sample[i] - weights[1][i]) ,			2		)
																	return 0 if da > da else 1
												return 0







							def  UpperCamelCase_						(   self      :     Optional[Any] ,			_A      :     list[list[int | float]] ,			_A      :     list[int] ,			_A      :     int ,			_A      :     float		):
												for i in range(len(_A		)		):
																	weights[j][i] += alpha * (sample[i] - weights[j][i])
												return weights




def 					_snake_case	(  ):
					# Training Examples ( m, n )
					_UpperCamelCase			     =     [[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

					# weight initialization ( n, C )
					_UpperCamelCase			     =     [[0.2, 0.6, 0.5, 0.9], [0.8, 0.4, 0.7, 0.3]]

					# training
					_UpperCamelCase			     =     SelfOrganizingMap()
					_UpperCamelCase			     =     3
					_UpperCamelCase			     =     0.5

					for _ in range(__snake_case						):
										for j in range(len(__snake_case						)						):
															# training sample
															_UpperCamelCase			     =     training_samples[j]

															# Compute the winning vector
															_UpperCamelCase			     =     self_organizing_map.get_winner(__snake_case  ,     __snake_case						)

															# Update the winning vector
															_UpperCamelCase			     =     self_organizing_map.update(__snake_case  ,     __snake_case  ,     __snake_case  ,     __snake_case						)

    # classify test sample
					_UpperCamelCase			     =     [0, 0, 0, 1]
					_UpperCamelCase			     =     self_organizing_map.get_winner(__snake_case  ,     __snake_case						)

					# results
					print(f"""Clusters that the test sample belongs to : {winner}"""						)
					print(f"""Weights that have been trained : {weights}"""						)


# running the main() function
if __name__ == "__main__":
					main()

import math
class     lowerCAmelCase_     :







							def __init__(   self      :     Tuple ,			_A      :     int=0		):  # a graph with Node 0,1,...,N-1
												_UpperCamelCase			     =     n
												_UpperCamelCase			     =     [
												    [math.inf for j in range(0 ,			_A		)] for i in range(0 ,			_A		)
												]  # adjacency matrix for weight
												_UpperCamelCase			     =     [
												    [math.inf for j in range(0 ,			_A		)] for i in range(0 ,			_A		)
												]  # dp[i][j] stores minimum distance from i to j







							def  UpperCamelCase_						(   self      :     Dict ,			_A      :     str ,			_A      :     List[str] ,			_A      :     Optional[Any]		):
												_UpperCamelCase			     =     w







							def  UpperCamelCase_						(   self      :     Optional[int]		):
												for k in range(0 ,			self.n		):
																	for i in range(0 ,			self.n		):
																						for j in range(0 ,			self.n		):
																											_UpperCamelCase			     =     min(self.dp[i][j] ,			self.dp[i][k] + self.dp[k][j]		)







							def  UpperCamelCase_						(   self      :     List[str] ,			_A      :     Optional[int] ,			_A      :     Optional[int]		):
												return self.dp[u][v]


if __name__ == "__main__":
					_lowerCAmelCase       =		Graph(5)
					graph.add_edge(0, 2, 9)
					graph.add_edge(0, 4, 10)
					graph.add_edge(1, 3, 5)
					graph.add_edge(2, 3, 7)
					graph.add_edge(3, 0, 10)
					graph.add_edge(3, 1, 2)
					graph.add_edge(3, 2, 1)
					graph.add_edge(3, 4, 6)
					graph.add_edge(4, 1, 3)
					graph.add_edge(4, 2, 4)
					graph.add_edge(4, 3, 9)
					graph.floyd_warshall()
					graph.show_min(1, 4)
					graph.show_min(0, 3)
