


'''simple docstring'''




import unittest

from datasets import load_dataset

from transformers.pipelines import pipeline
from transformers.testing_utils import is_pipeline_test, nested_simplify, require_torch, slow

@is_pipeline_test
@require_torch
class 		UpperCAmelCase_      (  unittest.TestCase		):





     @require_torch
     def 							__UpperCAmelCase      ( self       :      Any    )				->  Optional[Any]:
        lowerCAmelCase     =			pipeline(
            task='zero-shot-audio-classification'    ,      model='hf-internal-testing/tiny-clap-htsat-unfused'    )
        lowerCAmelCase     =			load_dataset('ashraq/esc50'    )
        lowerCAmelCase     =			dataset['train']['audio'][-1]['array']
        lowerCAmelCase     =			audio_classifier(UpperCAmelCase__    ,      candidate_labels=['Sound of a dog', 'Sound of vaccum cleaner']    )
        self.assertEqual(
            nested_simplify(UpperCAmelCase__    )    ,      [{'score': 0.501, 'label': 'Sound of a dog'}, {'score': 0.499, 'label': 'Sound of vaccum cleaner'}]    ,      )





     @unittest.skip('No models are available in TF'    )
     def 							__UpperCAmelCase      ( self       :      Any    )				->  Optional[Any]:
        pass





     @slow
     @require_torch
     def 							__UpperCAmelCase      ( self       :      Tuple    )				->  List[Any]:
        lowerCAmelCase     =			pipeline(
            task='zero-shot-audio-classification'    ,      model='laion/clap-htsat-unfused'    ,      )
        # This is an audio of a dog
        lowerCAmelCase     =			load_dataset('ashraq/esc50'    )
        lowerCAmelCase     =			dataset['train']['audio'][-1]['array']
        lowerCAmelCase     =			audio_classifier(UpperCAmelCase__    ,      candidate_labels=['Sound of a dog', 'Sound of vaccum cleaner']    )

        self.assertEqual(
            nested_simplify(UpperCAmelCase__    )    ,      [
                {'score': 0.999, 'label': 'Sound of a dog'},
                {'score': 0.001, 'label': 'Sound of vaccum cleaner'},
            ]    ,      )

        lowerCAmelCase     =			audio_classifier([audio] * 5    ,      candidate_labels=['Sound of a dog', 'Sound of vaccum cleaner']    )
        self.assertEqual(
            nested_simplify(UpperCAmelCase__    )    ,      [
                [
                    {'score': 0.999, 'label': 'Sound of a dog'},
                    {'score': 0.001, 'label': 'Sound of vaccum cleaner'},
                ],
            ]
            * 5    ,      )
        lowerCAmelCase     =			audio_classifier(
            [audio] * 5    ,      candidate_labels=['Sound of a dog', 'Sound of vaccum cleaner']    ,      batch_size=5    )
        self.assertEqual(
            nested_simplify(UpperCAmelCase__    )    ,      [
                [
                    {'score': 0.999, 'label': 'Sound of a dog'},
                    {'score': 0.001, 'label': 'Sound of vaccum cleaner'},
                ],
            ]
            * 5    ,      )





     @unittest.skip('No models are available in TF'    )
     def 							__UpperCAmelCase      ( self       :      Any    )				->  Union[str, Any]:
        pass










"""simple docstring"""
import math
class 				lowerCamelCase  :






					'''simple docstring'''





					def    lowerCAmelCase_				(       self:							Tuple						,     snake_case:							list[list[float]]						,     snake_case:							list[int]						)   ->	int:
											snake_case_ :Any						=			0.0
											snake_case_ :Tuple						=			0.0
											for i in range(len(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    lowerCAmelCase_				(       self:							Optional[int]						,     snake_case:							list[list[int | float]]						,     snake_case:							list[int]						,     snake_case:							int						,     snake_case:							float						)   ->	list[list[int | float]]:
											for i in range(len(snake_case						)						):
																	weights[j][i] += alpha * (sample[i] - weights[j][i])
											return weights

def    A_  (			):







						'''simple docstring'''


						snake_case_ :Dict						=			[[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

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

						# training
						snake_case_ :Optional[Any]						=			SelfOrganizingMap()
						snake_case_ :Dict						=			3
						snake_case_ :Dict						=			0.5

						for _ in range(_lowercase	):
												for j in range(len(_lowercase	)	):
																		# training sample
																		snake_case_ :List[Any]						=			training_samples[j]

																		# Compute the winning vector
																		snake_case_ :Optional[int]						=			self_organizing_map.get_winner(_lowercase,					_lowercase	)

																		# Update the winning vector
																		snake_case_ :List[str]						=			self_organizing_map.update(_lowercase,					_lowercase,					_lowercase,					_lowercase	)

    # classify test sample
						snake_case_ :str						=			[0, 0, 0, 1]
						snake_case_ :List[Any]						=			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()
