From 768d04eda02f23317111e61ff7754b4445a7901f Mon Sep 17 00:00:00 2001 From: Chengbin Hou Date: Tue, 20 Nov 2018 11:33:24 +0000 Subject: [PATCH] grarep_checked_v0.0 --- src/libnrl/grarep.py | 13 +++++++++++++ src/main.py | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/libnrl/grarep.py b/src/libnrl/grarep.py index db3f7f3..2649a27 100644 --- a/src/libnrl/grarep.py +++ b/src/libnrl/grarep.py @@ -1,7 +1,16 @@ +""" +a matrix factorization based NE method: GraRep + +modified by Chengbin Hou 2018 + +originally from https://github.com/thunlp/OpenNE/blob/master/src/openne/grarep.py +""" + import math import numpy as np from numpy import linalg as la from sklearn.preprocessing import normalize +from .utils import row_as_probdist class GraRep(object): @@ -13,6 +22,7 @@ class GraRep(object): self.train() def getAdjMat(self): + ''' graph = self.g.G node_size = self.g.get_num_nodes() look_up = self.g.look_up_dict @@ -22,6 +32,9 @@ class GraRep(object): adj[look_up[edge[1]]][look_up[edge[0]]] = 1.0 # ScaleSimMat return np.matrix(adj/np.sum(adj, axis=1)) + ''' + adj = self.g.get_adj_mat() #for isolated node row, normalize to [1/n, 1/n, ...] + return row_as_probdist(adj, dense_output=True, preserve_zeros=False) def GetProbTranMat(self, Ak): probTranMat = np.log(Ak/np.tile( diff --git a/src/main.py b/src/main.py index f954851..7d2b6d4 100644 --- a/src/main.py +++ b/src/main.py @@ -91,7 +91,7 @@ def parse_args(): parser.add_argument('--Node2Vec-q', default=0.5, type=float, help='trade-off BFS and DFS; rid search [0.25; 0.50; 1; 2; 4]') parser.add_argument('--GraRep-kstep', default=4, type=int, - help='use k-step transition probability matrix') + help='use k-step transition probability matrix, error if dim%Kstep!=0') parser.add_argument('--LINE-order', default=3, type=int, help='choices of the order(s), 1st order, 2nd order, 1st+2nd order') parser.add_argument('--LINE-no-auto-save', action='store_true',