



"""simple docstring"""


def  _lowerCAmelCase      (   lowercase_		,	lowercase_						):
						return int((input_a, input_a).count(0						) != 0						)

def  _lowerCAmelCase      (   ):
						assert nand_gate(0		,	0						) == 1
						assert nand_gate(0		,	1						) == 1
						assert nand_gate(1		,	0						) == 1
						assert nand_gate(1		,	1						) == 0


if __name__ == "__main__":
				print(nand_gate(0, 0))
				print(nand_gate(0, 1))
				print(nand_gate(1, 0))
				print(nand_gate(1, 1))











import numpy

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



def 					UpperCAmelCase__     (   lowerCamelCase,	lowerCamelCase="train"      ):
  return calculate_hypothesis_value(lowerCamelCase,	lowerCamelCase      ) - output(
      lowerCamelCase,	lowerCamelCase      )



def 					UpperCAmelCase__     (   lowerCamelCase      ):
  lowercase			:str							=  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      ):
  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      ):
  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      ):
  lowercase			:Union[str, Any]							=  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      ):
  lowercase			:int							=  summation_of_cost_derivative(lowerCamelCase,	lowerCamelCase      ) / m
  return cost_derivative_value



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



def 					UpperCAmelCase__     (   ):
  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()



