





'''simple docstring'''




import math






class 				__snake_case     :





	def   _snake_case   (		self      ,       UpperCamelCase_      ,       UpperCamelCase_		)      ->		int:
		snake_case__	       =   0.0
		snake_case__	       =   0.0
		for i in range(len(UpperCamelCase_		)		):
			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   _snake_case   (		self      ,       UpperCamelCase_      ,       UpperCamelCase_      ,       UpperCamelCase_      ,       UpperCamelCase_		)      ->		list[list[int | float]]:
		for i in range(len(UpperCamelCase_		)		):
			weights[j][i] += alpha * (sample[i] - weights[j][i])
		return weights





def 						__lowerCamelCase			(	)   ->None:
	# Training Examples ( m, n )
	snake_case__	       =   [[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

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

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

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

			# Compute the winning vector
			snake_case__	       =   self_organizing_map.get_winner(UpperCAmelCase_					,				UpperCAmelCase_							)

			# Update the winning vector
			snake_case__	       =   self_organizing_map.update(UpperCAmelCase_					,				UpperCAmelCase_					,				UpperCAmelCase_					,				UpperCAmelCase_							)

    # classify test sample
	snake_case__	       =   [0, 0, 0, 1]
	snake_case__	       =   self_organizing_map.get_winner(UpperCAmelCase_					,				UpperCAmelCase_							)

	# 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'''




from math import loga




def 						__lowerCamelCase			(	UpperCAmelCase_							)   ->int:
	if a < 0:
		raise ValueError('Input value must be a positive integer'							)
	elif isinstance(UpperCAmelCase_					,				UpperCAmelCase_							):
		raise TypeError('Input value must be a \'int\' type'							)
	return 0 if (a == 0) else int(loga(a & -a							)							)


if __name__ == "__main__":
			import doctest

			doctest.testmod()



