Commit 3512df30 authored by Tiago Peixoto's avatar Tiago Peixoto

Documentation improvements and fixes

parent 9d71c105
...@@ -184,8 +184,8 @@ intersphinx_mapping = {'python': ('https://docs.python.org/3', None), ...@@ -184,8 +184,8 @@ intersphinx_mapping = {'python': ('https://docs.python.org/3', None),
'ipython': ('https://ipython.org/ipython-doc/stable/', None), 'ipython': ('https://ipython.org/ipython-doc/stable/', None),
'panda': ('https://pandas.pydata.org/pandas-docs/stable/', None)} 'panda': ('https://pandas.pydata.org/pandas-docs/stable/', None)}
extlinks_fancy = {'ticket': (['https://graph-tool.skewed.de/tickets/ticket/{0}'], extlinks_fancy = {'issue': (['https://git.skewed.de/count0/graph-tool/issues/{0}'],
['ticket {0}']), ['issue #{0}']),
'doi': (['https://dx.doi.org/{0}', 'doi': (['https://dx.doi.org/{0}',
'https://sci-hub.tw/{0}', 'https://sci-hub.tw/{0}',
'https://scihub22266oqcxt.onion.link/{0}'], 'https://scihub22266oqcxt.onion.link/{0}'],
......
...@@ -219,8 +219,8 @@ approach for the same network, using the nested model. ...@@ -219,8 +219,8 @@ approach for the same network, using the nested model.
.. testoutput:: model-evidence .. testoutput:: model-evidence
Model evidence for deg_corr = True: -555.768070... (mean field), -731.501041... (Bethe) Model evidence for deg_corr = True: -523.722360... (mean field), -686.592569... (Bethe)
Model evidence for deg_corr = False: -544.346500... (mean field), -630.951518... (Bethe) Model evidence for deg_corr = False: -516.006708... (mean field), -619.110456... (Bethe)
The results are similar: If we consider the most accurate approximation, The results are similar: If we consider the most accurate approximation,
the non-degree-corrected model possesses the largest evidence. Note also the non-degree-corrected model possesses the largest evidence. Note also
......
...@@ -21,7 +21,7 @@ We set up the classification task by dividing the edges/non-edges into ...@@ -21,7 +21,7 @@ We set up the classification task by dividing the edges/non-edges into
two sets :math:`\boldsymbol A` and :math:`\delta \boldsymbol A`, where two sets :math:`\boldsymbol A` and :math:`\delta \boldsymbol A`, where
the former corresponds to the observed network and the latter either to the former corresponds to the observed network and the latter either to
the missing or spurious edges. We may compute the posterior of the missing or spurious edges. We may compute the posterior of
:math:`\delta \boldsymbol A` as [valles-catala-consistency-2017]_ :math:`\delta \boldsymbol A` as [valles-catala-consistencies-2018]_
.. math:: .. math::
:label: posterior-missing :label: posterior-missing
......
...@@ -5,11 +5,12 @@ An important application of generative models is to be able to ...@@ -5,11 +5,12 @@ An important application of generative models is to be able to
generalize from observations and make predictions that go beyond what is generalize from observations and make predictions that go beyond what is
seen in the data. This is particularly useful when the network we seen in the data. This is particularly useful when the network we
observe is incomplete, or contains errors, i.e. some of the edges are observe is incomplete, or contains errors, i.e. some of the edges are
either missing or are outcomes of mistakes in measurement. In this either missing or are outcomes of mistakes in measurement, or is not
situation, we can use statistical inference to reconstruct the original even observed at all. In this situation, we can use statistical
network. Following [peixoto-reconstructing-2018]_, if inference to reconstruct the original network. Following
:math:`\boldsymbol{\mathcal{D}}` is the observed data, the network can [peixoto-reconstructing-2018]_, if :math:`\boldsymbol{\mathcal{D}}` is
be reconstructed according to the posterior distribution, the observed data, the network can be reconstructed according to the
posterior distribution,
.. math:: .. math::
...@@ -55,7 +56,7 @@ information and the uncertainty in the measurement data. Furthermore, ...@@ -55,7 +56,7 @@ information and the uncertainty in the measurement data. Furthermore,
the use of the SBM means that the reconstruction can take advantage of the use of the SBM means that the reconstruction can take advantage of
the *correlations* observed in the data to further inform it, which the *correlations* observed in the data to further inform it, which
generally can lead to substantial improvements generally can lead to substantial improvements
[peixoto-reconstructing-2018]_. [peixoto-reconstructing-2018]_ [peixoto-network-2019]_.
In graph-tool there is support for reconstruction with the above In graph-tool there is support for reconstruction with the above
framework for three measurement processes: 1. Repeated measurements with framework for three measurement processes: 1. Repeated measurements with
...@@ -67,6 +68,9 @@ and 3. Extraneously obtained edge probabilities (via ...@@ -67,6 +68,9 @@ and 3. Extraneously obtained edge probabilities (via
:class:`~graph_tool.inference.uncertain_blockmodel.UncertainBlockState`), :class:`~graph_tool.inference.uncertain_blockmodel.UncertainBlockState`),
which we describe in the following. which we describe in the following.
In addition, it is also possible to reconstruct networks from observed
dynamical, as described in :ref:`reconstruction_dynamics`.
Measured networks Measured networks
+++++++++++++++++ +++++++++++++++++
...@@ -185,9 +189,9 @@ Which yields the following output: ...@@ -185,9 +189,9 @@ Which yields the following output:
.. testoutput:: measured .. testoutput:: measured
Posterior probability of edge (11, 36): 0.841384... Posterior probability of edge (11, 36): 0.890889...
Posterior probability of non-edge (15, 73): 0.100010... Posterior probability of non-edge (15, 73): 0.056005...
Estimated average local clustering: 0.571836 ± 0.005152... Estimated average local clustering: 0.572758 ± 0.003998...
We have a successful reconstruction, where both ambiguous adjacency We have a successful reconstruction, where both ambiguous adjacency
matrix entries are correctly recovered. The value for the average matrix entries are correctly recovered. The value for the average
...@@ -306,9 +310,9 @@ Which yields: ...@@ -306,9 +310,9 @@ Which yields:
.. testoutput:: measured .. testoutput:: measured
Posterior probability of edge (11, 36): 0.593359... Posterior probability of edge (11, 36): 0.515651...
Posterior probability of non-edge (15, 73): 0.050705... Posterior probability of non-edge (15, 73): 0.009000...
Estimated average local clustering: 0.570958 ± 0.006660... Estimated average local clustering: 0.571673 ± 0.003228...
The results are very similar to the ones obtained with the uniform model The results are very similar to the ones obtained with the uniform model
in this case, but can be quite different in situations where a large in this case, but can be quite different in situations where a large
...@@ -434,9 +438,9 @@ The above yields the output: ...@@ -434,9 +438,9 @@ The above yields the output:
.. testoutput:: uncertain .. testoutput:: uncertain
Posterior probability of edge (11, 36): 0.948894... Posterior probability of edge (11, 36): 0.951195...
Posterior probability of non-edge (15, 73): 0.049004... Posterior probability of non-edge (15, 73): 0.020702...
Estimated average local clustering: 0.552446 ± 0.019751... Estimated average local clustering: 0.538731 ± 0.017645...
The reconstruction is accurate, despite the two ambiguous entries having The reconstruction is accurate, despite the two ambiguous entries having
the same measurement probability. The reconstructed network is visualized below. the same measurement probability. The reconstructed network is visualized below.
...@@ -480,3 +484,5 @@ the same measurement probability. The reconstructed network is visualized below. ...@@ -480,3 +484,5 @@ the same measurement probability. The reconstructed network is visualized below.
ambiguity, both errors are successfully corrected by the ambiguity, both errors are successfully corrected by the
reconstruction. The pie fractions on the nodes correspond to the reconstruction. The pie fractions on the nodes correspond to the
probability of being in group associated with the respective color. probability of being in group associated with the respective color.
.. include:: _reconstruction_dynamics.rst
.. _reconstruction_dynamics:
Reconstruction from dynamics
++++++++++++++++++++++++++++
.. testsetup:: dynamics
import os
try:
os.chdir("demos/inference")
except FileNotFoundError:
pass
np.random.seed(42)
gt.seed_rng(44)
.. testcode:: dynamics
g = gt.collection.data["dolphins"]
ss = []
for i in range(1000):
si_state = gt.SIState(g, beta=1)
s = []
for j in range(10):
si_state.iterate_sync()
s.append(si_state.get_state().copy())
s = gt.group_vector_property(s)
ss.append(s)
u = g.copy()
u.clear_edges()
ss = [u.own_property(s) for s in ss]
rstate = gt.EpidemicsBlockState(u, s=ss, beta=None, r=1e-6, global_beta=.99,
state_args=dict(B=1), nested=False)
# Now we collect the marginals for exactly 100,000 sweeps, at
# intervals of 10 sweeps:
gm = None
bm = None
def collect_marginals(s):
global gm, bm
gm = s.collect_marginal(gm)
b = gt.perfect_prop_hash([s.bstate.b])[0]
bm = s.bstate.collect_vertex_marginals(bm, b=b)
gt.mcmc_equilibrate(rstate, force_niter=10000, mcmc_args=dict(niter=10, xstep=0, p=0, h=0),
callback=collect_marginals)
b = bm.new_vp("int", vals=[bm[v].a.argmax() for v in bm.vertices()])
graph_draw(gm, gm.own_property(g.vp.pos), vertex_shape="square", vertex_color="black",
vertex_fill_color=b, vertex_pen_width=1,
edge_pen_width=prop_to_size(gm.ep.eprob, 0, 5), eorder=gm.ep.eprob, output="dolphins")
eprob = u.ep.eprob
print("Posterior probability of edge (11, 36):", eprob[u.edge(11, 36)])
print("Posterior probability of non-edge (15, 73):", eprob[u.edge(15, 73)])
print("Estimated average local clustering: %g ± %g" % (np.mean(cs), np.std(cs)))
...@@ -275,8 +275,8 @@ network as above. ...@@ -275,8 +275,8 @@ network as above.
.. testoutput:: nested-model-averaging .. testoutput:: nested-model-averaging
Change in description length: 20.223115... Change in description length: 15.483135...
Number of accepted vertex moves: 58320 Number of accepted vertex moves: 57684
Similarly to the the non-nested case, we can use Similarly to the the non-nested case, we can use
:func:`~graph_tool.inference.mcmc.mcmc_equilibrate` to do most of the boring :func:`~graph_tool.inference.mcmc.mcmc_equilibrate` to do most of the boring
......
...@@ -73,7 +73,11 @@ References ...@@ -73,7 +73,11 @@ References
:arxiv:`1310.4378` :arxiv:`1310.4378`
.. [peixoto-reconstructing-2018] Tiago P. Peixoto, "Reconstructing .. [peixoto-reconstructing-2018] Tiago P. Peixoto, "Reconstructing
networks with unknown and heterogeneous errors", :arxiv:`1806.07956` networks with unknown and heterogeneous errors", Phys. Rev. X 8
041011 (2018). :doi:`10.1103/PhysRevX.8.041011`, :arxiv:`1806.07956`
.. [peixoto-network-2019] Tiago P. Peixoto, "Network reconstruction and
community detection from dynamics", :arxiv:`1903.10833`
.. [martin-structural-2015] Travis Martin, Brian Ball, M. E. J. Newman, .. [martin-structural-2015] Travis Martin, Brian Ball, M. E. J. Newman,
"Structural inference for uncertain networks", Phys. Rev. E 93, "Structural inference for uncertain networks", Phys. Rev. E 93,
...@@ -88,13 +92,15 @@ References ...@@ -88,13 +92,15 @@ References
spurious interactions and the reconstruction of complex networks", PNAS spurious interactions and the reconstruction of complex networks", PNAS
vol. 106 no. 52 (2009). :doi:`10.1073/pnas.0908366106` vol. 106 no. 52 (2009). :doi:`10.1073/pnas.0908366106`
.. [valles-catala-consistency-2017] Toni Vallès-Català, .. [valles-catala-consistencies-2018] Toni Vallès-Català,
Tiago P. Peixoto, Roger Guimerà, Marta Sales-Pardo, "On the consistency Tiago P. Peixoto, Roger Guimerà, Marta Sales-Pardo, "Consistencies
between model selection and link prediction in networks". :arxiv:`1705.07967` and inconsistencies between model selection and link prediction in
networks", Phys. Rev. E 97 062316 (2018),
:doi:`10.1103/PhysRevE.97.062316`, :arxiv:`1705.07967`
.. [mezard-information-2009] Marc Mézard, Andrea Montanari, "Information, .. [mezard-information-2009] Marc Mézard, Andrea Montanari, "Information,
Physics, and Computation", Oxford Univ Press (2009). Physics, and Computation", Oxford Univ Press (2009).
:DOI:`10.1093/acprof:oso/9780198570837.001.0001` :doi:`10.1093/acprof:oso/9780198570837.001.0001`
.. [guimera-modularity-2004] Roger Guimerà, Marta Sales-Pardo, and .. [guimera-modularity-2004] Roger Guimerà, Marta Sales-Pardo, and
Luís A. Nunes Amaral, "Modularity from fluctuations in random graphs Luís A. Nunes Amaral, "Modularity from fluctuations in random graphs
......
.. automodule:: graph_tool.draw .. automodule:: graph_tool.draw
:no-members: :members:
:undoc-members:
.. container:: sec_title :show-inheritance:
Layout algorithms
.. autofunction:: sfdp_layout
.. autofunction:: fruchterman_reingold_layout
.. autofunction:: arf_layout
.. autofunction:: radial_tree_layout
.. autofunction:: planar_layout
.. autofunction:: random_layout
.. container:: sec_title
Graph drawing
.. autofunction:: graph_draw
.. autofunction:: draw_hierarchy
.. autofunction:: graphviz_draw
.. autofunction:: prop_to_size
.. autofunction:: get_hierarchy_control_points
.. container:: sec_title
Low-level graph drawing
.. autofunction:: cairo_draw
.. autofunction:: interactive_window
.. autoclass:: GraphWidget
:show-inheritance:
:members:
:undoc-members:
.. autoclass:: GraphWindow
:show-inheritance:
:members:
:undoc-members:
...@@ -392,13 +392,13 @@ ol.arabic li dl dt { ...@@ -392,13 +392,13 @@ ol.arabic li dl dt {
background-color: inherit; background-color: inherit;
} }
.brackets:before { /* .brackets:before { */
content: "["; /* content: "["; */
} /* } */
.brackets:after { /* .brackets:after { */
content: "]"; /* content: "]"; */
} /* } */
.fn-backref { .fn-backref {
margin-right: 10px; margin-right: 10px;
......
...@@ -47,6 +47,7 @@ import numpy as np ...@@ -47,6 +47,7 @@ import numpy as np
from pylab import * from pylab import *
from numpy import * from numpy import *
import graph_tool.all as gt import graph_tool.all as gt
import graph_tool.draw
import random as prandom import random as prandom
figure() figure()
......
...@@ -289,6 +289,24 @@ methods should be used: ...@@ -289,6 +289,24 @@ methods should be used:
for e in g.edges(): for e in g.edges():
print(e) print(e)
.. testoutput::
:hide:
0
1
2
3
4
5
6
7
8
9
10
11
(0, 1)
(2, 3)
The code above will print the vertices and edges of the graph in the order they The code above will print the vertices and edges of the graph in the order they
are found. are found.
...@@ -302,7 +320,6 @@ and :meth:`~graph_tool.Vertex.in_neighbors` methods, respectively. ...@@ -302,7 +320,6 @@ and :meth:`~graph_tool.Vertex.in_neighbors` methods, respectively.
.. testcode:: .. testcode::
from itertools import izip
for v in g.vertices(): for v in g.vertices():
for e in v.out_edges(): for e in v.out_edges():
print(e) print(e)
...@@ -310,9 +327,17 @@ and :meth:`~graph_tool.Vertex.in_neighbors` methods, respectively. ...@@ -310,9 +327,17 @@ and :meth:`~graph_tool.Vertex.in_neighbors` methods, respectively.
print(w) print(w)
# the edge and neighbors order always match # the edge and neighbors order always match
for e, w in izip(v.out_edges(), v.out_neighbors()): for e, w in zip(v.out_edges(), v.out_neighbors()):
assert e.target() == w assert e.target() == w
.. testoutput::
:hide:
(0, 1)
1
(2, 3)
3
The code above will print the out-edges and out-neighbors of all The code above will print the out-edges and out-neighbors of all
vertices in the graph. vertices in the graph.
...@@ -352,7 +377,7 @@ For example, using this interface we can get the out-degree of each node via: ...@@ -352,7 +377,7 @@ For example, using this interface we can get the out-degree of each node via:
.. testoutput:: .. testoutput::
[1 0 1 0 0 0 0 0 0 0 0 0] [0 1 0 1 0 0 0 0 0 0 0 0]
or the sum of the product of the in and out-degrees of the endpoints of or the sum of the product of the in and out-degrees of the endpoints of
each edge with: each edge with:
...@@ -415,14 +440,13 @@ such: ...@@ -415,14 +440,13 @@ such:
.. testcode:: .. testcode::
from itertools import izip
from numpy.random import randint from numpy.random import randint
g = Graph() g = Graph()
g.add_vertex(100) g.add_vertex(100)
# insert some random links # insert some random links
for s,t in izip(randint(0, 100, 100), randint(0, 100, 100)): for s,t in zip(randint(0, 100, 100), randint(0, 100, 100)):
g.add_edge(g.vertex(s), g.vertex(t)) g.add_edge(g.vertex(s), g.vertex(t))
vprop_double = g.new_vertex_property("double") # Double-precision floating point vprop_double = g.new_vertex_property("double") # Double-precision floating point
......
...@@ -1193,7 +1193,7 @@ def infect_vertex_property(g, prop, vals=None): ...@@ -1193,7 +1193,7 @@ def infect_vertex_property(g, prop, vals=None):
Parameters Parameters
---------- ----------
prop : :class:`~graph_tool.PropertyMap` prop : :class:`~graph_tool.VertexPropertyMap`
Property map to be modified. Property map to be modified.
vals : list (optional, default: `None`) vals : list (optional, default: `None`)
List of values to be propagated. If not provided, all values List of values to be propagated. If not provided, all values
...@@ -1225,17 +1225,17 @@ def edge_endpoint_property(g, prop, endpoint, eprop=None): ...@@ -1225,17 +1225,17 @@ def edge_endpoint_property(g, prop, endpoint, eprop=None):
Parameters Parameters
---------- ----------
prop : :class:`~graph_tool.PropertyMap` prop : :class:`~graph_tool.VertexPropertyMap`
Vertex property map to be used to propagated to the edge. Vertex property map to be used to propagated to the edge.
endpoint : `"source"` or `"target"` endpoint : `"source"` or `"target"`
Edge endpoint considered. If the graph is undirected, the source is Edge endpoint considered. If the graph is undirected, the source is
always the vertex with the lowest index. always the vertex with the lowest index.
eprop : :class:`~graph_tool.PropertyMap` (optional, default: `None`) eprop : :class:`~graph_tool.EdgePropertyMap` (optional, default: `None`)
If provided, the resulting edge properties will be stored here. If provided, the resulting edge properties will be stored here.
Returns Returns
------- -------
eprop : :class:`~graph_tool.PropertyMap` eprop : :class:`~graph_tool.EdgePropertyMap`
Propagated edge property. Propagated edge property.
Examples Examples
...@@ -1283,14 +1283,14 @@ def incident_edges_op(g, direction, op, eprop, vprop=None): ...@@ -1283,14 +1283,14 @@ def incident_edges_op(g, direction, op, eprop, vprop=None):
Direction of the incident edges. Direction of the incident edges.
op : `"sum"`, `"prod"`, `"min"` or `"max"` op : `"sum"`, `"prod"`, `"min"` or `"max"`
Operation performed on incident edges. Operation performed on incident edges.
eprop : :class:`~graph_tool.PropertyMap` eprop : :class:`~graph_tool.EdgePropertyMap`
Edge property map to be summed. Edge property map to be summed.
vprop : :class:`~graph_tool.PropertyMap` (optional, default: `None`) vprop : :class:`~graph_tool.VertexPropertyMap` (optional, default: `None`)
If provided, the resulting vertex properties will be stored here. If provided, the resulting vertex properties will be stored here.
Returns Returns
------- -------
vprop : :class:`~graph_tool.PropertyMap` vprop : :class:`~graph_tool.VertexPropertyMap`
Resulting vertex property. Resulting vertex property.
Examples Examples
...@@ -1581,7 +1581,7 @@ class Graph(object): ...@@ -1581,7 +1581,7 @@ class Graph(object):
filters, respectively. filters, respectively.
If ``vorder`` is specified, it should correspond to a vertex If ``vorder`` is specified, it should correspond to a vertex
:class:`~graph_tool.PropertyMap` specifying the ordering of the vertices in :class:`~graph_tool.VertexPropertyMap` specifying the ordering of the vertices in
the copied graph. the copied graph.
The graph is implemented as an `adjacency list`_, where both vertex and edge The graph is implemented as an `adjacency list`_, where both vertex and edge
...@@ -1842,7 +1842,7 @@ class Graph(object): ...@@ -1842,7 +1842,7 @@ class Graph(object):
>>> g.add_vertex(5) >>> g.add_vertex(5)
<...> <...>
>>> g.get_vertices() >>> g.get_vertices()
array([0, 1, 2, 3, 4], dtype=uint64) array([0, 1, 2, 3, 4])
""" """
vertices = libcore.get_vertex_list(self.__graph, 0, vertices = libcore.get_vertex_list(self.__graph, 0,
...@@ -1949,9 +1949,9 @@ class Graph(object): ...@@ -1949,9 +1949,9 @@ class Graph(object):
-------- --------
>>> g = gt.random_graph(6, lambda: 1, directed=False) >>> g = gt.random_graph(6, lambda: 1, directed=False)
>>> g.get_edges([g.edge_index]) >>> g.get_edges([g.edge_index])
array([[2, 1, 2], array([[0, 3, 2],
[3, 4, 0], [1, 4, 1],
[5, 0, 1]]) [2, 5, 0]])
""" """
edges = libcore.get_edge_list(self.__graph, 0, edges = libcore.get_edge_list(self.__graph, 0,
[ep._get_any() for ep in eprops]) [ep._get_any() for ep in eprops])
...@@ -2038,8 +2038,7 @@ class Graph(object): ...@@ -2038,8 +2038,7 @@ class Graph(object):
>>> g.get_in_edges(66, [g.edge_index]) >>> g.get_in_edges(66, [g.edge_index])
array([[ 8687, 66, 179681], array([[ 8687, 66, 179681],
[ 20369, 66, 255033], [ 20369, 66, 255033],
[ 38674, 66, 300230]], dtype=uint64) [ 38674, 66, 300230]])
""" """
edges = libcore.get_in_edge_list(self.__graph, int(v), edges = libcore.get_in_edge_list(self.__graph, int(v),
[ep._get_any() for ep in eprops]) [ep._get_any() for ep in eprops])
...@@ -2082,7 +2081,7 @@ class Graph(object): ...@@ -2082,7 +2081,7 @@ class Graph(object):
>>> g.get_all_edges(66, [g.edge_index]) >>> g.get_all_edges(66, [g.edge_index])
array([[ 8687, 66, 179681], array([[ 8687, 66, 179681],
[ 20369, 66, 255033], [ 20369, 66, 255033],
[ 38674, 66, 300230]], dtype=uint64) [ 38674, 66, 300230]])
""" """
edges = libcore.get_all_edge_list(self.__graph, int(v), edges = libcore.get_all_edge_list(self.__graph, int(v),
...@@ -2126,7 +2125,7 @@ class Graph(object): ...@@ -2126,7 +2125,7 @@ class Graph(object):
-------- --------
>>> g = gt.collection.data["pgp-strong-2009"] >>> g = gt.collection.data["pgp-strong-2009"]
>>> g.get_out_neighbors(66) >>> g.get_out_neighbors(66)
array([ 63, 20369, 13980, 8687, 38674], dtype=uint64) array([ 63, 20369, 13980, 8687, 38674])
""" """
vertices = libcore.get_out_neighbors_list(self.__graph, int(v), vertices = libcore.get_out_neighbors_list(self.__graph, int(v),
...@@ -2175,7 +2174,7 @@ class Graph(object): ...@@ -2175,7 +2174,7 @@ class Graph(object):
-------- --------
>>> g = gt.collection.data["pgp-strong-2009"] >>> g = gt.collection.data["pgp-strong-2009"]
>>> g.get_in_neighbors(66) >>> g.get_in_neighbors(66)
array([ 8687, 20369, 38674], dtype=uint64) array([ 8687, 20369, 38674])
""" """
vertices = libcore.get_in_neighbors_list(self.__graph, int(v), vertices = libcore.get_in_neighbors_list(self.__graph, int(v),
...@@ -2224,7 +2223,7 @@ class Graph(object): ...@@ -2224,7 +2223,7 @@ class Graph(object):
-------- --------
>>> g = gt.collection.data["pgp-strong-2009"] >>> g = gt.collection.data["pgp-strong-2009"]
>>> g.get_all_neighbors(66) >>> g.get_all_neighbors(66)
array([ 8687, 20369, 38674], dtype=uint64) array([ 8687, 20369, 38674])
""" """
vertices = libcore.get_all_neighbors_list(self.__graph, int(v), vertices = libcore.get_all_neighbors_list(self.__graph, int(v),
...@@ -2240,13 +2239,13 @@ class Graph(object): ...@@ -2240,13 +2239,13 @@ class Graph(object):
def get_out_degrees(self, vs, eweight=None): def get_out_degrees(self, vs, eweight=None):
"""Return a :class:`numpy.ndarray` containing the out-degrees of vertex list """Return a :class:`numpy.ndarray` containing the out-degrees of vertex list
``vs``. If supplied, the degrees will be weighted according to the edge ``vs``. If supplied, the degrees will be weighted according to the edge
:class:`~graph_tool.PropertyMap` ``eweight``. :class:`~graph_tool.EdgePropertyMap` ``eweight``.
Examples Examples
-------- --------
>>> g = gt.collection.data["pgp-strong-2009"] >>> g = gt.collection.data["pgp-strong-2009"]
>>> g.get_out_degrees([42, 666]) >>> g.get_out_degrees([42, 666])
array([20, 38], dtype=uint64) array([20, 38])
""" """
return libcore.get_degree_list(self.__graph, return libcore.get_degree_list(self.__graph,
...@@ -2256,13 +2255,13 @@ class Graph(object): ...@@ -2256,13 +2255,13 @@ class Graph(object):
def get_in_degrees(self, vs, eweight=None): def get_in_degrees(self, vs, eweight=None):
"""Return a :class:`numpy.ndarray` containing the in-degrees of vertex list """Return a :class:`numpy.ndarray` containing the in-degrees of vertex list
``vs``. If supplied, the degrees will be weighted according to the edge ``vs``. If supplied, the degrees will be weighted according to the edge
:class:`~graph_tool.PropertyMap` ``eweight``. :class:`~graph_tool.EdgePropertyMap` ``eweight``.
Examples Examples
-------- --------
>>> g = gt.collection.data["pgp-strong-2009"] >>> g = gt.collection.data["pgp-strong-2009"]
>>> g.get_in_degrees([42, 666]) >>> g.get_in_degrees([42, 666])
array([20, 39], dtype=uint64) array([20, 39])
""" """
return libcore.get_degree_list(self.__graph, return libcore.get_degree_list(self.__graph,
...@@ -2571,7 +2570,7 @@ class Graph(object): ...@@ -2571,7 +2570,7 @@ class Graph(object):
.. note:: .. note::
Like :attr:`~graph_tool.Graph.edge_index`, this Like :attr:`~graph_tool.Graph.edge_index`, this
is a special instance of a :class:`~graph_tool.PropertyMap` is a special instance of a :class:`~graph_tool.VertexPropertyMap`
class, which is **immutable**, and cannot be class, which is **immutable**, and cannot be
accessed as an array.""") accessed as an array.""")
...@@ -2585,7 +2584,7 @@ class Graph(object): ...@@ -2585,7 +2584,7 @@ class Graph(object):
.. note:: .. note::
Like :attr:`~graph_tool.Graph.vertex_index`, this Like :attr:`~graph_tool.Graph.vertex_index`, this
is a special instance of a :class:`~graph_tool.PropertyMap` is a special instance of a :class:`~graph_tool.EdgePropertyMap`
class, which is **immutable**, and cannot be class, which is **immutable**, and cannot be
accessed as an array. accessed as an array.
...@@ -2770,7 +2769,7 @@ class Graph(object): ...@@ -2770,7 +2769,7 @@ class Graph(object):
def degree_property_map(self, deg, weight=None): def degree_property_map(self, deg, weight=None):
"""Create and return a vertex property map containing the degree type """Create and return a vertex property map containing the degree type
given by ``deg``, which can be any of ``"in"``, ``"out"``, or ``"total"``. given by ``deg``, which can be any of ``"in"``, ``"out"``, or ``"total"``.
If provided, ``weight`` should be an edge :class:`~graph_tool.PropertyMap` If provided, ``weight`` should be an edge :class:`~graph_tool.EdgePropertyMap`
containing the edge weights which should be summed.""" containing the edge weights which should be summed."""
pmap = self.__graph.degree_map(_to_str(deg), _prop("e", self, weight)) pmap = self.__graph.degree_map(_to_str(deg), _prop("e", self, weight))
return VertexPropertyMap(pmap, self) return VertexPropertyMap(pmap, self)
...@@ -3556,7 +3555,7 @@ def _all_neighbors(self): ...@@ -3556,7 +3555,7 @@ def _all_neighbors(self):
def _in_degree(self, weight=None): def _in_degree(self, weight=None):
"""Return the in-degree of the vertex. If provided, ``weight`` should be a """Return the in-degree of the vertex. If provided, ``weight`` should be a
scalar edge :class:`~graph_tool.PropertyMap`, and the in-degree will scalar edge :class:`~graph_tool.EdgePropertyMap`, and the in-degree will
correspond to the sum of the weights of the in-edges. correspond to the sum of the weights of the in-edges.
""" """
...@@ -3567,7 +3566,7 @@ def _in_degree(self, weight=None): ...@@ -3567,7 +3566,7 @@ def _in_degree(self, weight=None):
def _out_degree(self, weight=None): def _out_degree(self, weight=None):
"""Return the out-degree of the vertex. If provided, ``weight`` should be a """Return the out-degree of the vertex. If provided, ``weight`` should be a
scalar edge :class:`~graph_tool.PropertyMap`, and the out-degree will scalar edge :class:`~graph_tool.EdgePropertyMap`, and the out-degree will
correspond to the sum of the weights of the out-edges. correspond to the sum of the weights of the out-edges.