예제 #1
0
파일: measures.py 프로젝트: omerch/pyconto
def participation_coef(cmatrix, Ci):
    """ Computes nodal participation coefficient for a binary graph and its
    corresponding community structure.  For a directed graph, computes "out-
    neighbor" participation coefficient.
    
    Only for binary networks.
 
    Parameters
    ----------
    cmatrix : adjacency matrix
    Ci : community structure vector Ci
         
    Returns
    -------
    P : Participation coefficient
        Output for directed graphs: "out-neighbor" participation coef 

    Reference: Guimera R, Amaral L. Nature (2005) 433:895-900.

    Mika Rubinov, UNSW, 2008
    """
    m = bct.to_gslm(cmatrix.tolist())
    cil = bct.to_gslv(Ci.tolist())
    str = bct.participation_coef(m, cil)
    strnp = bct.from_gsl(str)
    bct.gsl_free(m)
    bct.gsl_free(str)
    return np.asarray(strnp)
예제 #2
0
def participation_coef(cmatrix, Ci):
    """ Computes nodal participation coefficient for a binary graph and its
    corresponding community structure.  For a directed graph, computes "out-
    neighbor" participation coefficient.
    
    Only for binary networks.
 
    Parameters
    ----------
    cmatrix : adjacency matrix
    Ci : community structure vector Ci
         
    Returns
    -------
    P : Participation coefficient
        Output for directed graphs: "out-neighbor" participation coef 

    Reference: Guimera R, Amaral L. Nature (2005) 433:895-900.

    Mika Rubinov, UNSW, 2008
    """    
    m = bct.to_gslm(cmatrix.tolist())
    cil = bct.to_gslv(Ci.tolist())
    str = bct.participation_coef(m, cil)
    strnp = bct.from_gsl(str)
    bct.gsl_free(m)
    bct.gsl_free(str)
    return np.asarray(strnp)
예제 #3
0
파일: measures.py 프로젝트: omerch/pyconto
def module_degree_zscore(cmatrix, Ci):
    """ Computes 'within module degree z-score'
    
    Computes z-score for a binary graph and its corresponding community
    structure.  For a directed graph, computes out-neighbor z-score.
     
    Degree based measures for classifying nodes in the context of community
    structure. The z-score describes how well the nodes are connected to other
    nodes within their modules.
     
    Note that, for directed networks, these functions compute the measures
    based on the out-degree.
    
    function Z=module_degree_zscore(A,Ci)

    Parameters
    ---------
    cmatrix : binary adjacency matrix
    Ci : community structure vector
    
    Returns
    -------
    Z : z-score
        Output for directed graphs: "out-neighbor" z-score.

    Reference: Guimera R, Amaral L. Nature (2005) 433:895-900.

    Mika Rubinov, UNSW, 2008
    """
    m = bct.to_gslm(cmatrix.tolist())
    cil = bct.to_gslv(Ci.tolist())
    str = bct.module_degree_zscore(m, cil)
    strnp = bct.from_gsl(str)
    bct.gsl_free(m)
    bct.gsl_free(str)
    return np.asarray(strnp)
예제 #4
0
def module_degree_zscore(cmatrix, Ci):
    """ Computes 'within module degree z-score'
    
    Computes z-score for a binary graph and its corresponding community
    structure.  For a directed graph, computes out-neighbor z-score.
     
    Degree based measures for classifying nodes in the context of community
    structure. The z-score describes how well the nodes are connected to other
    nodes within their modules.
     
    Note that, for directed networks, these functions compute the measures
    based on the out-degree.
    
    function Z=module_degree_zscore(A,Ci)

    Parameters
    ---------
    cmatrix : binary adjacency matrix
    Ci : community structure vector
    
    Returns
    -------
    Z : z-score
        Output for directed graphs: "out-neighbor" z-score.

    Reference: Guimera R, Amaral L. Nature (2005) 433:895-900.

    Mika Rubinov, UNSW, 2008
    """
    m = bct.to_gslm(cmatrix.tolist())
    cil = bct.to_gslv(Ci.tolist())
    str = bct.module_degree_zscore(m, cil)
    strnp = bct.from_gsl(str)
    bct.gsl_free(m)
    bct.gsl_free(str)
    return np.asarray(strnp)
예제 #5
0
파일: bct.py 프로젝트: aestrivex/pyconto
def to_gslv(*args):
  return _bct.to_gslv(*args)
예제 #6
0
def to_gslv(*args):
    return _bct.to_gslv(*args)
예제 #7
0
파일: bct.py 프로젝트: aestrivex/pyconto
def to_gslv(*args):
  """
    to_gslv(double array, int size) -> gsl_vector
    to_gslv(PyObject list) -> gsl_vector
    """
  return _bct.to_gslv(*args)
