def input_type_fun(input_type): if input_type==1: C = nx.read_gml(filelist[file_num]) elif input_type==2: C = nx.Graph(formal_edgelist(base +'/benchmark_LFR_OC_UU/network.dat')) # get true.dat f = file(base +'/benchmark_LFR_OC_UU/community.dat', 'r') fw = file(base +'/evaluations/mutual3/true.dat','w+') d={} for line in f: kx = line.strip().split('\t') kv = [] if ' ' in kx[1]: kc = kx[1].strip().split(' ') kv.append(int(kx[0])) for x in kc: kv.append(int(x)) else: kv =[int(kx[0]), int(kx[1])] for kk in kv[1:]: if d.get(kk): d[kk].append(kv[0]) else: d[kk]=[kv[0]] ground_truth = [] for x in d: ground_truth.append(d[x]) print "lens of ground_truth: ", len(ground_truth) print "ground_truth is:", ground_truth for line in ground_truth: content = " ".join([str(x) for x in line]) fw.write(content) fw.write('\n') f.close() fw.close() elif input_type==3: from inputs.friendster_dataset.friendster_graph import get_friendster_graph # C = nx.Graph() C = get_friendster_graph() print len(C) return C
from random import random from common.transform import split_list from multiprocessing import Process, Pool from inputs.formal_edgelist import * # from SeedDrivenDete import * from socket import gethostname hn = gethostname() exec ("from config.%s import *" % hn) if input_type == 1: C = nx.read_gml(filelist[file_num]) elif input_type == 2: C = nx.Graph(formal_edgelist(base + "/benchmark_LFR_OC_UU/network.dat")) elif input_type == 3: from inputs.friendster_dataset.friendster_graph import get_friendster_graph C = get_friendster_graph() # print "nodes_______",len(C.nodes()) # print C.edges() # print len(C.edges()) # exit() len_C = len(C) nodes_C = C.nodes() degree_dict = C.degree() betweenness_dict = nx.betweenness_centrality(C)
__author__ = 'nourl' import networkx as nx from inputs.formal_edgelist import * from sys import exit from copy import deepcopy C = nx.DiGraph(formal_edgelist('./benchmark_directed_networks/network.dat')) print C.in_edges(2) print C.out_edges(2) eg = nx.DiGraph() outedges = C.out_edges(2) out_edges_final = deepcopy(outedges) a = len(outedges) print a for x in outedges: out_two = C.out_edges(x[1]) out_edges_final += out_two print len(out_edges_final), "_______", out_edges_final out_edges_weighted = [] for x in out_edges_final: out_edges_weighted.append((x[0], x[1], 1)) eg.add_weighted_edges_from(out_edges_weighted) egnodes = eg.nodes() nw = {} for x in egnodes: weight = eg.degree(x, weight=True) * nx.closeness_centrality(C, x) nw[x] = weight #print "node_weighted: ",nw
__author__ = 'nourl' import networkx as nx from inputs.formal_edgelist import * from sys import exit from copy import deepcopy C = nx.DiGraph(formal_edgelist('./benchmark_directed_networks/network.dat')) print C.in_edges(2) print C.out_edges(2) eg = nx.DiGraph() outedges = C.out_edges(2) out_edges_final = deepcopy(outedges) a = len(outedges) print a for x in outedges: out_two = C.out_edges(x[1]) out_edges_final += out_two print len(out_edges_final),"_______",out_edges_final out_edges_weighted = [] for x in out_edges_final: out_edges_weighted.append((x[0],x[1],1)) eg.add_weighted_edges_from(out_edges_weighted) egnodes=eg.nodes() nw = {} for x in egnodes: weight = eg.degree(x,weight=True) * nx.closeness_centrality(C,x) nw[x] = weight #print "node_weighted: ",nw
import networkx as nx import pickle from random import random from common.transform import split_list from multiprocessing import Process, Pool from inputs.formal_edgelist import * #from SeedDrivenDete import * from socket import gethostname hn = gethostname() exec("from config.%s import *" % hn) if input_type == 1: C = nx.read_gml(filelist[file_num]) elif input_type == 2: C = nx.Graph(formal_edgelist(base + '/benchmark_LFR_OC_UU/network.dat')) elif input_type == 3: from inputs.friendster_dataset.friendster_graph import get_friendster_graph C = get_friendster_graph() #print "nodes_______",len(C.nodes()) #print C.edges() #print len(C.edges()) #exit() len_C = len(C) nodes_C = C.nodes() degree_dict = C.degree() betweenness_dict = nx.betweenness_centrality(C) len_max = len_C
__author__ = 'nourl' from common.transform import * from PyCommDete import * from networkx import nx from inputs.formal_edgelist import * from multiprocessing import Pool from sys import exit #C = nx.read_gml(filelist[1]) C = nx.Graph(formal_edgelist('./benchmarks/network.dat')) print "length:", len(C) betw_ori = nx.betweenness_centrality(C) degr_ori = C.degree() nodes = C.nodes() betw_ori = sorted(betw_ori.iteritems(), key=lambda x: x[1], reverse=True) average = sum(x[1] for x in betw_ori) / len(betw_ori) betw = [x for x in betw_ori if x[1] >= 0.2 * average] betw_ex_nei = [x[0] for x in betw] bitmap = [0] * len(betw_ori) print "len of betw_ex_nei:", len(betw_ex_nei) for x in betw_ex_nei: bitmap[x - 1] = x recover = [] for x in betw_ex_nei: if bitmap[x - 1] > 0: recover.append(x) nei = C.neighbors(x)
__author__ = 'nourl' from common.transform import * from PyCommDete import * from networkx import nx from inputs.formal_edgelist import * from multiprocessing import Pool from sys import exit #C = nx.read_gml(filelist[1]) C = nx.Graph(formal_edgelist('./benchmarks/network.dat')) print "length:",len(C) betw_ori = nx.betweenness_centrality(C) degr_ori = C.degree() nodes = C.nodes() betw_ori = sorted(betw_ori.iteritems(), key=lambda x:x[1],reverse=True) average = sum(x[1] for x in betw_ori)/len(betw_ori) betw=[x for x in betw_ori if x[1]>=0.2*average] betw_ex_nei=[x[0] for x in betw] bitmap = [0]*len(betw_ori) print "len of betw_ex_nei:",len(betw_ex_nei) for x in betw_ex_nei: bitmap[x-1]=x recover=[] for x in betw_ex_nei: if bitmap[x-1] >0: recover.append(x) nei = C.neighbors(x)