def analyze_structure_for_fixed_degree_seq(n, max_degree=None):
    # Not sure how to aggregate this into one graph for many different
    # degree sequences

    mean_degrees = []
    mean_neighbor_degrees = []
    # Note, this is the diameter of the largest connected component
    diameters = []
    components_count = []
    global_clustering_coefficients = []
    largest_component_sizes = []

    degree_sequence = generate_random_degree_sequence(n, max_degree)
    for i in range(500):
        G = random_graphs.configuration_model(degree_sequence, cleaned=False)
        print(i)

        mean_degrees.append(graph_measures.mean_degree(G))
        mean_neighbor_degrees.append(graph_measures.mean_neighbor_degree(G))
        diameters.append(graph_measures.diameter(G))
        components_count.append(graph_measures.connected_components_count(G))
        global_clustering_coefficients.append(
            graph_measures.global_clustering_coefficient(G))
        largest_component_sizes.append(graph_measures.largest_component(G))

    # Graph results
    plt.figure(1)

    plt.subplot(234)
    plt.hist(diameters)
    plt.title("Diameter")

    plt.subplot(235)
    plt.hist(components_count)
    plt.title("Components Count")

    plt.subplot(233)
    plt.hist(global_clustering_coefficients)
    plt.title("Clustering Coefficient")

    plt.subplot(231)
    plt.hist(mean_degrees)
    plt.title("Mean Degree")

    plt.subplot(232)
    plt.hist(mean_neighbor_degrees)
    plt.title("Mean Neighbor Degree")

    plt.subplot(236)
    plt.hist(largest_component_sizes)
    plt.title("Largest Component Size")

    plt.show()
Пример #2
0
def pull_graph_statistics(G):
    statistics = {}
    statistics[degree_centrality] = degree_centrality(G)
    statistics[harmonic_centrality] = harmonic_centrality(G)
    statistics[eigenvector_centrality] = eigenvector_centrality(G)
    statistics[betweenness_centrality] = betweenness_centrality(G)
    statistics[diameter] = diameter(G)
    statistics[mean_degree] = mean_degree(G)
    statistics[mean_neighbor_degree] = mean_neighbor_degree(G)
    statistics[global_clustering_coefficient] = global_clustering_coefficient(G)
    statistics[degree_assortativity] = degree_assortativity(G)
    statistics[coefficient_of_variation] = coefficient_of_variation(G)

    return statistics
def analyze_structural_identity_graphs(Gs, fig, constraints=None):
    # Not sure how to aggregate this into one graph for many different
    # degree sequences
    print constraints

    mean_degrees = []
    mean_neighbor_degrees = []
    # Note, this is the diameter of the largest connected component
    diameters = []
    components_count = []
    global_clustering_coefficients = []
    largest_component_sizes = []
    coefficients_of_variations = []
    low_centrals = []
    high_centrals = []

    for i in xrange(len(Gs)):
        G = Gs[i]
        #print G.number_of_edges()
        print "Trial, ", i

        mean_degrees.append(graph_measures.mean_degree(G))
        mean_neighbor_degrees.append(graph_measures.mean_neighbor_degree(G))
        diameters.append(graph_measures.diameter(G))
        components_count.append(graph_measures.connected_components_count(G))
        global_clustering_coefficients.append(
            graph_measures.global_clustering_coefficient(G))
        largest_component_sizes.append(graph_measures.largest_component(G))
        coefficients_of_variations.append(
            graph_measures.coefficient_of_variation(G))
        centrals = graph_measures.hi_lo_centrality(
            graph_measures.betweenness_centrality, G)
        low_centrals.append(centrals[0])
        high_centrals.append(centrals[1])

    # Graph results
    plt.figure(fig)

    kwargs = dict(histtype='stepfilled', alpha=0.5, normed=True, bins=20)

    dic = {331:"Mean Degree", 332:"Mean Neighbor Degree",\
        333:"Clustering Coefficient", 334:"Diameter",\
        335:"Components Count", 336:"Largest Component Size",\
        337:"Coefficient of Variation", 338:"Smallest Betweenness Centrality",\
        339:"Largest Betweenness Centrality"}

    # plt.subplot(334)
    # plt.hist(diameters, **kwargs)
    # plt.title("Diameter")

    # plt.subplot(335)
    # plt.hist(components_count, **kwargs)
    # plt.title("Components Count")

    # plt.subplot(333)
    # plt.hist(global_clustering_coefficients, **kwargs)
    # plt.title("Clustering Coefficient")

    # plt.subplot(331)
    # plt.hist(mean_degrees, **kwargs)
    # plt.title("Mean Degree")

    # plt.subplot(332)
    # plt.hist(mean_neighbor_degrees, **kwargs)
    # plt.title("Mean Neighbor Degree")

    # plt.subplot(336)
    # plt.hist(largest_component_sizes, **kwargs)
    # plt.title("Largest Component Size")

    # plt.subplot(337)
    # plt.hist(coefficients_of_variations, **kwargs)
    # plt.title("Coefficient of Variation")

    # plt.subplot(338)
    # plt.hist(low_centrals, **kwargs)
    # plt.title("Smallest Betweenness Centrality")

    # plt.subplot(339)
    # plt.hist(high_centrals, **kwargs)
    # plt.title("Largest Betweenness Centrality")
    # plt.tight_layout()

    #plt.show()

    return [mean_degrees, mean_neighbor_degrees, global_clustering_coefficients,\
      diameters, components_count, largest_component_sizes,\
      coefficients_of_variations, low_centrals, high_centrals], dic