utils.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:cnn-graph-classification 作者: giannisnik 项目源码 文件源码
def generate_synthetic():
    import random
    max_nodes=200
    min_nodes=100
    community_num_nodes=10
    graphs=[]
    labels=[]
    com_1= nx.caveman_graph(1, community_num_nodes)
    com_2= nx.star_graph(community_num_nodes)

    for i in range(500):
        num_nodes= random.randint(min_nodes, max_nodes)
        graph= nx.fast_gnp_random_graph(num_nodes, 0.1)
        graph = nx.disjoint_union(graph,com_1)
        for i in range(num_nodes,graph.number_of_nodes()):
            for j in range(num_nodes):
                if random.random() > 0.9:
                    graph.add_edge(graph.nodes()[i], graph.nodes()[j])
        graphs.append(graph)
        labels.append(1)
        num_nodes = random.randint(min_nodes, max_nodes)
        graph = nx.fast_gnp_random_graph(num_nodes, 0.1)
        for i in range(num_nodes, graph.number_of_nodes()):
            for j in range(num_nodes):
                if random.random() > 0.9:
                    graph.add_edge(graph.nodes[i], graph.nodes[j])
        graphs.append(graph)
        labels.append(0)

    return graphs,labels
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号