





import numpy

# List of input, output pairs
__UpperCAmelCase	:       Union[str, Any]    	=							(
    ((5, 2, 3), 15),
    ((6, 5, 9), 25),
    ((11, 12, 13), 41),
    ((1, 1, 1), 8),
    ((11, 12, 13), 41),
)
__UpperCAmelCase	:       Tuple    	=							(((515, 22, 13), 555), ((61, 35, 49), 150))
__UpperCAmelCase	:       Optional[Any]    	=							[2, 4, 1, 5]
__UpperCAmelCase	:       List[Any]    	=							len(train_data)
__UpperCAmelCase	:       Union[str, Any]    	=							0.0_09







def       A__							(   SCREAMING_SNAKE_CASE__ , SCREAMING_SNAKE_CASE__="train")       ->   List[Any]:
  return calculate_hypothesis_value(_lowerCAmelCase , _lowerCAmelCase) - output(
      _lowerCAmelCase , _lowerCAmelCase)







def       A__							(   SCREAMING_SNAKE_CASE__)       ->   int:
  __snake_case:						Union[str, Any]			  =						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       A__							(   SCREAMING_SNAKE_CASE__ , 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__ , 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__ , SCREAMING_SNAKE_CASE__=m)       ->   Dict:
  __snake_case:						Tuple			  =						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       A__							(   SCREAMING_SNAKE_CASE__)       ->   str:
  __snake_case:						Optional[int]			  =						summation_of_cost_derivative(_lowerCAmelCase , _lowerCAmelCase) / m
  return cost_derivative_value







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







def       A__							(   )       ->   List[str]:



  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()









from __future__ import annotations

import numpy as np







def       A__							(   SCREAMING_SNAKE_CASE__)       ->   List[str]:
  return np.maximum(0 , SCREAMING_SNAKE_CASE__)


if __name__ == "__main__":
      print(np.array(relu([-1, 0, 5])))  # --> [0, 0, 5]






