



"""simple docstring"""






import numpy

# List of input, output pairs
_lowercase				:				Tuple   		=		(
    ((5, 2, 3), 1_5),
    ((6, 5, 9), 2_5),
    ((1_1, 1_2, 1_3), 4_1),
    ((1, 1, 1), 8),
    ((1_1, 1_2, 1_3), 4_1),
)
_lowercase				:				Tuple   		=		(((5_1_5, 2_2, 1_3), 5_5_5), ((6_1, 3_5, 4_9), 1_5_0))
_lowercase				:				List[str]   		=		[2, 4, 1, 5]
_lowercase				:				Tuple   		=		len(train_data)
_lowercase				:				Optional[Any]   		=		0.009






def   snake_case__     (	__lowerCamelCase       :					Any							,	__lowerCamelCase       :					Any="train"			):
			"""simple docstring"""
			return calculate_hypothesis_value(_lowerCamelCase							,	_lowerCamelCase			) - output(
			    _lowerCamelCase							,	_lowerCamelCase			)






def   snake_case__     (	__lowerCamelCase       :					Optional[Any]			):
			"""simple docstring"""
			lowerCamelCase__	:	Dict				=0
			for i in range(len(_lowerCamelCase			) - 1			):
						hyp_val += data_input_tuple[i] * parameter_vector[i + 1]
			hyp_val += parameter_vector[0]
			return hyp_val






def   snake_case__     (	__lowerCamelCase       :					Any							,	__lowerCamelCase       :					List[Any]			):
			"""simple docstring"""





			if data_set == "train":
						return train_data[example_no][1]
			elif data_set == "test":
						return test_data[example_no][1]
			return None






def   snake_case__     (	__lowerCamelCase       :					Dict							,	__lowerCamelCase       :					Tuple			):
			"""simple docstring"""





			if data_set == "train":
						return _hypothesis_value(train_data[example_no][0]			)
			elif data_set == "test":
						return _hypothesis_value(test_data[example_no][0]			)
			return None






def   snake_case__     (	__lowerCamelCase       :					Dict							,	__lowerCamelCase       :					Optional[Any]=m			):
			"""simple docstring"""
			lowerCamelCase__	:	int				=0
			for i in range(_lowerCamelCase			):
						if index == -1:
									summation_value += _error(_lowerCamelCase			)
						else:
									summation_value += _error(_lowerCamelCase			) * train_data[i][0][index]
			return summation_value






def   snake_case__     (	__lowerCamelCase       :					Any			):
			"""simple docstring"""
			lowerCamelCase__	:	Tuple				=summation_of_cost_derivative(_lowerCamelCase							,	_lowerCamelCase			) / m
			return cost_derivative_value






def   snake_case__     (	):
			"""simple docstring"""
			global parameter_vector
			# Tune these values to set a tolerance value for predicted output
			lowerCamelCase__	:	List[str]				=0.00_00_02
			lowerCamelCase__	:	List[str]				=0
			lowerCamelCase__	:	Any				=0
			while True:
						j += 1
						lowerCamelCase__	:	int				=[0, 0, 0, 0]
						for i in range(0							,	len(_lowerCamelCase			)			):
									lowerCamelCase__	:	Union[str, Any]				=get_cost_derivative(i - 1			)
									lowerCamelCase__	:	Any				=(
									    parameter_vector[i] - LEARNING_RATE * cost_derivative
									)
						if numpy.allclose(
						    _lowerCamelCase							,	_lowerCamelCase							,	atol=_lowerCamelCase							,	rtol=_lowerCamelCase							,	):
									break
						lowerCamelCase__	:	Any				=temp_parameter_vector
			print(('''Number of iterations:''', j)			)






def   snake_case__     (	):
			"""simple docstring"""





			for i in range(len(_lowerCamelCase			)			):
						print(('''Actual output value:''', output(_lowerCamelCase							,	'''test'''			))			)
						print(('''Hypothesis output:''', calculate_hypothesis_value(_lowerCamelCase							,	'''test'''			))			)


if __name__ == "__main__":
		run_gradient_descent()
		print("\nTesting gradient descent for a linear hypothesis function.\n")
		test_gradient_descent()









"""simple docstring"""






import os






def   snake_case__     (	):
			"""simple docstring"""
			with open(os.path.dirname(__lowerCamelCase			) + '''/p022_names.txt'''			) as file:
						lowerCamelCase__	:	Tuple				=str(file.readlines()[0]			)
						lowerCamelCase__	:	int				=names.replace('''"'''							,	''''''			).split(''','''			)

			names.sort()

			lowerCamelCase__	:	Union[str, Any]				=0
			lowerCamelCase__	:	str				=0

			for i, name in enumerate(__lowerCamelCase			):
						for letter in name:
									name_score += ord(__lowerCamelCase			) - 64

						total_score += (i + 1) * name_score
						lowerCamelCase__	:	Dict				=0
			return total_score


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




