def build_model(rand_test_indices, train_indices,traint,testt, labels ,X, adj_tr, adj_te, in_features, hid_features,out_features,ds_name, activation, optimizer, epochs, dropout, lr, l2_pen, beta, gamma, dumping_name, GS,is_nni=False): optim_name="SGD" if optimizer==optim.Adam: optim_name = "Adam" conf = {"in_features":in_features, "hid_features": hid_features, "out_features":out_features,"ds_name":ds_name, "dropout": dropout, "lr": lr, "weight_decay": l2_pen, "beta": beta, "gamma": gamma, #"training_mat": training_data, "training_labels": training_labels, # "test_mat": test_data, "test_labels": test_labels, "train_ind": train_indices, "test_ind": rand_test_indices, "traint":traint,"testt":testt, "labels":labels, "X":X, "adj_tr": adj_tr,"adj_te": adj_te, "optimizer": optimizer, "epochs": epochs, "activation": activation,"optim_name":optim_name} products_path = os.path.join(os.getcwd(), "logs", dumping_name, time.strftime("%Y%m%d_%H%M%S")) if not os.path.exists(products_path): os.makedirs(products_path) logger = multi_logger([ PrintLogger("MyLogger", level=logging.DEBUG), FileLogger("results_%s" % dumping_name, path=products_path, level=logging.INFO)], name=None) data_logger = CSVLogger("results_%s" % dumping_name, path=products_path) data_logger.info("model_name", "loss", "acc") runner = ModelRunner(conf, GS,logger=logger, data_logger=data_logger, is_nni=is_nni) return runner
def build_model(training_data, training_labels, test_data, test_labels, adjacency_matrices, hid_features, activation, optimizer, epochs, dropout, lr, l2_pen, temporal_pen, dumping_name, feature_matrices, is_nni=False): optim_name="SGD" if optimizer==optim.Adam: optim_name = "Adam" conf = {"hid_features": hid_features, "dropout": dropout, "lr": lr, "weight_decay": l2_pen, "temporal_pen": temporal_pen, "training_mat": training_data, "training_labels": training_labels, "test_mat": test_data, "test_labels": test_labels, "adj_matrices": adjacency_matrices, "optimizer": optimizer, "epochs": epochs, "feature_matrices": feature_matrices, "activation": activation,"optim_name":optim_name} products_path = os.path.join(os.getcwd(), "logs", dumping_name, time.strftime("%Y%m%d_%H%M%S")) if not os.path.exists(products_path): os.makedirs(products_path) logger = multi_logger([ PrintLogger("MyLogger", level=logging.DEBUG), FileLogger("results_%s" % dumping_name, path=products_path, level=logging.INFO)], name=None) data_logger = CSVLogger("results_%s" % dumping_name, path=products_path) data_logger.info("model_name", "loss", "acc") ## logger.info('STARTING with lr= {:.4f} '.format(lr) + ' dropout= {:.4f} '.format(dropout)+ ' regulariztion_l2_pen= {:.4f} '.format(l2_pen) + ' temporal_pen= {:.10f} '.format(temporal_pen)+ ' optimizer= %s ' %optim_name) logger.debug('STARTING with lr= {:.4f} '.format(lr) + ' dropout= {:.4f} '.format(dropout) + ' regulariztion_l2_pen= {:.4f} '.format(l2_pen) + ' temporal_pen= {:.10f} '.format(temporal_pen) + ' optimizer= %s ' %optim_name) ## runner = ModelRunner(conf, logger=logger, data_logger=data_logger, is_nni=is_nni) return runner
def main_clean(): args = parse_args() dataset = "citeseer" seed = random.randint(1, 1000000000) # "feat_type": "neighbors", conf = { "kipf": { "hidden": args.hidden, "dropout": args.dropout, "lr": args.lr, "weight_decay": args.weight_decay }, "hidden_layers": [16], "multi_hidden_layers": [100, 35], "dropout": 0.6, "lr": 0.01, "weight_decay": 0.001, "dataset": dataset, "epochs": args.epochs, "cuda": args.cuda, "fastmode": args.fastmode, "seed": seed } init_seed(conf['seed'], conf['cuda']) dataset_path = os.path.join(PROJ_DIR, "data", dataset) products_path = os.path.join(CUR_DIR, "logs", args.prefix + dataset, time.strftime("%Y_%m_%d_%H_%M_%S")) if not os.path.exists(products_path): os.makedirs(products_path) logger = multi_logger([ PrintLogger("IdansLogger", level=logging.DEBUG), FileLogger("results_%s" % conf["dataset"], path=products_path, level=logging.INFO), FileLogger("results_%s_all" % conf["dataset"], path=products_path, level=logging.DEBUG), ], name=None) data_logger = CSVLogger("results_%s" % conf["dataset"], path=products_path) data_logger.info("model_name", "loss", "acc", "train_p") runner = ModelRunner(dataset_path, conf, logger=logger, data_logger=data_logger) # execute_runner(runner, logger, 5, num_iter=30) for train_p in range(5, 90, 10): execute_runner(runner, logger, train_p, num_iter=10) logger.info("Finished")
def build_model(training_data, training_adj, training_labels, test_data, test_adj, test_labels, optimizer, epochs, lr, l2_pen, class_weights, graph_params, dumping_name, iterations, is_nni=False): conf = { "lr": lr, "weight_decay": l2_pen, "training_mat": training_data, "training_adj": training_adj, "training_labels": training_labels, "test_mat": test_data, "test_adj": test_adj, "test_labels": test_labels, "optimizer": optimizer, "epochs": epochs, "iterations": iterations } products_path = os.path.join(os.getcwd(), "logs", dumping_name, time.strftime("%Y%m%d_%H%M%S")) if not os.path.exists(products_path): os.makedirs(products_path) logger = multi_logger([ PrintLogger("MyLogger", level=logging.DEBUG), FileLogger( "results_" + dumping_name, path=products_path, level=logging.INFO) ], name=None) data_logger = CSVLogger("results_" + dumping_name, path=products_path) data_logger.info("model_name", "loss", "acc", "auc") runner = ModelRunner(conf, logger=logger, data_logger=data_logger, weights=class_weights, graph_params=graph_params, is_nni=is_nni) return runner
def set_logs(data_name): grid_outputs_folder = time.strftime("%Y%m%d_%H%M%S") res_path = os.path.join(os.getcwd(), "dataset", data_name, "grid", grid_outputs_folder) if not os.path.exists(res_path): os.makedirs(res_path) grid_logger = CSVLogger("results_%s" % 'grid' + time.strftime("%Y%m%d_%H%M%S"), path=res_path) grid_logger_avg = CSVLogger("results_%s" % 'grid_it_avg' + time.strftime("%Y%m%d_%H%M%S"), path=res_path) grid_logger.info("data_name", "weights", "iteration", "total_it", "lr", "do", "wd", "hid_size", "temp_pen", "epochs", "best_epoch", "train_loss", "train_temp_loss", "total_train_loss", "train_f1_macro", "train_f1_micro", "val_loss", "val_temp_loss", "total_val_loss", "val_f1_macro", "val_f1_micro", "test_loss", "test_temp_loss", "total_test_loss", "test_f1_macro", "test_f1_micro", "diag_sum", "diag_elements") grid_logger_avg.info( "data_name", "weights", "iterations", "lr", "do", "hid_size", "wd", "temp_pen", "epochs", "train_loss", "train_temp_loss", "total_train_loss", "train_f1_macro_mean", "train_f1_macro_std", "train_f1_micro_mean", "train_f1_micro_std", "val_loss", "val_temp_loss", "total_val_loss", "val_f1_macro_mean", "val_f1_macro_std", "val_f1_micro_mean", "val_f1_micro_std", "test_loss", "test_temp_loss", "total_test_loss", "test_f1_macro_mean", "test_f1_macro_std", "test_f1_micro_mean", "test_f1_micro_std", "diag_sum", "diag_elements") return grid_logger, grid_logger_avg
def get_loggers(name, products_path, is_debug=True, set_titles=True): logger = multi_logger([ PrintLogger("IdansLogger", level=logging.DEBUG if is_debug else logging.INFO), FileLogger("results_%s" % name, path=products_path, level=logging.INFO), FileLogger( "results_%s_all" % name, path=products_path, level=logging.DEBUG), ], name=None) data_logger = CSVLogger("results_%s" % name, path=products_path) if set_titles: data_logger.set_titles("feat_type", "year", "loss_val", "loss_test", "acc", "auc_test", "train_p", "norm_adj", "epoch") logger.dump_location() data_logger.dump_location() return logger, data_logger
def main(): args = parse_args() dataset = "cora" # args.dataset seed = random.randint(1, 1000000000) conf = { "kipf": { "hidden": 16, "dropout": 0.5, "lr": 0.01, "weight_decay": 5e-4 }, "hidden_layers": [16], "multi_hidden_layers": [100, 20], "dropout": 0.6, "lr": 0.01, "weight_decay": 0.001, "dataset": dataset, "epochs": args.epochs, "cuda": args.cuda, "fastmode": args.fastmode, "seed": seed } init_seed(conf['seed'], conf['cuda']) dataset_path = os.path.join(PROJ_DIR, "data", dataset) products_path = os.path.join(CUR_DIR, "logs", dataset, time.strftime("%Y_%m_%d_%H_%M_%S")) if not os.path.exists(products_path): os.makedirs(products_path) logger = multi_logger([ PrintLogger("IdansLogger", level=logging.INFO), FileLogger("results_%s" % conf["dataset"], path=products_path, level=logging.INFO), FileLogger("results_%s_all" % conf["dataset"], path=products_path, level=logging.DEBUG), ], name=None) data_logger = CSVLogger("results_%s" % conf["dataset"], path=products_path) data_logger.set_titles("model_name", "loss", "acc", "train_p", "norm_adj", "feat_type") num_iter = 5 for norm_adj in [True, False]: conf["norm_adj"] = norm_adj runner = ModelRunner(products_path, dataset_path, conf, logger=logger, data_logger=data_logger) for train_p in chain([1], range(5, 90, 10)): conf["train_p"] = train_p train_p /= 100 val_p = test_p = (1 - train_p) / 2. train_p /= (val_p + train_p) runner.loader.split_test(test_p) for ft, feat_type in enumerate( ["combined", "neighbors", "features"]): conf["feat_type"] = feat_type results = [ runner.run(train_p, feat_type) for _ in range(num_iter) ] conf_path = os.path.join( runner.products_path, "t%d_n%d_ft%d.pkl" % ( conf["train_p"], norm_adj, ft, )) pickle.dump({ "res": results, "conf": conf }, open(conf_path, "wb")) logger.info("Finished")
gtc = GCNTemporalCommunities(nni=params['is_nni']) gtc.load_data() gtc.prep_trial(params, grid_logger, grid_logger_avg) if __name__ == "__main__": pr = cProfile.Profile() pr.enable() grid_outputs_folder = time.strftime("%Y%m%d_%H%M%S") res_path = os.path.join(os.getcwd(), "dataset", Dataset_name, "grid", grid_outputs_folder) if not os.path.exists(res_path): os.makedirs(res_path) grid_logger = CSVLogger("results_%s" % 'grid' + time.strftime("%Y%m%d_%H%M%S"), path=res_path) grid_logger_avg = CSVLogger("results_%s" % 'grid_it_avg' + time.strftime("%Y%m%d_%H%M%S"), path=res_path) grid_logger.info("iteration", "total_it", "lr", "do", "hid_size", "wd", "temp_pen", "epochs", "train_reg_loss", "train_temp_loss", "total_train_loss", "train_acc_f1_macro", "train_f1_micro", "test_reg_loss", "test_temp_loss", "total_test_loss", "test_f1_macro", "test_f1_micro") grid_logger_avg.info("iterations", "lr", "do", "hid_size", "wd", "temp_pen", "epochs", "train_reg_loss", "train_temp_loss", "total_train_loss", "train_f1_macro", "train_f1_micro", "test_reg_loss", "test_temp_loss", "total_test_loss", "test_f1_macro", "test_f1_micro") num_of_grids = len(LR) * len(Hid_size) * len(Regularization) * len(Temporal_pen) * len(Dropout) grid_counter = 0 configurations = list(product(*[LR, Hid_size, Regularization, Temporal_pen, Dropout])) for LR, Hid_size, Regularization, Temporal_pen, Dropout in configurations: grid_counter += 1