Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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
Exemplo n.º 4
0
def logFact(x):
    while(x>=len(logFactMemo)):
        logFactMemo.append(logFactMemo[-1]+numberType.log(len(logFactMemo)))
    return logFactMemo[x]
Exemplo n.º 5
0
def logFact(x):
    while (x >= len(logFactMemo)):
        logFactMemo.append(logFactMemo[-1] + numberType.log(len(logFactMemo)))
    return logFactMemo[x]
Exemplo n.º 6
0
def shannon(probs):
    e=0
    for p in probs:
        if(p>0):
            e-=p*numberType.log(p)
    return e