You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for v2 in degrees[degree_v]['vertices']:
if (v != v2):
vertices.append(v2) # same degree
c_v += 1
if (c_v > a_vertices_selected):
raise StopIteration
if ('before' not in degrees[degree_v]):
degree_b = -1
else:
degree_b = degrees[degree_v]['before']
if ('after' not in degrees[degree_v]):
degree_a = -1
else:
degree_a = degrees[degree_v]['after']
if (degree_b == -1 and degree_a == -1):
raise StopIteration # not anymore v
degree_now = verifyDegrees(degrees, degree_v, degree_a, degree_b)
# nearest valid degree
while True:
for v2 in degrees[degree_now]['vertices']:
if (v != v2):
vertices.append(v2)
c_v += 1
if (c_v > a_vertices_selected):
raise StopIteration
if (degree_now == degree_b):
if ('before' not in degrees[degree_b]):
degree_b = -1
else:
degree_b = degrees[degree_b]['before']
else:
if ('after' not in degrees[degree_a]):
degree_a = -1
else:
degree_a = degrees[degree_a]['after']
if (degree_b == -1 and degree_a == -1):
raise StopIteration
degree_now = verifyDegrees(degrees, degree_v, degree_a, degree_b)
except StopIteration:
return list(vertices)
return list(vertices)
研究了一下struc2vec相关论文:
对于捕获网络中节点的结构身份的学习表示,一个有效的方法应具备:
节点的潜在表征( latent representation)之间的距离应该与节点的结构相似性密切相关。具有相同局域网结构的两个节点应该具有相同的潜在表示而具有不同结构身份的节点 应该相距很远(这里的距离是指节点latent representation之间的距离)潜在表示不应该依赖于任何节点或边缘属性,包括节点标签。因此,在结构上相似的节点应该有紧密的潜在表示,独立于节点和边缘的属性。
节点的结构身份必须独立于其在网络中的“位置”
struct2vec框架的四个步骤:
1.对于不同的邻域大小,确定图中每个顶点对之间的结构相似性:
在度量节点之间的结构相似度时引入了层次,提供了更多的信息来评估层次的每一层的结构相似度。
2.构造一个加权多层图:
网络中的所有节点都存在于每一层,每一层对应于层次的一个层次,用于度量结构相似性每层内每个节点对之间的边权值与它们的结构相似度成反比
3.使用多层图为每个节点生成上下文:
在多层图上使用有偏随机游走,用来生成节点序列结构上更相似的节点更大概率会在这些序列中
4.应用一种技术,从节点序列给出的上下文学习潜在表示,例如SkipGram:
和deepwalk一样,利用这些序列进行学习
struct2vec是相当灵活的,因为它不要求任何特定的结构相似性测量或表征学习框架
总结:
struc2vec模型完全是利用图的结构信息训练节点的向量表示,没有利用节点的任何标签信息。在实际运用中这可以是一个优化方案。
相对于DeepWalk和Node2Vec来说,Struc2Vec是从另一个角度出发构造节点序列。更加侧重节点的同构信息。
附上源代码:
class Struc2Vec():
def init(self, graph, walk_length=10, num_walks=100, workers=1, verbose=0, stay_prob=0.3, opt1_reduce_len=True, opt2_reduce_sim_calc=True, opt3_num_layers=None, temp_path='./temp_struc2vec/', reuse=False):
self.graph = graph
self.idx2node, self.node2idx = preprocess_nxgraph(graph)
self.idx = list(range(len(self.idx2node)))
def cost(a, b):
ep = 0.5
m = max(a, b) + ep
mi = min(a, b) + ep
return ((m / mi) - 1)
def cost_min(a, b):
ep = 0.5
m = max(a[0], b[0]) + ep
mi = min(a[0], b[0]) + ep
return ((m / mi) - 1) * min(a[1], b[1])
def cost_max(a, b):
ep = 0.5
m = max(a[0], b[0]) + ep
mi = min(a[0], b[0]) + ep
return ((m / mi) - 1) * max(a[1], b[1])
def convert_dtw_struc_dist(distances, startLayer=1):
"""
def get_vertices(v, degree_v, degrees, n_nodes):
a_vertices_selected = 2 * math.log(n_nodes, 2)
vertices = []
try:
c_v = 0
def verifyDegrees(degrees, degree_v_root, degree_a, degree_b):
张宇飞Tencent进度汇报结营.pdf
张宇飞Tencent进度汇报结营.pdf
def compute_dtw_dist(part_list, degreeList, dist_func):
dtw_dist = {}
for v1, nbs in part_list:
lists_v1 = degreeList[v1] # lists_v1 :orderd degree list of v1
for v2 in nbs:
lists_v2 = degreeList[v2] # lists_v1 :orderd degree list of v2
max_layer = min(len(lists_v1), len(lists_v2)) # valid layer
dtw_dist[v1, v2] = {}
for layer in range(0, max_layer):
dist, path = fastdtw(
lists_v1[layer], lists_v2[layer], radius=1, dist=dist_func)
dtw_dist[v1, v2][layer] = dist
return [dtw_dist](url)
The text was updated successfully, but these errors were encountered: