






import math




class 							_lowerCAmelCase:





       """simple docstring"""







       def      _a       (   self    ,     _lowerCamelCase    ,     _lowerCamelCase				):
         UpperCamelCase_:   int        =							0.0
         UpperCamelCase_:   Tuple        =							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      _a       (   self    ,     _lowerCamelCase    ,     _lowerCamelCase    ,     _lowerCamelCase    ,     _lowerCamelCase				):
         for i in range(len(_lowerCamelCase				)				):
           weights[j][i] += alpha * (sample[i] - weights[j][i])
         return weights







def     snake_case   ()			->							None:
  # Training Examples ( m, n )
  UpperCamelCase_:   List[str]        =							[[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

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

  # training
  UpperCamelCase_:   Dict        =							SelfOrganizingMap()
  UpperCamelCase_:   List[Any]        =							3
  UpperCamelCase_:   List[str]        =							0.5

  for _ in range(UpperCAmelCase__    ):
    for j in range(len(UpperCAmelCase__    )    ):
      # training sample
      UpperCamelCase_:   int        =							training_samples[j]

      # Compute the winning vector
      UpperCamelCase_:   Tuple        =							self_organizing_map.get_winner(UpperCAmelCase__      ,       UpperCAmelCase__    )

      # Update the winning vector
      UpperCamelCase_:   Union[str, Any]        =							self_organizing_map.update(UpperCAmelCase__      ,       UpperCAmelCase__      ,       UpperCAmelCase__      ,       UpperCAmelCase__    )

    # classify test sample
  UpperCamelCase_:   Dict        =							[0, 0, 0, 1]
  UpperCamelCase_:   Union[str, Any]        =							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()





from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tokenizers_available,
    is_torch_available,
    is_vision_available,
)


__magic_name__  :  Any					=       {
    """configuration_layoutlmv2""": ["""LAYOUTLMV2_PRETRAINED_CONFIG_ARCHIVE_MAP""", """LayoutLMv2Config"""],
    """processing_layoutlmv2""": ["""LayoutLMv2Processor"""],
    """tokenization_layoutlmv2""": ["""LayoutLMv2Tokenizer"""],
}

try:
      if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __magic_name__  :  List[str]					=       ["""LayoutLMv2TokenizerFast"""]

try:
      if not is_vision_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __magic_name__  :  Any					=       ["""LayoutLMv2FeatureExtractor"""]
      __magic_name__  :  Any					=       ["""LayoutLMv2ImageProcessor"""]

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __magic_name__  :  Any					=       [
          """LAYOUTLMV2_PRETRAINED_MODEL_ARCHIVE_LIST""",
          """LayoutLMv2ForQuestionAnswering""",
          """LayoutLMv2ForSequenceClassification""",
          """LayoutLMv2ForTokenClassification""",
          """LayoutLMv2Layer""",
          """LayoutLMv2Model""",
          """LayoutLMv2PreTrainedModel""",
      ]

if TYPE_CHECKING:
      from .configuration_layoutlmva import LAYOUTLMV2_PRETRAINED_CONFIG_ARCHIVE_MAP, LayoutLMvaConfig
      from .processing_layoutlmva import LayoutLMvaProcessor
      from .tokenization_layoutlmva import LayoutLMvaTokenizer

      try:
            if not is_tokenizers_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .tokenization_layoutlmva_fast import LayoutLMvaTokenizerFast

      try:
            if not is_vision_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .feature_extraction_layoutlmva import LayoutLMvaFeatureExtractor, LayoutLMvaImageProcessor

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_layoutlmva import (
                LAYOUTLMV2_PRETRAINED_MODEL_ARCHIVE_LIST,
                LayoutLMvaForQuestionAnswering,
                LayoutLMvaForSequenceClassification,
                LayoutLMvaForTokenClassification,
                LayoutLMvaLayer,
                LayoutLMvaModel,
                LayoutLMvaPreTrainedModel,
            )
else:
      import sys

      __magic_name__  :  Union[str, Any]					=       _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)

