grarep_checked_v0.0

This commit is contained in:
Chengbin Hou 2018-11-20 11:33:24 +00:00
parent 359d0aeea7
commit 768d04eda0
2 changed files with 14 additions and 1 deletions

View File

@ -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(

View File

@ -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',