

import numpy as np
import requests







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

 """simple docstring"""






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







def _a			(	SCREAMING_SNAKE_CASE		:      str   , SCREAMING_SNAKE_CASE		:      Any   , SCREAMING_SNAKE_CASE		:      int   , SCREAMING_SNAKE_CASE		:      List[str]   , SCREAMING_SNAKE_CASE		:      int		)   ->   Any:

 """simple docstring"""






 __lowerCAmelCase:       Optional[Any]            =				len_data

 __lowerCAmelCase:       Union[str, Any]            =				np.dot(SCREAMING_SNAKE_CASE   , data_x.transpose()		)
 prod -= data_y.transpose()
 __lowerCAmelCase:       List[Any]            =				np.dot(SCREAMING_SNAKE_CASE   , SCREAMING_SNAKE_CASE		)
 __lowerCAmelCase:       Union[str, Any]            =				theta - (alpha / n) * sum_grad
 return theta







def _a			(	SCREAMING_SNAKE_CASE		:      int   , SCREAMING_SNAKE_CASE		:      Union[str, Any]   , SCREAMING_SNAKE_CASE		:      Any   , SCREAMING_SNAKE_CASE		:      Optional[Any]		)   ->   Dict:

 """simple docstring"""






 __lowerCAmelCase:       str            =				np.dot(SCREAMING_SNAKE_CASE   , data_x.transpose()		)
 prod -= data_y.transpose()
 __lowerCAmelCase:       Dict            =				np.sum(np.square(SCREAMING_SNAKE_CASE		)		)
 __lowerCAmelCase:       Any            =				sum_elem / (2 * len_data)
 return error







def _a			(	SCREAMING_SNAKE_CASE		:      Union[str, Any]   , SCREAMING_SNAKE_CASE		:      Dict		)   ->   List[Any]:

 """simple docstring"""






 __lowerCAmelCase:       List[Any]            =				10_00_00
 __lowerCAmelCase:       int            =				0.0_0_0_1_5_5_0

 __lowerCAmelCase:       List[Any]            =				data_x.shape[1]
 __lowerCAmelCase:       Union[str, Any]            =				data_x.shape[0] - 1

 __lowerCAmelCase:       Tuple            =				np.zeros((1, no_features)		)

 for i in range(0   , SCREAMING_SNAKE_CASE		):
  __lowerCAmelCase:       Any            =				run_steep_gradient_descent(SCREAMING_SNAKE_CASE   , SCREAMING_SNAKE_CASE   , SCREAMING_SNAKE_CASE   , SCREAMING_SNAKE_CASE   , SCREAMING_SNAKE_CASE		)
  __lowerCAmelCase:       Tuple            =				sum_of_square_error(SCREAMING_SNAKE_CASE   , SCREAMING_SNAKE_CASE   , SCREAMING_SNAKE_CASE   , SCREAMING_SNAKE_CASE		)
  print(f'''At Iteration {i + 1} - Error is {error:.5f}'''		)

 return theta







def _a			(	SCREAMING_SNAKE_CASE		:      int   , SCREAMING_SNAKE_CASE		:      Any		)   ->   List[str]:

 """simple docstring"""






 __lowerCAmelCase:       Optional[int]            =				sum(abs(y - predicted_y[i]		) for i, y in enumerate(SCREAMING_SNAKE_CASE		)		)
 return total / len(SCREAMING_SNAKE_CASE		)







def _a			(	)   ->   List[Any]:

 """simple docstring"""






 __lowerCAmelCase:       Optional[Any]            =				collect_dataset()

 __lowerCAmelCase:       Tuple            =				data.shape[0]
 __lowerCAmelCase:       Optional[int]            =				np.c_[np.ones(SCREAMING_SNAKE_CASE		), data[:, :-1]].astype(SCREAMING_SNAKE_CASE		)
 __lowerCAmelCase:       str            =				data[:, -1].astype(SCREAMING_SNAKE_CASE		)

 __lowerCAmelCase:       Dict            =				run_linear_regression(SCREAMING_SNAKE_CASE   , SCREAMING_SNAKE_CASE		)
 __lowerCAmelCase:       Union[str, Any]            =				theta.shape[1]
 print('Resultant Feature vector : '		)
 for i in range(0   , SCREAMING_SNAKE_CASE		):
  print(f'''{theta[0, i]:.5f}'''		)


