Пример #1
0
def pagerank(adj_csr, tol=0):
    N = adj_csr.shape[0]

    # Get transition matrix
    T = atMatrix.toRightStochasticCSR(adj_csr)

    # Get First Eigen-Vector
    x = np.matrix(np.ones((N, )) * 1. / N)
    xi = x * T
    k = 1
    eps = np.abs(xi - x).sum()
    while eps > tol:
        x = xi.copy()
        xi = x * T
        k += 1
        eps = np.abs(xi - x).sum()

    return np.array(xi)
Пример #2
0
def pagerank(adj_csr, tol=0):
    N = adj_csr.shape[0]

    # Get transition matrix
    T = atMatrix.toRightStochasticCSR(adj_csr)

    # Get First Eigen-Vector
    x = np.matrix(np.ones((N,)) * 1. / N)
    xi = x * T
    k = 1
    eps = np.abs(xi - x).sum()
    while eps > tol:
        x = xi.copy()
        xi = x * T
        k += 1
        eps = np.abs(xi - x).sum()
    
    return np.array(xi)
Пример #3
0
def com2comTrans(T, member):
# Get the flow matrix of the module partition from
# the PageRank, Degree and membership of its nodes
    coms = np.unique(member)
    ncom = coms.shape[0]
    com2com = np.zeros((ncom, ncom))

    if sparse.issparse(T):
        for ii in range(ncom):
            iiCom = member == coms[ii]
            Tii = T[iiCom]
            if T.format == 'csr':
                rowIndices = Tii.indices
            # elif T.format == 'lil':
            #     rowIndices = Tii.rows[0]
            else:
                sys.exit('Type %s of sparse matrix not implemented.' % T.format)
            for k in range(Tii.nnz):
                jj = rowIndices[k]
                com2com[ii, np.nonzero(coms == member[jj])] += Tii.data[k]
    com2com = atMatrix.toRightStochasticCSR(sparse.csr_matrix(com2com))

    return com2com
Пример #4
0
def com2comTrans(T, member):
    # Get the flow matrix of the module partition from
    # the PageRank, Degree and membership of its nodes
    coms = np.unique(member)
    ncom = coms.shape[0]
    com2com = np.zeros((ncom, ncom))

    if sparse.issparse(T):
        for ii in range(ncom):
            iiCom = member == coms[ii]
            Tii = T[iiCom]
            if T.format == 'csr':
                rowIndices = Tii.indices
            # elif T.format == 'lil':
            #     rowIndices = Tii.rows[0]
            else:
                sys.exit('Type %s of sparse matrix not implemented.' %
                         T.format)
            for k in range(Tii.nnz):
                jj = rowIndices[k]
                com2com[ii, np.nonzero(coms == member[jj])] += Tii.data[k]
    com2com = atMatrix.toRightStochasticCSR(sparse.csr_matrix(com2com))

    return com2com