






"""simple docstring"""
import numpy

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






def       __UpperCamelCase						(		snake_case__ , snake_case__="train"       ):
	return calculate_hypothesis_value(snake_case__ , snake_case__       ) - output(
	    snake_case__ , snake_case__       )






def       __UpperCamelCase						(		snake_case__       ):
	A_		:    List[Any]						     = 0
	for i in range(len(snake_case__       ) - 1       ):
		hyp_val += data_input_tuple[i] * parameter_vector[i + 1]
	hyp_val += parameter_vector[0]
	return hyp_val






def       __UpperCamelCase						(		snake_case__ , snake_case__       ):
	if data_set == "train":
		return train_data[example_no][1]
	elif data_set == "test":
		return test_data[example_no][1]
	return None






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






def       __UpperCamelCase						(		snake_case__       ):
	A_		:    List[str]						     = summation_of_cost_derivative(snake_case__ , snake_case__       ) / m
	return cost_derivative_value






def       __UpperCamelCase						(		):
	global parameter_vector
	# Tune these values to set a tolerance value for predicted output
	A_		:    Dict						     = 0.000_002
	A_		:    List[Any]						     = 0
	A_		:    str						     = 0
	while True:
		j += 1
		A_		:    Tuple						     = [0, 0, 0, 0]
		for i in range(0 , len(snake_case__       )       ):
			A_		:    int						     = get_cost_derivative(i - 1       )
			A_		:    Optional[int]						     = (
			    parameter_vector[i] - LEARNING_RATE * cost_derivative
			)
		if numpy.allclose(
		    snake_case__ , snake_case__ , atol=snake_case__ , rtol=snake_case__ , ):
			break
		A_		:    Tuple						     = temp_parameter_vector
	print(("""Number of iterations:""", j)       )






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


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









"""simple docstring"""
from __future__ import annotations






def       __UpperCamelCase						(		snake_case__ , snake_case__ = None , snake_case__ = None       ):
	if start is None:
		A_		:    Dict						     = 0

	if end is None:
		A_		:    Dict						     = len(snake_case__       ) - 1

	if start >= end:
		return

	A_		:    List[Any]						     = (start + end) // 2

	slowsort(snake_case__ , snake_case__ , snake_case__       )
	slowsort(snake_case__ , mid + 1 , snake_case__       )

	if sequence[end] < sequence[mid]:
		A_     ,  A_		:    Dict						     = sequence[mid], sequence[end]

	slowsort(snake_case__ , snake_case__ , end - 1       )


if __name__ == "__main__":
							from doctest import testmod

							testmod()

