diff --git a/constructor.py b/constructor.py index a4f3159..f16397f 100644 --- a/constructor.py +++ b/constructor.py @@ -1,5 +1,7 @@ import tensorflow as tf import numpy as np + +from load_data import load_data_1 from model import GCN, Generator_z2g, Discriminator, D_graph from optimizer import OptimizerAE, OptimizerCycle import scipy.sparse as sp @@ -51,7 +53,8 @@ def get_model(model_str, placeholders, num_features, num_nodes, features_nonzero def format_data(data_name): # Load data - adj, features, y_test, tx, ty, test_maks, true_labels = load_data(data_name) + # adj, features, y_test, tx, ty, test_maks, true_labels = load_data(data_name) + adj, features, y_test, tx, ty, test_maks, true_labels = load_data_1("e") # Store original adjacency matrix (without diagonal entries) for later adj_orig = adj diff --git a/link_prediction.py b/link_prediction.py index 06112af..c90197b 100644 --- a/link_prediction.py +++ b/link_prediction.py @@ -91,8 +91,7 @@ class Link_pred_Runner(): roc_curr, ap_curr, _ = lm_train.get_roc_score(emb, feas) val_roc_score.append(roc_curr) print("Epoch:", '%04d' % (epoch + 1), - "train_loss= {:.5f}, d_loss= {:.5f}, g_loss= {:.5f}, GD_loss= {:.5f}, GG_loss= {:.5f}".format(avg_cost[0], avg_cost[1], avg_cost[2], avg_cost[3], - avg_cost[4]), "val_roc=", + "train_loss= {:.5f}, d_loss= {:.5f}, g_loss= {:.5f}, GD_loss= {:.5f}, GG_loss= {:.5f}".format(avg_cost[0], avg_cost[1], avg_cost[2], avg_cost[3], avg_cost[4]), "val_roc=", "{:.5f}".format(val_roc_score[-1]), "val_ap=", "{:.5f}".format(ap_curr)) if (epoch + 1) % 10 == 0: @@ -106,6 +105,5 @@ class Link_pred_Runner(): index = rec[:, 0].tolist().index(max(rec[:, 0].tolist())) emb = record_emb[index] ana = record[index] - scio.savemat('result/{}_link_64_64_new.mat'.format(self.data_name), {'embedded': emb, - 'labels': feas['true_labels']}) + # scio.savemat('result/{}_link_64_64_new.mat'.format(self.data_name), {'embedded': emb,'labels': feas['true_labels']}) print('The peak val_roc=%f, ap = %f' % (ana[0], ana[1])) diff --git a/load_data.py b/load_data.py new file mode 100644 index 0000000..1b96e05 --- /dev/null +++ b/load_data.py @@ -0,0 +1,27 @@ +import pickle + +import numpy as np +import scipy.sparse as sp + + +def load_data_1(dataset): + adj = np.loadtxt('./data/partitioned_data/{}/orig/e_adj_orig.txt'.format(dataset), dtype=int) + adj = sp.csr_matrix(adj) + + features = pickle.load(open("data/partitioned_data/e/feature/e_feature.pkl",'rb')) + + y_test = 0 + + tx = 0 + + ty = 0 + + test_mask = 0 + + labels = 0 + + return adj, features, y_test, tx, ty, test_mask, labels + + +if __name__ == "__main__": + load_data_1('e')