當前位置: 首頁>>代碼示例>>Python>>正文


Python munkres.make_cost_matrix方法代碼示例

本文整理匯總了Python中munkres.make_cost_matrix方法的典型用法代碼示例。如果您正苦於以下問題:Python munkres.make_cost_matrix方法的具體用法?Python munkres.make_cost_matrix怎麽用?Python munkres.make_cost_matrix使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在munkres的用法示例。


在下文中一共展示了munkres.make_cost_matrix方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: make_cost_matrix

# 需要導入模塊: import munkres [as 別名]
# 或者: from munkres import make_cost_matrix [as 別名]
def make_cost_matrix(profit_matrix, inversion_function):
    """
    Create a cost matrix from a profit matrix by calling
    'inversion_function' to invert each value. The inversion
    function must take one numeric argument (of any type) and return
    another numeric argument which is presumed to be the cost inverse
    of the original profit.
    This is a static method. Call it like this:
    .. python::
        cost_matrix = Munkres.make_cost_matrix(matrix, inversion_func)
    For example:
    .. python::
        cost_matrix = Munkres.make_cost_matrix(matrix, lambda x : sys.maxsize - x)
    :Parameters:
        profit_matrix : list of lists
            The matrix to convert from a profit to a cost matrix
        inversion_function : function
            The function to use to invert each entry in the profit matrix
    :rtype: list of lists
    :return: The converted matrix
    """
    cost_matrix = []
    for row in profit_matrix:
        cost_matrix.append([inversion_function(value) for value in row])
    return cost_matrix 
開發者ID:chrisdxie,項目名稱:uois,代碼行數:27,代碼來源:munkres.py

示例2: make_cost_matrix

# 需要導入模塊: import munkres [as 別名]
# 或者: from munkres import make_cost_matrix [as 別名]
def make_cost_matrix(profit_matrix, inversion_function):
        """
        **DEPRECATED**

        Please use the module function ``make_cost_matrix()``.
        """
        import munkres
        return munkres.make_cost_matrix(profit_matrix, inversion_function) 
開發者ID:tobiasfshr,項目名稱:MOTSFusion,代碼行數:10,代碼來源:munkres.py

示例3: calc_hungarian_alignment_score

# 需要導入模塊: import munkres [as 別名]
# 或者: from munkres import make_cost_matrix [as 別名]
def calc_hungarian_alignment_score(self, s, t):
        """Calculate the alignment score between the two texts s and t
        using the implementation of the Hungarian alignment algorithm
        provided in https://pypi.python.org/pypi/munkres/."""
        s_toks = get_tokenized_lemmas(s)
        t_toks = get_tokenized_lemmas(t)
        #print("#### new ppdb calculation ####")
        #print(s_toks)
        #print(t_toks)
        df = pd.DataFrame(index=s_toks, columns=t_toks, data=0.)

        for c in s_toks:
            for a in t_toks:
                df.ix[c, a] = self.compute_paraphrase_score(c, a)

        matrix = df.values
        cost_matrix = make_cost_matrix(matrix, lambda cost: _max_ppdb_score - cost)

        indexes = _munk.compute(cost_matrix)
        total = 0.0
        for row, column in indexes:
            value = matrix[row][column]
            total += value
        #print(s + ' || ' + t + ' :' + str(indexes) + ' - ' + str(total / float(np.min(matrix.shape))))

        # original procedure returns indexes and score - i do not see any use for the indexes as a feature
        # return indexes, total / float(np.min(matrix.shape))
        return total / float(np.min(matrix.shape)) 
開發者ID:UKPLab,項目名稱:coling2018_fake-news-challenge,代碼行數:30,代碼來源:hungarian_alignment.py

示例4: score

# 需要導入模塊: import munkres [as 別名]
# 或者: from munkres import make_cost_matrix [as 別名]
def score(self, seq_gt, seq_pred):
        seq_gt = self.prep_seq(seq_gt)
        seq_pred = self.prep_seq(seq_pred)
        m, n = len(seq_gt), len(seq_pred)  # length of two sequences

        if m == 0:
            return 1.
        if n == 0:
            return 0.

        similarities = torch.zeros((m, n))
        for i in range(m):
            for j in range(n):
                a = self.vectors[seq_gt[i]]
                b = self.vectors[seq_pred[j]]
                a = torch.from_numpy(a)
                b = torch.from_numpy(b)
                similarities[i, j] = torch.mean(F.cosine_similarity(a.unsqueeze(0), b.unsqueeze(0))).unsqueeze(-1)

        similarities = (similarities + 1) / 2
        similarities = similarities.numpy()
        ass = self.munkres.compute(munkres.make_cost_matrix(similarities))

        intersection_score = .0
        for a in ass:
            intersection_score += similarities[a]
        iou_score = intersection_score / (m + n - intersection_score)

        return iou_score 
開發者ID:aimagelab,項目名稱:show-control-and-tell,代碼行數:31,代碼來源:noun_iou.py


注:本文中的munkres.make_cost_matrix方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。