Commit 45f28a19 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Update docstrings

parent 26cdde1e
...@@ -1485,8 +1485,8 @@ class Graph(object): ...@@ -1485,8 +1485,8 @@ class Graph(object):
>>> g.graph_properties["gnat"] = g.new_graph_property("string", "hi there!") >>> g.graph_properties["gnat"] = g.new_graph_property("string", "hi there!")
>>> g.list_properties() >>> g.list_properties()
gnat (graph) (type: string, val: hi there!) gnat (graph) (type: string, val: hi there!)
foo (vertex) (type: double)
bar (vertex) (type: python::object) bar (vertex) (type: python::object)
foo (vertex) (type: double)
foo (edge) (type: vector<double>) foo (edge) (type: vector<double>)
""" """
......
...@@ -695,7 +695,7 @@ def katz(g, alpha=0.01, beta=None, weight=None, vprop=None, epsilon=1e-6, ...@@ -695,7 +695,7 @@ def katz(g, alpha=0.01, beta=None, weight=None, vprop=None, epsilon=1e-6,
>>> g = gt.collection.data["polblogs"] >>> g = gt.collection.data["polblogs"]
>>> g = gt.GraphView(g, vfilt=gt.label_largest_component(g)) >>> g = gt.GraphView(g, vfilt=gt.label_largest_component(g))
>>> w = g.new_edge_property("double") >>> w = g.new_edge_property("double")
>>> w.a = np.random.random(len(w.a)) * 42 >>> w.a = np.random.random(len(w.a))
>>> x = gt.katz(g, weight=w) >>> x = gt.katz(g, weight=w)
>>> gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=x, >>> gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=x,
... vertex_size=gt.prop_to_size(x, mi=5, ma=15), ... vertex_size=gt.prop_to_size(x, mi=5, ma=15),
......
...@@ -121,7 +121,7 @@ def local_clustering(g, prop=None, undirected=True): ...@@ -121,7 +121,7 @@ def local_clustering(g, prop=None, undirected=True):
>>> g = gt.random_graph(1000, lambda: (5,5)) >>> g = gt.random_graph(1000, lambda: (5,5))
>>> clust = gt.local_clustering(g) >>> clust = gt.local_clustering(g)
>>> print(gt.vertex_average(g, clust)) >>> print(gt.vertex_average(g, clust))
(0.0072, 0.00039746045691969764) (0.007177777777777778, 0.0003966968553716155)
References References
---------- ----------
...@@ -182,7 +182,7 @@ def global_clustering(g): ...@@ -182,7 +182,7 @@ def global_clustering(g):
>>> g = gt.random_graph(1000, lambda: (5,5)) >>> g = gt.random_graph(1000, lambda: (5,5))
>>> print(gt.global_clustering(g)) >>> print(gt.global_clustering(g))
(0.007182172103638073, 0.0003970213508956326) (0.007177777777777778, 0.0003970939493209407)
References References
---------- ----------
......
...@@ -1870,7 +1870,7 @@ def collect_edge_marginals(state, p=None): ...@@ -1870,7 +1870,7 @@ def collect_edge_marginals(state, p=None):
... ds, nmoves = gt.mcmc_sweep(state) ... ds, nmoves = gt.mcmc_sweep(state)
... pe = gt.collect_edge_marginals(state, pe) ... pe = gt.collect_edge_marginals(state, pe)
>>> gt.bethe_entropy(state, pe)[0] >>> gt.bethe_entropy(state, pe)[0]
16.31947774487215 17.443089842818125
""" """
if p is None: if p is None:
...@@ -1922,7 +1922,7 @@ def collect_vertex_marginals(state, p=None): ...@@ -1922,7 +1922,7 @@ def collect_vertex_marginals(state, p=None):
... ds, nmoves = gt.mcmc_sweep(state) ... ds, nmoves = gt.mcmc_sweep(state)
... pv = gt.collect_vertex_marginals(state, pv) ... pv = gt.collect_vertex_marginals(state, pv)
>>> gt.mf_entropy(state, pv) >>> gt.mf_entropy(state, pv)
18.348761352514927 19.94955528942717
>>> gt.graph_draw(g, pos=g.vp["pos"], vertex_shape="pie", vertex_pie_fractions=pv, output="polbooks_blocks_soft_B4.pdf") >>> gt.graph_draw(g, pos=g.vp["pos"], vertex_shape="pie", vertex_pie_fractions=pv, output="polbooks_blocks_soft_B4.pdf")
<...> <...>
......
...@@ -328,7 +328,7 @@ def nested_mcmc_sweep(state, beta=1., random_move=False, c=1., sequential=True, ...@@ -328,7 +328,7 @@ def nested_mcmc_sweep(state, beta=1., random_move=False, c=1., sequential=True,
>>> state = gt.NestedBlockState(g, Bs=[10, 5, 3, 2, 1], deg_corr=True) >>> state = gt.NestedBlockState(g, Bs=[10, 5, 3, 2, 1], deg_corr=True)
>>> ret = gt.nested_mcmc_sweep(state) >>> ret = gt.nested_mcmc_sweep(state)
>>> print(ret) >>> print(ret)
[(-0.23943486013787463, 57), (-0.017558577944127587, 2), (0.0, 0), (-0.0012759602078996138, 1), (0.0, 0)] [(-0.11881394061738723, 58), (-1.2855474804244876e-05, 1), (0.0, 0), (-0.003488958656098635, 1), (0.0, 0)]
References References
---------- ----------
......
...@@ -115,7 +115,7 @@ def assortativity(g, deg): ...@@ -115,7 +115,7 @@ def assortativity(g, deg):
... vertex_corr=lambda i,k: 1.0 / (1 + abs(i - k)), directed=False, ... vertex_corr=lambda i,k: 1.0 / (1 + abs(i - k)), directed=False,
... n_iter=100) ... n_iter=100)
>>> gt.assortativity(g, "out") >>> gt.assortativity(g, "out")
(0.13903518011375607, 0.005051876804786422) (0.1419534824769149, 0.005098622437085927)
References References
---------- ----------
...@@ -191,13 +191,13 @@ def scalar_assortativity(g, deg): ...@@ -191,13 +191,13 @@ def scalar_assortativity(g, deg):
... vertex_corr=lambda i,k: abs(i-k), ... vertex_corr=lambda i,k: abs(i-k),
... directed=False, n_iter=100) ... directed=False, n_iter=100)
>>> gt.scalar_assortativity(g, "out") >>> gt.scalar_assortativity(g, "out")
(-0.44070158356400696, 0.010592022444678632) (-0.45182410730944034, 0.010288182870044639)
>>> g = gt.random_graph(1000, lambda: sample_k(40), model="probabilistic", >>> g = gt.random_graph(1000, lambda: sample_k(40), model="probabilistic",
... vertex_corr=lambda i, k: 1.0 / (1 + abs(i - k)), ... vertex_corr=lambda i, k: 1.0 / (1 + abs(i - k)),
... directed=False, n_iter=100) ... directed=False, n_iter=100)
>>> gt.scalar_assortativity(g, "out") >>> gt.scalar_assortativity(g, "out")
(0.6007430887839058, 0.011569809783643956) (0.6421210898147616, 0.010632143985746339)
References References
---------- ----------
......
...@@ -189,7 +189,7 @@ def random_graph(N, deg_sampler, directed=True, ...@@ -189,7 +189,7 @@ def random_graph(N, deg_sampler, directed=True,
... vertex_corr=lambda i, k: 1.0 / (1 + abs(i - k)), directed=False, ... vertex_corr=lambda i, k: 1.0 / (1 + abs(i - k)), directed=False,
... n_iter=100) ... n_iter=100)
>>> gt.scalar_assortativity(g, "out") >>> gt.scalar_assortativity(g, "out")
(0.6285094791115295, 0.010745128857935755) (0.6197157767573332, 0.010781011616659146)
The following samples an in,out-degree pair from the joint distribution: The following samples an in,out-degree pair from the joint distribution:
...@@ -584,7 +584,7 @@ def random_rewire(g, model="uncorrelated", n_iter=1, edge_sweep=True, ...@@ -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.graph_draw(g, pos=pos, output="rewire_orig.png", output_size=(300, 300))
>>> gt.random_rewire(g, "correlated") >>> gt.random_rewire(g, "correlated")
189 212
>>> pos = gt.arf_layout(g) >>> pos = gt.arf_layout(g)
>>> gt.graph_draw(g, pos=pos, output="rewire_corr.pdf", output_size=(300, 300)) >>> 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, ...@@ -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.graph_draw(g, pos=pos, output="rewire_corr.png", output_size=(300, 300))
>>> gt.random_rewire(g) >>> gt.random_rewire(g)
197 207
>>> pos = gt.arf_layout(g) >>> pos = gt.arf_layout(g)
>>> gt.graph_draw(g, pos=pos, output="rewire_uncorr.pdf", output_size=(300, 300)) >>> 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, ...@@ -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.graph_draw(g, pos=pos, output="rewire_uncorr.png", output_size=(300, 300))
>>> gt.random_rewire(g, "erdos") >>> gt.random_rewire(g, "erdos")
26 21
>>> pos = gt.arf_layout(g) >>> pos = gt.arf_layout(g)
>>> gt.graph_draw(g, pos=pos, output="rewire_erdos.pdf", output_size=(300, 300)) >>> 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, ...@@ -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") >>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="o-", label="Original")
<...> <...>
>>> gt.random_rewire(g, "correlated") >>> gt.random_rewire(g, "correlated")
206 212
>>> corr = gt.avg_neighbour_corr(g, "out", "out") >>> corr = gt.avg_neighbour_corr(g, "out", "out")
>>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="*", label="Correlated") >>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="*", label="Correlated")
<...> <...>
>>> gt.random_rewire(g) >>> gt.random_rewire(g)
109 120
>>> corr = gt.avg_neighbour_corr(g, "out", "out") >>> corr = gt.avg_neighbour_corr(g, "out", "out")
>>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="o-", label="Uncorrelated") >>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="o-", label="Uncorrelated")
<...> <...>
>>> gt.random_rewire(g, "erdos") >>> gt.random_rewire(g, "erdos")
13 20
>>> corr = gt.avg_neighbour_corr(g, "out", "out") >>> 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") >>> 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, ...@@ -693,7 +693,7 @@ def random_rewire(g, model="uncorrelated", n_iter=1, edge_sweep=True,
... label=r"$\left<\text{i}\right>$ vs o") ... label=r"$\left<\text{i}\right>$ vs o")
<...> <...>
>>> gt.random_rewire(g, "correlated") >>> gt.random_rewire(g, "correlated")
4323 4130
>>> corr = gt.avg_neighbour_corr(g, "in", "out") >>> corr = gt.avg_neighbour_corr(g, "in", "out")
>>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="o-", >>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="o-",
... label=r"$\left<\text{o}\right>$ vs i, corr.") ... 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, ...@@ -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.") ... label=r"$\left<\text{i}\right>$ vs o, corr.")
<...> <...>
>>> gt.random_rewire(g, "uncorrelated") >>> gt.random_rewire(g, "uncorrelated")
153 194
>>> corr = gt.avg_neighbour_corr(g, "in", "out") >>> corr = gt.avg_neighbour_corr(g, "in", "out")
>>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="o-", >>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="o-",
... label=r"$\left<\text{o}\right>$ vs i, uncorr.") ... label=r"$\left<\text{o}\right>$ vs i, uncorr.")
......
...@@ -797,12 +797,12 @@ def label_largest_component(g, directed=None): ...@@ -797,12 +797,12 @@ def label_largest_component(g, directed=None):
>>> g = gt.random_graph(100, lambda: poisson(1), directed=False) >>> g = gt.random_graph(100, lambda: poisson(1), directed=False)
>>> l = gt.label_largest_component(g) >>> l = gt.label_largest_component(g)
>>> print(l.a) >>> print(l.a)
[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 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 0 1 0 0 0 0 0 0 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 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 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] 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 1 1 1 0]
>>> u = gt.GraphView(g, vfilt=l) # extract the largest component as a graph >>> u = gt.GraphView(g, vfilt=l) # extract the largest component as a graph
>>> print(u.num_vertices()) >>> print(u.num_vertices())
16 18
""" """
label = g.new_vertex_property("bool") label = g.new_vertex_property("bool")
...@@ -848,18 +848,18 @@ def label_out_component(g, root): ...@@ -848,18 +848,18 @@ def label_out_component(g, root):
>>> g = gt.random_graph(100, lambda: poisson(2.2), directed=False) >>> g = gt.random_graph(100, lambda: poisson(2.2), directed=False)
>>> l = gt.label_out_component(g, g.vertex(2)) >>> l = gt.label_out_component(g, g.vertex(2))
>>> print(l.a) >>> print(l.a)
[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 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 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 0 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 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] 1 1 0 1 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. The in-component can be obtained by reversing the graph.
>>> l = gt.label_out_component(gt.GraphView(g, reversed=True, directed=True), >>> l = gt.label_out_component(gt.GraphView(g, reversed=True, directed=True),
... g.vertex(1)) ... g.vertex(1))
>>> print(l.a) >>> print(l.a)
[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 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 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 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0
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] 0 0 0 0 0 1 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0]
""" """
label = g.new_vertex_property("bool") label = g.new_vertex_property("bool")
...@@ -931,18 +931,17 @@ def label_biconnected_components(g, eprop=None, vprop=None): ...@@ -931,18 +931,17 @@ def label_biconnected_components(g, eprop=None, vprop=None):
>>> g = gt.random_graph(100, lambda: poisson(2), directed=False) >>> g = gt.random_graph(100, lambda: poisson(2), directed=False)
>>> comp, art, hist = gt.label_biconnected_components(g) >>> comp, art, hist = gt.label_biconnected_components(g)
>>> print(comp.a) >>> print(comp.a)
[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 [35 23 35 35 32 32 35 35 1 37 32 28 32 35 32 2 32 29 35 35 13 14 34 12 17
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 35 35 35 35 35 3 35 35 35 35 35 35 28 28 35 33 35 19 35 35 35 35 6 35 35
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 24 39 35 31 35 10 9 22 32 35 4 25 26 35 35 7 35 35 35 35 35 35 36 35 35
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] 35 32 35 0 35 35 35 32 35 28 32 35 20 30 27 18 38 16 5 15 11 28 35 8 21]
>>> print(art.a) >>> print(art.a)
[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 [1 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 1 0 0 1 1 0 0 1 0 0 0 0 0 1 0 0 1 0 0 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 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 1 0 0 1 1 0 0 0 0 0 1 0
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] 1 0 1 1 0 0 0 0 1 0 0 1 0 1 1 1 0 0 0 0 0 0 0 1 0 0]
>>> print(hist) >>> 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 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 5 1 1 1 10 1 1 48 1 1 1 1]
1 47 1 1]
""" """
if vprop is None: if vprop 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