本文整理汇总了Python中networkx.classes.digraph.DiGraph.node['dum']['dummy']方法的典型用法代码示例。如果您正苦于以下问题:Python DiGraph.node['dum']['dummy']方法的具体用法?Python DiGraph.node['dum']['dummy']怎么用?Python DiGraph.node['dum']['dummy']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx.classes.digraph.DiGraph
的用法示例。
在下文中一共展示了DiGraph.node['dum']['dummy']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_variance_based_cost
# 需要导入模块: from networkx.classes.digraph import DiGraph [as 别名]
# 或者: from networkx.classes.digraph.DiGraph import node['dum']['dummy'] [as 别名]
def test_variance_based_cost():
D = {'u': {}, 'v': {10: {'x', 'dum'}}, 'w': {12: {'y'}}}
G = DiGraph()
G.add_edges_from([('u', 'v'),
('u', 'w'),
('v', 'dum'),
('dum', 'x'),
('w', 'y')])
G.node['dum']['dummy'] = True
reprs = np.array([[0, 1],
[1, 0],
[0, 1],
[1, 1],
[0, 0]])
real_nodes = ['u', 'v', 'w', 'x', 'y']
for r, n in zip(reprs, real_nodes):
G.node[n]['r'] = r
n = 'u'
children = [(10, 'v'),
(12, 'w')]
actual = get_all_nodes(G, n, D, children, ignore_dummy=True)
expected = real_nodes
assert_equal(sorted(expected), sorted(actual))
cost_func = make_variance_cost_func(euclidean, 'r')
actual = cost_func(n, D, G,
children)
mean_vec = np.mean(reprs, axis=0)
expected = np.sum([euclidean(mean_vec, v)
for v in reprs])
np.testing.assert_almost_equal(expected, actual)
# with fixed_point
cost_func_fp = make_variance_cost_func(euclidean, 'r', fixed_point=2)
actual = cost_func_fp(n, D, G,
children)
assert_equal(int(expected*100), actual)