

'''simple docstring'''



import math







class 		lowerCAmelCase__  :



 """simple docstring"""



 def  UpperCAmelCase__						(						self   :			List[Any]   ,				__SCREAMING_SNAKE_CASE   :			list[list[float]]   ,				__SCREAMING_SNAKE_CASE   :			list[int]     )    ->					int:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE      = 0.0
      __SCREAMING_SNAKE_CASE      = 0.0
      for i in range(len(__SCREAMING_SNAKE_CASE     )     ):
           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  UpperCAmelCase__						(						self   :			int   ,				__SCREAMING_SNAKE_CASE   :			list[list[int | float]]   ,				__SCREAMING_SNAKE_CASE   :			list[int]   ,				__SCREAMING_SNAKE_CASE   :			int   ,				__SCREAMING_SNAKE_CASE   :			float     )    ->					list[list[int | float]]:


      """simple docstring"""




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







def   a__			(    ):




     """simple docstring"""


     __SCREAMING_SNAKE_CASE      = [[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

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

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

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

               # Compute the winning vector
               __SCREAMING_SNAKE_CASE      = self_organizing_map.get_winner(a__ ,       a__		)

               # Update the winning vector
               __SCREAMING_SNAKE_CASE      = self_organizing_map.update(a__ ,       a__ ,       a__ ,       a__		)

    # classify test sample
     __SCREAMING_SNAKE_CASE      = [0, 0, 0, 1]
     __SCREAMING_SNAKE_CASE      = self_organizing_map.get_winner(a__ ,       a__		)

     # 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()









'''simple docstring'''



from typing import Optional, Union

import torch
from torch import nn

from ...configuration_utils import ConfigMixin, register_to_config
from ...models.modeling_utils import ModelMixin







class 		lowerCAmelCase__  ( a					,   a   ):



 """simple docstring"""



 @register_to_config
 def __init__(						self   :			int   ,				__SCREAMING_SNAKE_CASE   :			int = 768   ,				)    ->					int:


      """simple docstring"""




      super().__init__()

      __SCREAMING_SNAKE_CASE      = nn.Parameter(torch.zeros(1   ,				__SCREAMING_SNAKE_CASE     )     )
      __SCREAMING_SNAKE_CASE      = nn.Parameter(torch.ones(1   ,				__SCREAMING_SNAKE_CASE     )     )
 def  UpperCAmelCase__						(						self   :			Any   ,				__SCREAMING_SNAKE_CASE   :			Optional[Union[str, torch.device]] = None   ,				__SCREAMING_SNAKE_CASE   :			Optional[torch.dtype] = None   ,				)    ->					List[str]:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE      = nn.Parameter(self.mean.to(__SCREAMING_SNAKE_CASE     ).to(__SCREAMING_SNAKE_CASE     )     )
      __SCREAMING_SNAKE_CASE      = nn.Parameter(self.std.to(__SCREAMING_SNAKE_CASE     ).to(__SCREAMING_SNAKE_CASE     )     )
      return self
 def  UpperCAmelCase__						(						self   :			Optional[Any]   ,				__SCREAMING_SNAKE_CASE   :			Optional[int]     )    ->					Optional[int]:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE      = (embeds - self.mean) * 1.0 / self.std
      return embeds


 def  UpperCAmelCase__						(						self   :			Tuple   ,				__SCREAMING_SNAKE_CASE   :			Any     )    ->					Optional[int]:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE      = (embeds * self.std) + self.mean
      return embeds






