Commit e1dd1665 authored by Tiago Peixoto's avatar Tiago Peixoto

Improve correlated graph generation

random_graph() now uses a modified algorithm for generation of
correlated graphs, which is more efficient. Instead of giving a function
which returns a sample of the correlated target degree, the user must
give a function which will just compute its probability. This
probability will then be used to choose the edges.
parent 6c77669e
......@@ -45,16 +45,11 @@ public:
return python::extract<size_t>(ret);
size_t operator()(size_t k) const
double operator()(pair<size_t, size_t> deg, pair<size_t, size_t> degl) const
python::object ret = _o(k);
return python::extract<size_t>(ret);
pair<size_t, size_t> operator()(pair<size_t, size_t> deg) const
python::object ret = _o(deg.first, deg.second);
return python::extract<pair<size_t,size_t> >(ret);
python::object ret = _o(python::make_tuple(deg.first, deg.second),
python::make_tuple(degl.first, degl.second));
return python::extract<double>(ret);
This diff is collapsed.
......@@ -29,6 +29,9 @@ import sys, numpy
__all__ = ["random_graph"]
def _corr_wrap(i, j, corr):
return corr(i[1], j[1])
def random_graph(N, deg_sampler, deg_corr=None, directed=True,
parallel=False, self_loops=False,
seed=0, verbose=False):
......@@ -39,8 +42,12 @@ def random_graph(N, deg_sampler, deg_corr=None, directed=True,
uncorrelated = True
uncorrelated = False
if not directed and deg_corr != None:
corr = lambda i,j: _corr_wrap(i, j, deg_corr)
corr = deg_corr
libgraph_tool_generation.gen_random_graph(g._Graph__graph, N,
deg_sampler, deg_corr,
deg_sampler, corr,
uncorrelated, not parallel,
not self_loops, not directed,
seed, verbose)
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