

"""simple docstring"""




import math







class   __lowercase      :

  def  __lowercase							(	self		:      Any       ,A		:      list[list[float]]       ,A		:      list[int]     ):






   '''simple docstring'''
   UpperCAmelCase__       :	List[Any]        =       0.0
   UpperCAmelCase__       :	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		:      Union[str, Any]       ,A		:      list[list[int | float]]       ,A		:      list[int]       ,A		:      int       ,A		:      float     ):






   '''simple docstring'''
   for i in range(len(A     )     ):
    weights[j][i] += alpha * (sample[i] - weights[j][i])
   return weights







def 	lowerCAmelCase    (       ):
 '''simple docstring'''





 UpperCAmelCase__       :	int        =       [[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

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

 # training
 UpperCAmelCase__       :	int        =       SelfOrganizingMap()
 UpperCAmelCase__       :	Any        =       3
 UpperCAmelCase__       :	Optional[int]        =       0.5

 for _ in range(__UpperCamelCase   ):
  for j in range(len(__UpperCamelCase   )   ):
   # training sample
   UpperCAmelCase__       :	int        =       training_samples[j]

   # Compute the winning vector
   UpperCAmelCase__       :	List[str]        =       self_organizing_map.get_winner(__UpperCamelCase				,     __UpperCamelCase   )

   # Update the winning vector
   UpperCAmelCase__       :	Optional[Any]        =       self_organizing_map.update(__UpperCamelCase				,     __UpperCamelCase				,     __UpperCamelCase				,     __UpperCamelCase   )

    # classify test sample
 UpperCAmelCase__       :	List[str]        =       [0, 0, 0, 1]
 UpperCAmelCase__       :	Optional[int]        =       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"""
from datetime import datetime

import matplotlib.pyplot as plt
import torch

def 				_snake_case      (   __snake_case							:      List[str]   ):




   """simple docstring"""







   for param in module.parameters():
      _lowerCamelCase	:					Optional[Any]   =		False

def 				_snake_case      (   ):




   """simple docstring"""







   _lowerCamelCase	:					Any   =		"""cuda""" if torch.cuda.is_available() else """cpu"""
   if torch.backends.mps.is_available() and torch.backends.mps.is_built():
      _lowerCamelCase	:					Any   =		"""mps"""
   if device == "mps":
      print(
          """WARNING: MPS currently doesn't seem to work, and messes up backpropagation without any visible torch"""
          """ errors. I recommend using CUDA on a colab notebook or CPU instead if you're facing inexplicable issues"""
          """ with generations."""   )
   return device

def 				_snake_case      (   __snake_case							:      Union[str, Any]   ):




   """simple docstring"""







   _lowerCamelCase	:					int   =		plt.imshow(__snake_case   )
   fig.axes.get_xaxis().set_visible(__snake_case   )
   fig.axes.get_yaxis().set_visible(__snake_case   )
   plt.show()





def 				_snake_case      (   ):




   """simple docstring"""







   _lowerCamelCase	:					Tuple   =		datetime.now()
   _lowerCamelCase	:					Optional[Any]   =		current_time.strftime("""%H:%M:%S"""   )
   return timestamp

