Example #1
0
def q3():
    harmonic = []
    loc_glob = []
    for mu in np.arange(0.1, 1, 0.1):
        graph = LFR_benchmark_graph(1000,
                                    3,
                                    1.5,
                                    mu=mu,
                                    min_community=20,
                                    average_degree=5,
                                    seed=3)
        nodes = graph.nodes
        communities = {frozenset(graph.nodes[v]['community']) for v in graph}
        res = np.zeros(len(nodes)).astype(int)
        for i, part in enumerate(communities):
            for j in part:
                res[j] = i

        harmonic_accs = []
        local_global_accs = []

        for i in range(10):
            harmonic_acc, local_global_acc = drop_label(graph.copy(), res, 0.8)
            harmonic_accs.append(harmonic_acc)
            local_global_accs.append(local_global_acc)

        harmonic.append(np.mean(harmonic_accs))
        loc_glob.append(np.mean(local_global_accs))

    for i in harmonic:
        print("{:.4f}".format(i))
    print()
    for i in loc_glob:
        print("{:.4f}".format(i))
Example #2
0
    print("Generating communities..")

    n = 500
    tau1 = 4
    tau2 = 1.5
    mu = 0.1
    #    _RANK_GRAPH = nx.windmill_graph(20, 5)
    _RANK_GRAPH = LFR_benchmark_graph(n,
                                      tau1,
                                      tau2,
                                      mu,
                                      average_degree=5,
                                      min_community=30,
                                      seed=10)
    print(nx.info(_RANK_GRAPH))
    A = _RANK_GRAPH.copy()
    _RANK_GRAPH = nx.to_scipy_sparse_matrix(_RANK_GRAPH)
    _RANK_GRAPH = stochastic_normalization(_RANK_GRAPH)  ## normalize
    n = _RANK_GRAPH.shape[1]
    with mp.Pool(processes=mp.cpu_count()) as p:
        results = p.map(page_rank_kernel, range(n))

    vectors = np.zeros((n, n))
    for pr_vector in results:
        if pr_vector != None:
            vectors[pr_vector[0], :] = pr_vector[1]

    vectors = np.nan_to_num(vectors)
    option = "cpu"
    dx_rc = defaultdict(list)
    dx_lx = defaultdict(list)