def sigmoid(x):
s = 1/(1+np.exp(-x))
return s
t_x = np.array([1,2,3])
print(sigmoid(t_x))
sigmoid_derivative(x)=f(x)(1-f(x))
def sigmoid_derivative(x):
s=sigmoid(x)
ds=s*(1-s)
return ds
t_x = np.array([1,2,3])
sigmoid_derivative(t_x)
(length, height, 3)를 넣으면 벡터값(length x height x3, 1)을 리턴해주는 함수
def image2vector(image):
v = image.reshape((image.shape[0]*image.shape[1]*image.shape[2],1))
return v
def normalize_rows(x):
x_norm = np.linalg.norm(x, axis=1, keepdims = True)
x = x / x_norm
axis = 1
, keepsdim =1
에 대한 설명은 여기 참고하면 도움이 된다.
def softmax(x):
x_exp = np.exp(x)
x_sum = np.sum(x_exp, axis=1, keepdims=True)
s = x_exp / x_sum
return s
def L1(yhat, y):
loss = np.sum(np.abs(yhat-y) , axis = 0)
return loss
def L2(yhat, y):
loss = np.dot(np.abs(yhat-y), np.abs(yhat-y))
return loss