def test_snowball_sampler():
    """
    Testing the number of nodes and the connectivity.
    """
    sampler = SnowBallSampler()

    graph = nx.watts_strogatz_graph(200, 10, 0)

    new_graph = sampler.sample(graph)

    assert sampler.number_of_nodes == new_graph.number_of_nodes()
    assert nx.is_connected(new_graph)
Пример #2
0
def test_snowball_sampler():
    """
    Testing the number of nodes and the connectivity.
    """
    sampler = SnowBallSampler()

    graph = nx.watts_strogatz_graph(200, 10, 0)

    new_graph = sampler.sample(graph)

    assert sampler.number_of_nodes == new_graph.number_of_nodes()
    assert nx.is_connected(new_graph)
    assert type(new_graph) == NXGraph

    sampler = SnowBallSampler(number_of_nodes=25)

    graph = nx.watts_strogatz_graph(100, 10, 0)

    new_graph = sampler.sample(graph)

    assert sampler.number_of_nodes == new_graph.number_of_nodes()
    assert nx.is_connected(new_graph)
    assert type(new_graph) == NXGraph

    sampler = SnowBallSampler()

    graph = nk.nxadapter.nx2nk(nx.watts_strogatz_graph(200, 10, 0))

    new_graph = sampler.sample(graph)

    assert sampler.number_of_nodes == new_graph.numberOfNodes()
    assert 1 == nk.components.ConnectedComponents(
        new_graph).run().numberOfComponents()
    assert type(new_graph) == NKGraph

    new_graph = sampler.sample(graph, 0)

    assert sampler.number_of_nodes == new_graph.numberOfNodes()
    assert 1 == nk.components.ConnectedComponents(
        new_graph).run().numberOfComponents()
    assert type(new_graph) == NKGraph

    new_graph = sampler.sample(graph, 111)

    assert sampler.number_of_nodes == new_graph.numberOfNodes()
    assert 1 == nk.components.ConnectedComponents(
        new_graph).run().numberOfComponents()
    assert type(new_graph) == NKGraph

    new_graph = sampler.sample(graph, 199)

    assert sampler.number_of_nodes == new_graph.numberOfNodes()
    assert 1 == nk.components.ConnectedComponents(
        new_graph).run().numberOfComponents()
    assert type(new_graph) == NKGraph

    sampler = SnowBallSampler(number_of_nodes=25)

    graph = nk.nxadapter.nx2nk(nx.watts_strogatz_graph(150, 10, 0))

    new_graph = sampler.sample(graph)

    assert sampler.number_of_nodes == new_graph.numberOfNodes()
    assert 1 == nk.components.ConnectedComponents(
        new_graph).run().numberOfComponents()
    assert type(new_graph) == NKGraph
Пример #3
0
"""Snow ball sampler example"""

import networkx as nx

from littleballoffur.exploration_sampling import SnowBallSampler

graph = nx.watts_strogatz_graph(1000, 10, 0)

sampler = SnowBallSampler()

new_graph = sampler.sample(graph)


Пример #4
0
# reader = GraphReader("facebook")
reader = GraphReader("tinghua_se_all_partial_graph_numeric")
graph = reader.get_graph()
# #画图
# pos = nx.spring_layout(graph)
# #nx.draw_spring(graph, node_size=15, node_color=node_lable, cmap=plt.get_cmap('hsv'), with_labels = True )
# plt.figure(1)
# nx.draw(graph, node_size=20, cmap=plt.get_cmap('hsv'), with_labels = True, font_size = 6, edge_color = 'red')
# plt.savefig("ba.png")           #输出方式1: 将图像存为一个png格式的图片文件
# plt.show()                            #输出方式2: 在窗口中显示这幅图像

#-------------------
# Snow Ball Sampler
#-------------------

sampler = SnowBallSampler()
sampler.__init__(number_of_nodes=1000, k=100, seed=42)
new_graph = sampler.sample(graph)

#画图
pos = nx.spring_layout(new_graph)
#nx.draw_spring(graph, node_size=15, node_color=node_lable, cmap=plt.get_cmap('hsv'), with_labels = True )
plt.figure(2)
nx.draw(new_graph,
        node_size=20,
        cmap=plt.get_cmap('hsv'),
        with_labels=True,
        font_size=6,
        edge_color='red')
plt.savefig("ba2.png")  #输出方式1: 将图像存为一个png格式的图片文件
plt.show()  #输出方式2: 在窗口中显示这幅图像