コード例 #1
0
ファイル: bct.py プロジェクト: aestrivex/pyconto
def distance_bin(*args):
  return _bct.distance_bin(*args)
コード例 #2
0
def distance_bin(*args):
    return _bct.distance_bin(*args)
コード例 #3
0
ファイル: bct.py プロジェクト: aestrivex/pyconto
def distance_bin(*args):
  """distance_bin(gsl_matrix G) -> gsl_matrix"""
  return _bct.distance_bin(*args)
コード例 #4
0
ファイル: measures.py プロジェクト: omerch/pyconto
def distance(cmatrix, weighted):
    """ Computes the distance matrix for a weighted or binary graph.
    
    Distance matrix for weighted networks. The input matrix must be a mapping
    from weight to distance. For instance, in a weighted correlation network,
    higher correlations are more naturally interpreted as shorter distances.
    Consequently, in this case, the input matrix should be some inverse of
    the connectivity matrix.
    
    Distance matrix for binary graphs. If any two nodes u and v are
    disconnected, the value of the entry (u,v) is set to infinity.
    The value of self-self distances (u,u) is set to 0. Consequently,
    two nodes are connected if they have a finite non-zero distance.
    
    Parameters
    ----------
    
    cmatrix : connection/adjacency matrix
    
    weighted : {True, False}
               Apply the distance computation for weighted or unweighted
               (binary) matrices
    
    Returns
    -------
    
    weighted == True:
        
        D : distance matrix for a weighted directed graph -
            the mean distance is the characteristic path length.
    
        The input matrix must be a mapping from weight to distance (eg.
        higher correlations may be interpreted as short distances via
        an inverse mapping).
    
        Dijkstra's Algorithm.
    
        Mika Rubinov, UNSW
    
        Modification history
        2007: original
        2009-08-04: min() function vectorized

    weighted == False:

        D : distance matrix for binary undirected graph G
            Mean distance (excluding the main diagonal) equals the
            characteristic path length
    
        Algebraic shortest path algorithm.
    
        Mika Rubinov, UNSW, 2007 (last modified September 2008).

    """
    if weighted:
        m = bct.to_gslm(cmatrix.tolist())
        dist = bct.distance_wei(m)
        distnp = bct.from_gsl(dist)
        bct.gsl_free(m)
        bct.gsl_free(dist)
        return np.asarray(distnp)
    else:
        m = bct.to_gslm(cmatrix.tolist())
        dist = bct.distance_bin(m)
        distnp = bct.from_gsl(dist)
        bct.gsl_free(m)
        bct.gsl_free(dist)
        return np.asarray(distnp)
コード例 #5
0
ファイル: bct.py プロジェクト: omerch/pyconto
def distance_bin(*args):
    """distance_bin(gsl_matrix G) -> gsl_matrix"""
    return _bct.distance_bin(*args)
コード例 #6
0
ファイル: measures.py プロジェクト: aestrivex/pyconto
def distance(cmatrix, weighted):
    """ Computes the distance matrix for a weighted or binary graph.
    
    Distance matrix for weighted networks. The input matrix must be a mapping
    from weight to distance. For instance, in a weighted correlation network,
    higher correlations are more naturally interpreted as shorter distances.
    Consequently, in this case, the input matrix should be some inverse of
    the connectivity matrix.
    
    Distance matrix for binary graphs. If any two nodes u and v are
    disconnected, the value of the entry (u,v) is set to infinity.
    The value of self-self distances (u,u) is set to 0. Consequently,
    two nodes are connected if they have a finite non-zero distance.
    
    Parameters
    ----------
    
    cmatrix : connection/adjacency matrix
    
    weighted : {True, False}
               Apply the distance computation for weighted or unweighted
               (binary) matrices
    
    Returns
    -------
    
    weighted == True:
        
        D : distance matrix for a weighted directed graph -
            the mean distance is the characteristic path length.
    
        The input matrix must be a mapping from weight to distance (eg.
        higher correlations may be interpreted as short distances via
        an inverse mapping).
    
        Dijkstra's Algorithm.
    
        Mika Rubinov, UNSW
    
        Modification history
        2007: original
        2009-08-04: min() function vectorized

    weighted == False:

        D : distance matrix for binary undirected graph G
            Mean distance (excluding the main diagonal) equals the
            characteristic path length
    
        Algebraic shortest path algorithm.
    
        Mika Rubinov, UNSW, 2007 (last modified September 2008).

    """
    if weighted:
        m = bct.to_gslm(cmatrix.tolist())
        dist = bct.distance_wei(m)
        distnp = bct.from_gsl(dist)
        bct.gsl_free(m)
        bct.gsl_free(dist)
        return np.asarray(distnp)
    else:
        m = bct.to_gslm(cmatrix.tolist())
        dist = bct.distance_bin(m)
        distnp = bct.from_gsl(dist)
        bct.gsl_free(m)
        bct.gsl_free(dist)
        return np.asarray(distnp)