本文整理汇总了Python中networkx.karate_club_graph函数的典型用法代码示例。如果您正苦于以下问题:Python karate_club_graph函数的具体用法?Python karate_club_graph怎么用?Python karate_club_graph使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了karate_club_graph函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_edge_num_attribute
def test_edge_num_attribute(self):
g = nx.karate_club_graph()
attr = {(u, v): {"even": int((u+v) % 10)} for (u, v) in g.edges()}
nx.set_edge_attributes(g, attr)
model = gc.CompositeModel(g)
model.add_status("Susceptible")
model.add_status("Infected")
c = cpm.EdgeNumericalAttribute("even", value=0, op="==", probability=1)
model.add_rule("Susceptible", "Infected", c)
config = mc.Configuration()
config.add_model_parameter('percentage_infected', 0.1)
model.set_initial_status(config)
iterations = model.iteration_bunch(10)
self.assertEqual(len(iterations), 10)
model = gc.CompositeModel(g)
model.add_status("Susceptible")
model.add_status("Infected")
c = cpm.EdgeNumericalAttribute("even", value=[3, 10], op="IN", probability=1)
model.add_rule("Susceptible", "Infected", c)
config = mc.Configuration()
config.add_model_parameter('percentage_infected', 0.1)
model.set_initial_status(config)
iterations = model.iteration_bunch(10)
self.assertEqual(len(iterations), 10)
示例2: main
def main():
# Load the karate.GraphML and store that into a g
g =nx.karate_club_graph()
data = json_graph.node_link_data(g)
with open ('graph.json' , 'w') as f:
json.dump(data, f, indent=1)
示例3: test_nodes_all_labeled
def test_nodes_all_labeled(self):
G = nx.karate_club_graph()
label_name = 'club'
predicted = node_classification.local_and_global_consistency(
G, alpha=0, label_name=label_name)
for i in range(len(G)):
assert_equal(predicted[i], G.node[i][label_name])
示例4: test_run
def test_run(self):
karate = nx.karate_club_graph()
louvain = wm.LouvainCommunityDetection(karate)
final_partitions = louvain.run()
self.assertEqual(final_partitions[-1].modularity() > .38,
True)
self.assertEqual(len(final_partitions), 2)
示例5: test_clustering_integer_nodes
def test_clustering_integer_nodes(self):
# This tests an error that would happen when a node had an integer value
# greater than the size of the graph
orig_club = nx.karate_club_graph()
club = nx.relabel_nodes(orig_club, { n: n + 5 for n in orig_club.nodes() })
dendrogram = GreedyAgglomerativeClusterer().cluster(club)
dendrogram.clusters() # This would crash
示例6: test_nodes_all_labeled
def test_nodes_all_labeled(self):
G = nx.karate_club_graph()
label_name = 'club'
predicted = node_classification.harmonic_function(
G, label_name=label_name)
for i in range(len(G)):
assert_equal(predicted[i], G.node[i][label_name])
示例7: test_graphs_karate
def test_graphs_karate():
G = nx.karate_club_graph()
nx.draw(G, with_labels=True, node_color="lightblue", edge_color="grey")
plt.show()
# plt.savefig("karate.pdf")
print(G.number_of_edges())
print(G.number_of_nodes())
print(G.degree(0) is G.degree()[0])
示例8: test_net_load
def test_net_load(self):
base = os.path.dirname(os.path.abspath(__file__))
g = nx.karate_club_graph()
fname = "%s/edge.txt" % base
nx.write_edgelist(g, fname)
query = "LOAD_NETWORK g1 FROM %s\n" \
"\n" \
"MODEL model1\n" \
"\n" \
"STATUS Susceptible\n" \
"\n" \
"STATUS Infected\n" \
"\n" \
"STATUS Removed\n" \
"\n" \
"COMPARTMENT c1\n" \
"TYPE NodeStochastic\n" \
"PARAM rate 0.1\n" \
"TRIGGER Infected\n" \
"\n" \
"COMPARTMENT c2\n" \
"TYPE NodeStochastic\n" \
"PARAM rate 0.1\n" \
"COMPOSE c1\n" \
"TRIGGER Infected\n" \
"\n" \
"COMPARTMENT c3\n" \
"TYPE NodeStochastic\n" \
"PARAM rate 0.1\n" \
"\n" \
"RULE\n" \
"FROM Susceptible\n" \
"TO Infected\n" \
"USING c2\n" \
"\n" \
"RULE\n" \
"FROM Infected\n" \
"TO Removed\n" \
"USING c3\n" \
"\n" \
"INITIALIZE\n" \
"SET Infected 0.1\n" \
"\n" \
"EXECUTE model1 ON g1 FOR 10" % fname
parser = ep.ExperimentParser()
parser.set_query(query)
parser.parse()
iterations = parser.execute_query()
try:
os.remove("%s/edge.txt" % base)
except OSError:
pass
self.assertIn('trends', iterations[0])
示例9: test_karate_1
def test_karate_1():
karate_k_num = {0: 4, 1: 4, 2: 4, 3: 4, 4: 3, 5: 3, 6: 3, 7: 4, 8: 4, 9: 2,
10: 3, 11: 1, 12: 2, 13: 4, 14: 2, 15: 2, 16: 2, 17: 2, 18: 2,
19: 3, 20: 2, 21: 2, 22: 2, 23: 3, 24: 3, 25: 3, 26: 2, 27: 3,
28: 3, 29: 3, 30: 4, 31: 3, 32: 4, 33: 4}
G = nx.karate_club_graph()
k_comps = k_components(G)
k_num = build_k_number_dict(k_comps)
assert_equal(karate_k_num, k_num)
示例10: test_karate_club_graph_cutset
def test_karate_club_graph_cutset(self):
G = nx.karate_club_graph()
nx.set_edge_attributes(G, 1, 'capacity')
T = nx.gomory_hu_tree(G)
assert_true(nx.is_tree(T))
u, v = 0, 33
cut_value, edge = self.minimum_edge_weight(T, u, v)
cutset = self.compute_cutset(G, T, edge)
assert_equal(cut_value, len(cutset))
示例11: test_default_flow_function_karate_club_graph
def test_default_flow_function_karate_club_graph(self):
G = nx.karate_club_graph()
nx.set_edge_attributes(G, 1, 'capacity')
T = nx.gomory_hu_tree(G)
assert_true(nx.is_tree(T))
for u, v in combinations(G, 2):
cut_value, edge = self.minimum_edge_weight(T, u, v)
assert_equal(nx.minimum_cut_value(G, u, v),
cut_value)
示例12: main
def main():
G = nx.karate_club_graph()
N = NewmanGreedy(G)
print N.quality_history
try:
N.plot_dendrogram()
N.plot_quality_history("Karate", os.path.join(os.path.dirname(__file__), "pics", "karate"))
except:
pass
示例13: test_biconnected_karate
def test_biconnected_karate():
K = nx.karate_club_graph()
answer = [{0, 1, 2, 3, 7, 8, 9, 12, 13, 14, 15, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33},
{0, 4, 5, 6, 10, 16},
{0, 11}]
bcc = list(nx.biconnected_components(K))
assert_components_equal(bcc, answer)
assert_equal(set(nx.articulation_points(K)), {0})
示例14: test_biconnected_karate
def test_biconnected_karate():
K = nx.karate_club_graph()
answer = [set([0, 1, 2, 3, 7, 8, 9, 12, 13, 14, 15, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33]),
set([0, 4, 5, 6, 10, 16]),
set([0, 11])]
bcc = list(biconnected.biconnected_components(K))
bcc.sort(key=len, reverse=True)
assert_true(list(biconnected.biconnected_components(K)) == answer)
assert_equal(list(biconnected.articulation_points(K)),[0])
示例15: main
def main():
graph = nx.karate_club_graph();
dendrogram = GreedyAgglomerativeClusterer().cluster(graph)
print dendrogram.quality_history
print dendrogram.clusters()
try:
dendrogram.plot(os.path.join(os.path.dirname(__file__), '..', 'pics', 'karate_dend.png'), show=False)
dendrogram.plot_quality_history('Karate', os.path.join(os.path.dirname(__file__), '..', 'pics', 'karate'), show=False)
except:
pass