def entropiesFast(counts, locPrior, likelihoodsObj, d): # d=dag.linearTestDag(len(locPrior)) one = numberType.const(1.0) renyiFactor = one / (one - entropy.alpha) lk = likelihoodsObj.calc(counts, locPrior, entropy.alpha, d) (rsum, osum) = lk.orig() currEntropy = rsum / numberType.pow(osum, entropy.alpha) currEntropy = numberType.log(currEntropy) * renyiFactor entropyResults = [] findProbs = [] for i in xrange(len(locPrior)): (findProb, renyLksFoundTot, renyLksNFoundTot, evDProb, NfoundNorm) = lk[i] findProbs.append(findProb) #entropyFound:normalise try: eFound = renyLksFoundTot / numberType.pow(evDProb, entropy.alpha) eFound = numberType.log(eFound) * renyiFactor except numberType.zeroDivisionError: eFound = 0 except numberType.overflowError: eFound = 0 #entropyNotFound:normalise try: eNotFound = renyLksNFoundTot / numberType.pow( NfoundNorm, entropy.alpha) eNotFound = numberType.log(eNotFound) * renyiFactor except numberType.zeroDivisionError: eNotFound = 0 except numberType.overflowError: eNotFound = 0 # expected entropy after testing at i: if debug: print "b", eFound, eNotFound, findProb eResult = eFound * findProb + eNotFound * (1 - findProb) entropyResults.append(eResult) return (currEntropy, entropyResults, findProbs)
def entropiesFast(counts,locPrior,likelihoodsObj,d): # d=dag.linearTestDag(len(locPrior)) one=numberType.const(1.0) renyiFactor=one/(one-entropy.alpha) lk=likelihoodsObj.calc(counts,locPrior,entropy.alpha,d) (rsum,osum)=lk.orig() currEntropy=rsum/numberType.pow(osum,entropy.alpha) currEntropy =numberType.log(currEntropy)*renyiFactor entropyResults=[] findProbs=[] for i in xrange(len(locPrior)): (findProb,renyLksFoundTot,renyLksNFoundTot,evDProb,NfoundNorm)=lk[i] findProbs.append(findProb) #entropyFound:normalise try: eFound=renyLksFoundTot/numberType.pow(evDProb,entropy.alpha) eFound=numberType.log(eFound)*renyiFactor except numberType.zeroDivisionError: eFound=0 except numberType.overflowError: eFound=0 #entropyNotFound:normalise try: eNotFound=renyLksNFoundTot/numberType.pow(NfoundNorm,entropy.alpha) eNotFound=numberType.log(eNotFound)*renyiFactor except numberType.zeroDivisionError: eNotFound=0 except numberType.overflowError: eNotFound=0 # expected entropy after testing at i: if debug: print "b",eFound,eNotFound,findProb eResult=eFound*findProb+eNotFound*(1-findProb) entropyResults.append(eResult) return (currEntropy,entropyResults,findProbs)
def renyi(probs): e=0 one=numberType.const(1.0) d=one/(one-alpha) for p in probs: e=e+numberType.pow(p,alpha) return numberType.log(e)*d
def nD(k,n,p): return numberType.pow(p,k)*numberType.pow(1-p,n-k)
def powList(l,p): return [numberType.pow(x,p) for x in l]
def __init__(self,decayFactor): self.decayFactor=numberType.pow(decayFactor,numberType.const(0.5))
def nD(k, n, p): return numberType.pow(p, k) * numberType.pow(1 - p, n - k)
def powList(l, p): return [numberType.pow(x, p) for x in l]