





import numpy

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



def 	_a						(   UpperCAmelCase      ,  UpperCAmelCase="train"					)    ->    Optional[int]:







   """simple docstring"""
   return calculate_hypothesis_value(UpperCAmelCase      ,  UpperCAmelCase					) - output(
       UpperCAmelCase      ,  UpperCAmelCase					)



def 	_a						(   UpperCAmelCase					)    ->    List[str]:







   """simple docstring"""
   lowerCamelCase__       :						List[str]        =							0
   for i in range(len(UpperCAmelCase					) - 1					):
      hyp_val += data_input_tuple[i] * parameter_vector[i + 1]
   hyp_val += parameter_vector[0]
   return hyp_val



def 	_a						(   UpperCAmelCase      ,  UpperCAmelCase					)    ->    Optional[int]:







   """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 	_a						(   UpperCAmelCase      ,  UpperCAmelCase					)    ->    Union[str, Any]:







   """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 	_a						(   UpperCAmelCase      ,  UpperCAmelCase=m					)    ->    List[str]:







   """simple docstring"""
   lowerCamelCase__       :						List[Any]        =							0
   for i in range(UpperCAmelCase					):
      if index == -1:
         summation_value += _error(UpperCAmelCase					)
      else:
         summation_value += _error(UpperCAmelCase					) * train_data[i][0][index]
   return summation_value



def 	_a						(   UpperCAmelCase					)    ->    Any:







   """simple docstring"""
   lowerCamelCase__       :						Union[str, Any]        =							summation_of_cost_derivative(UpperCAmelCase      ,  UpperCAmelCase					) / m
   return cost_derivative_value



def 	_a						(   )    ->    str:







   """simple docstring"""
   global parameter_vector
   # Tune these values to set a tolerance value for predicted output
   lowerCamelCase__       :						Dict        =							0.00_00_02
   lowerCamelCase__       :						List[str]        =							0
   lowerCamelCase__       :						Optional[Any]        =							0
   while True:
      j += 1
      lowerCamelCase__       :						int        =							[0, 0, 0, 0]
      for i in range(0      ,  len(UpperCAmelCase					)					):
         lowerCamelCase__       :						Optional[int]        =							get_cost_derivative(i - 1					)
         lowerCamelCase__       :						Any        =							(
             parameter_vector[i] - LEARNING_RATE * cost_derivative
         )
      if numpy.allclose(
          UpperCAmelCase      ,  UpperCAmelCase      ,  atol=UpperCAmelCase      ,  rtol=UpperCAmelCase      ,  ):
         break
      lowerCamelCase__       :						str        =							temp_parameter_vector
   print(('''Number of iterations:''', j)					)



def 	_a						(   )    ->    int:







   """simple docstring"""
   for i in range(len(UpperCAmelCase					)					):
      print(('''Actual output value:''', output(UpperCAmelCase      ,  '''test'''					))					)
      print(('''Hypothesis output:''', calculate_hypothesis_value(UpperCAmelCase      ,  '''test'''					))					)


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










import math
import random



def 	_a						(   UpperCAmelCase      ,  UpperCAmelCase = False					)    ->    float:







   """simple docstring"""
   if deriv:
      return value * (1 - value)
   return 1 / (1 + math.exp(-value					))


# Initial Value
_A :   Tuple  			=  0.02



def 	_a						(   UpperCAmelCase      ,  UpperCAmelCase					)    ->    float:







   """simple docstring"""
   lowerCamelCase__       :						List[Any]        =							float(2 * (random.randint(1      ,  100					)) - 1					)

   for _ in range(UpperCAmelCase					):
      # Forward propagation
      lowerCamelCase__       :						Optional[int]        =							sigmoid_function(INITIAL_VALUE * weight					)
      # How much did we miss?
      lowerCamelCase__       :						int        =							(expected / 100) - layer_a
      # Error delta
      lowerCamelCase__       :						Union[str, Any]        =							layer_1_error * sigmoid_function(UpperCAmelCase      ,  UpperCAmelCase					)
      # Update weight
      weight += INITIAL_VALUE * layer_1_delta

   return layer_a * 100


if __name__ == "__main__":
       import doctest

       doctest.testmod()

       _A :   Union[str, Any]  			=  int(input('Expected value: '))
       _A :   int  			=  int(input('Number of propagations: '))
       print(forward_propagation(expected, number_propagations))



