def init(args, params, whole_params): info = {} for k, w in params.items(): info[k] = w info["time"] = ct.get_time_str() info["whole_params"] = whole_params info["conf_name"] = args.conf info["res_home"] = os.path.join(os.path.join(RES_PATH, args.conf), info["time"]) info["data_path"] = DATA_PATH info["home_path"] = ROOT_PATH info["network_path"] = os.path.join(DATA_PATH, params["network_path"]) ct.check_attr(info, "mem_interval", 0.001) # if not exists, then mkdir ct.mkdir(info["res_home"]) log_path = os.path.join(LOG_PATH, info["time"] + ".log") info["log_path"] = log_path info["log"] = ct.get_logger(log_path) ct.symlink(log_path, os.path.join(LOG_PATH, "new_log")) ct.symlink(info["res_home"], os.path.join(RES_PATH, "new_res")) random.seed(info["random_seed"]) np.random.seed(info["np_seed"]) return info
def params_handler(params, info, pre_res, **kwargs): res = {} if ct.check_attr(params, "save_path", info["res_home"]): params["save_path"] = os.path.join(info["home_path"], params["save_path"]) params["folder_path"] = os.path.join(info["data_path"], info["network_folder"]["name"]) ct.mkdir(params["save_path"]) res["save_path"] = params["save_path"] return res
def params_handler(params, info, pre_res, **kwargs): res = {} if ct.check_attr(params, "save_path", info["res_home"]): params["save_path"] = os.path.join(info["home_path"], params["save_path"]) params["folder_path"] = os.path.join(info["data_path"], info["network_folder"]["name"]) ct.check_attr(params, "is_direct", False) res["train_path"] = os.path.join(params["save_path"], "train") res["test_path"] = os.path.join(params["save_path"], "test") ct.mkdir(res["train_path"]) ct.mkdir(res["test_path"]) return res
def split_graph(params, info, res, **kwargs): params_handler(params, info, res) n = params["num_nodes"] k = params["num_community"] #print n, k #print np.argpartition(params["degree_distrib"], n-k) params["top_set"] = set( np.argpartition(params["degree_distrib"], n - k)[-k:]) uf = UnionFind(params) ret = {} #print params["top_set"] with open(params["network_path"], "r") as f: for line in f: line = line.strip() if len(line) == 0: continue items = line.split() if len(items) != 2: continue u, v = [int(i) for i in items] flag = uf.union(u, v) #print u, v, flag ret["community_info"] = uf.refine() home_path = os.path.join(info["res_home"], "split_graph") com_info = ret["community_info"] ct.mkdir(home_path) wf = {} for u in com_info: com_info[u]["file_path"] = os.path.join(home_path, str(u) + ".dat") wf[u] = open(com_info[u]["file_path"], "w") with open(params["network_path"], "r") as f: for line in f: line = line.strip() if len(line) == 0: continue items = line.split() if len(items) != 2: continue u = uf.find(int(items[0])) v = uf.find(int(items[1])) if u != v: continue wf[u].write(items[0] + "\t" + items[1] + "\n") for it in wf: wf[it].close() return ret
def params_handler(params, info, pre_res, **kwargs): params["num_nodes"] = info["num_nodes"] params["community_size"] = info["community_size"] params["num_community"] = info["num_community"] params["num_top"] = info["num_top"] params["res_path"] = info["res_home"] params["network_path"] = info["network_path"] params["dim"] = info["embedding_size"] params["tmp_path"] = os.path.join(info["res_home"], "tmp") ct.mkdir(params["tmp_path"]) ct.check_attr(params, "is_directed", False) if "data_path" in params: params["data_path"] = os.path.join(info["home_path"], params["data_path"]) else: params["data_path"] = params["res_path"] return {}