forked from wazaahhh/bayesLearn
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLoss.py
31 lines (23 loc) · 738 Bytes
/
Loss.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import scipy as sp
from math import sqrt
from numpy.random import random
from scipy.stats.stats import pearsonr
truth =random( 8 ); truth = truth/sum(truth)
#with a normalization so that all entries add to 1.0.
def logloss(act, pred):
epsilon = 1e-15
pred = sp.maximum(epsilon, pred)
pred = sp.minimum(1-epsilon, pred)
ll = sum(act*sp.log(pred) + sp.subtract(1,act)*sp.log(sp.subtract(1,pred)))
ll = ll * -1.0/len(act)
return ll
def quadloss(act, pred):
return sqrt(sum([(act[i]-pred[i])**2 for i in range(len(pred))]))
ll = []
ql =[]
for i in range(1000):
model = random(8)
model = random(8)
ll.append(logloss(truth, model))
ql.append(quadloss(truth, model))
print(pearsonr(ll, ql))