def process(self, matrix): lMatrix = matrix matrix = tn.matrix2numpy(matrix.getMatrix()) # hungarian_pairs = self._context["pairs"] # minDim = min(lMatrix._width, lMatrix._height) # m = [array('f',[1.0 for _ in xrange(lMatrix._min)]) for _ in xrange(lMatrix._min)] # clean_matrix = tn.matrix2numpy(m) lClean_matrix = LinedMatrix(lMatrix._min, lMatrix._min, 1.0) # lClean_matrix.convertMatrix(m) # pairs = copy.copy(self._context["pairs"]) pairs = self._context['pairs'] l = pairs[0:lMatrix._min] l.sort() new_pairs = [] for i, j in enumerate(self._context["pairs"]): if i >= lMatrix._min: break new_j = l.index(j) # clean_matrix[i][new_j] = matrix[i][j] lClean_matrix.set(new_j, i, matrix[i][j]) new_pairs.append(new_j) self._context["pairs"] = new_pairs # lClean_matrix = LinedMatrix(0,0) # lClean_matrix.convertDistMatrix(clean_matrix) return lClean_matrix
def process(self, matrixOrig): lDim = sorted([matrixOrig._height, matrixOrig._width]) matrixOrig = tds.squarify(matrixOrig, 1.) matrix = matrixOrig.getMatrix() nMatrix = [[1. - val for val in line] for line in matrix] pairs = hungarian.lap(matrix)[0] # res = munk.maxWeightMatching(nMatrix) # pairs = [res[0][i] for i in res[0].keys()] lA_void = LinedMatrix(lDim[1], lDim[0], 1.) for i in xrange(lDim[0]): # j = pairs[i] ni = pairs[i] + i * lA_void._width lA_void.data[ni] = matrix[i][pairs[i]] # lA_void.set(j,i,matrix[i][j]) self._context["pairs"] = pairs return lA_void