Пример #1
0
 def saveTransitionProb(self, transFile):
     transProb = {}
     ''' your code here '''
     for oldTile, newDict in self.posDict.iteritems():
         weightSum = 0.0
         for newTile, weight in newDict.iteritems():
             weightSum += weight
         for newTile, weight in newDict.iteritems():
             self.posDict[oldTile][newTile] = weight / weightSum
     transProb = self.posDict
     util.saveTransProb(transProb, transFile)
Пример #2
0
    def saveTransitionProb(self, transFile):
        transProb = {}

        # transProb is a dict {(oldTile, newTile) : prob}
        # First normalize the counters
        for oldTile in self.transitions:
            counter = self.transitions[oldTile]
            s = float(sum(counter.values()))
            for key in counter:
                counter[key] /= s
        for oldTile in self.transitions:
            for newTile in self.transitions:
                transProb[(oldTile, newTile)] = self.transitions[oldTile][newTile]
        
        util.saveTransProb(transProb, transFile) ### COMMENTED SO THAT WE DO NOT OVERRIDE ANY LEARNED PROBABILITIES
Пример #3
0
    def saveTransitionProb(self, transFile):
        transProb = {}
        transProb = self.transTable
        print transProb
        for oldRow in self.transTable:
            for oldCol in self.transTable[oldRow]:
                total = float(self.visitedTable[oldRow][oldCol])
                for newRow in self.transTable[oldRow][oldCol]:
                    for newCol, freq in self.transTable[oldRow][oldCol][newRow].iteritems():
                        transProb[oldRow][oldCol][newRow][newCol] = freq/total

        #print "transProb: ", transProb
        #data = [transProb, self.visitedTable]
        #util.saveTransProb(data, transFile)
        util.saveTransProb(transProb, transFile)
Пример #4
0
    def saveTransitionProb(self, transFile):
        transProb = {}
        ''' your code here '''

        for oldTile in self.info.keys():
            sum = (float)(0)
            for newTile in self.info[oldTile].keys():
                sum += self.info[oldTile][newTile]

            for newTile in self.info[oldTile].keys():
                val = self.info[oldTile][newTile] / sum
                self.info[oldTile][newTile] = val

        for oldTile in self.info.keys():
            for newTile in self.info[oldTile].keys():
                transProb[(oldTile, newTile)] = self.info[oldTile][newTile]

        util.saveTransProb(transProb, transFile)
Пример #5
0
 def saveTransitionProb(self, transFile):
     transProb = {}
     ''' your code here '''
     util.saveTransProb(transProb, transFile)