




'''simple docstring'''



import math






class 							_a				:





       '''simple docstring'''






       def        UpperCamelCase_							(      self,							A,							A  ):







             '''simple docstring'''







             SCREAMING_SNAKE_CASE   :      Any    					=						0.0
             SCREAMING_SNAKE_CASE   :      int    					=						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        UpperCamelCase_							(      self,							A,							A,							A,							A  ):







             '''simple docstring'''







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




def   lowercase__(			):

      """simple docstring"""






      SCREAMING_SNAKE_CASE   :      str    					=						[[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

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

      # training
      SCREAMING_SNAKE_CASE   :      Optional[Any]    					=						SelfOrganizingMap()
      SCREAMING_SNAKE_CASE   :      List[Any]    					=						3
      SCREAMING_SNAKE_CASE   :      Union[str, Any]    					=						0.5

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

                  # Compute the winning vector
                  SCREAMING_SNAKE_CASE   :      Any    					=						self_organizing_map.get_winner(__UpperCamelCase      ,__UpperCamelCase    )

                  # Update the winning vector
                  SCREAMING_SNAKE_CASE   :      int    					=						self_organizing_map.update(__UpperCamelCase      ,__UpperCamelCase      ,__UpperCamelCase      ,__UpperCamelCase    )

    # classify test sample
      SCREAMING_SNAKE_CASE   :      Optional[Any]    					=						[0, 0, 0, 1]
      SCREAMING_SNAKE_CASE   :      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'''



class 							_a				:





       '''simple docstring'''






       def __init__(      self,							A  ):







             '''simple docstring'''







             SCREAMING_SNAKE_CASE   :      Tuple    					=						val
             SCREAMING_SNAKE_CASE   :      Any    					=						None
             SCREAMING_SNAKE_CASE   :      Union[str, Any]    					=						None







       def        UpperCamelCase_							(      self,							A  ):







             '''simple docstring'''







             if self.val:
                   if val < self.val:
                         if self.left is None:
                               SCREAMING_SNAKE_CASE   :      Optional[int]    					=						Node(A  )
                         else:
                               self.left.insert(A  )
                   elif val > self.val:
                         if self.right is None:
                               SCREAMING_SNAKE_CASE   :      int    					=						Node(A  )
                         else:
                               self.right.insert(A  )
             else:
                   SCREAMING_SNAKE_CASE   :      int    					=						val




def   lowercase__(			__UpperCamelCase:					Optional[int]      ,__UpperCamelCase:					List[str]    ):

      """simple docstring"""






      if root:
            inorder(root.left      ,__UpperCamelCase    )
            res.append(root.val    )
            inorder(root.right      ,__UpperCamelCase    )




def   lowercase__(			__UpperCamelCase:					List[Any]    ):

      """simple docstring"""






      if len(__UpperCamelCase    ) == 0:
            return arr
      SCREAMING_SNAKE_CASE   :      Optional[int]    					=						Node(arr[0]    )
      for i in range(1      ,len(__UpperCamelCase    )    ):
            root.insert(arr[i]    )
      # Traverse BST in order.
      SCREAMING_SNAKE_CASE   :      Dict    					=						[]
      inorder(__UpperCamelCase      ,__UpperCamelCase    )
      return res


if __name__ == "__main__":
      print(tree_sort([1_0, 1, 3, 2, 9, 1_4, 1_3]))


