Example #1
0
def stat_worker(inputlist, outqueue, print_queue):
    for el in inputlist:
        alg = el[0]
        A = el[1]
        B = el[2]
        if alg == "clust_ratio":
            a = nm.average(nx.clustering(A).values())
            b = nm.average(nx.clustering(B).values())
            v = a / b
        if alg == "degree_corr":
            v = gu.correlation(sorted(nx.degree(A)), sorted(nx.degree(B)))
        if alg == "dist_dist":
            v = gu.correlate_dist_dict(gu.node_distance_dist(A),
                                       gu.node_distance_dist(B))
        if alg == "deg_bet_corr":
            v = gu.correlate_dist_dict(gu.get_degree_betweeness(A),
                                       gu.get_degree_betweeness(B))
        if alg == "kcore_corr":
            v = gu.correlate_dist_dict(gu.get_kcoreness(A),
                                       gu.get_kcoreness(B))
        if alg == "comm_neigh_corr":
            v = gu.correlate_dist_dict(gu.get_common_neigh_dist(A),
                                       gu.get_common_neigh_dist(B))
        if alg == "mod_ratio":
            v = community.modularity(community.best_partition(A), A) /\
                community.modularity(community.best_partition(B), B)
        if alg == "avg_neigh_deg_corr":
            v = gu.correlate_dist_dict(gu.get_avg_neighbour_degree(A),
                                       gu.get_avg_neighbour_degree(B))
        eg.info("Computed " + alg)
        outqueue.put({alg: v})
Example #2
0
def test_correlate_dist_dict():
    d1 = {1: 2, 3: 45, 9: 2}
    d2 = {3: 2, 8: 4, 12: 45.3}
    v1 = nm.matrix("2. 0 45 0 0 0 0 0 2 0 0 0")
    v2 = nm.matrix("0 0 2 0 0 0 0 4 0 0 0 45.3")

    assert (gu.correlate_dist_dict(d1, d2) == gu.correlation(v1, v2))

    d1 = {1: 2, 3: 4, 4: 5, 0: 1}
    d2 = {3: 4, 0: 1, 4: 5, 1: 2}

    assert (gu.correlate_dist_dict(d1, d2) == 1)
Example #3
0
def get_statistics(G, H, A, B, x, l, duration):
    eg.info("Computing statistics...")
    if not H:
        eg.info("Building networkx graph...")
        H = gu.simm_matrix_2_graph(B)
    eg.info("Computing centrality...")
    y, m = (-1, -1)  #eg.eigen_centrality(B, maxiter=100000)
    # nx.write_weighted_edgelist(H,  "pgp_spectre0.9_" +
    #                            str(random.randint(0, 99999999)) + ".edges")

    eg.info("Computing centrality distance...")
    eigen_err = -1  #eg.vec_dist(x, y)
    eg.info("Computing clustering ratio...")
    clust_err = gu.average_clustering(A) / gu.average_clustering(B)
    # clust_err = nm.average(nx.clustering(G).values()) /\
    #     nm.average(nx.clustering(H).values())
    eg.info("Computing lambda ratio...")
    lambda_err = -1  #abs(l / m)
    eg.info("Computing degree correlation...")
    degree_corr = gu.correlation(gu.get_degrees(A), gu.get_degrees(B))
    eg.info("Check connectivity...")
    if nx.is_connected(H):
        conn = 1
    else:
        conn = 0

    eg.info("Distance distribution correlation...")
    distance_dist_corr = -1  #gu.correlate_dist_dict(gu.node_distance_dist(A),
    #                    gu.node_distance_dist(B))
    eg.info("Degree betweenness correlation...")
    degree_bet_corr = -1  #gu.correlate_dist_dict(gu.get_degree_betweeness(A),
    #                 gu.get_degree_betweeness(B))
    eg.info("K-coreness correlation...")
    kcore_corr = -1  #gu.correlate_dist_dict(gu.get_kcoreness(A),
    #                    gu.get_kcoreness(B))
    eg.info("Common neighbourhood correlation...")
    common_neigh_corr = -1  #gu.correlate_dist_dict(gu.get_common_neigh_dist(A),
    #                    gu.get_common_neigh_dist(B))
    eg.info("Modularity ratio...")
    Gm = gu.norm_modularity(G)
    Hm = gu.norm_modularity(H)
    modularity_ratio = Gm[0] / Hm[0]
    partition_ratio = Gm[1] / float(Hm[1])
    eg.info("Avg neighbourhood degree correlation...")
    avg_neigh_deg_corr = -1  #gu.correlate_dist_dict(gu.get_avg_neighbour_degree(A),
    #                    gu.get_avg_neighbour_degree(B))
    eg.info("Done with stats")
    return (eigen_err, degree_corr, clust_err, lambda_err, distance_dist_corr,
            degree_bet_corr, kcore_corr, common_neigh_corr, modularity_ratio,
            partition_ratio, avg_neigh_deg_corr, conn, duration)
Example #4
0
def write_statistics(A, B, label, net, x, l, output=True):
    eg.info("Computing new centrality..")
    G = nx.from_numpy_matrix(A)
    H = nx.from_numpy_matrix(B)
    nx.write_weighted_edgelist(
        H,
        net + "_" + label + "_" + str(random.randint(0, 99999999)) + ".edges")
    y, m = eg.eigen_centrality(B, maxiter=100000)

    eg.info("Printing out results..")
    eigen_err = eg.vec_dist(x, y)
    clust_err = nm.average(nx.clustering(G).values()) /\
        nm.average(nx.clustering(H).values())
    lambda_err = abs(l / m)

    degree_corr = gu.correlation(sorted(nx.degree(G)), sorted(nx.degree(H)))
    if nx.is_connected(H):
        conn = 1
    else:
        conn = 0
    out = (
        str(label) + "," + str(net.split(".")[0].split("/")[-1]) + "," +
        str(eigen_err) + "," + str(degree_corr) + "," + str(clust_err) + "," +
        str(lambda_err) + "," + str(-1) + "," + str(-1) + "," +
        #  str(gu.correlate_dist_dict(gu.node_distance_dist(A),
        #                             gu.node_distance_dist(B))) + "," +
        #  str(gu.correlate_dist_dict(gu.get_degree_betweeness(A),
        #                             gu.get_degree_betweeness(B))) + "," +
        str(gu.correlate_dist_dict(gu.get_kcoreness(A), gu.get_kcoreness(B))) +
        "," + str(
            gu.correlate_dist_dict(gu.get_common_neigh_dist(A),
                                   gu.get_common_neigh_dist(B))) + "," +
        str(-1) + "," +
        #  str(community.modularity(
        #      community.best_partition(G), G) /
        #      community.modularity(
        #      community.best_partition(H), H)) + "," +
        str(
            gu.correlate_dist_dict(gu.get_avg_neighbour_degree(A),
                                   gu.get_avg_neighbour_degree(B))) + "," +
        str(conn))
    if output:
        print(out, file=sys.stderr)
    return out
Example #5
0
def test_correlation():
    gu.correlation([1, 2, 3], [2, 9])