Example #1
0
 def print_ordered(self):
     pq = PriorityQueue()
     for n in self.d:
         prob = self.d[n]
         pq.add_task(n, prob)
     #endfor
     sorted = pq.sorted_queue()
     norms = [x for x in reversed(sorted)]
     for n in norms:
         print n, self.d[n]
  def most_probable_norms(self, topN):
    """Computes the topN most probable norms within a suite, returning either a single norm 
       (if there is a unique most likely norm) or all norms tied at the top"""
    pq = PriorityQueue()
    for n in self.d:
        prob = self.d[n]
        pq.add_task(n, prob)
    #endfor
    sorted_norms = pq.sorted_queue()
    norms = [x for x in reversed(sorted_norms)]
    
    # Check that we select either the topN, or the first ones with the same odds
    for (i,n) in enumerate(norms):
        if(i+1 == topN):
            tied = len(norms) > i+1 and (self.d[n] == self.d[norms[i+1]])
            if (tied): 
                topN += 1
#                 print "Tie between norms %s and %s with prob=%d, topN is now %d" % (n,norms[i-1],self.d[n],topN)                         else: 
                break
    #endfor
    return (norms[0:topN],topN)
Example #3
0
    def most_probable_norms(self, topN):
        """Computes the topN most probable norms within a suite, returning either """
        pq = PriorityQueue()
        for n in self.d:
            prob = self.d[n]
            pq.add_task(n, prob)
        #endfor
        sorted = pq.sorted_queue()
        norms = [x for x in reversed(sorted)]
        # Check that we select either the topN, or the first ones with the same odds
        i = 1
        for n in norms[1:]:
            tied = (self.d[n] == self.d[norms[i - 1]])
            if (i > topN):
                if (tied):
                    topN += 1


#                 print "Tie between norms %s and %s with prob=%d, topN is now %d" % (n,norms[i-1],self.d[n],topN)
                else:
                    break
            i += 1
        #endfor
        return (norms[0:topN], topN)