Commit 8180fd35 authored by Tiago Peixoto's avatar Tiago Peixoto

Documentation tweaks

parent b42ee3f3
......@@ -103,4 +103,4 @@ xlabel("$k_{in}$")
ylabel("$NP(k_{in})$")
tight_layout()
savefig("price-deg-dist.pdf")
savefig("price-deg-dist.png")
savefig("price-deg-dist.svg")
......@@ -177,7 +177,7 @@ Edges and vertices can also be removed at any time with the
the rest of the list. Thus, fast :math:`O(1)` removals are only
possible either if one can guarantee that only vertices in the end of
the list are removed (the ones last added to the graph), or if the
relative vertex ordering is invalidated. This last behavior can be
relative vertex ordering is invalidated. The latter behavior can be
achieved by passing the option ``fast == True``, to
:meth:`~graph_tool.Graph.remove_vertex`, which causes the vertex
being deleted to be 'swapped' with the last vertex (i.e. with the
......@@ -206,7 +206,8 @@ Edges and vertices can also be removed at any time with the
performed internally (in C++).
Note that property map values (see :ref:`sec_property_maps`) are
unaffected by the index changes due to vertex removal.
unaffected by the index changes due to vertex removal, as they are
modified accordingly by the library.
.. note::
......@@ -217,11 +218,12 @@ Edges and vertices can also be removed at any time with the
`True`, in which case it becomes :math:`O(1)`, at the expense of
additional data of size :math:`O(E)`.
No edge descriptors are ever invalidated after edge removal.
No edge descriptors are ever invalidated after edge removal, with the
exception of the edge being removed.
Since vertices are uniquely identifiable by their indexes, there is no
need to keep the vertex descriptor lying around to access them at a
later point. If we know its index, one can obtain the descriptor of a
later point. If we know its index, we can obtain the descriptor of a
vertex with a given index using the :meth:`~graph_tool.Graph.vertex`
method,
......@@ -231,7 +233,7 @@ method,
which takes an index, and returns a vertex descriptor. Edges cannot be
directly obtained by its index, but if the source and target vertices of
a given edge is known, it can be obtained with the
a given edge are known, it can be retrieved with the
:meth:`~graph_tool.Graph.edge` method
.. doctest::
......@@ -259,8 +261,8 @@ any specific range. If no edges are ever removed, the indexes will be in
the range :math:`[0, E-1]`, where :math:`E` is the number of edges, and
edges added earlier have lower indexes. However if an edge is removed,
its index will be "vacant", and the remaining indexes will be left
unmodified, and thus will not lie in the range :math:`[0, E-1]`. If a
new edge is added, it will reuse old indexes, in an increasing order.
unmodified, and thus will not all lie in the range :math:`[0, E-1]`. If
a new edge is added, it will reuse old indexes, in an increasing order.
.. _sec_iteration:
......@@ -505,10 +507,10 @@ and a custom binary format ``gt`` (see :ref:`sec_gt_format`).
.. warning::
The binary format ``gt`` and ``graphml`` are the preferred formats,
since they are by far the most complete. Both these formats are
equally complete, but the ``gt`` format is faster and requires less
storage.
The binary format ``gt`` and the text-based ``graphml`` are the
preferred formats, since they are by far the most complete. Both
these formats are equally complete, but the ``gt`` format is faster
and requires less storage.
The ``dot`` and ``gml`` formats are fully supported, but since they
contain no precise type information, all properties are read as
......@@ -579,9 +581,9 @@ The following is what should happen when the program is run.
vertex: 0 in-degree: 210 out-degree: 0 age: 0
Nowhere else to go... We found the main hub!
Below is the degree distribution, with 100000 nodes. If you want to see
a broader power law, try to increase the number of vertices to something
like :math:`10^6` or :math:`10^7`.
Below is the degree distribution, with :math:`10^5` nodes (in order to
the asymptotic behavior to be even clearer, the number of vertices needs
to be increased to something like :math:`10^6` or :math:`10^7`).
.. figure:: price-deg-dist.*
:align: center
......@@ -645,13 +647,13 @@ edge filtering.
g, pos = triangulation(random((500, 2)) * 4, type="delaunay")
tree = min_spanning_tree(g)
graph_draw(g, pos=pos, edge_color=tree, output="min_tree.pdf")
graph_draw(g, pos=pos, edge_color=tree, output="min_tree.svg")
.. testcode::
:hide:
graph_draw(g, pos=pos, edge_color=tree, output_size=(400, 400),
output="min_tree.png")
output="min_tree.pdf")
The ``tree`` property map has a bool type, with value "1" if the edge belongs to
......@@ -660,23 +662,25 @@ marked edges.
.. figure:: min_tree.*
:align: center
:figwidth: 400
We can now filter out the edges which don't belong to the minimum spanning tree.
.. testcode::
g.set_edge_filter(tree)
graph_draw(g, pos=pos, output="min_tree_filtered.pdf")
graph_draw(g, pos=pos, output="min_tree_filtered.svg")
.. testcode::
:hide:
graph_draw(g, pos=pos, output_size=(400, 400), output="min_tree_filtered.png")
graph_draw(g, pos=pos, output_size=(400, 400), output="min_tree_filtered.pdf")
This is how the graph looks when filtered:
.. figure:: min_tree_filtered.*
:align: center
:figwidth: 400
Everything should work transparently on the filtered graph, simply as if the
masked edges were removed. For instance, the following code will calculate the
......@@ -688,16 +692,17 @@ and draws them as colors and line thickness in the graph.
bv, be = betweenness(g)
be.a /= be.a.max() / 5
graph_draw(g, pos=pos, vertex_fill_color=bv, edge_pen_width=be,
output="filtered-bt.pdf")
output="filtered-bt.svg")
.. testcode::
:hide:
graph_draw(g, pos=pos, vertex_fill_color=bv, edge_pen_width=be,
output_size=(400, 400), output="filtered-bt.png")
output_size=(400, 400), output="filtered-bt.pdf")
.. figure:: filtered-bt.*
:align: center
:figwidth: 400
The original graph can be recovered by setting the edge filter to ``None``.
......@@ -708,16 +713,17 @@ The original graph can be recovered by setting the edge filter to ``None``.
bv, be = betweenness(g)
be.a /= be.a.max() / 5
graph_draw(g, pos=pos, vertex_fill_color=bv, edge_pen_width=be,
output="nonfiltered-bt.pdf")
output="nonfiltered-bt.svg")
.. testcode::
:hide:
graph_draw(g, pos=pos, vertex_fill_color=bv, edge_pen_width=be,
output_size=(400, 400), output="nonfiltered-bt.png")
output_size=(400, 400), output="nonfiltered-bt.pdf")
.. figure:: nonfiltered-bt.*
:align: center
:figwidth: 400
Everything works in analogous fashion with vertex filtering.
......@@ -770,7 +776,7 @@ Like above, the result should be the isolated minimum spanning tree:
>>> bv, be = betweenness(tv)
>>> be.a /= be.a.max() / 5
>>> graph_draw(tv, pos=pos, vertex_fill_color=bv,
... edge_pen_width=be, output="mst-view.pdf")
... edge_pen_width=be, output="mst-view.svg")
<...>
.. testcode::
......@@ -778,10 +784,11 @@ Like above, the result should be the isolated minimum spanning tree:
graph_draw(tv, pos=pos, vertex_fill_color=bv,
edge_pen_width=be, output_size=(400, 400),
output="mst-view.png")
output="mst-view.pdf")
.. figure:: mst-view.*
:align: center
:figwidth: 400
A view of the Delaunay graph, isolating only the minimum spanning tree.
......@@ -821,18 +828,19 @@ The graph view constructed above can be visualized as
.. doctest::
>>> be.a /= be.a.max() / 5
>>> graph_draw(u, pos=pos, vertex_fill_color=bv, output="central-edges-view.pdf")
>>> graph_draw(u, pos=pos, vertex_fill_color=bv, output="central-edges-view.svg")
<...>
.. testcode::
:hide:
graph_draw(u, pos=pos, vertex_fill_color=bv, output_size=(400, 400),
output="central-edges-view.png")
output="central-edges-view.pdf")
.. figure:: central-edges-view.*
:align: center
:figwidth: 400
A view of the Delaunay graph, isolating only the edges with
normalized betweenness centrality larger than 0.01.
......@@ -855,16 +863,17 @@ The resulting graph view can be visualized as
.. doctest::
>>> graph_draw(u, pos=pos, output="composed-filter.pdf")
>>> graph_draw(u, pos=pos, output="composed-filter.svg")
<...>
.. testcode::
:hide:
graph_draw(u, pos=pos, output_size=(400, 400), output="composed-filter.png")
graph_draw(u, pos=pos, output_size=(400, 400), output="composed-filter.pdf")
.. figure:: composed-filter.*
:align: center
:figwidth: 400
A composed view, obtained as the minimum spanning tree of all vertices
in the graph which have a degree larger than four.
\ No newline at end of file
......@@ -266,12 +266,12 @@ def corr_hist(g, deg_source, deg_target, bins=[[0, 1], [0, 1]], weight=None,
<...>
>>> colorbar()
<...>
>>> savefig("corr.pdf")
>>> savefig("corr.svg")
.. testcode:: corr_hist
:hide:
savefig("corr.png")
savefig("corr.pdf")
.. figure:: corr.*
:align: center
......@@ -363,12 +363,12 @@ def combined_corr_hist(g, deg1, deg2, bins=[[0, 1], [0, 1]], float_count=True):
<...>
>>> colorbar()
<...>
>>> savefig("combined_corr.pdf")
>>> savefig("combined_corr.svg")
.. testcode:: combined_corr_hist
:hide:
savefig("combined_corr.png")
savefig("combined_corr.pdf")
.. figure:: combined_corr.*
:align: center
......@@ -466,12 +466,12 @@ def avg_neighbour_corr(g, deg_source, deg_target, bins=[0, 1], weight=None):
<...>
>>> errorbar(h[2][:-1], h[0], yerr=h[1], fmt="o")
<...>
>>> savefig("avg_corr.pdf")
>>> savefig("avg_corr.svg")
.. testcode:: avg_neighbour_corr
:hide:
savefig("avg_corr.png")
savefig("avg_corr.pdf")
.. figure:: avg_corr.*
:align: center
......@@ -555,12 +555,12 @@ def avg_combined_corr(g, deg1, deg2, bins=[0, 1]):
<...>
>>> errorbar(h[2][:-1], h[0], yerr=h[1], fmt="o")
<...>
>>> savefig("combined_avg_corr.pdf")
>>> savefig("combined_avg_corr.svg")
.. testcode:: avg_combined_corr
:hide:
savefig("combined_avg_corr.png")
savefig("combined_avg_corr.pdf")
.. figure:: combined_avg_corr.*
:align: center
......
......@@ -235,12 +235,12 @@ def random_graph(N, deg_sampler, directed=True,
>>> ylabel("out-degree")
<...>
>>> tight_layout()
>>> savefig("combined-deg-hist.pdf")
>>> savefig("combined-deg-hist.svg")
.. testcode::
:hide:
savefig("combined-deg-hist.png")
savefig("combined-deg-hist.pdf")
.. figure:: combined-deg-hist.*
:align: center
......@@ -268,7 +268,7 @@ def random_graph(N, deg_sampler, directed=True,
Lets plot the average degree correlations to check.
>>> figure()
>>> figure(figsize=(6,3))
<...>
>>> corr = gt.avg_neighbour_corr(g, "in", "in")
>>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="o-",
......@@ -286,19 +286,21 @@ def random_graph(N, deg_sampler, directed=True,
>>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="o-",
... label=r"$\left<\text{out}\right>$ vs out")
<...>
>>> legend(loc="lower right", borderaxespad=0., framealpha=0.8)
>>> legend(loc='center left', bbox_to_anchor=(1, 0.5))
<...>
>>> xlabel("Source degree")
<...>
>>> ylabel("Average target degree")
<...>
>>> tight_layout()
>>> savefig("deg-corr-dir.pdf")
>>> box = gca().get_position()
>>> gca().set_position([box.x0, box.y0, box.width * 0.7, box.height])
>>> savefig("deg-corr-dir.svg")
.. testcode::
:hide:
savefig("deg-corr-dir.png")
savefig("deg-corr-dir.pdf")
.. figure:: deg-corr-dir.*
:align: center
......@@ -675,7 +677,7 @@ def random_rewire(g, model="configuration", n_iter=1, edge_sweep=True,
We can try with larger graphs to get better statistics, as follows.
>>> figure()
>>> figure(figsize=(6,3))
<...>
>>> g = gt.random_graph(30000, lambda: sample_k(20), model="probabilistic-configuration",
... edge_probs=lambda i, j: exp(abs(i-j)), directed=False,
......@@ -699,15 +701,17 @@ def random_rewire(g, model="configuration", n_iter=1, edge_sweep=True,
<...>
>>> ylabel(r"$\left<k_{nn}\right>$")
<...>
>>> legend(loc="best")
>>> legend(loc='center left', bbox_to_anchor=(1, 0.5))
<...>
>>> box = gca().get_position()
>>> gca().set_position([box.x0, box.y0, box.width * 0.7, box.height])
>>> tight_layout()
>>> savefig("shuffled-stats.pdf")
>>> savefig("shuffled-stats.svg")
.. testcode::
:hide:
savefig("shuffled-stats.png")
savefig("shuffled-stats.pdf")
.. figure:: shuffled-stats.*
......@@ -725,7 +729,7 @@ def random_rewire(g, model="configuration", n_iter=1, edge_sweep=True,
... model="probabilistic-configuration",
... edge_probs=lambda a, b: (p.pmf(a[0], b[1]) * p.pmf(a[1], 20 - b[0])),
... n_iter=100)
>>> figure()
>>> figure(figsize=(6,3))
<...>
>>> corr = gt.avg_neighbour_corr(g, "in", "out")
>>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="o-",
......@@ -753,19 +757,21 @@ def random_rewire(g, model="configuration", n_iter=1, edge_sweep=True,
>>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="o-",
... label=r"$\left<\text{i}\right>$ vs o, uncorr.")
<...>
>>> legend(loc="lower right", borderaxespad=0., framealpha=0.8)
>>> legend(loc='center left', bbox_to_anchor=(1, 0.5))
<...>
>>> xlabel("Source degree")
<...>
>>> ylabel("Average target degree")
<...>
>>> tight_layout()
>>> savefig("shuffled-deg-corr-dir.pdf")
>>> box = gca().get_position()
>>> gca().set_position([box.x0, box.y0, box.width * 0.7, box.height])
>>> savefig("shuffled-deg-corr-dir.svg")
.. testcode::
:hide:
savefig("shuffled-deg-corr-dir.png")
savefig("shuffled-deg-corr-dir.pdf")
.. figure:: shuffled-deg-corr-dir.*
:align: center
......
......@@ -1081,6 +1081,8 @@ class BlockState(object):
structures and high-resolution model selection in large networks ",
Phys. Rev. X 4, 011047 (2014), :doi:`10.1103/PhysRevX.4.011047`,
:arxiv:`1310.4377`.
.. [peixoto-weighted-2017] Tiago P. Peixoto, "Nonparametric weighted
stochastic block models", :arxiv:`1708.01432`
"""
......
......@@ -190,8 +190,8 @@ def minimize_blockmodel_dl(g, B_min=None, B_max=None, b_min=None, b_max=None,
.. testsetup:: mdl
gt.seed_rng(42)
np.random.seed(42)
gt.seed_rng(43)
np.random.seed(43)
.. doctest:: mdl
......
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