This commit is contained in:
Connor Olding 2017-02-27 02:43:51 +00:00
parent d442241e76
commit 5f87c7a56b

View file

@ -63,6 +63,18 @@ class CategoricalCrossentropy(Loss):
df = (p - y) / (p * (1 - p)) df = (p - y) / (p * (1 - p))
return df / len(y) return df / len(y)
class Accuracy(Loss):
# returns percentage of categories correctly predicted.
# utilizes max(), so it cannot be used for gradient descent.
# use CategoricalCrossentropy for that instead.
def F(self, p, y):
correct = np.argmax(p, axis=-1) == np.argmax(y, axis=-1)
return np.mean(correct)
def dF(self, p, y):
raise NotImplementedError("cannot take the gradient of Accuracy")
class ResidualLoss(Loss): class ResidualLoss(Loss):
def F(self, p, y): # mean def F(self, p, y): # mean
return np.mean(self.f(p - y)) return np.mean(self.f(p - y))