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 54250a4 commit 6ca6059
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions code/loss_functions.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,57 @@
import math
import numpy as np

# using the common convention:
# yHat is the prediction while y is the truth (true label)
### Note ###

# yHat is prediction
# y is the target (true label)


### Functions ###

def CrossEntropy(yHat, y):
pass
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)


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


def Huber(yHat, y):
pass


def KLDivergence(yHat, y):
pass
pass


def L1(yHat, y):s
return np.sum(np.absolute(yHat - y))
def L1(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 ###

def MSE_prime(yHat, y):
return yHat - y

0 comments on commit 6ca6059

Please sign in to comment.