




import numpy

# List of input, output pairs
UpperCamelCase__         =      (
    ((5, 2, 3), 15),
    ((6, 5, 9), 25),
    ((11, 12, 13), 41),
    ((1, 1, 1), 8),
    ((11, 12, 13), 41),
)
UpperCamelCase__         =      (((515, 22, 13), 555), ((61, 35, 49), 150))
UpperCamelCase__         =      [2, 4, 1, 5]
UpperCamelCase__         =      len(train_data)
UpperCamelCase__         =      0.009







def      _a				(						SCREAMING_SNAKE_CASE_							:    Union[str, Any]				,				SCREAMING_SNAKE_CASE_							:    str="train"					):
					return calculate_hypothesis_value(SCREAMING_SNAKE_CASE_				,				SCREAMING_SNAKE_CASE_					) - output(
					    SCREAMING_SNAKE_CASE_				,				SCREAMING_SNAKE_CASE_					)







def      _a				(						SCREAMING_SNAKE_CASE_							:    Optional[int]					):
					__lowerCAmelCase           =	0
					for i in range(len(SCREAMING_SNAKE_CASE_					) - 1					):
										hyp_val += data_input_tuple[i] * parameter_vector[i + 1]
					hyp_val += parameter_vector[0]
					return hyp_val







def      _a				(						SCREAMING_SNAKE_CASE_							:    Optional[int]				,				SCREAMING_SNAKE_CASE_							:    List[str]					):
					if data_set == "train":
										return train_data[example_no][1]
					elif data_set == "test":
										return test_data[example_no][1]
					return None







def      _a				(						SCREAMING_SNAKE_CASE_							:    Union[str, Any]				,				SCREAMING_SNAKE_CASE_							:    Optional[Any]					):
					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      _a				(						SCREAMING_SNAKE_CASE_							:    Dict				,				SCREAMING_SNAKE_CASE_							:    Any=m					):
					__lowerCAmelCase           =	0
					for i in range(SCREAMING_SNAKE_CASE_					):
										if index == -1:
															summation_value += _error(SCREAMING_SNAKE_CASE_					)
										else:
															summation_value += _error(SCREAMING_SNAKE_CASE_					) * train_data[i][0][index]
					return summation_value







def      _a				(						SCREAMING_SNAKE_CASE_							:    Optional[Any]					):
					__lowerCAmelCase           =	summation_of_cost_derivative(SCREAMING_SNAKE_CASE_				,				SCREAMING_SNAKE_CASE_					) / m
					return cost_derivative_value







def      _a				(						):
					global parameter_vector
					# Tune these values to set a tolerance value for predicted output
					__lowerCAmelCase           =	0.00_00_02
					__lowerCAmelCase           =	0
					__lowerCAmelCase           =	0
					while True:
										j += 1
										__lowerCAmelCase           =	[0, 0, 0, 0]
										for i in range(0				,				len(SCREAMING_SNAKE_CASE_					)					):
															__lowerCAmelCase           =	get_cost_derivative(i - 1					)
															__lowerCAmelCase           =	(
															    parameter_vector[i] - LEARNING_RATE * cost_derivative
															)
										if numpy.allclose(
										    SCREAMING_SNAKE_CASE_				,				SCREAMING_SNAKE_CASE_				,				atol=SCREAMING_SNAKE_CASE_				,				rtol=SCREAMING_SNAKE_CASE_				,				):
															break
										__lowerCAmelCase           =	temp_parameter_vector
					print(("Number of iterations:", j)					)







def      _a				(						):
					for i in range(len(SCREAMING_SNAKE_CASE_					)					):
										print(("Actual output value:", output(SCREAMING_SNAKE_CASE_				,				"test"					))					)
										print(("Hypothesis output:", calculate_hypothesis_value(SCREAMING_SNAKE_CASE_				,				"test"					))					)


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










import enum
import shutil
import sys


UpperCamelCase__      ,     UpperCamelCase__         =      shutil.get_terminal_size()

UpperCamelCase__         =      {"""UP""": """A""", """DOWN""": """B""", """RIGHT""": """C""", """LEFT""": """D"""}
class       a__   ( enum.Enum				):
						_a							:   Any =   0
						_a							:   Dict =   1







def      _a				(						SCREAMING_SNAKE_CASE_							:    Tuple				,				SCREAMING_SNAKE_CASE_							:    Dict=""					):
					sys.stdout.write(str(SCREAMING_SNAKE_CASE_					) + end					)
					sys.stdout.flush()







def      _a				(						SCREAMING_SNAKE_CASE_							:    Any				,				SCREAMING_SNAKE_CASE_							:    Union[str, Any]				,				SCREAMING_SNAKE_CASE_							:    str=""					):
					forceWrite(F"""\u001b[{color}m{content}\u001b[0m"""				,				SCREAMING_SNAKE_CASE_					)







def      _a				(						):
					forceWrite("\r"					)







def      _a				(						SCREAMING_SNAKE_CASE_							:    int				,				SCREAMING_SNAKE_CASE_							:    str					):
					forceWrite(F"""\033[{num_lines}{CURSOR_TO_CHAR[direction.upper()]}"""					)







def      _a				(						):
					forceWrite(" " * TERMINAL_WIDTH					)
					reset_cursor()







def      _a				(						):
					reset_cursor()
					forceWrite("-" * TERMINAL_WIDTH					)




