
'''simple docstring'''







import math


class 						__UpperCAmelCase      :


							def  lowerCamelCase				(       self    ,   lowerCAmelCase_    ,   lowerCAmelCase_  ):





								"""simple docstring"""






								_snake_case   						=		0.0
								_snake_case   						=		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  lowerCamelCase				(       self    ,   lowerCAmelCase_    ,   lowerCAmelCase_    ,   lowerCAmelCase_    ,   lowerCAmelCase_  ):





								"""simple docstring"""






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







def 				SCREAMING_SNAKE_CASE__	(   )       ->	None:
	# Training Examples ( m, n )
	_snake_case   						=		[[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

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

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

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

			# Compute the winning vector
			_snake_case   						=		self_organizing_map.get_winner(__A			,				__A	)

			# Update the winning vector
			_snake_case   						=		self_organizing_map.update(__A			,				__A			,				__A			,				__A	)

    # classify test sample
	_snake_case   						=		[0, 0, 0, 1]
	_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 __future__ import annotations

import requests


def 	SCREAMING_SNAKE_CASE_					(  _UpperCAmelCase	:	str  )  ->			dict:
       _a    : Any     					=F"https://hacker-news.firebaseio.com/v0/item/{story_id}.json?print=pretty"
       return requests.get(_UpperCAmelCase  ).json()


def 	SCREAMING_SNAKE_CASE_					(  _UpperCAmelCase	:	int = 10  )  ->			list[dict]:
       _a    : Union[str, Any]     					="""https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty"""
       _a    : int     					=requests.get(_UpperCAmelCase  ).json()[:max_stories]
       return [get_hackernews_story(_UpperCAmelCase  ) for story_id in story_ids]


def 	SCREAMING_SNAKE_CASE_					(  _UpperCAmelCase	:	int = 10  )  ->			str:
       _a    : Union[str, Any]     					=hackernews_top_stories(_UpperCAmelCase  )
       return "\n".join("""* [{title}]({url})""".format(**_UpperCAmelCase  ) for story in stories  )


if __name__ == "__main__":
   print(hackernews_top_stories_as_markdown())


