Commit 2301bff2 authored by Tiago Peixoto's avatar Tiago Peixoto

Documentation fixups

parent 13a0fce4
......@@ -78,3 +78,24 @@ g.edge_properties["age"] = e_age
# now we can save it
g.save("price.xml.gz")
# Let's plot its in-degree distribution
in_hist = vertex_hist(g, "in")
y = in_hist[0]
err = sqrt(in_hist[0])
err[err >= y] = y[err >= y] - 1e-2
figure(figsize=(6,4))
errorbar(in_hist[1][:-1], in_hist[0], fmt="o", yerr=err,
label="in")
gca().set_yscale("log")
gca().set_xscale("log")
gca().set_ylim(1e-1, 1e5)
gca().set_xlim(0.8, 1e3)
subplots_adjust(left=0.2, bottom=0.2)
xlabel("$k_{in}$")
ylabel("$NP(k_{in})$")
tight_layout()
savefig("price-deg-dist.pdf")
......@@ -452,38 +452,14 @@ 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!
This 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 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`.
.. plot::
:context:
.. figure:: price-deg-dist.*
:align: center
#from pyenv import *
from pylab import *
import graph_tool.all as gt
g = gt.load_graph("price.xml.gz")
in_hist = gt.vertex_hist(g, "in")
figure()
y = in_hist[0]
err = sqrt(in_hist[0])
err[err >= y] = y[err >= y] - 1e-2
errorbar(in_hist[1][:-1], in_hist[0], fmt="o", yerr=err,
label="in")
gca().set_yscale("log")
gca().set_xscale("log")
gca().set_ylim(1e-1, 1e5)
gca().set_xlim(0.8, 1e3)
subplots_adjust(left=0.2, bottom=0.2)
xlabel("$k_{in}$")
ylabel("$NP(k_{in})$")
Title ("In-degree distribution of a price network with $10^5$ nodes.")
tight_layout()
show()
In-degree distribution of a price network with :math:`10^5` nodes.
We can draw the graph to see some other features of its topology. For that we
......
......@@ -638,20 +638,20 @@ def dijkstra_search(g, source, weight, visitor=DijkstraVisitor(), dist_map=None,
Source vertex.
weight : :class:`~graph_tool.PropertyMap`
Edge property map with weight values.
visitor : :class:`~graph_tool.search.DijkstraVisitor` (optional, default: DijkstraVisitor())
visitor : :class:`~graph_tool.search.DijkstraVisitor` (optional, default: ``DijkstraVisitor()``)
A visitor object that is invoked at the event points inside the
algorithm. This should be a subclass of
:class:`~graph_tool.search.DijkstraVisitor`.
dist_map : :class:`~graph_tool.PropertyMap` (optional, default: None)
dist_map : :class:`~graph_tool.PropertyMap` (optional, default: ``None``)
A vertex property map where the distances from the source will be
stored.
pred_map : :class:`~graph_tool.PropertyMap` (optional, default: None)
pred_map : :class:`~graph_tool.PropertyMap` (optional, default: ``None``)
A vertex property map where the predecessor map will be
stored (must have value type "int").
combine : binary function (optional, default: lambda a, b: a + b)
combine : binary function (optional, default: ``lambda a, b: a + b``)
This function is used to combine distances to compute the distance of a
path.
compare : binary function (optional, default: lambda a, b: a < b)
compare : binary function (optional, default: ``lambda a, b: a < b``)
This function is use to compare distances to determine which vertex is
closer to the source vertex.
......@@ -905,20 +905,20 @@ def bellman_ford_search(g, source, weight, visitor=BellmanFordVisitor(),
Source vertex.
weight : :class:`~graph_tool.PropertyMap`
Edge property map with weight values.
visitor : :class:`~graph_tool.search.DijkstraVisitor` (optional, default: DijkstraVisitor())
visitor : :class:`~graph_tool.search.DijkstraVisitor` (optional, default: ``DijkstraVisitor()``)
A visitor object that is invoked at the event points inside the
algorithm. This should be a subclass of
:class:`~graph_tool.search.DijkstraVisitor`.
dist_map : :class:`~graph_tool.PropertyMap` (optional, default: None)
dist_map : :class:`~graph_tool.PropertyMap` (optional, default: ``None``)
A vertex property map where the distances from the source will be
stored.
pred_map : :class:`~graph_tool.PropertyMap` (optional, default: None)
pred_map : :class:`~graph_tool.PropertyMap` (optional, default: ``None``)
A vertex property map where the predecessor map will be
stored (must have value type "int").
combine : binary function (optional, default: lambda a, b: a + b)
combine : binary function (optional, default: ``lambda a, b: a + b``)
This function is used to combine distances to compute the distance of a
path.
compare : binary function (optional, default: lambda a, b: a < b)
compare : binary function (optional, default: ``lambda a, b: a < b``)
This function is use to compare distances to determine which vertex is
closer to the source vertex.
......@@ -926,7 +926,7 @@ def bellman_ford_search(g, source, weight, visitor=BellmanFordVisitor(),
Returns
-------
minimized : bool
True if all edges were successfully minimize, or False if there is a
True if all edges were successfully minimized, or False if there is a
negative loop in the graph.
dist_map : :class:`~graph_tool.PropertyMap`
A vertex property map with the computed distances from the source.
......@@ -1178,7 +1178,7 @@ def astar_search(g, source, weight, visitor=AStarVisitor(),
Source vertex.
weight : :class:`~graph_tool.PropertyMap`
Edge property map with weight values.
visitor : :class:`~graph_tool.search.AStarVisitor` (optional, default: AStarVisitor())
visitor : :class:`~graph_tool.search.AStarVisitor` (optional, default: ``AStarVisitor()``)
A visitor object that is invoked at the event points inside the
algorithm. This should be a subclass of
:class:`~graph_tool.search.AStarVisitor`.
......@@ -1186,13 +1186,13 @@ def astar_search(g, source, weight, visitor=AStarVisitor(),
The heuristic function that guides the search. It should take a single
argument which is a :class:`~graph_tool.Vertex`, and output an estimated
distance from the source vertex.
dist_map : :class:`~graph_tool.PropertyMap` (optional, default: None)
dist_map : :class:`~graph_tool.PropertyMap` (optional, default: ``None``)
A vertex property map where the distances from the source will be
stored.
pred_map : :class:`~graph_tool.PropertyMap` (optional, default: None)
pred_map : :class:`~graph_tool.PropertyMap` (optional, default: ``None``)
A vertex property map where the predecessor map will be
stored (must have value type "int").
cost_map : :class:`~graph_tool.PropertyMap` (optional, default: None)
cost_map : :class:`~graph_tool.PropertyMap` (optional, default: ``None``)
A vertex property map where the vertex costs will be stored. It must
have the same value type as ``dist_map``. This parameter is only used if
``implicit`` is True.
......@@ -1202,7 +1202,7 @@ def astar_search(g, source, weight, visitor=AStarVisitor(),
compare : binary function (optional, default: ``lambda a, b: a < b``)
This function is use to compare distances to determine which vertex is
closer to the source vertex.
implicit : bool (optional, default: False)
implicit : bool (optional, default: ``False``)
If true, the underlying graph will be assumed to be implicit
(i.e. constructed during the search).
......
......@@ -189,21 +189,20 @@ def subgraph_isomorphism(sub, g, max_n=0, random=False):
>>> g.set_vertex_filter(None)
>>> g.set_edge_filter(None)
>>> ewidth = g.copy_property(emask, value_type="double")
>>> ewidth.a *= 1.5
>>> ewidth.a += 0.5
>>> gt.graph_draw(g, vertex_fill_color=vmask, edge_color=emask, edge_pen_width=ewidth,
>>> ewidth.a *= 2
>>> gt.graph_draw(g, vertex_fill_color=vmask, edge_color=emask,
... edge_pen_width=ewidth, output_size=(200, 200),
... output="subgraph-iso-embed.pdf")
<...>
>>> gt.graph_draw(sub, output="subgraph-iso.pdf")
>>> gt.graph_draw(sub, output_size=(200, 200), output="subgraph-iso.pdf")
<...>
.. figure:: subgraph-iso.*
.. image:: subgraph-iso.*
.. image:: subgraph-iso-embed.*
Subgraph searched
.. figure:: subgraph-iso-embed.*
One isomorphic subgraph found in main graph.
**Left:** Subgraph searched, **Right:** One isomorphic subgraph found in main graph.
Notes
-----
......@@ -1055,7 +1054,7 @@ def is_planar(g, embedding=False, kuratowski=False):
>>> print p
False
>>> g.set_edge_filter(kur, True)
>>> gt.graph_draw(g, output="kuratowski.pdf")
>>> gt.graph_draw(g, output_size=(300, 300), output="kuratowski.pdf")
<...>
.. figure:: kuratowski.*
......@@ -1104,7 +1103,7 @@ def is_planar(g, embedding=False, kuratowski=False):
def max_cardinality_matching(g, heuristic=False, weight=None, minimize=True,
match=None):
r"""Find the maximum cardinality matching in the graph.
r"""Find a maximum cardinality matching in the graph.
Parameters
----------
......@@ -1136,17 +1135,24 @@ def max_cardinality_matching(g, heuristic=False, weight=None, minimize=True,
share a common vertex. A *maximum cardinality matching* has maximum size
over all matchings in the graph.
This algorithm runs in time :math:`O(EV\times\alpha(E,V))`, where
:math:`\alpha(m,n)` is a slow growing function that is at most 4 for any
feasible input. If `heuristic == True`, the algorithm runs in time :math:`O(V + E)`.
For a more detailed description, see [boost-max-matching]_.
Examples
--------
>>> from numpy.random import seed, random
>>> from numpy.random import seed
>>> seed(43)
>>> g = gt.random_graph(100, lambda: (2,2))
>>> g = gt.GraphView(gt.price_network(300), directed=False)
>>> res = gt.max_cardinality_matching(g)
>>> print res[1]
True
>>> gt.graph_draw(g, edge_color=res[0], output="max_card_match.pdf")
>>> w = res[0].copy("double")
>>> w.a = 2 * w.a + 2
>>> gt.graph_draw(g, edge_color=res[0], edge_pen_width=w, vertex_fill_color="grey",
... output="max_card_match.pdf")
<...>
.. figure:: max_card_match.*
......@@ -1183,7 +1189,7 @@ def max_cardinality_matching(g, heuristic=False, weight=None, minimize=True,
def max_independent_vertex_set(g, high_deg=False, mivs=None):
r"""Find the maximum cardinality matching in the graph.
r"""Find a maximal independent vertex set in the graph.
Parameters
----------
......@@ -1197,42 +1203,38 @@ def max_independent_vertex_set(g, high_deg=False, mivs=None):
Returns
-------
match : :class:`~graph_tool.PropertyMap`
Boolean edge property map where the matching is specified.
is_maximal : bool
True if the matching is indeed maximal, or False otherwise. This is only
returned if ``heuristic == False``.
mivs : :class:`~graph_tool.PropertyMap`
Boolean vertex property map where the set is specified.
Notes
-----
A *matching* is a subset of the edges of a graph such that no two edges
share a common vertex. A *maximum cardinality matching* has maximum size
over all matchings in the graph.
A maximal independent vertex set is an independent set such that adding any
other vertex to the set forces the set to contain an edge between two
vertices of the set.
For a more detailed description, see [boost-max-matching]_.
This implements the algorithm described in [mivs-luby]_, which runs in time
:math:`O(V + E)`.
Examples
--------
>>> from numpy.random import seed, random
>>> from numpy.random import seed
>>> seed(43)
>>> g = gt.random_graph(100, lambda: (2,2))
>>> res = gt.max_cardinality_matching(g)
>>> print res[1]
True
>>> gt.graph_draw(g, edge_color=res[0], output="max_card_match.pdf")
>>> g = gt.GraphView(gt.price_network(300), directed=False)
>>> res = gt.max_independent_vertex_set(g)
>>> gt.graph_draw(g, vertex_fill_color=res, output="mivs.pdf")
<...>
.. figure:: max_card_match.*
.. figure:: mivs.*
:align: center
Edges belonging to the matching are in red.
Vertices belonging to the set are in red.
References
----------
.. [boost-max-matching] http://www.boost.org/libs/graph/doc/maximum_matching.html
.. [matching-heuristic] B. Hendrickson and R. Leland. "A Multilevel Algorithm
for Partitioning Graphs." In S. Karin, editor, Proc. Supercomputing ’95,
San Diego. ACM Press, New York, 1995, :doi:`10.1145/224170.224228`
.. [mivs-wikipedia] http://en.wikipedia.org/wiki/Independent_set_%28graph_theory%29
.. [mivs-luby] Luby, M., "A simple parallel algorithm for the maximal independent set problem",
Proc. 17th Symposium on Theory of Computing, Association for Computing Machinery, pp. 1–10, (1985)
:doi:`10.1145/22145.22146`.
"""
if mivs is None:
......
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