コード例 #1
0
ファイル: vtag.py プロジェクト: sindhuula/sem3
def getSingleEmission(observations, v):
    if ('ocpEmission', observations, v) not in singleCountEmission:
        if observations == boundaryWord and v == boundaryState:
            ocp = 1.0
        elif v == boundaryState:
            ocp = 0.0
        else:
            singleCountLambda = len(singletonEmissions[v])
            singleCountLambda = addLambda if singleCountLambda == 0 else singleCountLambda
            if observations not in currentMLEs[obsVocab]:
                V = len(currentMLEs[obsVocab])
                addOnePW = 1.0 / float(currentMLEs[N1] - 1 + V)
            else:
                V = len(currentMLEs[obsVocab])
                addOnePW = (currentMLEs[('countObserved', observations)] + 1.0) / float(currentMLEs[N1] - 1 + V)
            countObservedV = currentMLEs.get(('emission', observations, v), 0.0)
            countV = currentMLEs[('emissionsFrom', v)]
            if countV == 0:
                pdb.setTrace()
            ocp = (countObservedV + singleCountLambda * addOnePW) / float(countV + singleCountLambda)
        if ocp == 0 and v != boundaryState and observations != boundaryWord:
            pdb.setTrace()
            raise "Single count smoothed probability for emission is 0"
        singleCountEmission[('ocpEmission', observations, v)] = log(ocp) if ocp > 0.0 else float('-inf')
    return singleCountEmission[('ocpEmission', observations, v)]
コード例 #2
0
ファイル: vtag.py プロジェクト: sindhuula/sem3
def getSingleTransitions(v, u):
    if ('ocpTransition', v, u) not in singleCountTransition:
        singleCountLambda = len(singletonTransitions[u])
        singleCountLambda = addLambda if singleCountLambda == 0 else singleCountLambda
        countUV = currentMLEs.get(('transition', v, u), 0.0)
        countU = currentMLEs[('countState', u)] if u != boundaryState else (currentMLEs[('transitionsFrom', u)] )
        countV = currentMLEs[('countState', v)] if v != boundaryState else (currentMLEs[('transitionsFrom', v)] )
        unsmoothedPV = countV / (currentMLEs[N1] - 1.0)
        ocp = (countUV + singleCountLambda * unsmoothedPV) / float(countU + singleCountLambda)
        if ocp == 0:
            pdb.setTrace()
            raise "This is the single count smoothed probability for transition 0"
        singleCountTransition[('ocpTransition', v, u)] = log(ocp)
    return singleCountTransition[('ocpTransition', v, u)]
コード例 #3
0
 def fishRemove(self, code):
     spawnId = int(code[1:len(code)])
     spawnerId = int(code[0])
     if self.spawners[spawnerId].fishArray.has_key(spawnId):
         fish = self.spawners[spawnerId].fishArray[spawnId]
         fish.specialLerp.finish()
         fish.moveLerp.finish()
         fish.specialLerp = None
         fish.moveLerp = None
         fish.removeNode()
         del fish
         del self.spawners[spawnerId].fishArray[spawnId]
     else:
         import pdb as pdb
         pdb.setTrace()
コード例 #4
0
 def fishRemove(self, code):
     spawnId = int(code[1:len(code)])
     spawnerId = int(code[0])
     if self.spawners[spawnerId].fishArray.has_key(spawnId):
         fish = self.spawners[spawnerId].fishArray[spawnId]
         fish.specialLerp.finish()
         fish.moveLerp.finish()
         fish.specialLerp = None
         fish.moveLerp = None
         fish.removeNode()
         del fish
         del self.spawners[spawnerId].fishArray[spawnId]
     else:
         import pdb as pdb
         pdb.setTrace()