Ejemplo n.º 1
0
    def collapseTargets(self):
        """
            Updates _matrix s.t. all cols of the same label get collapsed to a single col.
        """

        if self._targetsCollapsed:
            return

        self._targetsCollapsed = True

        targetTypes = utils.getNodesTypes(self._nodes, self._graph)
        newMatrix = []

        # Initialize newMatrix
        for i in range(0, len(self._matrix)):
            newRow = []
            for j in range(0, len(targetTypes)):
                newRow.append([])
            newMatrix.append(newRow)

        # Populate new matrix
        for i in range(0, len(self._matrix)):
            row = self._matrix[i]
            for j in range(0, len(row)):
                col = row[j]
                if len(col) > 0:
                    colType = utils.getNodeType(self._nodes[j], self._graph)
                    colIndex = targetTypes.index(colType)
                    newMatrix[i][colIndex] += col

        self._matrix = copy.deepcopy(newMatrix)
        self._colLabels = targetTypes
Ejemplo n.º 2
0
    def collapseSources(self):
        """
            Updates _matrix s.t. all rows of the same label get collapsed to a single row.
        """
        if self._sourcesCollapsed:
            return

        sourceTypes = utils.getNodesTypes(self._nodes, self._graph)
        newMatrix = []
        newCols = []
        for node in self._nodes:
            newCols.append(utils.getNodeId(node, self._graph))

        for sourceType in sourceTypes:
            newRow = [[] for node in self._nodes]
            for i in range(0, len(self._matrix)):
                rowType = utils.getNodeType(self._nodes[i], self._graph)
                row = self._matrix[i]
                if rowType == sourceType:
                    for j in range(0, len(row)):
                        col = row[j]
                        if len(col) > 0:
                            newRow[j] += col
            newMatrix.append(newRow)

        self._matrix = copy.deepcopy(newMatrix)
        self._colLabels = newCols
        self._rowLabels = sourceTypes