


from __future__ import annotations

from collections.abc import Iterator
from typing import Any

class   A__ :







    """simple docstring"""

    def __init__(	self      , __snake_case   ):
         snake_case					=    data
         snake_case					=    None






class   A__ :







    """simple docstring"""

    def __init__(	self   ):
         snake_case					=    None
         snake_case					=    None
    def __iter__(	self   ):
         snake_case					=    self.head
         while self.head:
              yield node.data
              snake_case					=    node.next
              if node == self.head:
                   break
    def __len__(	self   ):
         return sum(1 for _ in self   )
    def __repr__(	self   ):
         return "->".join(str(__snake_case   ) for item in iter(self   )   )
    def 		a_      (	self      , __snake_case   ):
         self.insert_nth(len(self   )      , __snake_case   )
    def 		a_      (	self      , __snake_case   ):
         self.insert_nth(0      , __snake_case   )
    def 		a_      (	self      , __snake_case      , __snake_case   ):
         if index < 0 or index > len(self   ):
              raise IndexError('''list index out of range.'''   )
         snake_case					=    Node(__snake_case   )
         if self.head is None:
              snake_case					=    new_node  # first node points itself
              snake_case					=    snake_case					=    new_node
         elif index == 0:  # insert at head
              snake_case					=    self.head
              snake_case					=    snake_case					=    new_node
         else:
              snake_case					=    self.head
              for _ in range(index - 1   ):
                   snake_case					=    temp.next
              snake_case					=    temp.next
              snake_case					=    new_node
              if index == len(self   ) - 1:  # insert at tail
                   snake_case					=    new_node
    def 		a_      (	self   ):
         return self.delete_nth(0   )
    def 		a_      (	self   ):
         return self.delete_nth(len(self   ) - 1   )
    def 		a_      (	self      , __snake_case = 0   ):
         if not 0 <= index < len(self   ):
              raise IndexError('''list index out of range.'''   )
         snake_case					=    self.head
         if self.head == self.tail:  # just one node
              snake_case					=    snake_case					=    None
         elif index == 0:  # delete head node
              snake_case					=    self.tail.next.next
              snake_case					=    self.head.next
         else:
              snake_case					=    self.head
              for _ in range(index - 1   ):
                   snake_case					=    temp.next
              snake_case					=    temp.next
              snake_case					=    temp.next.next
              if index == len(self   ) - 1:  # delete at tail
                   snake_case					=    temp
         return delete_node.data




    def 		a_      (	self   ):
         return len(self   ) == 0






def       UpperCAmelCase__						():



     """simple docstring"""






     snake_case					=    CircularLinkedList()
     assert len(UpperCamelCase_    ) == 0
     assert circular_linked_list.is_empty() is True
     assert str(UpperCamelCase_    ) == ""

     try:
          circular_linked_list.delete_front()
          raise AssertionError  # This should not happen
     except IndexError:
          assert True  # This should happen

     try:
          circular_linked_list.delete_tail()
          raise AssertionError  # This should not happen
     except IndexError:
          assert True  # This should happen

     try:
          circular_linked_list.delete_nth(-1    )
          raise AssertionError
     except IndexError:
          assert True

     try:
          circular_linked_list.delete_nth(0    )
          raise AssertionError
     except IndexError:
          assert True

     assert circular_linked_list.is_empty() is True
     for i in range(5    ):
          assert len(UpperCamelCase_    ) == i
          circular_linked_list.insert_nth(UpperCamelCase_							,i + 1    )
     assert str(UpperCamelCase_    ) == "->".join(str(UpperCamelCase_    ) for i in range(1							,6    )    )

     circular_linked_list.insert_tail(6    )
     assert str(UpperCamelCase_    ) == "->".join(str(UpperCamelCase_    ) for i in range(1							,7    )    )
     circular_linked_list.insert_head(0    )
     assert str(UpperCamelCase_    ) == "->".join(str(UpperCamelCase_    ) for i in range(0							,7    )    )

     assert circular_linked_list.delete_front() == 0
     assert circular_linked_list.delete_tail() == 6
     assert str(UpperCamelCase_    ) == "->".join(str(UpperCamelCase_    ) for i in range(1							,6    )    )
     assert circular_linked_list.delete_nth(2    ) == 3

     circular_linked_list.insert_nth(2							,3    )
     assert str(UpperCamelCase_    ) == "->".join(str(UpperCamelCase_    ) for i in range(1							,6    )    )

     assert circular_linked_list.is_empty() is False


if __name__ == "__main__":
 import doctest

 doctest.testmod()








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()




