
"""simple docstring"""




import math


class 			__magic_name__       :
       def 							lowercase_							(     self ,				A_ ,				A_       )     ->	int:





         """simple docstring"""




         _lowercase:			Optional[Any]       =     0.0
         _lowercase:			Union[str, Any]       =     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 							lowercase_							(     self ,				A_ ,				A_ ,				A_ ,				A_       )     ->	list[list[int | float]]:





         """simple docstring"""




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




def  _lowerCAmelCase		(		):






  """simple docstring"""



  _lowercase:			Optional[Any]       =     [[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

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

  # training
  _lowercase:			Union[str, Any]       =     SelfOrganizingMap()
  _lowercase:			int       =     3
  _lowercase:			Dict       =     0.5

  for _ in range(_UpperCamelCase						):
    for j in range(len(_UpperCamelCase						)						):
      # training sample
      _lowercase:			str       =     training_samples[j]

      # Compute the winning vector
      _lowercase:			Union[str, Any]       =     self_organizing_map.get_winner(_UpperCamelCase ,				_UpperCamelCase						)

      # Update the winning vector
      _lowercase:			Any       =     self_organizing_map.update(_UpperCamelCase ,				_UpperCamelCase ,				_UpperCamelCase ,				_UpperCamelCase						)

    # classify test sample
  _lowercase:			Dict       =     [0, 0, 0, 1]
  _lowercase:			List[str]       =     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"""




def  _lowerCAmelCase		(		_UpperCamelCase						):






  """simple docstring"""



  if not isinstance(_UpperCamelCase ,				_UpperCamelCase						):
    raise ValueError('''Input series is not valid, valid series - [2, 4, 6]'''						)
  if len(_UpperCamelCase						) == 0:
    raise ValueError('''Input list must be a non empty list'''						)
  if len(_UpperCamelCase						) == 1:
    return True
  _lowercase:			Any       =     series[1] - series[0]
  for index in range(len(_UpperCamelCase						) - 1						):
    if series[index + 1] - series[index] != common_diff:
      return False
  return True




def  _lowerCAmelCase		(		_UpperCamelCase						):






  """simple docstring"""



  if not isinstance(_UpperCamelCase ,				_UpperCamelCase						):
    raise ValueError('''Input series is not valid, valid series - [2, 4, 6]'''						)
  if len(_UpperCamelCase						) == 0:
    raise ValueError('''Input list must be a non empty list'''						)
  _lowercase:			Tuple       =     0
  for val in series:
    answer += val
  return answer / len(_UpperCamelCase						)


if __name__ == "__main__":
  import doctest

  doctest.testmod()
