



"""simple docstring"""
from __future__ import annotations

from collections.abc import Callable
from typing import Any, Generic, TypeVar

__a      =				TypeVar("T")
class 				lowerCamelCase  (			Generic[T]				):






					'''simple docstring'''





					def __init__(       self:							Optional[int]						,     snake_case:							list[T]						,     snake_case:							Callable[[T, T], T]						)   ->	None:
											snake_case_ :Any | T						=			None

											snake_case_ :int						=			len(snake_case						)
											snake_case_ :list[T]						=			[any_type for _ in range(self.N						)] + arr
											snake_case_ :Union[str, Any]						=			fnc
											self.build()






					def    lowerCAmelCase_				(       self:							Tuple						)   ->	None:
											for p in range(self.N - 1						,     0						,     -1						):
																	snake_case_ :str						=			self.fn(self.st[p * 2]						,     self.st[p * 2 + 1]						)






					def    lowerCAmelCase_				(       self:							Optional[int]						,     snake_case:							int						,     snake_case:							T						)   ->	None:
											p += self.N
											snake_case_ :Tuple						=			v
											while p > 1:
																	snake_case_ :Any						=			p // 2
																	snake_case_ :str						=			self.fn(self.st[p * 2]						,     self.st[p * 2 + 1]						)






					def    lowerCAmelCase_				(       self:							str						,     snake_case:							int						,     snake_case:							int						)   ->	T | None:  # noqa: E741
											snake_case_,       snake_case_ :Tuple						=			l + self.N, r + self.N

											snake_case_ :T | None						=			None
											while l <= r:
																	if l % 2 == 1:
																							snake_case_ :Tuple						=			self.st[l] if res is None else self.fn(snake_case						,     self.st[l]						)
																	if r % 2 == 0:
																							snake_case_ :Optional[Any]						=			self.st[r] if res is None else self.fn(snake_case						,     self.st[r]						)
																	snake_case_,       snake_case_ :Dict						=			(l + 1) // 2, (r - 1) // 2
											return res


if __name__ == "__main__":
						from functools import reduce

						__a      =				[1, 10, -2, 9, -3, 8, 4, -7, 5, 6, 11, -12]

						__a      =				{
						    0: 7,
						    1: 2,
						    2: 6,
						    3: -14,
						    4: 5,
						    5: 4,
						    6: 7,
						    7: -10,
						    8: 9,
						    9: 10,
						    10: 12,
						    11: 1,
						}

						__a      =				SegmentTree(test_array, min)
						__a      =				SegmentTree(test_array, max)
						__a      =				SegmentTree(test_array, lambda a, b: a + b)
						def    A_  (			):







												'''simple docstring'''


												for i in range(len(_lowercase	)	):
																		for j in range(_lowercase,					len(_lowercase	)	):
																								snake_case_ :Tuple						=			reduce(_lowercase,					test_array[i : j + 1]	)
																								snake_case_ :Union[str, Any]						=			reduce(_lowercase,					test_array[i : j + 1]	)
																								snake_case_ :Optional[Any]						=			reduce(lambda _lowercase,					_lowercase	: a + b,					test_array[i : j + 1]	)
																								assert min_range == min_segment_tree.query(_lowercase,					_lowercase	)
																								assert max_range == max_segment_tree.query(_lowercase,					_lowercase	)
																								assert sum_range == sum_segment_tree.query(_lowercase,					_lowercase	)

						test_all_segments()

						for index, value in test_updates.items():
												__a      =				value
												min_segment_tree.update(index, value)
												max_segment_tree.update(index, value)
												sum_segment_tree.update(index, value)
												test_all_segments()





"""simple docstring"""
import math
class 				lowerCamelCase  :






					'''simple docstring'''





					def    lowerCAmelCase_				(       self:							Tuple						,     snake_case:							list[list[float]]						,     snake_case:							list[int]						)   ->	int:
											snake_case_ :Any						=			0.0
											snake_case_ :Tuple						=			0.0
											for i in range(len(snake_case						)						):
																	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    lowerCAmelCase_				(       self:							Optional[int]						,     snake_case:							list[list[int | float]]						,     snake_case:							list[int]						,     snake_case:							int						,     snake_case:							float						)   ->	list[list[int | float]]:
											for i in range(len(snake_case						)						):
																	weights[j][i] += alpha * (sample[i] - weights[j][i])
											return weights

def    A_  (			):







						'''simple docstring'''


						snake_case_ :Dict						=			[[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

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

						# training
						snake_case_ :Optional[Any]						=			SelfOrganizingMap()
						snake_case_ :Dict						=			3
						snake_case_ :Dict						=			0.5

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

																		# Compute the winning vector
																		snake_case_ :Optional[int]						=			self_organizing_map.get_winner(_lowercase,					_lowercase	)

																		# Update the winning vector
																		snake_case_ :List[str]						=			self_organizing_map.update(_lowercase,					_lowercase,					_lowercase,					_lowercase	)

    # classify test sample
						snake_case_ :str						=			[0, 0, 0, 1]
						snake_case_ :List[Any]						=			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()
