

'''simple docstring'''
import numpy as np
import requests


def       a__    (  )			-> Union[str, Any]:


	"""simple docstring"""





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


def       a__    (  _SCREAMING_SNAKE_CASE					:    int     ,							_SCREAMING_SNAKE_CASE					:    List[Any]     ,							_SCREAMING_SNAKE_CASE					:    Tuple     ,							_SCREAMING_SNAKE_CASE					:    int     ,							_SCREAMING_SNAKE_CASE					:    Union[str, Any]							)			-> Any:


	"""simple docstring"""





	UpperCAmelCase_			:	int      =   len_data

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


def       a__    (  _SCREAMING_SNAKE_CASE					:    int     ,							_SCREAMING_SNAKE_CASE					:    Tuple     ,							_SCREAMING_SNAKE_CASE					:    int     ,							_SCREAMING_SNAKE_CASE					:    int							)			-> Optional[Any]:


	"""simple docstring"""





	UpperCAmelCase_			:	Dict      =   np.dot(_lowerCamelCase     ,							data_x.transpose()							)
	prod -= data_y.transpose()
	UpperCAmelCase_			:	Optional[Any]      =   np.sum(np.square(_lowerCamelCase							)							)
	UpperCAmelCase_			:	str      =   sum_elem / (2 * len_data)
	return error


def       a__    (  _SCREAMING_SNAKE_CASE					:    Dict     ,							_SCREAMING_SNAKE_CASE					:    Any							)			-> int:


	"""simple docstring"""





	UpperCAmelCase_			:	Optional[Any]      =   10_00_00
	UpperCAmelCase_			:	Union[str, Any]      =   0.0_001_550

	UpperCAmelCase_			:	Optional[Any]      =   data_x.shape[1]
	UpperCAmelCase_			:	int      =   data_x.shape[0] - 1

	UpperCAmelCase_			:	Union[str, Any]      =   np.zeros((1, no_features)							)

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

	return theta


def       a__    (  _SCREAMING_SNAKE_CASE					:    int     ,							_SCREAMING_SNAKE_CASE					:    Any							)			-> Tuple:


	"""simple docstring"""





	UpperCAmelCase_			:	Optional[Any]      =   sum(abs(y - predicted_y[i]							) for i, y in enumerate(_lowerCamelCase							)							)
	return total / len(_lowerCamelCase							)


def       a__    (  )			-> Union[str, Any]:


	"""simple docstring"""





	UpperCAmelCase_			:	int      =   collect_dataset()

	UpperCAmelCase_			:	int      =   data.shape[0]
	UpperCAmelCase_			:	Optional[int]      =   np.c_[np.ones(_lowerCamelCase							), data[:, :-1]].astype(_lowerCamelCase							)
	UpperCAmelCase_			:	List[Any]      =   data[:, -1].astype(_lowerCamelCase							)

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


if __name__ == "__main__":
					main()












"""simple docstring"""
from cva import destroyAllWindows, imread, imshow, waitKey






def        lowerCamelCase_  (						_lowerCamelCase			,   _lowerCamelCase				):
 lowerCamelCase__				,     lowerCamelCase__     :			Optional[Any]     				=						img.shape[0], img.shape[1]

 def to_grayscale(_lowerCamelCase			,   _lowerCamelCase			,   _lowerCamelCase				):
  return 0.2_126 * red + 0.587 * green + 0.114 * blue

 def normalize(_lowerCamelCase				):
  return min(_lowerCamelCase			,   255				)

 for i in range(_lowerCamelCase				):
  for j in range(_lowerCamelCase				):
   lowerCamelCase__     :			List[Any]     				=						int(to_grayscale(*img[i][j]				)				)
   lowerCamelCase__     :			Optional[int]     				=						[
       normalize(_lowerCamelCase				),
       normalize(greyscale + factor				),
       normalize(greyscale + 2 * factor				),
   ]

 return img


if __name__ == "__main__":
      # read original image
      A_			: List[str]				=			{
          percentage: imread("image_data/lena.jpg", 1) for percentage in (10, 20, 30, 40)
      }

      for percentage, img in images.items():
            make_sepia(img, percentage)

      for percentage, img in images.items():
            imshow(f"Original image with sepia (factor: {percentage})", img)

      waitKey(0)
      destroyAllWindows()

