


'''simple docstring'''





import unittest

from diffusers import FlaxAutoencoderKL
from diffusers.utils import is_flax_available
from diffusers.utils.testing_utils import require_flax

from .test_modeling_common_flax import FlaxModelTesterMixin


if is_flax_available():
 import jax






@require_flax
class   __lowercase				(  __snake_case ,					unittest.TestCase  ):
      UpperCamelCase								=       FlaxAutoencoderKL





      @property
      def        _lowercase				(		self						:					Tuple       )    ->   Optional[int]:






         """simple docstring"""







         UpperCAmelCase							=     4
         UpperCAmelCase							=     3
         UpperCAmelCase							=     (3_2, 3_2)

         UpperCAmelCase							=     jax.random.PRNGKey(0       )
         UpperCAmelCase							=     jax.random.uniform(__lowerCamelCase					,       ((batch_size, num_channels) + sizes)       )

         return {"sample": image, "prng_key": prng_key}





      def        _lowercase				(		self						:					str       )    ->   int:






         """simple docstring"""







         UpperCAmelCase							=     {
             """block_out_channels""": [3_2, 6_4],
             """in_channels""": 3,
             """out_channels""": 3,
             """down_block_types""": ["""DownEncoderBlock2D""", """DownEncoderBlock2D"""],
             """up_block_types""": ["""UpDecoderBlock2D""", """UpDecoderBlock2D"""],
             """latent_channels""": 4,
         }
         UpperCAmelCase							=     self.dummy_input
         return init_dict, inputs_dict







import math






class   __lowercase				:





      def        _lowercase				(		self						:					Union[str, Any]					,       __lowerCamelCase						:					list[list[float]]					,       __lowerCamelCase						:					list[int]       )    ->   int:






         """simple docstring"""







         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        _lowercase				(		self						:					List[Any]					,       __lowerCamelCase						:					list[list[int | float]]					,       __lowerCamelCase						:					list[int]					,       __lowerCamelCase						:					int					,       __lowerCamelCase						:					float       )    ->   list[list[int | float]]:






         """simple docstring"""







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

def   _UpperCamelCase				(						)						->None:
   # 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(lowerCAmelCase_   ):
      for j in range(len(lowerCAmelCase_   )   ):
         # training sample
         UpperCAmelCase							=     training_samples[j]

         # Compute the winning vector
         UpperCAmelCase							=     self_organizing_map.get_winner(lowerCAmelCase_  ,						lowerCAmelCase_   )

         # Update the winning vector
         UpperCAmelCase							=     self_organizing_map.update(lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_   )

    # classify test sample
   UpperCAmelCase							=     [0, 0, 0, 1]
   UpperCAmelCase							=     self_organizing_map.get_winner(lowerCAmelCase_  ,						lowerCAmelCase_   )

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



