Need help with code completion in python below.: class cross_entropy: def __init__(self): self.X = None self.Y = None def forward(self,X,Y): m = Y.shape[1] logprobs = np.multiply(np.log(X), Y) + np.multiply((1 - Y), np.log(1 - X)) cost = - np.sum(logprobs) / m cost = np.squeeze(cost) self.X = X self.Y = Y return cost def backward(self): m = self.Y.shape[1] diff = self.X-self.Y diff = np.divide(diff,np.multiply(self.X,(1-self.X)))/m self.X = None self.Y = None return diff class mse: def __init__(self): self.X = None self.Y = None def forward(self,X,Y): # YOUR CODE HERE return cost def backward(self): #YOUR CODE HERE return diff
Need help with code completion in python below.:
class cross_entropy:
def __init__(self):
self.X = None
self.Y = None
def forward(self,X,Y):
m = Y.shape[1]
logprobs = np.multiply(np.log(X), Y) + np.multiply((1 - Y), np.log(1 - X))
cost = - np.sum(logprobs) / m
cost = np.squeeze(cost)
self.X = X
self.Y = Y
return cost
def backward(self):
m = self.Y.shape[1]
diff = self.X-self.Y
diff = np.divide(diff,np.multiply(self.X,(1-self.X)))/m
self.X = None
self.Y = None
return diff
class mse:
def __init__(self):
self.X = None
self.Y = None
def forward(self,X,Y):
# YOUR CODE HERE
return cost
def backward(self):
#YOUR CODE HERE
return diff
I have provided explanation and full code to complete the python program given in the question.
Step by step
Solved in 2 steps