当前位置: 首页>>代码示例>>Python>>正文


Python Munkres.pad_matrix方法代码示例

本文整理汇总了Python中munkres.Munkres.pad_matrix方法的典型用法代码示例。如果您正苦于以下问题:Python Munkres.pad_matrix方法的具体用法?Python Munkres.pad_matrix怎么用?Python Munkres.pad_matrix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在munkres.Munkres的用法示例。


在下文中一共展示了Munkres.pad_matrix方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: str

# 需要导入模块: from munkres import Munkres [as 别名]
# 或者: from munkres.Munkres import pad_matrix [as 别名]
            print 'LINE=', line2

            matclust2 = scipy.io.loadmat(
                clusterpath + 'cluster-' + alg + '-peaks-' + norm + line2 + '-nc' + str(nc2) + '.mat')

            centers2 = matclust2['centers']
            print centers2.shape
            if nc1 <= nc2:
                inv = False
                dist = euclidean_distances(centers1, centers2)
            else:
                inv = True
                dist = euclidean_distances(centers2, centers1)
            print dist.shape
            m = Munkres()
            a = m.pad_matrix(dist, pad_value=1000)
            nm = np.array(a)
            print len(a), len(a[0])
            indexes = m.compute(dist)
            sumdist = 0

            for c1, c2 in indexes:
                if c1 < centers1.shape[0] and c2 < centers2.shape[0]:
                    sumdist += euclidean_distances(centers1[c1], centers2[c2])
            print sumdist

            print indexes
            mx = max(np.max(centers1), np.max(centers2))
            mn = min(np.min(centers1), np.min(centers2))
            if inv:
                plotHungarianSignals(indexes, centers2, centers1, mx, mn, 'HNG-' + line2 + line1,
开发者ID:bejar,项目名称:PeakDataAnalysis,代码行数:33,代码来源:ClusterHungarian.py

示例2: RequestMatching

# 需要导入模块: from munkres import Munkres [as 别名]
# 或者: from munkres.Munkres import pad_matrix [as 别名]
class RequestMatching():

    def __init__(self):
        self.days = 20
        self.cost_matrix = []
        self.categories = {} # maps each category to a list of the names that can provide it.
        self.name_row = {} # maps each name to the indices of the rows it corresponds to.
        self.count = 0
        self.munkres = Munkres()

    def main(self):
        print('--- snip ---')
        for line in stdin:
            self.process(line.rstrip('\n'))
        self.flush() # don't forget to flush :)
        print('--- snip ---')

    def process(self, line):
        words = line.split(' ')

        if words[0] == 'service':
            for word in words[1:]:
                # remember who does what
                self.categories.setdefault(word, []).append(words[1])
            # allocate rows
            self.cost_matrix += [[] for indices in range(self.days)]
            # remember which matrix rows correspond to who
            self.name_row.setdefault(words[1], range(self.count, self.count + self.days))
            self.count = self.count + self.days

        elif words[0] == 'request':
            # fill column
            for row in self.cost_matrix:
                row.append(maxint)

            category, days = words[2], words[3].split("-")
            # fill range
            if len(days) == 1:
                days += days

            for name in self.categories.get(category, []):
                for day in range(int(days[0]), int(days[1]) + 1):
                    # replace last element
                    row = self.cost_matrix[self.name_row[name][day-1]]
                    self.cost_matrix[self.name_row[name][day-1]][len(row)-1] = 1

        elif words[0] == '':
            self.flush()

        else:
            pass

    def flush(self):
        # compute and print total valid assignments using the hungarian algorithm
        self.cost_matrix = self.munkres.pad_matrix(self.cost_matrix, pad_value=maxint)
        matchings = self.munkres.compute(self.cost_matrix)
        print sum(filter(lambda x: x == 1, \
                         [self.cost_matrix[row][col] for row, col in matchings]))
        # reset
        self.categories = {}
        self.cost_matrix = []
        self.name_row = {}
        self.count = 0
开发者ID:greeshmma,项目名称:little-projects,代码行数:65,代码来源:request_matchings.py


注:本文中的munkres.Munkres.pad_matrix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。