



'''simple docstring'''






import numpy

# List of input, output pairs
lowerCAmelCase:      List[Any]		 =		(
    ((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),
)
lowerCAmelCase:      str		 =		(((5_1_5, 2_2, 1_3), 5_5_5), ((6_1, 3_5, 4_9), 1_5_0))
lowerCAmelCase:      Optional[Any]		 =		[2, 4, 1, 5]
lowerCAmelCase:      List[str]		 =		len(train_data)
lowerCAmelCase:      Optional[int]		 =		0.009
def    lowerCamelCase__ (		_A				,    _A="train"       ):
  return calculate_hypothesis_value(_A				,    _A       ) - output(
      _A				,    _A       )
def    lowerCamelCase__ (		_A       ):
  a		:      Any       =  0
  for i in range(len(_A       ) - 1       ):
    hyp_val += data_input_tuple[i] * parameter_vector[i + 1]
  hyp_val += parameter_vector[0]
  return hyp_val
def    lowerCamelCase__ (		_A				,    _A       ):
  if data_set == "train":
    return train_data[example_no][1]
  elif data_set == "test":
    return test_data[example_no][1]
  return None
def    lowerCamelCase__ (		_A				,    _A       ):
  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    lowerCamelCase__ (		_A				,    _A=m       ):
  a		:      List[Any]       =  0
  for i in range(_A       ):
    if index == -1:
      summation_value += _error(_A       )
    else:
      summation_value += _error(_A       ) * train_data[i][0][index]
  return summation_value
def    lowerCamelCase__ (		_A       ):
  a		:      List[str]       =  summation_of_cost_derivative(_A				,    _A       ) / m
  return cost_derivative_value
def    lowerCamelCase__ (		):
  global parameter_vector
  # Tune these values to set a tolerance value for predicted output
  a		:      List[str]       =  0.000002
  a		:      Union[str, Any]       =  0
  a		:      Union[str, Any]       =  0
  while True:
    j += 1
    a		:      str       =  [0, 0, 0, 0]
    for i in range(0				,    len(_A       )       ):
      a		:      Optional[Any]       =  get_cost_derivative(i - 1       )
      a		:      Tuple       =  (
          parameter_vector[i] - LEARNING_RATE * cost_derivative
      )
    if numpy.allclose(
        _A				,    _A				,    atol=_A				,    rtol=_A				,    ):
      break
    a		:      str       =  temp_parameter_vector
  print(('Number of iterations:', j)       )
def    lowerCamelCase__ (		):
  for i in range(len(_A       )       ):
    print(('Actual output value:', output(_A				,    'test'       ))       )
    print(('Hypothesis output:', calculate_hypothesis_value(_A				,    'test'       ))       )


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




'''simple docstring'''






from math import factorial, pi
def    lowerCamelCase__ (		_A				,    _A = 30       ):

  if not isinstance(_A				,    (int, float)       ):
    raise ValueError('maclaurin_sin() requires either an int or float for theta'       )

  if not isinstance(_A				,    _A       ) or accuracy <= 0:
    raise ValueError('maclaurin_sin() requires a positive int for accuracy'       )

  a		:      List[Any]       =  float(_A       )
  a		:      Optional[int]       =  theta // (2 * pi)
  theta -= 2 * div * pi
  return sum(
      (-1) ** r * theta ** (2 * r + 1) / factorial(2 * r + 1       ) for r in range(_A       )       )
def    lowerCamelCase__ (		_A				,    _A = 30       ):

  if not isinstance(_A				,    (int, float)       ):
    raise ValueError('maclaurin_cos() requires either an int or float for theta'       )

  if not isinstance(_A				,    _A       ) or accuracy <= 0:
    raise ValueError('maclaurin_cos() requires a positive int for accuracy'       )

  a		:      List[str]       =  float(_A       )
  a		:      List[str]       =  theta // (2 * pi)
  theta -= 2 * div * pi
  return sum((-1) ** r * theta ** (2 * r) / factorial(2 * r       ) for r in range(_A       )       )


if __name__ == "__main__":
     import doctest

     doctest.testmod()

     print(maclaurin_sin(1_0))
     print(maclaurin_sin(-1_0))
     print(maclaurin_sin(1_0, 1_5))
     print(maclaurin_sin(-1_0, 1_5))

     print(maclaurin_cos(5))
     print(maclaurin_cos(-5))
     print(maclaurin_cos(1_0, 1_5))
     print(maclaurin_cos(-1_0, 1_5))