





import math


class   A      :
			'''simple docstring'''




			def        a_	(      self       :   Optional[int]							,     __lowerCAmelCase       :   list[list[float]]							,     __lowerCAmelCase       :   list[int]       )     ->     List[Any]:







					"""simple docstring"""






					A__  				=       0.0
					A__  				=       0.0
					for i in range(len(UpperCAmelCase_       )       ):
							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       :   Dict							,     __lowerCAmelCase       :   list[list[int | float]]							,     __lowerCAmelCase       :   list[int]							,     __lowerCAmelCase       :   int							,     __lowerCAmelCase       :   float       )     ->     Tuple:







					"""simple docstring"""






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







def        __lowerCamelCase (							)		->    List[str]:






		"""simple docstring"""

		A__  				=       [[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

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

		# training
		A__  				=       SelfOrganizingMap()
		A__  				=       3
		A__  				=       0.5

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

						# Compute the winning vector
						A__  				=       self_organizing_map.get_winner(_UpperCAmelCase   ,					_UpperCAmelCase   )

						# Update the winning vector
						A__  				=       self_organizing_map.update(_UpperCAmelCase   ,					_UpperCAmelCase   ,					_UpperCAmelCase   ,					_UpperCAmelCase   )

    # classify test sample
		A__  				=       [0, 0, 0, 1]
		A__  				=       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()










def        __lowerCamelCase (							__a       :float   ,					__a       :list[float]   )		->    float:






		"""simple docstring"""

		if discount_rate < 0:
				raise ValueError("""Discount rate cannot be negative"""   )
		if not cash_flows:
				raise ValueError("""Cash flows list cannot be empty"""   )
		A__  				=       sum(
		    cash_flow / ((1 + discount_rate) ** i) for i, cash_flow in enumerate(__a   )   )
		return round(__a   ,					ndigits=2   )


if __name__ == "__main__":
					import doctest

					doctest.testmod()



