-
Notifications
You must be signed in to change notification settings - Fork 715
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |