


class   A__ (   snake_case__     ):







    """simple docstring"""

    pass






class   A__ (   snake_case__     ):







    """simple docstring"""

    pass






class   A__ :







    """simple docstring"""

    def __init__(	self   ):
         snake_case					=    [
             [],
             [],
             [],
         ]
    def 		a_      (	self      , __snake_case      , __snake_case   ):
         try:
              if len(self.queues[priority]   ) >= 1_0_0:
                   raise OverflowError('''Maximum queue size is 100'''   )
              self.queues[priority].append(__snake_case   )
         except IndexError:
              raise ValueError('''Valid priorities are 0, 1, and 2'''   )
    def 		a_      (	self   ):
         for queue in self.queues:
              if queue:
                   return queue.pop(0   )
         raise UnderFlowError('''All queues are empty'''   )




    def __str__(	self   ):
         return "\n".join(F'''Priority {i}: {q}''' for i, q in enumerate(self.queues   )   )






class   A__ :







    """simple docstring"""

    def __init__(	self   ):
         snake_case					=    []
    def 		a_      (	self      , __snake_case   ):
         if len(self.queue   ) == 1_0_0:
              raise OverFlowError('''Maximum queue size is 100'''   )
         self.queue.append(__snake_case   )
    def 		a_      (	self   ):
         if not self.queue:
              raise UnderFlowError('''The queue is empty'''   )
         else:
              snake_case					=    min(self.queue   )
              self.queue.remove(__snake_case   )
              return data




    def __str__(	self   ):
         return str(self.queue   )






def       UpperCAmelCase__						():



     """simple docstring"""






     snake_case					=    FixedPriorityQueue()
     fpq.enqueue(0							,10    )
     fpq.enqueue(1							,70    )
     fpq.enqueue(0							,1_00    )
     fpq.enqueue(2							,1    )
     fpq.enqueue(2							,5    )
     fpq.enqueue(1							,7    )
     fpq.enqueue(2							,4    )
     fpq.enqueue(1							,64    )
     fpq.enqueue(0							,1_28    )
     print(UpperCamelCase_    )
     print(fpq.dequeue()    )
     print(fpq.dequeue()    )
     print(fpq.dequeue()    )
     print(fpq.dequeue()    )
     print(fpq.dequeue()    )
     print(UpperCamelCase_    )
     print(fpq.dequeue()    )
     print(fpq.dequeue()    )
     print(fpq.dequeue()    )
     print(fpq.dequeue()    )
     print(fpq.dequeue()    )
def       UpperCAmelCase__						():



     """simple docstring"""






     snake_case					=    ElementPriorityQueue()
     epq.enqueue(10    )
     epq.enqueue(70    )
     epq.enqueue(1_00    )
     epq.enqueue(1    )
     epq.enqueue(5    )
     epq.enqueue(7    )
     epq.enqueue(4    )
     epq.enqueue(64    )
     epq.enqueue(1_28    )
     print(UpperCamelCase_    )
     print(epq.dequeue()    )
     print(epq.dequeue()    )
     print(epq.dequeue()    )
     print(epq.dequeue()    )
     print(epq.dequeue()    )
     print(UpperCamelCase_    )
     print(epq.dequeue()    )
     print(epq.dequeue()    )
     print(epq.dequeue()    )
     print(epq.dequeue()    )
     print(epq.dequeue()    )


if __name__ == "__main__":
 fixed_priority_queue()
 element_priority_queue()








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




