【问题标题】:Compute complementary CDF given a list of coefficients在给定系数列表的情况下计算互补 CDF
【发布时间】:2021-02-18 12:20:44
【问题描述】:

我有一个图中节点的聚类系数列表,我从 NetworkX 获得:

coefficients = nx.clustering(G)

现在我想绘制这些系数的互补 CDF,这样在 X 轴上我有系数值 x,在 Y 轴上是聚类系数大于或等于的节点的分数到 x,即P(X >= x)。

如何在 Python 中做到这一点?我应该使用scipy.stats.rv_discrete.cdf 吗? https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.rv_discrete.cdf.html?

【问题讨论】:

    标签: python numpy scipy networkx


    【解决方案1】:

    使用scipy.stats.rv_discrete.cdf 似乎有点矫枉过正。只需对系数列表进行排序并将它们与[1,0] 的范围进行对比,就可以得到所需的互补 CDF。

    这是一些示例代码,显示了不同随机图的互补 CDF:

    import networkx as nx
    import numpy as np
    from matplotlib import pyplot as plt
    from matplotlib.ticker import PercentFormatter
    
    for edges in range(200, 2001, 200):
        G = nx.gnm_random_graph(100, edges)
        coefficients = nx.clustering(G)
        x = np.concatenate([[0], np.sort(list(coefficients.values())), [1]])
        plt.plot(x, np.linspace(1, 0, len(x)), label=f'100 nodes, {edges} edges')
    plt.xlabel('Clustering coefficient')
    plt.ylabel('P(X ≥ x)')
    plt.margins(x=0.02)
    plt.gca().yaxis.set_major_formatter(PercentFormatter(1))
    plt.legend(title='Random graphs')
    plt.tight_layout()
    plt.show()
    

    使用np.linspace(0, 1, len(x)),您将获得P(X ≤ x)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-28
      • 1970-01-01
      • 1970-01-01
      • 2022-10-13
      相关资源
      最近更新 更多