コード例 #1
0
ファイル: modellist.py プロジェクト: samim23/rl-search
    def similarity_to(self, other, metric = "cosine"):
        """
        set-to-set similarity
        
        Param:
        docs: KeywordList

        Return:
        float        
        """
        assert type(other) in (scinet3.model.Keyword, KeywordList), "`other` should be either Keyword or KeywordList, but is %r" %other
        
        if isinstance(other, scinet3.model.Keyword):
            other = KeywordList([other])
        
        if metric == "cosine":
            return cosine_similarity(self.centroid, other.centroid)
        else:
            raise NotImplementedError("Only cosine similarity metric is implemented for now")
コード例 #2
0
    def similarity_to(self, other, metric="cosine"):
        """
        set-to-set similarity
        
        Param:
        docs: KeywordList

        Return:
        float        
        """
        assert type(other) in (
            scinet3.model.Keyword, KeywordList
        ), "`other` should be either Keyword or KeywordList, but is %r" % other

        if isinstance(other, scinet3.model.Keyword):
            other = KeywordList([other])

        if metric == "cosine":
            return cosine_similarity(self.centroid, other.centroid)
        else:
            raise NotImplementedError(
                "Only cosine similarity metric is implemented for now")
コード例 #3
0
    def test_sparse_matrix(self):
        v1 = csr_matrix([self.row1])
        v2 = csr_matrix([self.row2])

        self.assertAlmostEqual(self.expected,
                               cosine_similarity(v1, v2))
コード例 #4
0
 def test_array(self):
     v1 = np.array(self.row1)
     v2 = np.array(self.row2)
     
     self.assertAlmostEqual(self.expected,
                            cosine_similarity(v1, v2))
コード例 #5
0
 def test_list(self):
     v1 = self.row1
     v2 = self.row2
     self.assertAlmostEqual(self.expected,
                            cosine_similarity(v1, v2))
コード例 #6
0
    def test_sparse_matrix(self):
        v1 = csr_matrix([self.row1])
        v2 = csr_matrix([self.row2])

        self.assertAlmostEqual(self.expected, cosine_similarity(v1, v2))
コード例 #7
0
    def test_array(self):
        v1 = np.array(self.row1)
        v2 = np.array(self.row2)

        self.assertAlmostEqual(self.expected, cosine_similarity(v1, v2))
コード例 #8
0
 def test_list(self):
     v1 = self.row1
     v2 = self.row2
     self.assertAlmostEqual(self.expected, cosine_similarity(v1, v2))