ranking/cosine_similarity.py
def _smd(self, w1, w2):
        '''
        Use Sum of Minimum Distance method (SMD) to compute the similarity between two sites
        '''
        docs1 = np.array([p.get_vsm(self.vectorizer, self.text_type) for p in w1])
        docs2 = np.array([p.get_vsm(self.vectorizer, self.text_type) for p in w2])
        scores = cosine_similarity(docs1, docs2)

        max_scores1 = [0]*len(docs1)
        max_scores2 = [0]*len(docs2)
        for i in xrange(len(scores)):
            for j in xrange(len(scores[0])):
                max_scores1[i] = max(max_scores1[i], scores[i][j])
                max_scores2[j] = max(max_scores2[j], scores[i][j])

        sum_scores = sum(max_scores1) + sum(max_scores2)
        n = len(max_scores1) + len(max_scores2)
        return sum_scores/float(n) if n else 0

        Use Sum of Minimum Distance method (SMD) to compute the similarity between two sites
        
Use Sum of Minimum Distance method (SMD) to compute the similarity between two sites
Use Sum of Minimum Distance method ( SMD ) to compute the similarity between two sites
def _smd(self, w1, w2):
        docs1 = np.array([p.get_vsm(self.vectorizer, self.text_type) for p in w1])
        docs2 = np.array([p.get_vsm(self.vectorizer, self.text_type) for p in w2])
        scores = cosine_similarity(docs1, docs2)
        max_scores1 = [0]*len(docs1)
        max_scores2 = [0]*len(docs2)
        for i in xrange(len(scores)):
            for j in xrange(len(scores[0])):
                max_scores1[i] = max(max_scores1[i], scores[i][j])
                max_scores2[j] = max(max_scores2[j], scores[i][j])
        sum_scores = sum(max_scores1) + sum(max_scores2)
        n = len(max_scores1) + len(max_scores2)
        return sum_scores/float(n) if n else 0
def _smd ( self , w1 , w2 ) : docs1 = np . array ( [ p . get_vsm ( self . vectorizer , self . text_type ) for p in w1 ] ) docs2 = np . array ( [ p . get_vsm ( self . vectorizer , self . text_type ) for p in w2 ] ) scores = cosine_similarity ( docs1 , docs2 ) max_scores1 = [ 0 ] * len ( docs1 ) max_scores2 = [ 0 ] * len ( docs2 ) for i in xrange ( len ( scores ) ) : for j in xrange ( len ( scores [ 0 ] ) ) : max_scores1 [ i ] = max ( max_scores1 [ i ] , scores [ i ] [ j ] ) max_scores2 [ j ] = max ( max_scores2 [ j ] , scores [ i ] [ j ] ) sum_scores = sum ( max_scores1 ) + sum ( max_scores2 ) n = len ( max_scores1 ) + len ( max_scores2 ) return sum_scores / float ( n ) if n else 0
Use Sum of Minimum Distance method (SMD) to compute the similarity between two sites
Use Sum of Minimum Distance method ( SMD ) to compute the similarity between two sites
'''
        Use Sum of Minimum Distance method (SMD) to compute the similarity between two sites
        '''
self
w1
w2