Ejemplo n.º 1
0
def generate_results(network, overwrite=False):
    dt = real_networks[network]

    roc_df_path = os.path.join("results", network) + "_roc_res.p"
    graph, comms, mmatrix, nmap = load_network(dt["path"], network,
                                               dt["clusters"], dt["index"],
                                               dt["node_type"])

    if overwrite or not os.path.exists(roc_df_path):
        tmm, cmap = construct_true_memberships_matrix(nmap, comms)
        print(network, "gen_roc_curves")
        roc_results = get_rocs(mmatrix, nmap, comms, tmm)
        with open(roc_df_path, "wb+") as roc_df:
            pickle.dump(roc_results, roc_df)

    roc_df_path = os.path.join("results", network) + "_roc_res_rwr.p"

    if overwrite or not os.path.exists(roc_df_path):
        nmap = dict([(j, i) for i, j in enumerate(graph.nodes())])

        ngraph = nx.Graph()

        for edge in graph.edges():
            ngraph.add_edge(nmap[edge[0]], nmap[edge[1]])

        tmm, cmap = construct_true_memberships_matrix(nmap, comms)
        print(network, "gen_roc_curves_rwr")
        roc_results = get_rocs_rwr(ngraph, nmap, comms, tmm)
        with open(roc_df_path, "wb+") as roc_df:
            pickle.dump(roc_results, roc_df)
def auc_compute_rwr(seed, n, ol, results_folder):
    pset = _base_params.copy()
    pset['n'] = int(n)
    pset['overlapping_nodes'] = ol
    pset['seed'] = int(seed)

    rp = "{}_{}_{}_rwr.json".format(n, ol, seed)
    results_file = os.path.abspath(os.path.join(results_folder, rp))

    graph, communities = lfr_benchmark_graph(**pset)

    nmap = dict([(j, i) for i, j in enumerate(sorted(graph.nodes()))])

    tmm, cmap = construct_true_memberships_matrix(nmap, communities)
    results = []
    for c, comm in communities.items():
        for seed_size in _seed_sizes:
            if len(comm) > seed_size:
                # Seed of AUC scores for node this size
                scom = [nmap[i] for i in comm]
                auc_s = get_auc_scores_community_rwr(seed_size, scom, graph, nmap, tmm)
                results.append([int(n), int(ol), int(seed), c, seed_size, len(comm), np.mean(auc_s), np.std(auc_s)])

    with open(results_file, "w+") as rf:
        json.dump(results, rf)
def auc_compute(seed, n, ol, results_folder):
    pset = _base_params.copy()
    pset['n'] = int(n)
    pset['overlapping_nodes'] = ol
    pset['seed'] = int(seed)

    rp = "{}_{}_{}.json".format(n, ol, seed)
    results_file = os.path.abspath(os.path.join(results_folder, rp))

    graph, communities, index = get_benchmark(pset)

    membership_ma, nmap = membership_matrix(graph.nodes(), index)

    tmm, cmap = construct_true_memberships_matrix(nmap, communities)

    nodes = np.array(list(nmap.values()))
    results = []
    for c, comm in communities.items():
        for seed_size in _seed_sizes:
            if len(comm) > seed_size:
                # Seed of AUC scores for node this size
                scom = np.array([nmap[i] for i in comm])
                auc_s = get_auc_scores_community(seed_size, scom, nodes, membership_ma, tmm)
                results.append([int(n), int(ol), int(seed), c, seed_size, len(comm), np.mean(auc_s), np.std(auc_s)])

    with open(results_file, "w+") as rf:
        json.dump(results, rf)