def evalObjectiveFunction(clean_biascount,Pword_plus,Pword_minus,ratio,removing_words):
mlog(evalObjectiveFunction.__name__,"call")
import numpy as np
import math
#Obj = np.log(1)
Obj = 0
for doc in clean_biascount:
Pdoc = calcProbabilityDocument(Pword_plus,Pword_minus,doc[1],ratio,removing_words)
i = clean_biascount.index(doc)
if i == 0:
mlog(evalObjectiveFunction.__name__,'Pdoc 0 ' + str(Pdoc) + ' type ' + str(type(Pdoc)))
t00 = np.exp(np.float64(Pdoc[0]))
t01 = np.exp(np.float64(Pdoc[1]))
t1 = t00 - t01
#print str(t1)
t2 = abs(t1)
Obj = np.log(t2)
#print str(Obj)
if i % 100 == 0:
mlog(evalObjectiveFunction.__name__,"Pdoc + " + str(i) + "= " + str(Pdoc))
if doc[0] == True:
Obj = np.logaddexp(Obj,Pdoc[0])
if i % 100 == 1:
mlog(evalObjectiveFunction.__name__,"Obj+ " + str(i) + " after += " + str(Obj))
Obj = np.log(np.exp(Obj) - np.exp(Pdoc[1]))
elif doc[0] == False:
Obj = np.log(np.exp(np.float64(Obj)) + np.exp(np.float64(Pdoc[1])))
if i % 100 == 2:
mlog(evalObjectiveFunction.__name__,"Obj- " + str(i) + " after += " + str(Obj))
Obj = np.log(np.exp(Obj) - np.exp(Pdoc[0]))
if Obj == 0.0:
mlog(evalObjectiveFunction.__name__, "Obj=0 fuck " + str(i) + "")
mlog(evalObjectiveFunction.__name__,"Obj = " + str(np.exp(Obj)))
if math.isnan(np.exp(Obj))==False:
print 'J = ' + str(np.exp(Obj))
return Obj #type np.log
评论列表
文章目录