Commit 0f1ea319 authored by Tiago Peixoto's avatar Tiago Peixoto

Fix bug in usage of tr1::variate_generator

The RNG object must be passed by _reference_ not by value, as is the
default! Otherwise the RNG state does not change...
parent 54880035
......@@ -127,7 +127,7 @@ struct get_absolute_trust
// select edge according to its probability
typename graph_traits<Graph>::edge_descriptor e;
typedef tr1::uniform_real<t_type> dist_t;
tr1::variate_generator<rng_t, dist_t>
tr1::variate_generator<rng_t&, dist_t>
random(rng, dist_t(0, out_prob.back()));
t_type u;
......
......@@ -155,7 +155,7 @@ struct sample_some
void operator()(vector<val_type>& extend, size_t d)
{
typedef tr1::uniform_real<double> rdist_t;
tr1::variate_generator<rng_t, rdist_t> random(*_rng, rdist_t());
tr1::variate_generator<rng_t&, rdist_t> random(*_rng, rdist_t());
double pd = (*_p)[d+1];
size_t nc = extend.size();
......@@ -182,7 +182,7 @@ struct sample_some
typedef tr1::uniform_int<size_t> idist_t;
for (size_t i = 0; i < n; ++i)
{
tr1::variate_generator<rng_t, idist_t>
tr1::variate_generator<rng_t&, idist_t>
random_v(*_rng, idist_t(0, extend.size()-i-1));
size_t j;
{
......@@ -305,7 +305,7 @@ struct get_all_motifs
V.push_back(*v);
typedef tr1::uniform_real<double> rdist_t;
tr1::variate_generator<rng_t, rdist_t> random(rng, rdist_t());
tr1::variate_generator<rng_t&, rdist_t> random(rng, rdist_t());
size_t n;
if (random() < p)
......@@ -316,7 +316,7 @@ struct get_all_motifs
typedef tr1::uniform_int<size_t> idist_t;
for (size_t i = 0; i < n; ++i)
{
tr1::variate_generator<rng_t, idist_t>
tr1::variate_generator<rng_t&, idist_t>
random_v(rng, idist_t(0, V.size()-i-1));
size_t j = i + random_v();
......
......@@ -61,7 +61,7 @@ struct get_communities
rng_t rng(static_cast<rng_t::result_type>(seed));
tr1::variate_generator<rng_t, tr1::uniform_real<> >
tr1::variate_generator<rng_t&, tr1::uniform_real<> >
random(rng, tr1::uniform_real<>());
stringstream out_str;
......
......@@ -478,21 +478,31 @@ def absolute_trust(g, trust_map, source=None, vprop=None, epslon=0.001,
>>> trust.get_array()[:] = random(g.num_edges())
>>> t = gt.absolute_trust(g, trust)
>>> print array(t[g.vertex(10)])
[ 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.83889809 0. 0. 0. 0. 0.26116067
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0.54758746 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0.04949872 0. 0. 0. 0. 0.
0. 0. 0. 0.05011676 0. 0. 0.
0. 0. 0. 0.43799071 0. 0. 0.
0. 0. 0.04054452 0. 0. 0. 0.
0. 0. 0. 0.17447756]
[ 4.51906352e-01 1.01429943e-01 0.00000000e+00 0.00000000e+00
0.00000000e+00 2.44861537e-01 0.00000000e+00 3.02651461e-01
0.00000000e+00 1.74730923e-02 0.00000000e+00 4.29689123e-03
9.92174035e-04 4.87376703e-02 7.96102941e-06 2.33366853e-01
2.54084432e-01 1.21249107e-02 1.68187723e-01 1.63299672e-02
3.63286096e-02 7.26969527e-01 2.66379387e-01 2.60306326e-03
3.00337293e-04 3.45095945e-02 4.74197414e-02 3.47040393e-01
4.15994365e-01 2.58366543e-01 1.98886295e-02 1.84395387e-01
3.01526472e-01 4.17581597e-01 5.08199168e-01 2.39325151e-01
1.16653396e-01 0.00000000e+00 2.32122209e-01 1.74458369e-01
0.00000000e+00 2.28833708e-02 8.40459672e-02 1.13238046e-01
1.15211877e-01 1.64368525e-01 5.42106779e-03 8.21849155e-01
0.00000000e+00 1.10064601e-01 3.94971607e-01 2.40544425e-01
1.81781785e-01 4.27661874e-01 1.96505012e-01 2.22664312e-01
1.05942366e-01 1.45053992e-01 3.17854637e-01 0.00000000e+00
7.19074080e-02 6.01425735e-02 1.80652580e-01 1.64203118e-06
1.51091732e-01 2.15091245e-01 6.59231333e-01 5.29298126e-01
3.39640072e-01 2.85420503e-01 0.00000000e+00 0.00000000e+00
3.76245906e-01 2.26621429e-02 2.16958451e-01 5.43678807e-01
0.00000000e+00 7.01804977e-02 1.50118832e-01 3.44142938e-03
3.63454763e-01 2.55747857e-01 1.58862377e-01 4.74257967e-02
9.79787266e-02 1.33262415e-01 4.44120403e-01 2.13954368e-02
1.65309874e-01 2.22217618e-01 2.80359630e-02 3.78916751e-01
9.22800991e-03 2.89978731e-03 9.21281004e-02 0.00000000e+00
5.20985973e-01 5.47754676e-02 6.27828075e-01 2.28123051e-01]
"""
if seed != 0:
......
......@@ -90,7 +90,7 @@ def local_clustering(g, prop=None, undirected=False):
>>> g = gt.random_graph(1000, lambda: (5,5), seed=42)
>>> clust = gt.local_clustering(g)
>>> print gt.vertex_average(g, clust)
(0.005048478260869565, 0.00043544409486305209)
(0.0042016666666666669, 0.00041579094306313759)
References
----------
......@@ -149,7 +149,7 @@ def global_clustering(g):
--------
>>> g = gt.random_graph(1000, lambda: (5,5), seed=42)
>>> print gt.global_clustering(g)
(0.0079235400765494558, 0.00041721619682007839)
(0.0083567321834469854, 0.0004417198625120785)
References
----------
......@@ -221,11 +221,11 @@ def extended_clustering(g, props=None, max_depth=3, undirected=False):
>>> for i in xrange(0, 5):
... print gt.vertex_average(g, clusts[i])
...
(0.005048478260869565, 0.00043544409486305209)
(0.025116811594202898, 0.00096935403523205497)
(0.11178014492753624, 0.0019836458026216146)
(0.40412130434782606, 0.0030616964103718316)
(0.43449992753623184, 0.003195885251613022)
(0.0042016666666666669, 0.00041579094306313759)
(0.02409, 0.00095845344754511225)
(0.11065333333333334, 0.0019404812805074933)
(0.40180499999999997, 0.0031866048246265693)
(0.43999999999999995, 0.0031172994010129269)
References
----------
......@@ -305,9 +305,9 @@ def motifs(g, k, p=1.0, motif_list=None, undirected=None, seed=0):
>>> g = gt.random_graph(1000, lambda: (5,5), seed=42)
>>> motifs, counts = gt.motifs(g, 4, undirected=True)
>>> print len(motifs)
14
10
>>> print counts
[114942, 387657, 958, 1089, 2482, 2760, 844, 6, 16, 14, 8, 10, 16, 8]
[116138, 392344, 389, 445, 2938, 996, 792, 3, 14, 3]
References
----------
......@@ -459,12 +459,13 @@ def motif_significance(g, k, n_shuffles=10, p=1.0, motif_list=None,
>>> g = gt.random_graph(100, lambda: (3,3), seed=42)
>>> motifs, zscores = gt.motif_significance(g, 3)
>>> print len(motifs)
10
11
>>> print zscores
[-3.9501340809971031, -3.96459679349275, -5.95765904191577, -0.17407765595569785, 3.580195875015368, 3.5906624935876583, 2.2739701341354892, 1.8999999999999999, 0.0, -0.20000000000000001]
[-2.7573400429260952, -2.7711373148737528, -3.823295048129145, -0.6117752903214978, 2.9524205015061291, 2.9303545260261825, 1.4167427093634908, 1.8999999999999999, -0.29999999999999999, 0.0, -0.20000000000000001]
"""
from itertools import izip
from .. misc import random_rewire, isomorphism
from .. misc import isomorphism
from .. generation import random_rewire
s_ms, counts = motifs(g, k, p, motif_list, undirected, seed)
s_counts = [0]*len(s_ms)
......
......@@ -89,7 +89,7 @@ def assortativity(g, deg):
>>> g = gt.random_graph(1000, lambda: sample_k(40),
... lambda i,k: 1.0/(1+abs(i-k)), directed=False)
>>> gt.assortativity(g, "out")
(0.12276644944292621, 0.0047979660158573361)
(0.14754098360655737, 0.0051710617845570463)
References
----------
......@@ -159,12 +159,12 @@ def scalar_assortativity(g, deg):
>>> g = gt.random_graph(1000, lambda: sample_k(40), lambda i,k: abs(i-k),
... directed=False)
>>> gt.scalar_assortativity(g, "out")
(-0.41978974341801006, 0.010989368662810171)
(-0.45583464361842779, 0.010751070629208364)
>>> g = gt.random_graph(1000, lambda: sample_k(40),
... lambda i,k: 1.0/(1+abs(i-k)),
... directed=False, seed=42)
>>> gt.scalar_assortativity(g, "out")
(0.58078830725966446, 0.011882587893677807)
(0.58790674914799046, 0.011773357057290077)
References
----------
......
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