Skip to content

Commit

Permalink
Update loss_functions.py
Browse files Browse the repository at this point in the history
  • Loading branch information
bfortuner committed Nov 29, 2017
1 parent 2289699 commit 7d06f8d
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions code/loss_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,45 @@
### Functions ###

def CrossEntropy(yHat, y):
if yHat == 1:
return -log(y)
else:
return -log(1 - y)
if yHat == 1:
return -log(y)
else:
return -log(1 - y)


def Dice(yHat, y):
total = np.sum(y, dim=1) + np.sum(yHat, dim=1)
intersection = np.sum(y * yHat, dim=1)
dice = (2.0 * intersection) / (total + 1e-7)
return np.mean(dice)
total = np.sum(y, dim=1) + np.sum(yHat, dim=1)
intersection = np.sum(y * yHat, dim=1)
dice = (2.0 * intersection) / (total + 1e-7)
return np.mean(dice)


def Hinge(yHat, y):
return np.max(0, 1 - yHat * y)
return np.max(0, 1 - yHat * y)


def Huber(yHat, y):
pass
pass


def KLDivergence(yHat, y):
pass
pass


def L1(yHat, y):
return np.sum(np.absolute(yHat - y))
return np.sum(np.absolute(yHat - y))


def L2(yHat, y):
return np.sum((yHat - y)**2)
return np.sum((yHat - y)**2)


def MLE(yHat, y):
pass
pass


def MSE(yHat, y):
return np.sum((yHat - y)**2) / y.size
return np.sum((yHat - y)**2) / y.size


### Derivatives ###
Expand Down

0 comments on commit 7d06f8d

Please sign in to comment.