Example #1
0
 def probabilities(self):
     t = sum(itervalues(self.__weights))
     return dict((e, float(w) / t) for e, w in iteritems(self.__weights))
Example #2
0
 def sorted(self):
     return sorted(iteritems(self.__weights), key=lambda w: (-w[1], w[0]))
Example #3
0
 def mergedWith(self, other):
     weights = dict(self.__weights)
     for element, weight in iteritems(other.__weights):
         weights[element] = weights.get(element, 0) + weight
     return SoftElement(weights)
Example #4
0
 def pairs(self):
     return iteritems(self.__weights)
Example #5
0
 def __call__(self, firstElement, secondElement):
     score = 0.0
     for a, p in iteritems(firstElement.probabilities()):
         for b, q in iteritems(secondElement.probabilities()):
             score += p * q * self.scoring(a, b)
     return score