




import math
class 			a__    :






						def 				__SCREAMING_SNAKE_CASE(   self		,			_A		,			_A			):




											"""simple docstring"""



											__lowerCAmelCase				   =       0.0
											__lowerCAmelCase				   =       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		,			_A		,			_A		,			_A		,			_A			):




											"""simple docstring"""



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







def 	_a      (						):
					# Training Examples ( m, n )
					__lowerCAmelCase				   =       [[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

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

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

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

															# Compute the winning vector
															__lowerCAmelCase				   =       self_organizing_map.get_winner(SCREAMING_SNAKE_CASE_      ,      SCREAMING_SNAKE_CASE_     )

															# Update the winning vector
															__lowerCAmelCase				   =       self_organizing_map.update(SCREAMING_SNAKE_CASE_      ,      SCREAMING_SNAKE_CASE_      ,      SCREAMING_SNAKE_CASE_      ,      SCREAMING_SNAKE_CASE_     )

    # classify test sample
					__lowerCAmelCase				   =       [0, 0, 0, 1]
					__lowerCAmelCase				   =       self_organizing_map.get_winner(SCREAMING_SNAKE_CASE_      ,      SCREAMING_SNAKE_CASE_     )

					# 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 ...configuration_utils import PretrainedConfig
from ...utils import logging


A_       : int         =			logging.get_logger(__name__)

A_       : Optional[Any]         =			{
    'alibaba-damo/mgp-str-base': 'https://huggingface.co/alibaba-damo/mgp-str-base/resolve/main/config.json',
}



class     _a						(__magic_name__				):


					'''simple docstring'''






					UpperCAmelCase__:   List[Any]  							=       '''mgp-str'''






					def __init__( self    ,       A__=[32, 128]    ,       A__=4    ,       A__=3    ,       A__=27    ,       A__=38    ,       A__=5_0257    ,       A__=3_0522    ,       A__=768    ,       A__=12    ,       A__=12    ,       A__=4.0    ,       A__=True    ,       A__=False    ,       A__=1e-5    ,       A__=0.0    ,       A__=0.0    ,       A__=0.0    ,       A__=False    ,       A__=0.0_2    ,       **A__    ,       ):
						super().__init__(**A__			)

						A__							:    Dict        =		image_size
						A__							:    int        =		patch_size
						A__							:    Dict        =		num_channels
						A__							:    List[Any]        =		max_token_length
						A__							:    str        =		num_character_labels
						A__							:    Tuple        =		num_bpe_labels
						A__							:    Optional[Any]        =		num_wordpiece_labels
						A__							:    Optional[int]        =		hidden_size
						A__							:    Tuple        =		num_hidden_layers
						A__							:    Any        =		num_attention_heads
						A__							:    List[Any]        =		mlp_ratio
						A__							:    Tuple        =		distilled
						A__							:    Union[str, Any]        =		layer_norm_eps
						A__							:    Tuple        =		drop_rate
						A__							:    List[str]        =		qkv_bias
						A__							:    Optional[Any]        =		attn_drop_rate
						A__							:    Union[str, Any]        =		drop_path_rate
						A__							:    Optional[Any]        =		output_aa_attentions
						A__							:    Optional[int]        =		initializer_range