예제 #8
0
파일: measures.py 프로젝트: omerch/pyconto
def findpaths(cmatrix, sources, qmax):
    """ Paths are sequences of linked nodes, that never visit a single
    node more than once. This function finds all paths that start at a
    set of source vertices, up to a specified length. Warning: very
    memory-intensive.
    
    C++ Comment
     Finds paths from a set of source nodes up to a given length.  Note that
     there is no savepths argument; if all paths are desired, pass a valid
     pointer as he allpths argument.  There is also no tpath argument as its
     value may overflow a C++ long.  Since 0 is a valid node index in C++, -1
     is used as the "filler" value in allpths rather than 0 as in MATLAB. 
     Pq (the main return), plq, and util are indexed by path length.
     They therefore have (qmax + 1) elements and contain no valid data
     at index 0.
 
    function [Pq,tpath,plq,qstop,allpths,util] = 
        findpaths(CIJ,sources,qmax,savepths)

    Parameters
    ----------
    cmatrix : connection/adjacency matrix
    qmax : maximal path length
    sources : source units from which paths are grown
    savepths : set to 1 if all paths are to be collected in
               'allpths'
               
     Returns
     -------
    Pq : 3D matrix, with P(i,j,q) = number of paths from
         'i' to 'j' of length 'q'.
         
    Not returned by the C++ function:
    tpath      total number of paths found (lengths 1 to 'qmax')
    plq        path length distribution as a function of 'q'
    qstop      path length at which 'findpaths' is stopped
    allpths    a matrix containing all paths up to 'qmax'
    util       node use index

    Note that Pq[:,:,N] can only carry entries on the diagonal, as all "legal"
    paths of length N-1 must terminate.  Cycles of length N are possible, with
    all vertices visited exactly once (except for source and target).
    'qmax = N' can wreak havoc (due to memory problems).
    
    Note: Weights are discarded.
    Note: I am fairly certain that this algorithm is rather inefficient -
    suggestions for improvements are welcome.
    
    Olaf Sporns, Indiana University, 2002/2007/2008

    """
    # XXX: work on docstring
    m = bct.to_gslm(cmatrix.tolist())
    cil = bct.to_gslv(sources.tolist())
    pq, plq, qstop, allpths, util = bct.findpaths(m, cil, qmax)
    pqret = bct.from_gsl(pq)
    print pqret[0]
    print np.asarray(pqret[1])
    print plq
    print qstop
    print allpths
    print util
    bct.gsl_free(m)
    bct.gsl_free(pq)
    bct.gsl_free(plq)
    bct.gsl_free(allpths)
    bct.gsl_free(util)
    #logging.error("What to do with std::vector<gsl_matrix*> ??")
    return
예제 #9
0
파일: bct.py 프로젝트: omerch/pyconto
def to_gslv(*args):
    """
    to_gslv(double array, int size) -> gsl_vector
    to_gslv(PyObject list) -> gsl_vector
    """
    return _bct.to_gslv(*args)
예제 #10
0
def findpaths(cmatrix, sources, qmax):
    """ Paths are sequences of linked nodes, that never visit a single
    node more than once. This function finds all paths that start at a
    set of source vertices, up to a specified length. Warning: very
    memory-intensive.
    
    C++ Comment
     Finds paths from a set of source nodes up to a given length.  Note that
     there is no savepths argument; if all paths are desired, pass a valid
     pointer as he allpths argument.  There is also no tpath argument as its
     value may overflow a C++ long.  Since 0 is a valid node index in C++, -1
     is used as the "filler" value in allpths rather than 0 as in MATLAB. 
     Pq (the main return), plq, and util are indexed by path length.
     They therefore have (qmax + 1) elements and contain no valid data
     at index 0.
 
    function [Pq,tpath,plq,qstop,allpths,util] = 
        findpaths(CIJ,sources,qmax,savepths)

    Parameters
    ----------
    cmatrix : connection/adjacency matrix
    qmax : maximal path length
    sources : source units from which paths are grown
    savepths : set to 1 if all paths are to be collected in
               'allpths'
               
     Returns
     -------
    Pq : 3D matrix, with P(i,j,q) = number of paths from
         'i' to 'j' of length 'q'.
         
    Not returned by the C++ function:
    tpath      total number of paths found (lengths 1 to 'qmax')
    plq        path length distribution as a function of 'q'
    qstop      path length at which 'findpaths' is stopped
    allpths    a matrix containing all paths up to 'qmax'
    util       node use index

    Note that Pq[:,:,N] can only carry entries on the diagonal, as all "legal"
    paths of length N-1 must terminate.  Cycles of length N are possible, with
    all vertices visited exactly once (except for source and target).
    'qmax = N' can wreak havoc (due to memory problems).
    
    Note: Weights are discarded.
    Note: I am fairly certain that this algorithm is rather inefficient -
    suggestions for improvements are welcome.
    
    Olaf Sporns, Indiana University, 2002/2007/2008

    """
    # XXX: work on docstring
    m = bct.to_gslm(cmatrix.tolist())
    cil = bct.to_gslv(sources.tolist())
    pq, plq, qstop, allpths, util = bct.findpaths(m, cil, qmax)
    pqret = bct.from_gsl(pq)
    print pqret[0]
    print np.asarray(pqret[1])
    print plq
    print qstop
    print allpths
    print util
    bct.gsl_free(m)
    bct.gsl_free(pq)
    bct.gsl_free(plq)
    bct.gsl_free(allpths)
    bct.gsl_free(util)
    #logging.error("What to do with std::vector<gsl_matrix*> ??")
    return