"""simple docstring"""




import numpy

# List of input, output pairs
__lowerCAmelCase     :				str    				=    (
    ((5, 2, 3), 15),
    ((6, 5, 9), 25),
    ((11, 12, 13), 41),
    ((1, 1, 1), 8),
    ((11, 12, 13), 41),
)
__lowerCAmelCase     :				List[Any]    				=    (((5_15, 22, 13), 5_55), ((61, 35, 49), 1_50))
__lowerCAmelCase     :				Optional[int]    				=    [2, 4, 1, 5]
__lowerCAmelCase     :				Any    				=    len(train_data)
__lowerCAmelCase     :				Union[str, Any]    				=    0.0_09







def 				_UpperCAmelCase		(							lowerCamelCase__      ,	lowerCamelCase__="train"  ):





		"""simple docstring"""




		return calculate_hypothesis_value(lowerCamelCase__      ,	lowerCamelCase__  ) - output(
		    lowerCamelCase__      ,	lowerCamelCase__  )







def 				_UpperCAmelCase		(							lowerCamelCase__  ):





		"""simple docstring"""




		lowerCAmelCase__   = 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 				_UpperCAmelCase		(							lowerCamelCase__      ,	lowerCamelCase__  ):





		"""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 				_UpperCAmelCase		(							lowerCamelCase__      ,	lowerCamelCase__  ):





		"""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 				_UpperCAmelCase		(							lowerCamelCase__      ,	lowerCamelCase__=m  ):





		"""simple docstring"""




		lowerCAmelCase__   = 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 				_UpperCAmelCase		(							lowerCamelCase__  ):





		"""simple docstring"""




		lowerCAmelCase__   = summation_of_cost_derivative(lowerCamelCase__      ,	lowerCamelCase__  ) / m
		return cost_derivative_value







def 				_UpperCAmelCase		(							):





		"""simple docstring"""




		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(lowerCamelCase__  )  ):
						lowerCAmelCase__   = get_cost_derivative(i - 1  )
						lowerCAmelCase__   = (
						    parameter_vector[i] - LEARNING_RATE * cost_derivative
						)
				if numpy.allclose(
				    lowerCamelCase__      ,	lowerCamelCase__      ,	atol=lowerCamelCase__      ,	rtol=lowerCamelCase__      ,	):
						break
				lowerCAmelCase__   = temp_parameter_vector
		print(("""Number of iterations:""", j)  )







def 				_UpperCAmelCase		(							):





		"""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"""




def 				_UpperCAmelCase		(							lowerCamelCase__      ,	lowerCamelCase__  ):





		"""simple docstring"""




		return abs(lowerCamelCase__  ) if a == 0 else greatest_common_divisor(b % a      ,	lowerCamelCase__  )







def 				_UpperCAmelCase		(							lowerCamelCase__      ,	lowerCamelCase__  ):





		"""simple docstring"""




		while y:  # --> when y=0 then loop will terminate and return x as final GCD.
				lowerCAmelCase__ ,       lowerCAmelCase__   = y, x % y
		return abs(lowerCamelCase__  )







def 				_UpperCAmelCase		(							):





		"""simple docstring"""




		try:
				lowerCAmelCase__   = input("""Enter two integers separated by comma (,): """  ).split(""","""  )
				lowerCAmelCase__   = int(nums[0]  )
				lowerCAmelCase__   = int(nums[1]  )
				print(
				    f"""greatest_common_divisor({num_a}, {num_a}) = """
				    f"""{greatest_common_divisor(lowerCamelCase__      ,	lowerCamelCase__  )}"""  )
				print(f"""By iterative gcd({num_a}, {num_a}) = {gcd_by_iterative(lowerCamelCase__      ,	lowerCamelCase__  )}"""  )
		except (IndexError, UnboundLocalError, ValueError):
				print("""Wrong input"""  )


if __name__ == "__main__":
			main()




