from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tensorflow_text_available, is_torch_available


__lowerCamelCase					:	Tuple       =  {
    '''configuration_ernie''': ['''ERNIE_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''ErnieConfig''', '''ErnieOnnxConfig'''],
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__lowerCamelCase					:	List[Any]       =  [
		    '''ERNIE_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''ErnieForCausalLM''',
		    '''ErnieForMaskedLM''',
		    '''ErnieForMultipleChoice''',
		    '''ErnieForNextSentencePrediction''',
		    '''ErnieForPreTraining''',
		    '''ErnieForQuestionAnswering''',
		    '''ErnieForSequenceClassification''',
		    '''ErnieForTokenClassification''',
		    '''ErnieModel''',
		    '''ErniePreTrainedModel''',
		]

if TYPE_CHECKING:
		from .configuration_ernie import ERNIE_PRETRAINED_CONFIG_ARCHIVE_MAP, ErnieConfig, ErnieOnnxConfig

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_ernie import (
				    ERNIE_PRETRAINED_MODEL_ARCHIVE_LIST,
				    ErnieForCausalLM,
				    ErnieForMaskedLM,
				    ErnieForMultipleChoice,
				    ErnieForNextSentencePrediction,
				    ErnieForPreTraining,
				    ErnieForQuestionAnswering,
				    ErnieForSequenceClassification,
				    ErnieForTokenClassification,
				    ErnieModel,
				    ErniePreTrainedModel,
				)

else:
		import sys

		__lowerCamelCase					:	List[str]       =  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)

"""simple docstring"""


import math


class 				a :


    def    lowerCAmelCase_     (    self		:     Tuple      , __lowerCAmelCase		:     list[list[float]]      , __lowerCAmelCase		:     list[int]    ):
      _UpperCAmelCase         =					0.0
      _UpperCAmelCase         =					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    lowerCAmelCase_     (    self		:     Union[str, Any]      , __lowerCAmelCase		:     list[list[int | float]]      , __lowerCAmelCase		:     list[int]      , __lowerCAmelCase		:     int      , __lowerCAmelCase		:     float    ):
      for i in range(len(__lowerCAmelCase    )    ):
        weights[j][i] += alpha * (sample[i] - weights[j][i])
      return weights






def 			__UpperCAmelCase    (	):







  """simple docstring"""
  # Training Examples ( m, n )
  _UpperCAmelCase         =					[[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

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

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

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

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

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

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