Commit e1dd1665 by 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: ... @@ -45,16 +45,11 @@ public: return python::extract(ret); return python::extract(ret); } } size_t operator()(size_t k) const double operator()(pair deg, pair degl) const { { python::object ret = _o(k); python::object ret = _o(python::make_tuple(deg.first, deg.second), return python::extract(ret); python::make_tuple(degl.first, degl.second)); } return python::extract(ret); pair operator()(pair deg) const { python::object ret = _o(deg.first, deg.second); return python::extract >(ret); } } private: private: ... ...
This diff is collapsed.
 ... @@ -29,6 +29,9 @@ import sys, numpy ... @@ -29,6 +29,9 @@ import sys, numpy __all__ = ["random_graph"] __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, def random_graph(N, deg_sampler, deg_corr=None, directed=True, parallel=False, self_loops=False, parallel=False, self_loops=False, seed=0, verbose=False): seed=0, verbose=False): ... @@ -39,8 +42,12 @@ def random_graph(N, deg_sampler, deg_corr=None, directed=True, ... @@ -39,8 +42,12 @@ def random_graph(N, deg_sampler, deg_corr=None, directed=True, uncorrelated = True uncorrelated = True else: else: uncorrelated = False uncorrelated = False if not directed and deg_corr != None: corr = lambda i,j: _corr_wrap(i, j, deg_corr) else: corr = deg_corr libgraph_tool_generation.gen_random_graph(g._Graph__graph, N, libgraph_tool_generation.gen_random_graph(g._Graph__graph, N, deg_sampler, deg_corr, deg_sampler, corr, uncorrelated, not parallel, uncorrelated, not parallel, not self_loops, not directed, not self_loops, not directed, seed, verbose) 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