'''simple docstring'''

from cva import destroyAllWindows, imread, imshow, waitKey







def __UpperCamelCase(   _A					:				Tuple    ):
   '''simple docstring'''
   # getting number of pixels in the image
   UpperCAmelCase__				,      UpperCAmelCase__							:				Optional[Any]   				=  img.shape[0], img.shape[1]

   # converting each pixel's color to its negative
   for i in range(_A    ):
      for j in range(_A    ):
         UpperCAmelCase__							:				Any   				=  [2_55, 2_55, 2_55] - img[i][j]

   return img


if __name__ == "__main__":
  # read original image
  UpperCamelCase__     :	Optional[Any]				=			imread('image_data/lena.jpg', 1)

  # convert to its negative
  UpperCamelCase__     :	Tuple				=			convert_to_negative(img)

  # show result image
  imshow('negative of original image', img)
  waitKey(0)
  destroyAllWindows()





'''simple docstring'''

# Logistic Regression from scratch

# In[62]:

# In[63]:

# importing all the required libraries

import numpy as np
from matplotlib import pyplot as plt
from sklearn import datasets







def __UpperCamelCase(   _A					:				str    ):
   '''simple docstring'''
   return 1 / (1 + np.exp(-z    ))







def __UpperCamelCase(   _A					:				int  ,			_A					:				str    ):
   '''simple docstring'''
   return (-y * np.log(_A    ) - (1 - y) * np.log(1 - h    )).mean()







def __UpperCamelCase(   _A					:				Optional[Any]  ,			_A					:				Tuple  ,			_A					:				Any    ):
   '''simple docstring'''
   UpperCAmelCase__							:				Union[str, Any]   				=  np.dot(_A  ,			_A    )
   return np.sum(y * scores - np.log(1 + np.exp(_A    )    )    )







def __UpperCamelCase(   _A					:				Dict  ,			_A					:				Optional[int]  ,			_A					:				List[Any]  ,			_A					:				str=7_00_00    ):
   '''simple docstring'''
   UpperCAmelCase__							:				List[Any]   				=  np.zeros(x.shape[1]    )

   for iterations in range(_A    ):
      UpperCAmelCase__							:				Tuple   				=  np.dot(_A  ,			_A    )
      UpperCAmelCase__							:				Optional[Any]   				=  sigmoid_function(_A    )
      UpperCAmelCase__							:				Optional[int]   				=  np.dot(x.T  ,			h - y    ) / y.size
      UpperCAmelCase__							:				List[Any]   				=  theta - alpha * gradient  # updating the weights
      UpperCAmelCase__							:				Tuple   				=  np.dot(_A  ,			_A    )
      UpperCAmelCase__							:				Tuple   				=  sigmoid_function(_A    )
      UpperCAmelCase__							:				Optional[int]   				=  cost_function(_A  ,			_A    )
      if iterations % 1_00 == 0:
         print(F'''loss: {j} \t'''    )  # printing the loss after every 100 iterations
   return theta


# In[68]:

if __name__ == "__main__":
  UpperCamelCase__     :	str				=			datasets.load_iris()
  UpperCamelCase__     :	Tuple				=			iris.data[:, :2]
  UpperCamelCase__     :	str				=			(iris.target != 0) * 1

  UpperCamelCase__     :	Any				=			0.1
  UpperCamelCase__     :	List[str]				=			logistic_reg(alpha, x, y, max_iterations=70_000)
  print('theta: ', theta)  # printing the theta i.e our weights vector







  def __UpperCamelCase(   _A					:				Any    ):
     '''simple docstring'''
     return sigmoid_function(
         np.dot(_A  ,			_A    )    )  # predicting the value of probability from the logistic regression algorithm

  plt.figure(figsize=(10, 6))
  plt.scatter(x[y == 0][:, 0], x[y == 0][:, 1], color='b', label='0')
  plt.scatter(x[y == 1][:, 0], x[y == 1][:, 1], color='r', label='1')
  ((UpperCamelCase__)				,     (UpperCamelCase__))     :	Any				=			(x[:, 0].min(), x[:, 0].max())
  ((UpperCamelCase__)				,     (UpperCamelCase__))     :	Optional[Any]				=			(x[:, 1].min(), x[:, 1].max())
  ((UpperCamelCase__)				,     (UpperCamelCase__))     :	Any				=			np.meshgrid(np.linspace(xa_min, xa_max), np.linspace(xa_min, xa_max))
  UpperCamelCase__     :	str				=			np.c_[xxa.ravel(), xxa.ravel()]
  UpperCamelCase__     :	Union[str, Any]				=			predict_prob(grid).reshape(xxa.shape)
  plt.contour(xxa, xxa, probs, [0.5], linewidths=1, colors='black')

  plt.legend()
  plt.show()