if __name__ == "__main__":
  main()








from __future__ import annotations







def _a			(	SCREAMING_SNAKE_CASE		:      list[int]		)   ->   list[int]:

 """simple docstring"""






 if not list_of_ints:
  return []

 if min(SCREAMING_SNAKE_CASE		) < 0:
  raise ValueError('All numbers must be positive'		)

 __lowerCAmelCase:       Tuple            =				max(len(bin(SCREAMING_SNAKE_CASE		)[2:]		) for x in list_of_ints		)
 return _msd_radix_sort(SCREAMING_SNAKE_CASE   , SCREAMING_SNAKE_CASE		)







def _a			(	SCREAMING_SNAKE_CASE		:      list[int]   , SCREAMING_SNAKE_CASE		:      int		)   ->   list[int]:

 """simple docstring"""






 if bit_position == 0 or len(SCREAMING_SNAKE_CASE		) in [0, 1]:
  return list_of_ints

 __lowerCAmelCase:       List[str]            =				[]
 __lowerCAmelCase:       Any            =				[]
 # Split numbers based on bit at bit_position from the right
 for number in list_of_ints:
  if (number >> (bit_position - 1)) & 1:
   # number has a one at bit bit_position
   ones.append(SCREAMING_SNAKE_CASE		)
  else:
   # number has a zero at bit bit_position
   zeros.append(SCREAMING_SNAKE_CASE		)

    # recursively split both lists further
 __lowerCAmelCase:       Dict            =				_msd_radix_sort(SCREAMING_SNAKE_CASE   , bit_position - 1		)
 __lowerCAmelCase:       Union[str, Any]            =				_msd_radix_sort(SCREAMING_SNAKE_CASE   , bit_position - 1		)

 # recombine lists
 __lowerCAmelCase:       List[str]            =				zeros
 res.extend(SCREAMING_SNAKE_CASE		)

 return res







def _a			(	SCREAMING_SNAKE_CASE		:      list[int]		)   ->   List[str]:

 """simple docstring"""






 __lowerCAmelCase:       Optional[int]            =				len(SCREAMING_SNAKE_CASE		)
 if not list_of_ints or length == 1:
  return

 if min(SCREAMING_SNAKE_CASE		) < 0:
  raise ValueError('All numbers must be positive'		)

 __lowerCAmelCase:       Optional[int]            =				max(len(bin(SCREAMING_SNAKE_CASE		)[2:]		) for x in list_of_ints		)
 _msd_radix_sort_inplace(SCREAMING_SNAKE_CASE   , SCREAMING_SNAKE_CASE   , 0   , SCREAMING_SNAKE_CASE		)







def _a			(	SCREAMING_SNAKE_CASE		:      list[int]   , SCREAMING_SNAKE_CASE		:      int   , SCREAMING_SNAKE_CASE		:      int   , SCREAMING_SNAKE_CASE		:      int		)   ->   str:

 """simple docstring"""






 if bit_position == 0 or end_index - begin_index <= 1:
  return

 bit_position -= 1

 __lowerCAmelCase:       Optional[int]            =				begin_index
 __lowerCAmelCase:       Optional[Any]            =				end_index - 1
 while i <= j:
  __lowerCAmelCase:       Any            =				False
  if not (list_of_ints[i] >> bit_position) & 1:
   # found zero at the beginning
   i += 1
   __lowerCAmelCase:       Optional[Any]            =				True
  if (list_of_ints[j] >> bit_position) & 1:
   # found one at the end
   j -= 1
   __lowerCAmelCase:       List[str]            =				True

  if changed:
   continue

  __lowerCAmelCase     ,							__lowerCAmelCase:       Union[str, Any]            =				list_of_ints[j], list_of_ints[i]
  j -= 1
  if j != i:
   i += 1

 _msd_radix_sort_inplace(SCREAMING_SNAKE_CASE   , SCREAMING_SNAKE_CASE   , SCREAMING_SNAKE_CASE   , SCREAMING_SNAKE_CASE		)
 _msd_radix_sort_inplace(SCREAMING_SNAKE_CASE   , SCREAMING_SNAKE_CASE   , SCREAMING_SNAKE_CASE   , SCREAMING_SNAKE_CASE		)


if __name__ == "__main__":
  import doctest

  doctest.testmod()





