





"""simple docstring"""


import logging
import os
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

from tqdm import auto as tqdm_lib


lowerCamelCase__				  =   {
    "debug": logging.DEBUG,
    "info": logging.INFO,
    "warning": logging.WARNING,
    "error": logging.ERROR,
    "critical": logging.CRITICAL,
}

lowerCamelCase__				  =   logging.WARNING




def 					lowercase__    (					)					->		List[str]:




      """simple docstring"""

      _UpperCamelCase      :	List[Any]						=       os.getenv("DATASETS_VERBOSITY"		,lowercase_			)
      if env_level_str:
            if env_level_str in log_levels:
                  return log_levels[env_level_str]
            else:
                  logging.getLogger().warning(
                      F'''Unknown option DATASETS_VERBOSITY={env_level_str}, '''
                      F'''has to be one of: { ', '.join(log_levels.keys()			) }'''			)
      return _default_log_level




def 					lowercase__    (					)					->		str:




      """simple docstring"""

      return __name__.split("."			)[0]




def 					lowercase__    (					)					->		logging.Logger:




      """simple docstring"""

      return logging.getLogger(_get_library_name()			)




def 					lowercase__    (					)					->		None:




      """simple docstring"""

      _UpperCamelCase      :	List[Any]						=       _get_library_root_logger()
      library_root_logger.setLevel(_get_default_logging_level()			)




def 					lowercase__    (					)					->		None:




      """simple docstring"""

      _UpperCamelCase      :	List[Any]						=       _get_library_root_logger()
      library_root_logger.setLevel(logging.NOTSET			)




def 					lowercase__    (					lowercase_ = None			)					->		logging.Logger:




      """simple docstring"""

      if name is None:
            _UpperCamelCase      :	int						=       _get_library_name()
      return logging.getLogger(lowercase_			)




def 					lowercase__    (					)					->		int:




      """simple docstring"""

      return _get_library_root_logger().getEffectiveLevel()




def 					lowercase__    (					lowercase_			)					->		None:




      """simple docstring"""

      _get_library_root_logger().setLevel(lowercase_			)




def 					lowercase__    (					)					->		List[str]:




      """simple docstring"""

      return set_verbosity(lowercase_			)




def 					lowercase__    (					)					->		Optional[Any]:




      """simple docstring"""

      return set_verbosity(lowercase_			)




def 					lowercase__    (					)					->		List[str]:




      """simple docstring"""

      return set_verbosity(lowercase_			)




def 					lowercase__    (					)					->		Optional[int]:




      """simple docstring"""

      return set_verbosity(lowercase_			)




def 					lowercase__    (					)					->		None:




      """simple docstring"""

      _UpperCamelCase      :	str						=       False




def 					lowercase__    (					)					->		None:




      """simple docstring"""

      _UpperCamelCase      :	str						=       True


# Configure the library root logger at the module level (singleton-like)
_configure_library_root_logger()



class      __SCREAMING_SNAKE_CASE    :







  '''simple docstring'''


  def __init__(		self   :       Optional[Any]					,   *__a   :       int					,   **__a   :       List[str]	)		->				Tuple:  # pylint: disable=unused-argument
        _UpperCamelCase      :	Union[str, Any]						=       args[0] if args else None

  def __iter__(		self   :       str	)		->				List[str]:
        return iter(self._iterator	)

  def __getattr__(		self   :       Any					,   __a   :       str	)		->				Union[str, Any]:

        def empty_fn(*__a   :       Optional[int]					,   **__a   :       Tuple	):  # pylint: disable=unused-argument
              return

        return empty_fn

  def __enter__(		self   :       str	)		->				Dict:
        return self


  def __exit__(		self   :       int					,   __a   :       Tuple					,   __a   :       Dict					,   __a   :       Dict	)		->				Optional[Any]:
        return





lowerCamelCase__				  =   True



class      __SCREAMING_SNAKE_CASE    :







  '''simple docstring'''


  def __call__(		self   :       Optional[Any]					,   *__a   :       int					,   __a   :       Optional[Any]=False					,   **__a   :       int	)		->				List[Any]:
        if _tqdm_active and not disable:
              return tqdm_lib.tqdm(*__a					,   **__a	)
        else:
              return EmptyTqdm(*__a					,   **__a	)

  def    __SCREAMING_SNAKE_CASE				(		self   :       Dict					,   *__a   :       List[str]					,   **__a   :       Any	)		->				Optional[Any]:
        _UpperCamelCase      :	Union[str, Any]						=       None
        if _tqdm_active:
              return tqdm_lib.tqdm.set_lock(*__a					,   **__a	)


  def    __SCREAMING_SNAKE_CASE				(		self   :       int	)		->				Dict:
        if _tqdm_active:
              return tqdm_lib.tqdm.get_lock()





lowerCamelCase__				  =   _tqdm_cls()




def 					lowercase__    (					)					->		bool:




      """simple docstring"""

      global _tqdm_active
      return bool(_tqdm_active			)




def 					lowercase__    (					)					->		str:




      """simple docstring"""

      global _tqdm_active
      _UpperCamelCase      :	Union[str, Any]						=       True




def 					lowercase__    (					)					->		str:




      """simple docstring"""

      global _tqdm_active
      _UpperCamelCase      :	Tuple						=       False







"""simple docstring"""


import math



class      __SCREAMING_SNAKE_CASE    :







  '''simple docstring'''


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





def 					lowercase__    (					)					->		None:




      """simple docstring"""

      _UpperCamelCase      :	Optional[int]						=       [[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

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

      # training
      _UpperCamelCase      :	List[Any]						=       SelfOrganizingMap()
      _UpperCamelCase      :	int						=       3
      _UpperCamelCase      :	List[Any]						=       0.5

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

                  # Compute the winning vector
                  _UpperCamelCase      :	Tuple						=       self_organizing_map.get_winner(lowercase_		,lowercase_			)

                  # Update the winning vector
                  _UpperCamelCase      :	int						=       self_organizing_map.update(lowercase_		,lowercase_		,lowercase_		,lowercase_			)

    # classify test sample
      _UpperCamelCase      :	Optional[int]						=       [0, 0, 0, 1]
      _UpperCamelCase      :	Dict						=       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()
