
import math
class 			UpperCamelCase      :
     def 				__SCREAMING_SNAKE_CASE							(     self  ,     snake_case__  ,     snake_case__				):




       """simple docstring"""


       _SCREAMING_SNAKE_CASE   :				Tuple							    = 0.0
       _SCREAMING_SNAKE_CASE   :				int							    = 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 				__SCREAMING_SNAKE_CASE							(     self  ,     snake_case__  ,     snake_case__  ,     snake_case__  ,     snake_case__				):




       """simple docstring"""


       for i in range(len(_a				)				):
         weights[j][i] += alpha * (sample[i] - weights[j][i])
       return weights





def    _lowerCAmelCase    (     )  ->    None:
  # Training Examples ( m, n )
  _SCREAMING_SNAKE_CASE   :				Any							    = [[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

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

  # training
  _SCREAMING_SNAKE_CASE   :				str							    = SelfOrganizingMap()
  _SCREAMING_SNAKE_CASE   :				Union[str, Any]							    = 3
  _SCREAMING_SNAKE_CASE   :				Tuple							    = 0.5

  for _ in range(lowerCAmelCase__				):
    for j in range(len(lowerCAmelCase__				)				):
      # training sample
      _SCREAMING_SNAKE_CASE   :				Tuple							    = training_samples[j]

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

      # Update the winning vector
      _SCREAMING_SNAKE_CASE   :				List[Any]							    = self_organizing_map.update(lowerCAmelCase__,						lowerCAmelCase__,						lowerCAmelCase__,						lowerCAmelCase__				)

    # classify test sample
  _SCREAMING_SNAKE_CASE   :				Dict							    = [0, 0, 0, 1]
  _SCREAMING_SNAKE_CASE   :				int							    = self_organizing_map.get_winner(lowerCAmelCase__,						lowerCAmelCase__				)

  # 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 __future__ import annotations

import time
from collections.abc import Sequence
from random import randint

from matplotlib import pyplot as plt





def    _lowerCAmelCase    (     lowerCamelCase__							:							Sequence[float],						lowerCamelCase__							:							int,						lowerCamelCase__							:							int				)  ->    tuple[int | None, int | None, float]:
  if not arr:
    return None, None, 0
  if low == high:
    return low, high, arr[low]

  _SCREAMING_SNAKE_CASE   :				Any							    = (low + high) // 2
  _SCREAMING_SNAKE_CASE    ,		_SCREAMING_SNAKE_CASE    ,		_SCREAMING_SNAKE_CASE   :				Optional[int]							    = max_subarray(lowerCamelCase__,						lowerCamelCase__,						lowerCamelCase__				)
  _SCREAMING_SNAKE_CASE    ,		_SCREAMING_SNAKE_CASE    ,		_SCREAMING_SNAKE_CASE   :				List[str]							    = max_subarray(lowerCamelCase__,						mid + 1,						lowerCamelCase__				)
  _SCREAMING_SNAKE_CASE    ,		_SCREAMING_SNAKE_CASE    ,		_SCREAMING_SNAKE_CASE   :				str							    = max_cross_sum(lowerCamelCase__,						lowerCamelCase__,						lowerCamelCase__,						lowerCamelCase__				)
  if left_sum >= right_sum and left_sum >= cross_sum:
    return left_low, left_high, left_sum
  elif right_sum >= left_sum and right_sum >= cross_sum:
    return right_low, right_high, right_sum
  return cross_left, cross_right, cross_sum





def    _lowerCAmelCase    (     lowerCamelCase__							:							Sequence[float],						lowerCamelCase__							:							int,						lowerCamelCase__							:							int,						lowerCamelCase__							:							int				)  ->    tuple[int, int, float]:
  _SCREAMING_SNAKE_CASE    ,		_SCREAMING_SNAKE_CASE   :				List[Any]							    = float("-inf"				), -1
  _SCREAMING_SNAKE_CASE    ,		_SCREAMING_SNAKE_CASE   :				Dict							    = float("-inf"				), -1

  _SCREAMING_SNAKE_CASE   :				int | float							    = 0
  for i in range(lowerCamelCase__,						low - 1,						-1				):
    summ += arr[i]
    if summ > left_sum:
      _SCREAMING_SNAKE_CASE   :				int							    = summ
      _SCREAMING_SNAKE_CASE   :				Tuple							    = i

  _SCREAMING_SNAKE_CASE   :				Union[str, Any]							    = 0
  for i in range(mid + 1,						high + 1				):
    summ += arr[i]
    if summ > right_sum:
      _SCREAMING_SNAKE_CASE   :				int							    = summ
      _SCREAMING_SNAKE_CASE   :				Any							    = i

  return max_left, max_right, (left_sum + right_sum)





def    _lowerCAmelCase    (     lowerCamelCase__							:							int				)  ->    float:
  _SCREAMING_SNAKE_CASE   :				Any							    = [randint(1,						lowerCamelCase__				) for _ in range(lowerCamelCase__				)]
  _SCREAMING_SNAKE_CASE   :				int							    = time.time()
  max_subarray(lowerCamelCase__,						0,						input_size - 1				)
  _SCREAMING_SNAKE_CASE   :				List[str]							    = time.time()
  return end - start





def    _lowerCAmelCase    (     )  ->    None:
  _SCREAMING_SNAKE_CASE   :				Union[str, Any]							    = [1_0, 1_0_0, 1_0_0_0, 1_0_0_0_0, 5_0_0_0_0, 1_0_0_0_0_0, 2_0_0_0_0_0, 3_0_0_0_0_0, 4_0_0_0_0_0, 5_0_0_0_0_0]
  _SCREAMING_SNAKE_CASE   :				int							    = [time_max_subarray(lowerCamelCase__				) for input_size in input_sizes]
  print("No of Inputs\t\tTime Taken"				)
  for input_size, runtime in zip(lowerCamelCase__,						lowerCamelCase__				):
    print(lowerCamelCase__,						"\t\t",						lowerCamelCase__				)
  plt.plot(lowerCamelCase__,						lowerCamelCase__				)
  plt.xlabel("Number of Inputs"				)
  plt.ylabel("Time taken in seconds"				)
  plt.show()


if __name__ == "__main__":
      from doctest import testmod

      testmod()



