Skip to content
GitLab
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
c8c4518d
Commit
c8c4518d
authored
May 02, 2013
by
Tiago Peixoto
Browse files
Docstring tests update
parent
bb2e8bf4
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/graph_tool/community/blockmodel.py
View file @
c8c4518d
...
...
@@ -658,7 +658,7 @@ def get_akc(B, I, N=float("inf"), directed=False):
--------
>>> gt.get_akc(10, log(10) / 100, N=100)
2.4199998
721289937
2.4199998
936261204
References
----------
...
...
src/graph_tool/correlations/__init__.py
View file @
c8c4518d
...
...
@@ -191,13 +191,13 @@ def scalar_assortativity(g, deg):
... vertex_corr=lambda i,k: abs(i-k),
... directed=False, n_iter=100)
>>> gt.scalar_assortativity(g, "out")
(-0.4
334085753985522, 0.010571027872280038
)
(-0.4
4070158356400696, 0.010592022444678632
)
>>> g = gt.random_graph(1000, lambda: sample_k(40), model="probabilistic",
... vertex_corr=lambda i, k: 1.0 / (1 + abs(i - k)),
... directed=False, n_iter=100)
>>> gt.scalar_assortativity(g, "out")
(0.
5994169713159511, 0.011668093738666827
)
(0.
6007430887839058, 0.011569809783643956
)
References
----------
...
...
src/graph_tool/flow/__init__.py
View file @
c8c4518d
...
...
@@ -140,7 +140,7 @@ def edmonds_karp_max_flow(g, source, target, capacity, residual=None):
>>> res.a = cap.a - res.a # the actual flow
>>> max_flow = sum(res[e] for e in tgt.in_edges())
>>> print(max_flow)
44.89059578411614
4
44.89059578411614
>>> pos = g.vertex_properties["pos"]
>>> gt.graph_draw(g, pos=pos, edge_pen_width=gt.prop_to_size(res, mi=0, ma=5, power=1), output="example-edmonds-karp.pdf")
<...>
...
...
@@ -221,7 +221,7 @@ def push_relabel_max_flow(g, source, target, capacity, residual=None):
>>> res.a = cap.a - res.a # the actual flow
>>> max_flow = sum(res[e] for e in tgt.in_edges())
>>> print(max_flow)
44.89059578411614
4
44.89059578411614
>>> pos = g.vertex_properties["pos"]
>>> gt.graph_draw(g, pos=pos, edge_pen_width=gt.prop_to_size(res, mi=0, ma=5, power=1), output="example-push-relabel.pdf")
<...>
...
...
@@ -303,7 +303,7 @@ def boykov_kolmogorov_max_flow(g, source, target, capacity, residual=None):
>>> res.a = cap.a - res.a # the actual flow
>>> max_flow = sum(res[e] for e in tgt.in_edges())
>>> print(max_flow)
44.89059578411614
4
44.89059578411614
>>> pos = g.vertex_properties["pos"]
>>> gt.graph_draw(g, pos=pos, edge_pen_width=gt.prop_to_size(res, mi=0, ma=3, power=1), output="example-kolmogorov.pdf")
<...>
...
...
src/graph_tool/generation/__init__.py
View file @
c8c4518d
...
...
@@ -314,13 +314,13 @@ def random_graph(N, deg_sampler, directed=True,
... model="blockmodel-traditional",
... block_membership=lambda: randint(10),
... vertex_corr=corr)
>>> gt.graph_draw(g, vertex_fill_color=bm, output="blockmodel.pdf")
>>> gt.graph_draw(g, vertex_fill_color=bm,
edge_color="black",
output="blockmodel.pdf")
<...>
.. testcode::
:hide:
gt.graph_draw(g, vertex_fill_color=bm, output="blockmodel.png")
gt.graph_draw(g, vertex_fill_color=bm,
edge_color="black",
output="blockmodel.png")
.. figure:: blockmodel.*
:align: center
...
...
@@ -584,7 +584,7 @@ def random_rewire(g, model="uncorrelated", n_iter=1, edge_sweep=True,
gt.graph_draw(g, pos=pos, output="rewire_orig.png", output_size=(300, 300))
>>> gt.random_rewire(g, "correlated")
<...>
189
>>> pos = gt.arf_layout(g)
>>> gt.graph_draw(g, pos=pos, output="rewire_corr.pdf", output_size=(300, 300))
<...>
...
...
@@ -595,7 +595,7 @@ def random_rewire(g, model="uncorrelated", n_iter=1, edge_sweep=True,
gt.graph_draw(g, pos=pos, output="rewire_corr.png", output_size=(300, 300))
>>> gt.random_rewire(g)
<...>
197
>>> pos = gt.arf_layout(g)
>>> gt.graph_draw(g, pos=pos, output="rewire_uncorr.pdf", output_size=(300, 300))
<...>
...
...
@@ -606,7 +606,7 @@ def random_rewire(g, model="uncorrelated", n_iter=1, edge_sweep=True,
gt.graph_draw(g, pos=pos, output="rewire_uncorr.png", output_size=(300, 300))
>>> gt.random_rewire(g, "erdos")
<...>
26
>>> pos = gt.arf_layout(g)
>>> gt.graph_draw(g, pos=pos, output="rewire_erdos.pdf", output_size=(300, 300))
<...>
...
...
@@ -637,17 +637,17 @@ def random_rewire(g, model="uncorrelated", n_iter=1, edge_sweep=True,
>>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="o-", label="Original")
<...>
>>> gt.random_rewire(g, "correlated")
<...>
206
>>> corr = gt.avg_neighbour_corr(g, "out", "out")
>>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="*", label="Correlated")
<...>
>>> gt.random_rewire(g)
<...>
109
>>> corr = gt.avg_neighbour_corr(g, "out", "out")
>>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="o-", label="Uncorrelated")
<...>
>>> gt.random_rewire(g, "erdos")
<...>
13
>>> corr = gt.avg_neighbour_corr(g, "out", "out")
>>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="o-", label=r"Erd\H{o}s")
<...>
...
...
@@ -693,7 +693,7 @@ def random_rewire(g, model="uncorrelated", n_iter=1, edge_sweep=True,
... label=r"$\left<\text{i}\right>$ vs o")
<...>
>>> gt.random_rewire(g, "correlated")
<...>
4323
>>> corr = gt.avg_neighbour_corr(g, "in", "out")
>>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="o-",
... label=r"$\left<\text{o}\right>$ vs i, corr.")
...
...
@@ -703,7 +703,7 @@ def random_rewire(g, model="uncorrelated", n_iter=1, edge_sweep=True,
... label=r"$\left<\text{i}\right>$ vs o, corr.")
<...>
>>> gt.random_rewire(g, "uncorrelated")
<...>
153
>>> corr = gt.avg_neighbour_corr(g, "in", "out")
>>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="o-",
... label=r"$\left<\text{o}\right>$ vs i, uncorr.")
...
...
src/graph_tool/spectral/__init__.py
View file @
c8c4518d
...
...
@@ -64,7 +64,7 @@ def adjacency(g, weight=None, index=None):
Returns
-------
a : :
mod
:`~scipy.sparse.csr_matrix`
a : :
class
:`~scipy.sparse.csr_matrix`
The (sparse) adjacency matrix.
Notes
...
...
@@ -76,11 +76,12 @@ def adjacency(g, weight=None, index=None):
a_{i,j} =
\begin{cases}
1 & \text{if } v_i \text{ is adjacent to } v_j, \\
2 & \text{if } i = j, \text{ the graph is undirected and there is a self-loop incident in } v_i, \\
0 & \text{otherwise}
\end{cases}
In the case of weighted edges, the value
1 i
s re
placed
the weight
of the
respective edge.
In the case of weighted edges, the
entry
values
a
re
multiplied by
the weight
of the
respective edge.
In the case of networks with parallel edges, the entries in the matrix
become simply the edge multiplicities.
...
...
@@ -89,18 +90,33 @@ def adjacency(g, weight=None, index=None):
--------
.. testsetup::
gt.seed_rng(42)
import scipy.linalg
from pylab import *
>>> g = gt.random_graph(100, lambda: (10, 10))
>>> m = gt.adjacency(g)
>>> print(m.todense())
[[ 0. 0. 0. ..., 0. 1. 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. 1. ..., 0. 0. 0.]]
>>> g = gt.collection.data["polblogs"]
>>> A = gt.adjacency(g)
>>> ew, ev = scipy.linalg.eig(A.todense())
>>> figure(figsize=(8, 2))
<...>
>>> scatter(real(ew), imag(ew), c=abs(ew))
<...>
>>> xlabel(r"$\operatorname{Re}(\lambda)$")
<...>
>>> ylabel(r"$\operatorname{Im}(\lambda)$")
<...>
>>> tight_layout()
>>> savefig("adjacency-spectrum.pdf")
.. testcode::
:hide:
savefig("adjacency-spectrum.png")
.. figure:: adjacency-spectrum.*
:align: center
Adjacency matrix spectrum for the political blog network.
References
----------
...
...
@@ -121,13 +137,14 @@ def adjacency(g, weight=None, index=None):
libgraph_tool_spectral
.
adjacency
(
g
.
_Graph__graph
,
_prop
(
"v"
,
g
,
index
),
_prop
(
"e"
,
g
,
weight
),
data
,
i
,
j
)
m
=
scipy
.
sparse
.
coo_matrix
((
data
,
(
i
,
j
)))
V
=
max
(
g
.
num_vertices
(),
max
(
i
.
max
()
+
1
,
j
.
max
()
+
1
))
m
=
scipy
.
sparse
.
coo_matrix
((
data
,
(
i
,
j
)),
shape
=
(
V
,
V
))
m
=
m
.
tocsr
()
return
m
@
_limit_args
({
"deg"
:
[
"total"
,
"in"
,
"out"
]})
def
laplacian
(
g
,
deg
=
"total"
,
normalized
=
Tru
e
,
weight
=
None
,
index
=
None
):
def
laplacian
(
g
,
deg
=
"total"
,
normalized
=
Fals
e
,
weight
=
None
,
index
=
None
):
r
"""Return the Laplacian matrix of the graph.
Parameters
...
...
@@ -136,7 +153,7 @@ def laplacian(g, deg="total", normalized=True, weight=None, index=None):
Graph to be used.
deg : str (optional, default: "total")
Degree to be used, in case of a directed graph.
normalized : bool (optional, default:
Tru
e)
normalized : bool (optional, default:
Fals
e)
Whether to compute the normalized Laplacian.
weight : :class:`~graph_tool.PropertyMap` (optional, default: True)
Edge property map with the edge weights.
...
...
@@ -146,7 +163,7 @@ def laplacian(g, deg="total", normalized=True, weight=None, index=None):
Returns
-------
l : :
mod
:`~scipy.sparse.csr_matrix`
l : :
class
:`~scipy.sparse.csr_matrix`
The (sparse) Laplacian matrix.
Notes
...
...
@@ -182,20 +199,60 @@ def laplacian(g, deg="total", normalized=True, weight=None, index=None):
Examples
--------
.. testsetup::
gt.seed_rng(42)
import scipy.linalg
from pylab import *
>>> g = gt.random_graph(100, lambda: (10,10))
>>> m = gt.laplacian(g)
>>> print(m.todense())
[[ 1. -0.05 0. ..., 0. 0. 0. ]
[ 0. 1. 0. ..., 0. 0. -0.05]
[ 0. 0. 1. ..., 0. -0.05 0. ]
...,
[ 0. 0. 0. ..., 1. 0. 0. ]
[-0.05 0. 0. ..., 0. 1. 0. ]
[ 0. 0. 0. ..., -0.05 0. 1. ]]
>>> g = gt.collection.data["polblogs"]
>>> L = gt.laplacian(g)
>>> ew, ev = scipy.linalg.eig(L.todense())
>>> figure(figsize=(8, 2))
<...>
>>> scatter(real(ew), imag(ew), c=abs(ew))
<...>
>>> xlabel(r"$\operatorname{Re}(\lambda)$")
<...>
>>> ylabel(r"$\operatorname{Im}(\lambda)$")
<...>
>>> tight_layout()
>>> savefig("laplacian-spectrum.pdf")
.. testcode::
:hide:
savefig("laplacian-spectrum.png")
.. figure:: laplacian-spectrum.*
:align: center
Laplacian matrix spectrum for the political blog network.
>>> L = gt.laplacian(g, normalized=True)
>>> ew, ev = scipy.linalg.eig(L.todense())
>>> figure(figsize=(8, 2))
<...>
>>> scatter(real(ew), imag(ew), c=abs(ew))
<...>
>>> xlabel(r"$\operatorname{Re}(\lambda)$")
<...>
>>> ylabel(r"$\operatorname{Im}(\lambda)$")
<...>
>>> tight_layout()
>>> savefig("norm-laplacian-spectrum.pdf")
.. testcode::
:hide:
savefig("norm-laplacian-spectrum.png")
.. figure:: norm-laplacian-spectrum.*
:align: center
Normalized Laplacian matrix spectrum for the political blog network.
References
----------
...
...
@@ -209,6 +266,7 @@ def laplacian(g, deg="total", normalized=True, weight=None, index=None):
else
:
index
=
g
.
vertex_index
V
=
g
.
num_vertices
()
nself
=
label_self_loops
(
g
,
mark_only
=
True
).
a
.
sum
()
E
=
g
.
num_edges
()
-
nself
if
not
g
.
is_directed
():
...
...
@@ -224,7 +282,8 @@ def laplacian(g, deg="total", normalized=True, weight=None, index=None):
else
:
libgraph_tool_spectral
.
laplacian
(
g
.
_Graph__graph
,
_prop
(
"v"
,
g
,
index
),
_prop
(
"e"
,
g
,
weight
),
deg
,
data
,
i
,
j
)
m
=
scipy
.
sparse
.
coo_matrix
((
data
,
(
i
,
j
)))
V
=
max
(
g
.
num_vertices
(),
max
(
i
.
max
()
+
1
,
j
.
max
()
+
1
))
m
=
scipy
.
sparse
.
coo_matrix
((
data
,
(
i
,
j
)),
shape
=
(
V
,
V
))
m
=
m
.
tocsr
()
return
m
...
...
@@ -245,8 +304,8 @@ def incidence(g, vindex=None, eindex=None):
Returns
-------
a : :
mod
:`~scipy.sparse.csr_matrix`
The (sparse)
adjac
enc
y
matrix.
a : :
class
:`~scipy.sparse.csr_matrix`
The (sparse)
incid
enc
e
matrix.
Notes
-----
...
...
@@ -281,12 +340,12 @@ def incidence(g, vindex=None, eindex=None):
>>> m = gt.incidence(g)
>>> print(m.todense())
[[-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. -1. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., -1. 0. 0.]
[ 0. 0. 0. ..., 0. -1. -1.]]
[ 0. 0. 0. ..., 1. 0. 0.]]
References
----------
...
...
src/graph_tool/stats/__init__.py
View file @
c8c4518d
...
...
@@ -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.98, 0.068
40760191674607
)
(4.98
2
, 0.068
55418295042251
)
"""
ret
=
libgraph_tool_stats
.
\
...
...
@@ -284,7 +284,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.49
79474933948808, 0.004104589512548127
)
(0.49
849732125677476, 0.004086182531863621
)
"""
ret
=
libgraph_tool_stats
.
\
...
...
@@ -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., 8
5
6., 2
185
., 38
40
., 2
51
6.,
203
.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint64)]
[array([ 0., 300., 8
6
6., 2
206
., 38
93
., 2
47
6.,
159
.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint64)]
>>> hist = gt.distance_histogram(g, samples=10)
>>> print(hist)
[array([ 0., 30., 8
7
., 2
2
7., 3
90
., 24
2
.,
14
.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint64)]
[array([ 0., 30., 8
4
., 2
1
7., 3
85
., 24
9
.,
25
.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint64)]
"""
if
samples
!=
None
:
...
...
src/graph_tool/topology/__init__.py
View file @
c8c4518d
...
...
@@ -126,9 +126,10 @@ def similarity(g1, g2, label1=None, label2=None, norm=True):
>>> u = g.copy()
>>> gt.similarity(u, g)
1.0
>>> gt.random_rewire(u);
>>> gt.random_rewire(u)
21
>>> gt.similarity(u, g)
0.0
5
0.0
3
"""
if
label1
is
None
:
...
...
@@ -229,11 +230,11 @@ def subgraph_isomorphism(sub, g, max_n=0, random=False):
gt.seed_rng(44)
>>> from numpy.random import poisson
>>> g = gt.random_graph(30, lambda: (poisson(6.
0
), poisson(6.
0
)))
>>> g = gt.random_graph(30, lambda: (poisson(6.
1
), poisson(6.
1
)))
>>> sub = gt.random_graph(10, lambda: (poisson(1.9), poisson(1.9)))
>>> vm, em = gt.subgraph_isomorphism(sub, g)
>>> print(len(vm))
5
632
3
5
>>> for i in range(len(vm)):
... g.set_vertex_filter(None)
... g.set_edge_filter(None)
...
...
@@ -540,10 +541,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 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 62 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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]
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
References
----------
...
...
@@ -590,8 +591,8 @@ def topological_sort(g):
>>> g.set_edge_filter(tree)
>>> sort = gt.topological_sort(g)
>>> print(sort)
[
17 1
2
0
5 6 8 28
0
3
9 11 24 29
2
22
4 7
1
4
1
9 2
6 23 1
0
1
2
1
3 15
16 18
2
1
2
5
2
7
]
[
1 14
2
7 17 0 3
4
5
6 8
9
22
10 11
1
2
1
3 1
6 23
27
1
5
1
8
1
9 20 21
24 25
2
6
2
8
2
9
]
References
----------
...
...
@@ -699,17 +700,18 @@ 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)
[1
2
1
2
1
2
1
2
1
2 12 12
1
2
1
3
1
2
1
2
1
2 12 12
1
1
1
2 5
14 1
2 12
7
15
1
2
1
2
1
2
1
2
1
2
1
2 12 12
1
2
1
2
1
2 12
1
6
1
2 2
0
1
2
1
7
1
2 12
1 1
2 12 10
1
2
1
8 12
2
1
1
2 1
2
1
2
6
9
1
2
1
2 22
1
2
1
2 12
1
2
3
1
2 8 2
3
2
4 1
2
1
2
1
2 2
5 1
2
1
2
1
2
1
2
1
2 27 28 12 12 26 12 20
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2 29 30 1
9
1
2
4 12
3
1 1
2
1
2
]
[1
4
1
5
1
4
1
4
1
4 5
1
4
1
4
1
8
1
4
1
4 8
1
4
1
4 13
14 1
4 21 14 14
7
23
1
0
1
4
1
4
1
4 24 4
1
4
1
4 0
1
4
1
4
1
4 25
1
4
1
4
1
1
4 26
1
4
1
9 9
1
4
1
4 3
1
4
1
4 27
2
8
2
9
1
4
1
4
6
14
1
4
1
4 30
1
4
1
4 20
1
4
2
1
4 22 3
3
3
4 1
4
1
4
1
4 3
5 1
4
1
4
1
6
1
4
1
1 36 37 14 14 31
1
4
1
4
1
7
1
4
1
4
1
4
1
4
1
4 0 14 38 3
9
3
2
1
4 12 1
4 40
1
4
1
4
]
>>> print(hist)
[ 1 1 1 1 1 1 1 1 1 1 1 1
69 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1]
[
2 1
1 1 1 1 1 1 1 1 1 1 1 1
59
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]
>>> print(is_attractor)
[ True False False True True False True True True False False True
[ True True True False False False True True False False False False
True True False False False False False False False False True False
False False False False False False False False False False False False
False False False False
False False False
False]
False False False False False]
"""
if
vprop
is
None
:
...
...
@@ -770,12 +772,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)
[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
]
[
1
0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0
0
0 0 0 0 0
0
0 0 1 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0
1
0 0 0
1
0
1 1 1
0 0 0 0 0 0 0 0 0
1
0 0 0 0 0
1
0 0 0 0
0
0 0 0 1 1 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1]
>>> u = gt.GraphView(g, vfilt=l) # extract the largest component as a graph
>>> print(u.num_vertices())
1
0
1
6
"""
label
=
g
.
new_vertex_property
(
"bool"
)
...
...
@@ -821,18 +823,18 @@ 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 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]
[1 1 1 1 0 1
1
1 1 1 1 0 1 1
0
1
1
1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 0 1 1
1
0
1 1 0
0
1 1
0
1 1
0 0
1 1 1 1 0 1 0
0
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
0
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 0 0
0 0 0
0
0
0 0 0 0
0
0 0 0
0
0 0
0 0
0 0
0
0
0
0 0 0 0 0 0
0 0
0 0
0
0
0 0 0
0
0
0 0
0 0 0 0
0 0
0 0 0 0
0
0 0 0
0 0
0
0
0 0 0
0
0 0
0 0
0
0
0 0
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 1
1 0 0
1 1
0
1
0 0 0 0
1
0 0 0
1
0 0
1 1
0 0
1
0
1
0 0 0 0 0 0
1 1
0 0
0
1
0 0 0
1
0
1 1
0 0 0 0
1 1
0 0 0 0
1
0 0 0
1 1
0
1
0 0 0
1
0 0
1 1
0
1
1
0 0 0 0
1 1 0 1 1 0 1 1 1 0 0 1
0 0 0 0 0
1
0 0 0]
"""
label
=
g
.
new_vertex_property
(
"bool"
)
...
...
@@ -901,18 +903,21 @@ def label_biconnected_components(g, eprop=None, vprop=None):
numpy.random.seed(42)
gt.seed_rng(42)
>>> g = gt.random_graph(100, lambda:
2
, directed=False)
>>> g = gt.random_graph(100, lambda:
poisson(2)
, directed=False)
>>> comp, art, hist = gt.label_biconnected_components(g)
>>> print(comp.a)
[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]
[51 51 51 51 51 51 11 52 51 51 44 42 41 45 49 23 19 51 51 32 38 51 24 37 51
51 51 10 8 51 20 43 51 51 51 51 51 47 46 51 51 13 14 51 51 51 51 33 30 51
1 21 51 51 51 35 36 6 51 26 27 7 12 4 3 29 28 51 51 51 31 51 51 0 39
51 51 51 34 40 51 51 9 17 51 51 18 15 22 2 16 50 5 48 51 51 53 51 51 25]
>>> 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]
[
1
0
1
0 0
1
0 0
1 1
0 0
1 1
0 0 0 0 0 0
1
0 0 0
1
0
1
0 0 0
1
0 0 0
1 1
0
0
1
0 0
1 1 0 1 1 0 0 0 1 1 0 1 1
0 0 0
1
0 0
1
0
1
0 0
1 1
0 0 0 0 0
1 1
1
0
1 1
0
1
0
1 1
0 0 0 0
1 0 1
0 0 0
1
0 0 0
1
0 0]
>>> print(hist)
[14 59 14 9 4]
[ 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 1 1 1 1 1 1 1 1 1 1 1 1 1
1 47 1 1]
"""
if
vprop
is
None
:
...
...
@@ -1078,43 +1083,43 @@ def shortest_distance(g, source=None, target=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
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
]
[ 0
6
3
6
2147483647 2147483647
6
5
2
4 5
6
6
3
7
5
4
4
3
4
2
4
3
3
4
4
6
6
4
1
5
2
4 5
3 5
6
5
4
5
2147483647
9
4
4
4
6
3
4
6
6
3
2
4
4
5
4
5
8
6
6
5
5
4
5
6
3
4
3
5
5
2147483647 2147483647
5
5
8
3
7
4
5
2
7 5
2
5
5
5
7
7
4
3
6
5
5 4 5
5
4 4
6
5
]
>>> dist = gt.shortest_distance(g)
>>> print(dist[g.vertex(0)].a)
[ 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
]
[ 0
6
3
6
2147483647 2147483647
6
5
2
4 5
6
6
3
7
5
4
4
3
4
2
4
3
3
4
4
6
6
4
1
5
2
4 5
3 5
6
5
4
5
2147483647
9
4
4
4
6
3
4
6
6
3
2
4
4
5
4
5
8
6
6
5
5
4
5
6
3
4
3
5
5
2147483647 2147483647
5
5
8
3
7
4
5
2
7 5
2
5
5
5
7
7
4
3
6
5
5 4 5
5
4 4
6
5
]
References
----------
...
...
@@ -1232,9 +1237,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', '
267', '212
', '1
5
8', '
112
', '
160
', '11']
['10', '
131
', '18
4
', '
265
', '
223
', '11']
>>> print([str(e) for e in elist])
['(10,
267
)', '(
267, 212)', '(212
, 1
5
8)', '(1
58, 112)', '(112, 160
)', '(
160
, 11)']
['(10,
131
)', '(
131
, 18
4
)', '(1
84, 265)', '(265, 223
)', '(
223
, 11)']
References
----------
...
...
@@ -1337,9 +1342,9 @@ def pseudo_diameter(g, source=None, weights=None):
>>> g = gt.random_graph(300, lambda: (poisson(3), poisson(3)))