





'''simple docstring'''







import unittest

import numpy as np






def  _lowerCamelCase				( lowercase						:      np.ndarray    ,							lowercase						:      np.ndarray    ,							lowercase						:      np.ndarray    ,							lowercase						:      np.ndarray | None = None    ,							)	->	np.ndarray:
				_a								= np.shape(lowercase						)
				_a								= np.shape(lowercase						)
				_a								= np.shape(lowercase						)

				if shape_a[0] != shape_b[0]:
								_a								= (
								    "Expected the same number of rows for A and B. "
								    F'Instead found A of size {shape_a} and B of size {shape_b}'
								)
								raise ValueError(lowercase						)

				if shape_b[1] != shape_c[1]:
								_a								= (
								    "Expected the same number of columns for B and C. "
								    F'Instead found B of size {shape_b} and C of size {shape_c}'
								)
								raise ValueError(lowercase						)

				_a								= pseudo_inv
				if a_inv is None:
								try:
												_a								= np.linalg.inv(lowercase						)
								except np.linalg.LinAlgError:
												raise ValueError(
												    "Input matrix A is not invertible. Cannot compute Schur complement."						)

				return mat_c - mat_b.T @ a_inv @ mat_b
class 				__SCREAMING_SNAKE_CASE  (unittest.TestCase      ):






				"""simple docstring"""







				def   UpperCamelCase__   (  self     :					int					):
								_a								= np.array([[1, 2, 1], [2, 1, 2], [3, 2, 4]]					)
								_a								= np.array([[0, 3], [3, 0], [2, 3]]					)
								_a								= np.array([[2, 1], [6, 3]]					)

								_a								= schur_complement(__a					,				__a					,				__a					)

								_a								= np.block([[a, b], [b.T, c]]					)

								_a								= np.linalg.det(__a					)
								_a								= np.linalg.det(__a					)
								_a								= np.linalg.det(__a					)

								self.assertAlmostEqual(__a					,				det_a * det_s					)




				def   UpperCamelCase__   (  self     :					str					):
								_a								= np.array([[1, 2, 1], [2, 1, 2], [3, 2, 4]]					)
								_a								= np.array([[0, 3], [3, 0], [2, 3]]					)
								_a								= np.array([[2, 1], [6, 3]]					)

								with self.assertRaises(__a					):
												schur_complement(__a					,				__a					,				__a					)




				def   UpperCamelCase__   (  self     :					Optional[int]					):
								_a								= np.array([[1, 2, 1], [2, 1, 2], [3, 2, 4]]					)
								_a								= np.array([[0, 3], [3, 0], [2, 3]]					)
								_a								= np.array([[2, 1, 3], [6, 3, 5]]					)

								with self.assertRaises(__a					):
												schur_complement(__a					,				__a					,				__a					)


if __name__ == "__main__":
					import doctest

					doctest.testmod()
					unittest.main()







'''simple docstring'''







import math
class 				__SCREAMING_SNAKE_CASE  :






				"""simple docstring"""







				def   UpperCamelCase__   (  self     :					List[str]					,				__a     :					list[list[float]]					,				__a     :					list[int]					):
								_a								= 0.0
								_a								= 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     :					List[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  _lowerCamelCase				( )	->	None:
				# Training Examples ( m, n )
				_a								= [[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

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

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

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

												# Compute the winning vector
												_a								= self_organizing_map.get_winner(lowercase    ,							lowercase						)

												# Update the winning vector
												_a								= self_organizing_map.update(lowercase    ,							lowercase    ,							lowercase    ,							lowercase						)

    # classify test sample
				_a								= [0, 0, 0, 1]
				_a								= self_organizing_map.get_winner(lowercase    ,							lowercase						)

				# 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()
