Commit f74098a6 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Fix output of docstring tests.

parent ddd84961
......@@ -121,7 +121,7 @@ def local_clustering(g, prop=None, undirected=True):
>>> g = gt.random_graph(1000, lambda: (5,5))
>>> clust = gt.local_clustering(g)
>>> print(gt.vertex_average(g, clust))
(0.008622222222222222, 0.00043812507374825467)
(0.007988888888888889, 0.00042593962940918587)
References
----------
......@@ -182,7 +182,7 @@ def global_clustering(g):
>>> g = gt.random_graph(1000, lambda: (5,5))
>>> print(gt.global_clustering(g))
(0.008641479099678457, 0.00043945639266115854)
(0.00796839426811303, 0.00042625555150575134)
References
----------
......@@ -261,11 +261,11 @@ def extended_clustering(g, props=None, max_depth=3, undirected=False):
>>> for i in range(0, 5):
... print(gt.vertex_average(g, clusts[i]))
...
(0.005646666666666667, 0.000485653786148116)
(0.023786666666666668, 0.000912204314345811)
(0.11883, 0.0019560612322840113)
(0.4067333333333333, 0.0031162452478013408)
(0.4260333333333333, 0.003097392092999815)
(0.004208333333333333, 0.0004046856633377455)
(0.020531666666666667, 0.0009122518521037196)
(0.11366833333333333, 0.0019888303367389926)
(0.40287166666666663, 0.0032700366422513776)
(0.4392583333333333, 0.0031463122041703218)
References
----------
......@@ -340,9 +340,9 @@ def motifs(g, k, p=1.0, motif_list=None):
>>> g = gt.random_graph(1000, lambda: (5,5))
>>> motifs, counts = gt.motifs(gt.GraphView(g, directed=False), 4)
>>> print(len(motifs))
10
55
>>> print(counts)
[115392, 389974, 668, 761, 3056, 1698, 770, 4, 10, 7]
[28946, 29051, 28786, 29009, 32700, 97746, 98018, 162496, 117, 86, 184, 96, 94, 17, 65, 267, 266, 85, 697, 665, 253, 261, 482, 435, 122, 228, 253, 124, 249, 346, 143, 44, 236, 268, 274, 1, 6, 1, 6, 8, 2, 2, 1, 2, 1, 2, 4, 2, 2, 1, 1, 3, 1, 2, 1]
References
......@@ -503,7 +503,7 @@ def motif_significance(g, k, n_shuffles=100, p=1.0, motif_list=None,
>>> print(len(motifs))
12
>>> print(zscores)
[-0.26668839861225141, -0.37627454937420612, 0.63246648717833609, 1.9856284046854835, -0.60389512777130483, -0.35502673716019983, -1.2236332765203428, 0.87, -0.11, -0.47, -0.2, -0.01]
[1.1686248415493101, 1.1692144855989797, 0.28214101842848821, -0.67039795877350128, -0.8532661303912763, -0.85594303488376966, 1.9809930371921538, -0.09, -0.07, -0.2, -0.33, -0.01]
"""
......
......@@ -702,7 +702,7 @@ def min_dist(state, n=0):
>>> for i in range(1000):
... ds, nmoves = gt.mcmc_sweep(state)
>>> gt.min_dist(state)
(795.7694502418635, 2, 3)
(795.7694502418633, 2, 3)
"""
min_d, r, s = libcommunity.min_dist(state.bg._Graph__graph, int(n),
......
......@@ -115,7 +115,7 @@ def assortativity(g, deg):
... lambda i,k: 1.0 / (1 + abs(i - k)), directed=False,
... mix_time=100)
>>> gt.assortativity(g, "out")
(0.14282704866231305, 0.005109451062660124)
(0.13903518011375607, 0.005051876804786422)
References
----------
......@@ -190,13 +190,13 @@ def scalar_assortativity(g, deg):
>>> g = gt.random_graph(1000, lambda: sample_k(40), lambda i,k: abs(i-k),
... directed=False, mix_time=100)
>>> gt.scalar_assortativity(g, "out")
(-0.43719843848745943, 0.010593923895499584)
(-0.4334085753985522, 0.010571027872280038)
>>> g = gt.random_graph(1000, lambda: sample_k(40),
... lambda i, k: 1.0 / (1 + abs(i - k)),
... directed=False, mix_time=100)
>>> gt.scalar_assortativity(g, "out")
(0.6018887530895891, 0.011474042583027698)
(0.5994169713159511, 0.011668093738666827)
References
----------
......
......@@ -204,7 +204,7 @@ def random_graph(N, deg_sampler, deg_corr=None, cache_probs=True, directed=True,
... lambda i, k: 1.0 / (1 + abs(i - k)), directed=False,
... mix_time=100)
>>> gt.scalar_assortativity(g, "out")
(0.606974415793802, 0.010937932958096811)
(0.6285094791115295, 0.010745128857935755)
The following samples an in,out-degree pair from the joint distribution:
......
......@@ -90,13 +90,13 @@ def adjacency(g, sparse=True, weight=None):
>>> g = gt.random_graph(100, lambda: (10, 10))
>>> m = gt.adjacency(g)
>>> print(m.todense())
[[ 0. 0. 0. ..., 0. 0. 0.]
[[ 0. 0. 0. ..., 0. 1. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 1. 0. 1.]
[ 0. 0. 0. ..., 0. 0. 1.]
...,
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 1. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 1. 0. 0.]]
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 1. ..., 0. 0. 0.]]
References
----------
......@@ -165,31 +165,34 @@ def laplacian(g, deg="total", normalized=True, sparse=True, weight=None):
Notes
-----
The Laplacian matrix is defined as
The weighted Laplacian matrix is defined as
.. math::
\ell_{i,j} =
\ell_{ij} =
\begin{cases}
\Gamma(v_i) & \text{if } i = j \\
-1 & \text{if } i \neq j \text{ and } v_i \text{ is adjacent to } v_j \\
-w_{ij} & \text{if } i \neq j \text{ and } v_i \text{ is adjacent to } v_j \\
0 & \text{otherwise}.
\end{cases}
Where :math:`\Gamma(v_i)` is the degree of vertex :math:`v_i`. The
normalized version is
Where :math:`\Gamma(v_i)=\sum_j A_{ij}w_{ij}` is sum of the weights of
vertex :math:`v_i`. The normalized version is
.. math::
\ell_{i,j} =
\ell_{ij} =
\begin{cases}
1 & \text{ if } i = j \text{ and } \Gamma(v_i) \neq 0 \\
-\frac{1}{\sqrt{\Gamma(v_i)\Gamma(v_j)}} & \text{ if } i \neq j \text{ and } v_i \text{ is adjacent to } v_j \\
-\frac{w_{ij}}{\sqrt{\Gamma(v_i)\Gamma(v_j)}} & \text{ if } i \neq j \text{ and } v_i \text{ is adjacent to } v_j \\
0 & \text{otherwise}.
\end{cases}
In the case of weighted edges, the value 1 is replaced the weight of the
respective edge.
In the case of unweighted edges, it is assumed :math:`w_{ij} = 1`.
For directed graphs, it is assumed :math:`\Gamma(v_i)=\sum_j A_{ij}w_{ij} +
\sum_j A_{ji}w_{ji}` if ``deg=="total"``, :math:`\Gamma(v_i)=\sum_j A_{ij}w_{ij}`
if ``deg=="out"`` or :math:`\Gamma(v_i)=\sum_j A_{ji}w_{ji}` ``deg=="in"``.
Examples
--------
......@@ -200,13 +203,13 @@ def laplacian(g, deg="total", normalized=True, sparse=True, weight=None):
>>> g = gt.random_graph(100, lambda: (10,10))
>>> m = gt.laplacian(g)
>>> print(m.todense())
[[ 1. 0. 0. ..., 0. 0. 0. ]
[ 0. 1. 0. ..., 0. 0. 0. ]
[ 0. 0. 1. ..., 0. 0. 0.05]
[[ 1. -0.05 0. ..., 0. 0. 0. ]
[ 0. 1. 0. ..., 0. 0. -0.05]
[ 0. 0. 1. ..., 0. -0.05 0. ]
...,
[ 0. 0. 0.05 ..., 1. 0. 0.05]
[ 0.05 0. 0. ..., 0. 1. 0. ]
[ 0. 0.05 0. ..., 0. 0. 1. ]]
[ 0. 0. 0. ..., 1. 0. 0. ]
[-0.05 0. 0. ..., 0. 1. 0. ]
[ 0. 0. 0. ..., -0.05 0. 1. ]]
References
----------
......@@ -298,13 +301,13 @@ def incidence(g, sparse=True):
>>> g = gt.random_graph(100, lambda: (2,2))
>>> m = gt.incidence(g)
>>> print(m.todense())
[[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
[[-1. -1. 0. ..., 0. 0. 0.]
[ 0. 0. -1. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
...,
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]]
[ 0. 0. 0. ..., -1. 0. 0.]
[ 0. 0. 0. ..., 0. -1. -1.]]
References
----------
......
......@@ -408,10 +408,10 @@ def distance_histogram(g, weight=None, bins=[0, 1], samples=None,
>>> g = gt.random_graph(100, lambda: (3, 3))
>>> hist = gt.distance_histogram(g)
>>> print(hist)
[array([ 0., 300., 862., 2153., 3813., 2547., 225.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint64)]
[array([ 0., 300., 856., 2185., 3840., 2516., 203.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint64)]
>>> hist = gt.distance_histogram(g, samples=10)
>>> print(hist)
[array([ 0., 30., 88., 216., 384., 252., 20.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint64)]
[array([ 0., 30., 87., 227., 390., 242., 14.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint64)]
"""
if samples != None:
......
......@@ -127,7 +127,7 @@ def similarity(g1, g2, label1=None, label2=None, norm=True):
1.0
>>> gt.random_rewire(u);
>>> gt.similarity(u, g)
0.043333333333333335
0.05
"""
if label1 is None:
......@@ -232,7 +232,7 @@ def subgraph_isomorphism(sub, g, max_n=0, random=False):
>>> sub = gt.random_graph(10, lambda: (poisson(1.9), poisson(1.9)))
>>> vm, em = gt.subgraph_isomorphism(sub, g)
>>> print(len(vm))
2156
5632
>>> for i in range(len(vm)):
... g.set_vertex_filter(None)
... g.set_edge_filter(None)
......@@ -537,10 +537,10 @@ def dominator_tree(g, root, dom_map=None):
>>> root = [v for v in g.vertices() if v.in_degree() == 0]
>>> dom = gt.dominator_tree(g, root[0])
>>> print(dom.a)
[ 0 0 72 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 78 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 0 0 0 0 0]
0 0 0 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
References
----------
......@@ -587,8 +587,8 @@ def topological_sort(g):
>>> g.set_edge_filter(tree)
>>> sort = gt.topological_sort(g)
>>> print(sort)
[ 0 10 1 18 2 3 16 27 24 20 14 4 15 23 9 21 13 22 12 5 6 7 29 28 8
19 25 26 11 17]
[17 1 20 5 6 8 28 0 3 9 11 24 29 2 22 4 7 14 19 26 23 10 12 13 15
16 18 21 25 27]
References
----------
......@@ -688,11 +688,11 @@ def label_components(g, vprop=None, directed=None):
>>> g = gt.random_graph(100, lambda: (1, 1))
>>> comp, hist = gt.label_components(g)
>>> print(comp.a)
[0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 3 1 1 1 1 1 1 1 2 1 0
0 2 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 3 2 1
1 1 1 1 1 2 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
[0 1 1 1 2 1 3 1 4 0 0 4 2 0 0 2 1 1 2 1 0 4 1 5 2 4 0 1 1 1 1 0 4 5 1 1 4
0 4 1 4 4 2 1 4 4 1 2 3 0 0 4 2 4 2 4 4 4 4 1 4 2 0 1 1 2 4 2 2 4 5 4 0 2
1 1 4 1 0 1 2 1 0 0 4 0 1 4 2 4 0 4 4 1 1 1 0 2 1 1]
>>> print(hist)
[ 4 87 6 3]
[19 32 17 2 27 3]
"""
if vprop is None:
......@@ -745,12 +745,12 @@ def label_largest_component(g, directed=None):
>>> g = gt.random_graph(100, lambda: poisson(1), directed=False)
>>> l = gt.label_largest_component(g)
>>> print(l.a)
[1 1 0 0 1 1 0 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 1 0 0 0 0 0 1 0
0 0 1 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0
0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 1 1 0 1 0 0 1 0 0 0 0]
[0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0]
>>> u = gt.GraphView(g, vfilt=l) # extract the largest component as a graph
>>> print(u.num_vertices())
26
10
"""
label = g.new_vertex_property("bool")
......@@ -796,9 +796,9 @@ def label_out_component(g, root):
>>> g = gt.random_graph(100, lambda: poisson(2.2), directed=False)
>>> l = gt.label_out_component(g, g.vertex(2))
>>> print(l.a)
[1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 0 1 1 1 1 1 0 1 1 0 1 0 1 1 1 0 0 1 1 1 0
1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 0 0 0 1 1 1 1 1 1
1 1 0 1 1 1 1 0 1 1 1 1 1 1 0 1 1 0 1 1 1 0 1 1 1 0]
[1 1 1 1 0 1 0 1 1 1 1 0 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 0 0 1 1 0 0
1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 0 0 1 0 1 1 1 1 1
1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 1 1 0]
The in-component can be obtained by reversing the graph.
......@@ -806,7 +806,7 @@ def label_out_component(g, root):
... g.vertex(1))
>>> print(l.a)
[0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
"""
......@@ -879,15 +879,15 @@ def label_biconnected_components(g, eprop=None, vprop=None):
>>> g = gt.random_graph(100, lambda: 2, directed=False)
>>> comp, art, hist = gt.label_biconnected_components(g)
>>> print(comp.a)
[2 3 0 0 2 0 0 0 1 0 0 1 0 0 1 3 0 2 0 0 0 0 0 1 0 0 2 0 0 0 2 3 0 0 2 0 3
0 0 3 0 0 0 0 0 0 2 1 2 0 0 0 0 0 0 0 0 1 3 0 2 1 1 0 0 0 0 0 0 1 0 0 1 2
0 0 2 0 2 0 0 0 2 0 0 0 0 3 1 0 0 1 0 0 0 0 2 0 0 3]
[1 1 0 1 0 1 1 2 1 1 3 3 0 2 2 1 1 3 2 1 0 1 1 1 1 3 1 2 1 3 4 3 1 1 4 0 0
0 1 1 1 1 2 1 1 2 2 2 2 0 1 0 1 1 1 1 2 2 1 1 1 1 1 0 1 1 0 0 1 0 1 4 1 2
1 1 1 1 0 1 2 1 1 1 1 1 1 1 1 1 4 1 1 1 1 3 1 3 1 3]
>>> print(art.a)
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
>>> print(hist)
[66 12 14 8]
[14 59 14 9 4]
"""
if vprop is None:
......@@ -973,43 +973,43 @@ def shortest_distance(g, source=None, weights=None, max_dist=None,
>>> g = gt.random_graph(100, lambda: (poisson(3), poisson(3)))
>>> dist = gt.shortest_distance(g, source=g.vertex(0))
>>> print(dist.a)
[ 0 5 9 6 2147483647 2147483647
3 5 7 4 5 7
5 3 5 6 4 6
5 3 7 4 5 1
8 7 6 2 8 6
7 6 3 6 3 3
4 6 4 3 2147483647 4
5 4 6 5 9 6
8 7 6 4 4 7
2 7 7 6 4 4
6 9 4 4 2 3
7 5 6 5 2147483647 2147483647
6 5 4 5 6 6
6 5 7 5 5 7
5 6 4 3 6 4
6 5 5 5 4 7
5 5 4 3]
[ 0 4 4 4 2147483647 2147483647
6 7 6 4 5 5
6 4 6 7 4 6
6 1 7 5 6 3
5 7 5 6 7 7
8 6 5 4 5 7
6 7 6 6 2147483647 6
3 7 5 6 7 5
8 5 6 5 4 6
6 4 7 9 6 3
7 6 3 5 7 4
6 8 7 6 2147483647 2147483647
2 5 6 5 7 6
6 5 7 5 5 4
7 6 6 5 3 6
6 8 5 4 5 6
5 6 7 4]
>>> dist = gt.shortest_distance(g)
>>> print(dist[g.vertex(0)].a)
[ 0 5 9 6 2147483647 2147483647
3 5 7 4 5 7
5 3 5 6 4 6
5 3 7 4 5 1
8 7 6 2 8 6
7 6 3 6 3 3
4 6 4 3 2147483647 4
5 4 6 5 9 6
8 7 6 4 4 7
2 7 7 6 4 4
6 9 4 4 2 3
7 5 6 5 2147483647 2147483647
6 5 4 5 6 6
6 5 7 5 5 7
5 6 4 3 6 4
6 5 5 5 4 7
5 5 4 3]
[ 0 4 4 4 2147483647 2147483647
6 7 6 4 5 5
6 4 6 7 4 6
6 1 7 5 6 3
5 7 5 6 7 7
8 6 5 4 5 7
6 7 6 6 2147483647 6
3 7 5 6 7 5
8 5 6 5 4 6
6 4 7 9 6 3
7 6 3 5 7 4
6 8 7 6 2147483647 2147483647
2 5 6 5 7 6
6 5 7 5 5 4
7 6 6 5 3 6
6 8 5 4 5 6
5 6 7 4]
References
----------
......@@ -1118,9 +1118,9 @@ def shortest_path(g, source, target, weights=None, pred_map=None):
>>> g = gt.random_graph(300, lambda: (poisson(4), poisson(4)))
>>> vlist, elist = gt.shortest_path(g, g.vertex(10), g.vertex(11))
>>> print([str(v) for v in vlist])
['10', '149', '58', '227', '267', '11']
['10', '267', '212', '158', '112', '160', '11']
>>> print([str(e) for e in elist])
['(10, 149)', '(149, 58)', '(58, 227)', '(227, 267)', '(267, 11)']
['(10, 267)', '(267, 212)', '(212, 158)', '(158, 112)', '(112, 160)', '(160, 11)']
References
----------
......@@ -1224,7 +1224,7 @@ def pseudo_diameter(g, source=None, weights=None):
>>> print(dist)
10.0
>>> print(int(ends[0]), int(ends[1]))
116 196
0 295
References
----------
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment