


"""simple docstring"""






import math




class 							A_      :


  def 							_lowercase					(			self:						Tuple							,__lowerCAmelCase:						list[list[float]]							,__lowerCAmelCase:						list[int]    ):







     '''simple docstring'''







     _lowerCamelCase   :				List[str]							=     0.0
     _lowerCamelCase   :				Optional[Any]							=     0.0
     for i in range(len(__lowerCAmelCase    )    ):
        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:						str							,__lowerCAmelCase:						list[list[int | float]]							,__lowerCAmelCase:						list[int]							,__lowerCAmelCase:						int							,__lowerCAmelCase:						float    ):







     '''simple docstring'''







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







def        lowerCamelCase_(		)    ->     None:
   '''simple docstring'''





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

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

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

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

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

         # Update the winning vector
         _lowerCamelCase   :				Dict							=     self_organizing_map.update(_lowerCamelCase			,		_lowerCamelCase			,		_lowerCamelCase			,		_lowerCamelCase       )

    # classify test sample
   _lowerCamelCase   :				Tuple							=     [0, 0, 0, 1]
   _lowerCamelCase   :				Union[str, Any]							=     self_organizing_map.get_winner(_lowerCamelCase			,		_lowerCamelCase       )

   # 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 __future__ import annotations

from typing import TypedDict
class 				__SCREAMING_SNAKE_CASE							(				_lowerCAmelCase  ):
      __a	       =42
      __a	       =42







def  __UpperCAmelCase						(					SCREAMING_SNAKE_CASE__:						str     )	->      list[str]:

   """simple docstring"""
   if not isinstance(SCREAMING_SNAKE_CASE__,       SCREAMING_SNAKE_CASE__     ):
      raise TypeError('The parameter s type must be str.'     )

   return [s[i:] + s[:i] for i in range(len(SCREAMING_SNAKE_CASE__     )     )]



def  __UpperCAmelCase						(					SCREAMING_SNAKE_CASE__:						str     )	->      BWTTransformDict:

   """simple docstring"""
   if not isinstance(SCREAMING_SNAKE_CASE__,       SCREAMING_SNAKE_CASE__     ):
      raise TypeError('The parameter s type must be str.'     )
   if not s:
      raise ValueError('The parameter s must not be empty.'     )

   __a					  =     all_rotations(SCREAMING_SNAKE_CASE__     )
   rotations.sort()  # sort the list of rotations in alphabetically order
   # make a string composed of the last char of each rotation
   __a					  =     {
       "bwt_string": "".join([word[-1] for word in rotations]     ),
       "idx_original_string": rotations.index(SCREAMING_SNAKE_CASE__     ),
   }
   return response



def  __UpperCAmelCase						(					SCREAMING_SNAKE_CASE__:						str,       SCREAMING_SNAKE_CASE__:						int     )	->      str:

   """simple docstring"""
   if not isinstance(SCREAMING_SNAKE_CASE__,       SCREAMING_SNAKE_CASE__     ):
      raise TypeError('The parameter bwt_string type must be str.'     )
   if not bwt_string:
      raise ValueError('The parameter bwt_string must not be empty.'     )
   try:
      __a					  =     int(SCREAMING_SNAKE_CASE__     )
   except ValueError:
      raise TypeError(
          'The parameter idx_original_string type must be int or passive'
          ' of cast to int.'     )
   if idx_original_string < 0:
      raise ValueError('The parameter idx_original_string must not be lower than 0.'     )
   if idx_original_string >= len(SCREAMING_SNAKE_CASE__     ):
      raise ValueError(
          'The parameter idx_original_string must be lower than' ' len(bwt_string).'     )

   __a					  =     [''] * len(SCREAMING_SNAKE_CASE__     )
   for _ in range(len(SCREAMING_SNAKE_CASE__     )     ):
      for i in range(len(SCREAMING_SNAKE_CASE__     )     ):
         __a					  =     bwt_string[i] + ordered_rotations[i]
      ordered_rotations.sort()
   return ordered_rotations[idx_original_string]


if __name__ == "__main__":
 __UpperCamelCase   :							Any         =   """Provide a string that I will generate its BWT transform: """
 __UpperCamelCase   :							Dict         =   input(entry_msg).strip()
 __UpperCamelCase   :							Optional[int]         =   bwt_transform(s)
 print(
     f"""Burrows Wheeler transform for string '{s}' results """
     f"""in '{result["bwt_string"]}'"""
 )
 __UpperCamelCase   :							Dict         =   reverse_bwt(result["""bwt_string"""], result["""idx_original_string"""])
 print(
     f"""Reversing Burrows Wheeler transform for entry '{result["bwt_string"]}' """
     f"""we get original string '{original_string}'"""
 )