




import math




class 						__lowercase		:




      """simple docstring"""





      def      UpperCAmelCase				(				self    ,				A    ,				A     )		->    int:
         snake_case				:    Tuple           =	0.0
         snake_case				:    Dict           =	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     )		->    list[list[int | float]]:
         for i in range(len(A     )     ):
            weights[j][i] += alpha * (sample[i] - weights[j][i])
         return weights




def 						SCREAMING_SNAKE_CASE__ (   )  ->       None:
   # Training Examples ( m, n )
   snake_case				:    Any           =	[[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

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

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

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

         # Compute the winning vector
         snake_case				:    Tuple           =	self_organizing_map.get_winner(lowercase						,lowercase					)

         # Update the winning vector
         snake_case				:    int           =	self_organizing_map.update(lowercase						,lowercase						,lowercase						,lowercase					)

    # classify test sample
   snake_case				:    int           =	[0, 0, 0, 1]
   snake_case				:    Optional[int]           =	self_organizing_map.get_winner(lowercase						,lowercase					)

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











from math import pow




def 						SCREAMING_SNAKE_CASE__ (   lowercase						,lowercase						,lowercase						,lowercase						,lowercase						,)  ->       tuple[int, int]:
   if current_sum == needed_sum:
      # If the sum of the powers is equal to needed_sum, then we have a solution.
      solutions_count += 1
      return current_sum, solutions_count

   snake_case				:    Union[str, Any]           =	int(pow(lowercase						,lowercase					)					)
   if current_sum + i_to_n <= needed_sum:
      # If the sum of the powers is less than needed_sum, then continue adding powers.
      current_sum += i_to_n
      snake_case     , snake_case				:    List[Any]           =	backtrack(
          lowercase						,lowercase						,current_number + 1						,lowercase						,lowercase					)
      current_sum -= i_to_n
   if i_to_n < needed_sum:
      # If the power of i is less than needed_sum, then try with the next power.
      snake_case     , snake_case				:    str           =	backtrack(
          lowercase						,lowercase						,current_number + 1						,lowercase						,lowercase					)
   return current_sum, solutions_count




def 						SCREAMING_SNAKE_CASE__ (   lowercase						,lowercase					)  ->       int:
   if not (1 <= needed_sum <= 1000 and 2 <= power <= 10):
      raise ValueError(
          """Invalid input\n"""
          """needed_sum must be between 1 and 1000, power between 2 and 10."""					)

   return backtrack(lowercase						,lowercase						,1						,0						,0					)[1]  # Return the solutions_count


if __name__ == "__main__":
       import doctest

       doctest.testmod()





