"""simple docstring"""


from __future__ import annotations

import math

import numpy as np
from numpy.linalg import norm






def 			__UpperCAmelCase    (	lowercase      ,lowercase						):







  """simple docstring"""
  return math.sqrt(sum(pow(a - b      ,2						) for a, b in zip(lowercase      ,lowercase						)						)						)






def 			__UpperCAmelCase    (	lowercase      ,lowercase						):







  """simple docstring"""

  if dataset.ndim != value_array.ndim:
    _UpperCAmelCase         =					(
        """Wrong input data's dimensions... """
        f'''dataset : {dataset.ndim}, value_array : {value_array.ndim}'''
    )
    raise ValueError(lowercase						)

  try:
    if dataset.shape[1] != value_array.shape[1]:
      _UpperCAmelCase         =					(
          """Wrong input data's shape... """
          f'''dataset : {dataset.shape[1]}, value_array : {value_array.shape[1]}'''
      )
      raise ValueError(lowercase						)
  except IndexError:
    if dataset.ndim != value_array.ndim:
      raise TypeError("""Wrong shape"""						)

  if dataset.dtype != value_array.dtype:
    _UpperCAmelCase         =					(
        """Input data have different datatype... """
        f'''dataset : {dataset.dtype}, value_array : {value_array.dtype}'''
    )
    raise TypeError(lowercase						)

  _UpperCAmelCase         =					[]

  for value in value_array:
    _UpperCAmelCase         =					euclidean(lowercase      ,dataset[0]						)
    _UpperCAmelCase         =					dataset[0].tolist()

    for dataset_value in dataset[1:]:
      _UpperCAmelCase         =					euclidean(lowercase      ,lowercase						)

      if dist > temp_dist:
        _UpperCAmelCase         =					temp_dist
        _UpperCAmelCase         =					dataset_value.tolist()

    answer.append([vector, dist]						)

  return answer






def 			__UpperCAmelCase    (	lowercase      ,lowercase						):







  """simple docstring"""
  return np.dot(lowercase      ,lowercase						) / (norm(lowercase						) * norm(lowercase						))


if __name__ == "__main__":
    import doctest

    doctest.testmod()

"""simple docstring"""


import math


class 				a :


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






def 			__UpperCAmelCase    (	):







  """simple docstring"""
  # Training Examples ( m, n )
  _UpperCAmelCase         =					[[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

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

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

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

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

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

    # classify test sample
  _UpperCAmelCase         =					[0, 0, 0, 1]
  _UpperCAmelCase         =					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()
