Exemple #1
0
def SmallWorldIndex(CIJ):
    """
  Computes the small-world index of the graph with connection matrix CIJ.
  Self-connections are ignored, as they are cyclic paths.

  Inputs:
  CIJ  --  Graph connectivity matrix. Must be binary (0 or 1) and undirected.
  """

    N = len(CIJ)
    K = np.sum(np.sum(CIJ)) / len(CIJ)  # average degree

    # Clustering coefficient
    CC = np.mean(clustering_coef_bu(CIJ))

    # Distance matrix
    [RR, DD] = breadthdist(CIJ)

    # Note: the charpath implementation of bctpy is not very robust. Expect
    # some warnings. From the output of charpath use only the characteristic
    # path length
    PL = charpath(DD, include_diagonal=False)[0]

    # Calculate small-world index
    CCs = CC / (K / N)
    PLs = PL / (np.log(N) / np.log(K))
    SWI = CCs / PLs

    return (SWI)
def SmallWorldIndex(CIJ):
  """
  Computes the small-world index of the graph with connection matrix CIJ.
  Self-connections are ignored, as they are cyclic paths.

  Inputs:
  CIJ  --  Graph connectivity matrix. Must be binary (0 or 1) and undirected.
  """

  N = len(CIJ)
  K = np.sum(np.sum(CIJ))/len(CIJ)  # average degree

  # Clustering coefficient
  CC = np.mean(clustering_coef_bu(CIJ))

  # Distance matrix
  [RR, DD] = breadthdist(CIJ)

  # Note: the charpath implementation of bctpy is not very robust. Expect
  # some warnings. From the output of charpath use only the characteristic
  # path length
  PL = charpath(DD, include_diagonal=False)[0]

  # Calculate small-world index
  CCs = CC/(K/N)
  PLs = PL/(np.log(N)/np.log(K))
  SWI = CCs/PLs

  return(SWI)
Exemple #3
0
def test_breadthdist():
    x = load_sample(thres=.02)
    r, d = bct.breadthdist(x)
    d[np.where(np.isinf(d))] = 0
    print(np.sum(r), np.sum(d))
    assert np.sum(r) == 5804
    assert np.sum(d) == 30762
Exemple #4
0
def test_breadthdist():
    x = load_sample(thres=.02)
    r, d = bct.breadthdist(x)
    d[np.where(np.isinf(d))] = 0
    print(np.sum(r), np.sum(d))
    assert np.sum(r) == 5804
    assert np.sum(d) == 30762
Exemple #5
0
def small_world_wu(W):
    '''
    An implementation of small worldness. Returned is the coefficient cc/lambda,
    the ratio of the clustering coefficient to the characteristic path length.
    This ratio is >>1 for small world networks.

    inputs: W		weighted undirected connectivity matrix

    output: s		small world coefficient
    '''
    cc = clustering_coef_wu(W)
    _, dists = breadthdist(W)
    _lambda, _, _, _, _ = charpath(dists)
    return np.mean(cc) / _lambda
def small_world_wu(W):
    '''
    An implementation of small worldness. Returned is the coefficient cc/lambda,
    the ratio of the clustering coefficient to the characteristic path length.
    This ratio is >>1 for small world networks.

    inputs: W		weighted undirected connectivity matrix

    output: s		small world coefficient
    '''
    cc = clustering_coef_wu(W)
    _, dists = breadthdist(W)
    _lambda, _, _, _, _ = charpath(dists)
    return np.mean(cc) / _lambda
    def compute(self):
        distance_matrix = bct.breadthdist(self.binarized)[1]
        metrics = bct.charpath(distance_matrix)

        print("Average Path Length: " + str(metrics[0]))
        print("Network Diameter: " + str(metrics[4]))