import os
import sys
import time

from . import transposition_cipher as trans_cipher




def   _UpperCamelCase   (			)						->   None:
							__UpperCAmelCase						:			Union[str, Any]         =   "Prehistoric Men.txt"
							__UpperCAmelCase						:			List[Any]         =   "Output.txt"
							__UpperCAmelCase						:			Union[str, Any]         =   int(input("Enter key: "							)							)
							__UpperCAmelCase						:			int         =   input("Encrypt/Decrypt [e/d]: "							)

							if not os.path.exists(snake_case__							):
														print(f'''File {input_file} does not exist. Quitting...'''							)
														sys.exit()
							if os.path.exists(snake_case__							):
														print(f'''Overwrite {output_file}? [y/n]'''							)
														__UpperCAmelCase						:			List[Any]         =   input("> "							)
														if not response.lower().startswith("y"							):
																					sys.exit()

							__UpperCAmelCase						:			Any         =   time.time()
							if mode.lower().startswith("e"							):
														with open(snake_case__							) as f:
																					__UpperCAmelCase						:			List[Any]         =   f.read()
														__UpperCAmelCase						:			List[str]         =   trans_cipher.encrypt_message(snake_case__,    snake_case__							)
							elif mode.lower().startswith("d"							):
														with open(snake_case__							) as f:
																					__UpperCAmelCase						:			str         =   f.read()
														__UpperCAmelCase						:			str         =   trans_cipher.decrypt_message(snake_case__,    snake_case__							)

							with open(snake_case__,    "w"							) as output_obj:
														output_obj.write(snake_case__							)

							__UpperCAmelCase						:			Any         =   round(time.time() - start_time,    2							)
							print(("Done (", total_time, "seconds )")							)


if __name__ == "__main__":
	main()





import numpy as np
import requests




def   _UpperCamelCase   (			)						->   Tuple:
							__UpperCAmelCase						:			Tuple         =   requests.get(
							    "https://raw.githubusercontent.com/yashLadha/The_Math_of_Intelligence/"
							    "master/Week1/ADRvsRating.csv"							)
							__UpperCAmelCase						:			List[Any]         =   response.text.splitlines()
							__UpperCAmelCase						:			Any         =   []
							for item in lines:
														__UpperCAmelCase						:			Any         =   item.split(","							)
														data.append(snake_case__							)
							data.pop(0							)  # This is for removing the labels from the list
							__UpperCAmelCase						:			List[str]         =   np.matrix(snake_case__							)
							return dataset




def   _UpperCamelCase   (			snake_case__,    snake_case__,    snake_case__,    snake_case__,    snake_case__							)						->   Optional[Any]:
							__UpperCAmelCase						:			Tuple         =   len_data

							__UpperCAmelCase						:			int         =   np.dot(snake_case__,    data_x.transpose()							)
							prod -= data_y.transpose()
							__UpperCAmelCase						:			Optional[int]         =   np.dot(snake_case__,    snake_case__							)
							__UpperCAmelCase						:			List[Any]         =   theta - (alpha / n) * sum_grad
							return theta




def   _UpperCamelCase   (			snake_case__,    snake_case__,    snake_case__,    snake_case__							)						->   Optional[int]:
							__UpperCAmelCase						:			Any         =   np.dot(snake_case__,    data_x.transpose()							)
							prod -= data_y.transpose()
							__UpperCAmelCase						:			Optional[int]         =   np.sum(np.square(snake_case__							)							)
							__UpperCAmelCase						:			List[Any]         =   sum_elem / (2 * len_data)
							return error




def   _UpperCamelCase   (			snake_case__,    snake_case__							)						->   Tuple:
							__UpperCAmelCase						:			Any         =   10_0000
							__UpperCAmelCase						:			Dict         =   0.000_1550

							__UpperCAmelCase						:			str         =   data_x.shape[1]
							__UpperCAmelCase						:			Any         =   data_x.shape[0] - 1

							__UpperCAmelCase						:			List[str]         =   np.zeros((1, no_features)							)

							for i in range(0,    snake_case__							):
														__UpperCAmelCase						:			Union[str, Any]         =   run_steep_gradient_descent(snake_case__,    snake_case__,    snake_case__,    snake_case__,    snake_case__							)
														__UpperCAmelCase						:			Any         =   sum_of_square_error(snake_case__,    snake_case__,    snake_case__,    snake_case__							)
														print(f'''At Iteration {i + 1} - Error is {error:.5f}'''							)

							return theta




def   _UpperCamelCase   (			snake_case__,    snake_case__							)						->   Optional[int]:
							__UpperCAmelCase						:			str         =   sum(abs(y - predicted_y[i]							) for i, y in enumerate(snake_case__							)							)
							return total / len(snake_case__							)




def   _UpperCamelCase   (			)						->   List[str]:
							__UpperCAmelCase						:			str         =   collect_dataset()

							__UpperCAmelCase						:			List[Any]         =   data.shape[0]
							__UpperCAmelCase						:			Union[str, Any]         =   np.c_[np.ones(snake_case__							), data[:, :-1]].astype(snake_case__							)
							__UpperCAmelCase						:			int         =   data[:, -1].astype(snake_case__							)

							__UpperCAmelCase						:			List[Any]         =   run_linear_regression(snake_case__,    snake_case__							)
							__UpperCAmelCase						:			List[str]         =   theta.shape[1]
							print("Resultant Feature vector : "							)
							for i in range(0,    snake_case__							):
														print(f'''{theta[0, i]:.5f}'''							)


if __name__ == "__main__":
	main()




