





'''simple docstring'''



import math






class 							__lowercase       :







	'''simple docstring'''

	def 						_UpperCAmelCase     (self     ,_lowerCamelCase     ,_lowerCamelCase )							->							int:







				'''simple docstring'''





				__lowercase										=							0.0
				__lowercase										=							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 						_UpperCAmelCase     (self     ,_lowerCamelCase     ,_lowerCamelCase     ,_lowerCamelCase     ,_lowerCamelCase )							->							list[list[int | float]]:







				'''simple docstring'''





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





def    _lowerCAmelCase						(				):
			__lowercase										=							[[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

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

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

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

									# Compute the winning vector
									__lowercase										=							self_organizing_map.get_winner(lowerCamelCase_		,       lowerCamelCase_				)

									# Update the winning vector
									__lowercase										=							self_organizing_map.update(lowerCamelCase_		,       lowerCamelCase_		,       lowerCamelCase_		,       lowerCamelCase_				)

    # classify test sample
			__lowercase										=							[0, 0, 0, 1]
			__lowercase										=							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()










'''simple docstring'''



from typing import List, Optional, Union

import numpy as np
import PIL.Image

from ...image_processing_utils import BaseImageProcessor, BatchFeature
from ...image_transforms import rescale, resize, to_channel_dimension_format
from ...image_utils import (
    ChannelDimension,
    PILImageResampling,
    get_image_size,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


_SCREAMING_SNAKE_CASE					=    logging.get_logger(__name__)






class 							__lowercase       (      lowerCAmelCase__						):







	'''simple docstring'''

	a    :				int											=       ["pixel_values"]


	def __init__(self     ,_lowerCamelCase = True     ,_lowerCamelCase = 32     ,_lowerCamelCase=PILImageResampling.BILINEAR     ,_lowerCamelCase = True     ,**_lowerCamelCase     ,)							->							None:







				'''simple docstring'''





				__lowercase										=							do_resize
				__lowercase										=							do_rescale
				__lowercase										=							size_divisor
				__lowercase										=							resample
				super().__init__(**_lowerCamelCase )


	def 						_UpperCAmelCase     (self     ,_lowerCamelCase     ,_lowerCamelCase     ,_lowerCamelCase     ,_lowerCamelCase = None     ,**_lowerCamelCase )							->							np.ndarray:







				'''simple docstring'''





				__lowercase						,		__lowercase										=							get_image_size(_lowerCamelCase )
				# Rounds the height and width down to the closest multiple of size_divisor
				__lowercase										=							height // size_divisor * size_divisor
				__lowercase										=							width // size_divisor * size_divisor
				__lowercase										=							resize(_lowerCamelCase     ,(new_h, new_w)     ,resample=_lowerCamelCase     ,data_format=_lowerCamelCase     ,**_lowerCamelCase )
				return image


	def 						_UpperCAmelCase     (self     ,_lowerCamelCase     ,_lowerCamelCase     ,_lowerCamelCase = None     ,**_lowerCamelCase )							->							np.ndarray:







				'''simple docstring'''





				return rescale(image=_lowerCamelCase     ,scale=_lowerCamelCase     ,data_format=_lowerCamelCase     ,**_lowerCamelCase )


	def 						_UpperCAmelCase     (self     ,_lowerCamelCase     ,_lowerCamelCase = None     ,_lowerCamelCase = None     ,_lowerCamelCase=None     ,_lowerCamelCase = None     ,_lowerCamelCase = None     ,_lowerCamelCase = ChannelDimension.FIRST     ,**_lowerCamelCase     ,)							->							BatchFeature:







				'''simple docstring'''





				__lowercase										=							do_resize if do_resize is not None else self.do_resize
				__lowercase										=							do_rescale if do_rescale is not None else self.do_rescale
				__lowercase										=							size_divisor if size_divisor is not None else self.size_divisor
				__lowercase										=							resample if resample is not None else self.resample

				if do_resize and size_divisor is None:
							raise ValueError('''size_divisor is required for resizing''' )

				__lowercase										=							make_list_of_images(_lowerCamelCase )

				if not valid_images(_lowerCamelCase ):
							raise ValueError('''Invalid image(s)''' )

				# All transformations expect numpy arrays.
				__lowercase										=							[to_numpy_array(_lowerCamelCase ) for img in images]

				if do_resize:
							__lowercase										=							[self.resize(_lowerCamelCase     ,size_divisor=_lowerCamelCase     ,resample=_lowerCamelCase ) for image in images]

				if do_rescale:
							__lowercase										=							[self.rescale(_lowerCamelCase     ,scale=1 / 255 ) for image in images]

				__lowercase										=							[to_channel_dimension_format(_lowerCamelCase     ,_lowerCamelCase ) for image in images]

				__lowercase										=							{'''pixel_values''': images}
				return BatchFeature(data=_lowerCamelCase     ,tensor_type=_lowerCamelCase )





