





import math


class 					__a      :

							def     UpperCAmelCase__	(							self							:     str       ,     __magic_name__							:     list[list[float]]       ,     __magic_name__							:     list[int]   )					->       int:







													"""simple docstring"""
													UpperCAmelCase_			:      str     						=  0.0
													UpperCAmelCase_			:      Tuple     						=  0.0
													for i in range(len(__magic_name__   )   ):
																			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							:     str       ,     __magic_name__							:     list[list[int | float]]       ,     __magic_name__							:     list[int]       ,     __magic_name__							:     int       ,     __magic_name__							:     float   )					->       list[list[int | float]]:







													"""simple docstring"""
													for i in range(len(__magic_name__   )   ):
																			weights[j][i] += alpha * (sample[i] - weights[j][i])
													return weights





def        lowerCamelCase_      (  ) ->	None:
						# Training Examples ( m, n )
						UpperCAmelCase_			:      Dict     						=  [[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

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

						# training
						UpperCAmelCase_			:      int     						=  SelfOrganizingMap()
						UpperCAmelCase_			:      Optional[int]     						=  3
						UpperCAmelCase_			:      Optional[Any]     						=  0.5

						for _ in range(SCREAMING_SNAKE_CASE__   ):
												for j in range(len(SCREAMING_SNAKE_CASE__   )   ):
																		# training sample
																		UpperCAmelCase_			:      List[Any]     						=  training_samples[j]

																		# Compute the winning vector
																		UpperCAmelCase_			:      Tuple     						=  self_organizing_map.get_winner(SCREAMING_SNAKE_CASE__,			SCREAMING_SNAKE_CASE__   )

																		# Update the winning vector
																		UpperCAmelCase_			:      int     						=  self_organizing_map.update(SCREAMING_SNAKE_CASE__,			SCREAMING_SNAKE_CASE__,			SCREAMING_SNAKE_CASE__,			SCREAMING_SNAKE_CASE__   )

    # classify test sample
						UpperCAmelCase_			:      List[str]     						=  [0, 0, 0, 1]
						UpperCAmelCase_			:      List[str]     						=  self_organizing_map.get_winner(SCREAMING_SNAKE_CASE__,			SCREAMING_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()












'''simple docstring'''







def        lowerCamelCase_      (  SCREAMING_SNAKE_CASE__      :			list[int]   ) ->	list[list[int]]:
						UpperCAmelCase_			:      int     						=  []
						if len(SCREAMING_SNAKE_CASE__   ) == 1:
												return [nums.copy()]
						for _ in range(len(SCREAMING_SNAKE_CASE__   )   ):
												UpperCAmelCase_			:      List[Any]     						=  nums.pop(0   )
												UpperCAmelCase_			:      Optional[Any]     						=  permute(SCREAMING_SNAKE_CASE__   )
												for perm in permutations:
																		perm.append(SCREAMING_SNAKE_CASE__   )
												result.extend(SCREAMING_SNAKE_CASE__   )
												nums.append(SCREAMING_SNAKE_CASE__   )
						return result





def        lowerCamelCase_      (  SCREAMING_SNAKE_CASE__      :			List[str]   ) ->	Any:

						def backtrack(SCREAMING_SNAKE_CASE__      :			Union[str, Any]   ):
												if start == len(SCREAMING_SNAKE_CASE__   ) - 1:
																		output.append(nums[:]   )
												else:
																		for i in range(SCREAMING_SNAKE_CASE__,			len(SCREAMING_SNAKE_CASE__   )   ):
																								UpperCAmelCase_						,       UpperCAmelCase_			:      Tuple     						=  nums[i], nums[start]
																								backtrack(start + 1   )
																								UpperCAmelCase_						,       UpperCAmelCase_			:      int     						=  nums[i], nums[start]  # backtrack

						UpperCAmelCase_			:      Optional[int]     						=  []
						backtrack(0   )
						return output


if __name__ == "__main__":
					import doctest

					# use res to print the data in permute2 function
					snake_case_     :       Tuple						=  permutea([1, 2, 3])
					print(res)
					doctest.testmod()





