Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tiago Peixoto
graph-tool
Commits
b93fa303
Commit
b93fa303
authored
Sep 30, 2017
by
Tiago Peixoto
Browse files
Update doctests
parent
581ba9fe
Pipeline
#371
passed with stage
in 171 minutes and 44 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/graph_tool/__init__.py
View file @
b93fa303
...
...
@@ -1828,9 +1828,9 @@ class Graph(object):
--------
>>> g = gt.random_graph(6, lambda: 1, directed=False)
>>> g.get_edges()
array([[
0
,
4
,
0
],
[
2
,
1
,
2
],
[5,
3
, 1]], dtype=uint64)
array([[
2
,
1
,
2
],
[
3
,
4
,
0
],
[5,
0
, 1]], dtype=uint64)
"""
edges
=
libcore
.
get_edge_list
(
self
.
__graph
)
E
=
edges
.
shape
[
0
]
//
3
...
...
src/graph_tool/clustering/__init__.py
View file @
b93fa303
...
...
@@ -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.00
6
17777777777777
8
, 0.000
36966184079941211
)
(0.00
8
17777777777777
9
, 0.000
42080229075093...
)
References
----------
...
...
@@ -182,7 +182,7 @@ def global_clustering(g):
>>> g = gt.random_graph(1000, lambda: (5,5))
>>> print(gt.global_clustering(g))
(0.00
6
17777777777777
8
, 0.000
3700318726720
...)
(0.00
8
17777777777777
9
, 0.000
4212235142651
...)
References
----------
...
...
@@ -263,11 +263,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.00
421, 0.00041685103920811
...)
(0.02
7226666666666666, 0.00100735228307788
...)
(0.11
549166666666667, 0.00208139908541773
...)
(0.4
128066666666666, 0.00294792212319872
...)
(0.4
205716666666667, 0.00315646574114149
...)
(0.00
50483333333333335, 0.0004393940240073
...)
(0.02
4593787878787878, 0.0009963004021144
...)
(0.11
238924242424242, 0.001909615401971
...)
(0.4
0252272727272725, 0.003113987400030
...)
(0.4
3629378787878786, 0.003144159256565
...)
References
----------
...
...
@@ -349,10 +349,9 @@ def motifs(g, k, p=1.0, motif_list=None, return_maps=False):
>>> g = gt.random_graph(1000, lambda: (5,5))
>>> motifs, counts = gt.motifs(gt.GraphView(g, directed=False), 4)
>>> print(len(motifs))
1
3
1
8
>>> print(counts)
[115408, 388542, 1031, 1182, 2662, 2138, 833, 28, 16, 5, 5, 3, 4]
[115557, 390005, 627, 700, 1681, 2815, 820, 12, 27, 44, 15, 7, 12, 4, 6, 1, 2, 1]
References
----------
...
...
@@ -523,7 +522,7 @@ def motif_significance(g, k, n_shuffles=100, p=1.0, motif_list=None,
>>> print(len(motifs))
11
>>> print(zscores)
[0.
04162670293683441, 0.0467697812236798
97, 0.
55888261369689918, 0.82906624302416043, -0.41384527710386287, -0.42070845824900477, -1.3262411347517733, 1.82
, -0.
13
, -0.3
7
, -0.2
2
]
[0.
22728646681107012, 0.21409572051644
97
3
, 0.
0070220407889021114, 0.58721419671233477, -0.37770179603294357, -0.34847335047837341, 0.88618118013255021, -0.08
, -0.
2
, -0.3
8
, -0.2]
"""
s_ms
,
counts
=
motifs
(
g
,
k
,
p
,
motif_list
)
...
...
src/graph_tool/stats/__init__.py
View file @
b93fa303
...
...
@@ -231,7 +231,7 @@ def vertex_average(g, deg):
>>> from numpy.random import poisson
>>> g = gt.random_graph(1000, lambda: (poisson(5), poisson(5)))
>>> print(gt.vertex_average(g, "in"))
(4.9
75
, 0.06
8675869124460318
)
(4.9
6
, 0.06
7988234276233406
)
"""
if
isinstance
(
deg
,
PropertyMap
)
and
"string"
in
deg
.
value_type
():
...
...
@@ -293,7 +293,7 @@ def edge_average(g, eprop):
>>> eprop = g.new_edge_property("double")
>>> eprop.get_array()[:] = random(g.num_edges())
>>> print(gt.edge_average(g, eprop))
(0.498
97413697
204
12
, 0.004
1010659277832
54)
(0.498
8815658419
204
5
, 0.004
0967399234187
54
1
)
"""
if
"string"
in
eprop
.
value_type
():
...
...
@@ -426,10 +426,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., 8
65
., 22
14
., 3
857
., 2
480
., 1
84
.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint
...
)]
[array([ 0., 300., 8
80
., 22
69
., 3
974
., 2
358
., 1
19
.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint
64
)]
>>> hist = gt.distance_histogram(g, samples=10)
>>> print(hist)
[array([ 0., 30., 8
8
., 22
6
., 39
1
., 2
40
., 1
5
.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint
...
)]
[array([ 0., 30., 8
7
., 22
3
., 39
4
., 2
39
., 1
7
.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint
64
)]
"""
if
samples
is
not
None
:
...
...
src/graph_tool/topology/__init__.py
View file @
b93fa303
...
...
@@ -169,7 +169,7 @@ def similarity(g1, g2, eweight1=None, eweight2=None, label1=None, label2=None,
>>> gt.similarity(u, g)
1.0
>>> gt.random_rewire(u)
2
4
2
2
>>> gt.similarity(u, g)
0.04666666666666667
...
...
@@ -860,9 +860,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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 74 0 0 0 97 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 97 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 64 67 0 0 67 0 0 74 0 0 0 0 23 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 0 0]
References
----------
...
...
@@ -909,8 +910,8 @@ def topological_sort(g):
>>> g.set_edge_filter(tree)
>>> sort = gt.topological_sort(g)
>>> print(sort)
[2
9 28 27
26 2
3
2
4
2
2
2
1 20
18 17 16 15 1
4
11 10
9 6 5 4 19 12 13 3 2
25
1 0
7 8
]
[2
8
26 2
9
2
7
2
3
2
2
18 17 16
20 21
15 1
2
11 10
25 14 9 8 7 5 3 2 24 4
6
1 0
19 13
]
References
----------
...
...
@@ -1018,18 +1019,17 @@ def label_components(g, vprop=None, directed=None, attractors=False):
>>> g = gt.random_graph(100, lambda: (poisson(2), poisson(2)))
>>> comp, hist, is_attractor = gt.label_components(g, attractors=True)
>>> print(comp.a)
[
13 13 13 13 14 12 13 15 16 13 17 19 13 13 13 20 13 13 13 10 13 13 22 13 13
4 13 13 2 23 13 13 24 13
1
3
2
6 27 13 13 13
1
3
0 13 13 3 13 13 13
2
8
1
6 13 13 13 13 5 13 13 13 13 13 13 13 9 13 11 13 29 13 13 13 13 18 13 30
31 13 13 32 13 33 34 35 13 13 21 13 25 8 36 13 13 13 13 13 37 13 13
7
13
]
[
9 9 9 9 10 1 9 11 12 9 9 9 9 9 9 13 9 9 9 0 9 9 16 9 9
3 9 9 4 17 9 9 18 9 9
1
9
2
0 9 9 9
1
4
5 9 9 6 9 9 9
2
1
9
9 9 9 9 9 9 9 9 9 9 9 9 9 2 9 8 9 22 15 9 9 9 9 9 23
25 9 9 26 27 28 29 30 9 9 9 9 9 9 31 9 9 9 9 9 32 9 9
7
24
]
>>> print(hist)
[ 1 1 1 1 1 1 1 1 1 1 1 1 1
63
1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1
1]
[ 1 1 1 1 1 1 1 1 1
68
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1]
>>> print(is_attractor)
[ True False True True True False False True False True True True
True False True False False False False False False False False False
False False False False False False False False False True False True
False False]
[ True True True True True True True True True False True False
False False False False False False False False False False False False
False False False False True False True False False]
"""
if
vprop
is
None
:
...
...
@@ -1090,9 +1090,9 @@ 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)
[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
1 0 0 0 1 0 0 0 0 0 0 0
1
0 0 0 1 0 0 0 1 0 0 0 1 0 0
0
0 0 0
0
0 1 0 0 0 0 1 0 0 0 0 0 0
1
0 0 0
0 0
1 0 0
0 0 0 0 0 0 1 0 0 0 1
1
0 0 0 0 1 0
0 1
0]
[0 0 0 0 1 0 0 0 0
1
0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0
1
0 1 0 0 0 0 0 0 0
0
0 0 0 1 0 0 0 1 0 0 0 1 0 0
1
0 0 0
1
0 1 0 0 0 0 1 0 0 0 0 0 0
0
0 0 0
0 0 0 0 0 0 0 0 1 0 0
1
0 1
0 0 0 0 0
0 0 0 0 1 0 0]
>>> u = gt.GraphView(g, vfilt=l) # extract the largest component as a graph
>>> print(u.num_vertices())
18
...
...
@@ -1141,18 +1141,18 @@ def label_out_component(g, root, label=None):
>>> g = gt.random_graph(100, lambda: poisson(2.2), directed=False)
>>> l = gt.label_out_component(g, g.vertex(2))
>>> print(l.a)
[1 1 1 1 1 1
1
0 1 1 1 0 1 1
0
1 1 1 0 1 1
0 1
1 1 1 1 1 1 1 0 0 0 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 1 1
1
1 1 1 1 0 0 1
1
1 1 1 0
0
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]
[1 1 1 1 1 1 0 1 1 1 0
0
1 1
1
1 1 1 0 1 1
1 0
1 1 1 1 1 1 1 0 0 0 1 1 1 1
1 1 0
0
1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1
0
1 1 1 1 0 0 1
0
1 1 1 0
1
1 1 0
0
1 1 1 1 1 1 1 1 1
0
1 1 1 0 1 1 1 0 1 1 1 0]
The in-component can be obtained by reversing the graph.
>>> l = gt.label_out_component(gt.GraphView(g, reversed=True, directed=True),
... g.vertex(1))
>>> print(l.a)
[0 1
1 1 1 0 1
0 0 0 0 0 0 0 0 0
1 1
0 0
1
0 0
1 1
0 0 0
1 1
0 0 0 0
1 0 1
1
0 0 0 0 0 0 0
1
0 0 0 1
0
1
0 1 0 1
1 1 1
0 0
0 1 1 0 0 0 0
0
0 0 1 0 0
1
0 0 0 0
1 1 1
0 0
1 1
0 0 0
1 1 0 1 1
0 0
1
0
1
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 0 0 0 0
0 0
0
0
0
0]
"""
if
label
is
None
:
...
...
@@ -1228,18 +1228,18 @@ def label_biconnected_components(g, eprop=None, vprop=None):
>>> g = gt.random_graph(100, lambda: poisson(2), directed=False)
>>> comp, art, hist = gt.label_biconnected_components(g)
>>> print(comp.a)
[2
0 38 37 37 37 11 44 37 37 6 37 18 37 37 34 37 3 37 37 37 37 37 37 27 37
32 37 21 14 23 37 37 37 29 37 37 37 37 2 1 37 37 37 37 41 40 37 37 10 37
37 37 42 37 37 37 37 37 37 37 37 31 35 37 7 37 37 37 37 19 28 37 37 36 39
5 37 37 8 22 43 37 37 37 37 30 37 15
2
5
17
9 12 0 33 45 26 4 16 13 24
3
7
]
[2
6 26 26 26 26 26 26 26 19 25 26 26 23 26 26 26 26 6 26 24 18 26 26 13 26
26 26 26 26 26 26 26 26 26 26 16 29 26 26 26 26 26 26 15 26 26 26 26 26 0
26 26 12 2 26 26 26 26 26 26 26 26 9 3 26 28 26 26 8 26 4 26 26 26 14
26 26 26 26 30 11 26 26 26 20 26 26 27 26 33 26
2
2
17
7 5 32 21 26 1 10
3
1
]
>>> print(art.a)
[1 0 1 1 0
1
0 0 0
1
0 0 1 0 0 1
0
1 0 0 0
1
0 0 0 0 0 0 0 1 0 0 0 1 1 0
0
1 1 0 0 1 0 0 0
1 1
0 0 0
1
0
1
0 1
0
0 1 0 0 0 0 1
1
0 1 0 0 0 0 0 0
1 1
1 0 0
0
0 0 0 1 1 0 0
0
1 0 1 1 0 0 0 1 0 0
0 1
0 0]
[1 0 1 1 0
0
0 0 0
0
0 0 1 0 0 1 1 0 0 0
0
0 0 0 0 0 0 0 1
1 0
0 0 0 1 1 0
1 1 0 0 1 0 0 0
0 0
0 0 0
0
0
0
0 1
1
0 1 0 0 0 0 1
0
0 1 0 0 0 0 0 0
0 0
1 0 0
1
0 0 0 1 1 0 0 1 0
0
1 1 0 0 0 1 0 0
1 0
0 0]
>>> print(hist)
[ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1
1 1 1 1 1 1 1 1 1 1 1 56 1
1 1 1 1 1 1 1]
1
68
1 1 1 1 1 1 1]
"""
...
...
@@ -1613,49 +1613,49 @@ def shortest_distance(g, source=None, target=None, weights=None,
>>> g = gt.random_graph(100, lambda: (poisson(3), poisson(3)))
>>> dist = gt.shortest_distance(g, source=g.vertex(0))
>>> print(dist.a)
[ 0
1
5
4
2147483647
4
9
5 8
5
7
6
3
5
6
8
3
3
5
6
2147483647
1
4
5
5
2
5
7
4
5
5
5
4 4
5 2
5 2147483647 5
2
2147483647
6
5
6
6
2
5
4
3
6 5
4
4
5
3
3 5
5
1 5
4
6
3 4
3 3
7
5
5
4
2147483647 2147483647
2 5
3 5 5 6
3
5 6
6
5
4
5
3
6
3
4
2147483647
4
6
4
4
4
4
6
5
4
4
]
[ 0
4
5
6
2147483647
5
4
3 2147483647
4
4
6
6
5
5
4
4
2
5
1
2147483647
6
5
5
5
7
5
4
6
5
5
4 1
4 4
3
5 2147483647 5
1
2147483647
2
2
7
4
5
5
5
6 5
5 3
2
7
5 4
3 5
4
6
3 5
5
3 4
4
6
4
4
5
2147483647 2147483647
2 5
7 3 2147483647 2147483647
5 6
4 7
4
4
3
4
6
4
3
2147483647
5
6
3
4
6
5
5
3
4
5
]
>>>
>>> dist = gt.shortest_distance(g)
>>> print(dist[g.vertex(0)].a)
[ 0
1
5
4
2147483647
4
9
5 8
5
7
6
3
5
6
8
3
3
5
6
2147483647
1
4
5
5
2
5
7
4
5
5
5
4 4
5 2
5 2147483647 5
2
2147483647
6
5
6
6
2
5
4
3
6 5
4
4
5
3
3 5
5
1 5
4
6
3 4
3 3
7
5
5
4
2147483647 2147483647
2 5
3 5 5 6
3
5 6
6
5
4
5
3
6
3
4
2147483647
4
6
4
4
4
4
6
5
4
4
]
[ 0
4
5
6
2147483647
5
4
3 2147483647
4
4
6
6
5
5
4
4
2
5
1
2147483647
6
5
5
5
7
5
4
6
5
5
4 1
4 4
3
5 2147483647 5
1
2147483647
2
2
7
4
5
5
5
6 5
5 3
2
7
5 4
3 5
4
6
3 5
5
3 4
4
6
4
4
5
2147483647 2147483647
2 5
7 3 2147483647 2147483647
5 6
4 7
4
4
3
4
6
4
3
2147483647
5
6
3
4
6
5
5
3
4
5
]
>>> dist = gt.shortest_distance(g, source=g.vertex(0), target=g.vertex(2))
>>> print(dist)
5
>>> dist = gt.shortest_distance(g, source=g.vertex(0), target=[g.vertex(2), g.vertex(6)])
>>> print(dist)
[5
9
]
[5
4
]
References
----------
...
...
@@ -1802,9 +1802,9 @@ def shortest_path(g, source, target, weights=None, negative_weights=False,
>>> 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', '11']
['10',
'131', '118', '207', '195',
'11']
>>> print([str(e) for e in elist])
['(10, 11)']
['(10,
131)', '(131, 118)', '(118, 207)', '(207, 195)', '(195,
11)']
References
----------
...
...
@@ -2060,8 +2060,8 @@ def all_circuits(g, unique=False):
>>> g = gt.random_graph(10, lambda: (1, 1))
>>> for c in gt.all_circuits(g):
... print(c)
[0
8 4 5 3
]
[
1 6 7 9 2
]
[0
4 7 1 8 2
]
[
3 9 6 5
]
References
----------
...
...
@@ -2134,7 +2134,7 @@ def pseudo_diameter(g, source=None, weights=None):
>>> print(dist)
10.0
>>> print(int(ends[0]), int(ends[1]))
0 1
65
0 1
1
References
----------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment