


from typing import List

from .keymap import KEYMAP, get_character
def       UpperCAmelCase__						(UpperCamelCase_    ):



     """simple docstring"""






     def decorator(UpperCamelCase_    ):
          snake_case					=    getattr(UpperCamelCase_							,'''handle_key'''							,[]    )
          handle += [key]
          setattr(UpperCamelCase_							,'''handle_key'''							,UpperCamelCase_    )
          return func

     return decorator
def       UpperCAmelCase__						(*UpperCamelCase_    ):



     """simple docstring"""






     def decorator(UpperCamelCase_    ):
          snake_case					=    getattr(UpperCamelCase_							,'''handle_key'''							,[]    )
          handle += keys
          setattr(UpperCamelCase_							,'''handle_key'''							,UpperCamelCase_    )
          return func

     return decorator

class   A__ (   snake_case__     ):







    """simple docstring"""

    def __new__(	cls      , __snake_case      , __snake_case      , __snake_case   ):
         snake_case					=    super().__new__(cls      , __snake_case      , __snake_case      , __snake_case   )
         if not hasattr(__snake_case      , '''key_handler'''   ):
              setattr(__snake_case      , '''key_handler'''      , {}   )
         setattr(__snake_case      , '''handle_input'''      , KeyHandler.handle_input   )

         for value in attrs.values():
              snake_case					=    getattr(__snake_case      , '''handle_key'''      , []   )
              for key in handled_keys:
                   snake_case					=    value
         return new_cls




    @staticmethod
    def 		a_      (	cls   ):
         snake_case					=    get_character()
         if char != KEYMAP["undefined"]:
              snake_case					=    ord(__snake_case   )
         snake_case					=    cls.key_handler.get(__snake_case   )
         if handler:
              snake_case					=    char
              return handler(cls   )
         else:
              return None






def       UpperCAmelCase__						(cls    ):



     """simple docstring"""






     return KeyHandler(cls.__name__							,cls.__bases__							,cls.__dict__.copy()    )








import math

class   A__ :







    """simple docstring"""

    def 		a_      (	self      , __snake_case      , __snake_case   ):
         snake_case					=    0.0
         snake_case					=    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 		a_      (	self      , __snake_case      , __snake_case      , __snake_case      , __snake_case   ):
         for i in range(len(__snake_case   )   ):
              weights[j][i] += alpha * (sample[i] - weights[j][i])
         return weights






def       UpperCAmelCase__						():



     """simple docstring"""






     snake_case					=    [[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

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

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

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

               # Compute the winning vector
               snake_case					=    self_organizing_map.get_winner(UpperCamelCase_							,UpperCamelCase_    )

               # Update the winning vector
               snake_case					=    self_organizing_map.update(UpperCamelCase_							,UpperCamelCase_							,UpperCamelCase_							,UpperCamelCase_    )

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




