日志 7

全部评论

相关推荐

随机游走算法生成序列:def random_walk(graph, start_node, walk_length):    walk = []    for _ in range(walk_length - 1):        neighbors = graph[start_node]        if not neighbors:            break        next_node = random.choice(neighbors)        if (start_node,next_node) in id2edgename:            walk.append(f'{id2name[next_node]}是{id2name[start_node]}的{id2edgename[(start_node,next_node)]}')            # walk.append(id2name[start_node]+"的"+id2edgename[(start_node,next_node)]+"是"+id2name[next_node])        else:            walk.append(f'{id2name[start_node]}是{id2name[next_node]}的{id2edgename[(next_node, start_node)]}')            # walk.append(id2name[next_node] + "的" + id2edgename[(next_node, start_node)] + "是" + id2name[start_node])        start_node = next_node    return ','.join(walk)
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务