

import cva
import numpy as np







class 					lowercase							:




				def __init__(   self ,  snake_case ,  snake_case			):

											if k in (0.04, 0.06):
																		snake_case_     							=       k
																		snake_case_     							=       window_size
											else:
																		raise ValueError('invalid k value'			)




				def __str__(   self			):
											return str(self.k			)




				def        a				(   self ,  snake_case			):
											snake_case_     							=       cva.imread(snake_case ,  0			)
											snake_case_							,       snake_case_     							=       img.shape
											snake_case_     							=       []
											snake_case_     							=       img.copy()
											snake_case_     							=       cva.cvtColor(snake_case ,  cva.COLOR_GRAY2RGB			)
											snake_case_							,       snake_case_     							=       np.gradient(snake_case			)
											snake_case_     							=       dx**2
											snake_case_     							=       dy**2
											snake_case_     							=       dx * dy
											snake_case_     							=       0.04
											snake_case_     							=       self.window_size // 2
											for y in range(snake_case ,  h - offset			):
																		for x in range(snake_case ,  w - offset			):
																									snake_case_     							=       ixx[
																									    y - offset : y + offset + 1, x - offset : x + offset + 1
																									].sum()
																									snake_case_     							=       iyy[
																									    y - offset : y + offset + 1, x - offset : x + offset + 1
																									].sum()
																									snake_case_     							=       ixy[
																									    y - offset : y + offset + 1, x - offset : x + offset + 1
																									].sum()

																									snake_case_     							=       (wxx * wyy) - (wxy**2)
																									snake_case_     							=       wxx + wyy
																									snake_case_     							=       det - k * (trace**2)
																									# Can change the value
																									if r > 0.5:
																																corner_list.append([x, y, r]			)
																																color_img.itemset((y, x, 0) ,  0			)
																																color_img.itemset((y, x, 1) ,  0			)
																																color_img.itemset((y, x, 2) ,  255			)
											return color_img, corner_list


if __name__ == "__main__":
					_UpperCAmelCase						:  Any									=			HarrisCorner(0.04, 3)
					_UpperCAmelCase							,		_UpperCAmelCase						:  Any									=			edge_detect.detect("""path_to_image""")
					cva.imwrite("""detect.png""", color_img)







# 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    __lowerCamelCase      (					UpperCamelCase__ ):







							'''simple docstring'''






							return 1 / (1 + np.exp(-z ))





def    __lowerCamelCase      (					UpperCamelCase__  ,				UpperCamelCase__ ):







							'''simple docstring'''






							return (-y * np.log(UpperCamelCase__ ) - (1 - y) * np.log(1 - h )).mean()





def    __lowerCamelCase      (					UpperCamelCase__  ,				UpperCamelCase__  ,				UpperCamelCase__ ):







							'''simple docstring'''






							snake_case_     							=       np.dot(UpperCamelCase__  ,				UpperCamelCase__ )
							return np.sum(y * scores - np.log(1 + np.exp(UpperCamelCase__ ) ) )





def    __lowerCamelCase      (					UpperCamelCase__  ,				UpperCamelCase__  ,				UpperCamelCase__  ,				UpperCamelCase__=70000 ):







							'''simple docstring'''






							snake_case_     							=       np.zeros(x.shape[1] )

							for iterations in range(UpperCamelCase__ ):
														snake_case_     							=       np.dot(UpperCamelCase__  ,				UpperCamelCase__ )
														snake_case_     							=       sigmoid_function(UpperCamelCase__ )
														snake_case_     							=       np.dot(x.T  ,				h - y ) / y.size
														snake_case_     							=       theta - alpha * gradient  # updating the weights
														snake_case_     							=       np.dot(UpperCamelCase__  ,				UpperCamelCase__ )
														snake_case_     							=       sigmoid_function(UpperCamelCase__ )
														snake_case_     							=       cost_function(UpperCamelCase__  ,				UpperCamelCase__ )
														if iterations % 100 == 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						:  Union[str, Any]									=			iris.data[:, :2]
					_UpperCAmelCase						:  List[str]									=			(iris.target != 0) * 1

					_UpperCAmelCase						:  Optional[int]									=			0.1
					_UpperCAmelCase						:  Dict									=			logistic_reg(alpha, x, y, max_iterations=7_0000)
					print("""theta: """, theta)  # printing the theta i.e our weights vector





					def    __lowerCamelCase      (					UpperCamelCase__ ):







												'''simple docstring'''






												return sigmoid_function(
												    np.dot(UpperCamelCase__  ,				UpperCamelCase__ ) )  # 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))						:  Union[str, Any]									=			(x[:, 1].min(), x[:, 1].max())
					((_UpperCAmelCase)							,		(_UpperCAmelCase))						:  int									=			np.meshgrid(np.linspace(xa_min, xa_max), np.linspace(xa_min, xa_max))
					_UpperCAmelCase						:  List[Any]									=			np.c_[xxa.ravel(), xxa.ravel()]
					_UpperCAmelCase						:  Dict									=			predict_prob(grid).reshape(xxa.shape)
					plt.contour(xxa, xxa, probs, [0.5], linewidths=1, colors="""black""")

					plt.legend()


					plt.show()




