-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsa_FPC.py
119 lines (90 loc) · 3.23 KB
/
csa_FPC.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
'''
@author: Daniel Hjertholm
Tests for network with fixed connection probability for all
possible connections, created by CSA.
'''
import numpy.random as rnd
import random
import csa
from testsuite.FPC_test import FPCTester
class CSA_FPCTester(FPCTester):
'''
Tests for network with fixed connection probability for all
possible connections, created by CSA.
'''
def __init__(self, N_s, N_t, p, e_min=5):
'''
Construct a test object.
Parameters
----------
N_s : Number of nodes in source population.
N_t : Number of nodes in target population.
p : Connection probability.
e_min : Minimum expected number of observations in each bin.
'''
FPCTester.__init__(self, N_s=N_s, N_t=N_t, p=p, e_min=e_min)
def _reset(self, seed):
'''
Reset simulator and seed the PRNGs.
Parameters
----------
seed: PRNG seed value.
'''
# Set PRNG seed values:
if seed == None:
seed = rnd.randint(10 ** 10)
seed = 2 * seed # Reduces probability of overlapping seed values.
random.seed(seed) # CSA uses random.
rnd.seed(seed + 1) # _get_expected_distribution uses numpy.random.
def _build(self):
'''Create populations.'''
pass
def _connect(self):
'''Connect populations.'''
finite_set = csa.cross(xrange(self._N_s), xrange(self._N_t))
self._cs = csa.cset(csa.random(p=self._p) * finite_set)
def _degrees(self):
'''Return list of degrees.'''
i = 0 if self._degree == 'out' else 1
connections = [c[i] for c in self._cs]
return self._counter(connections)
class InDegreeTester(CSA_FPCTester):
'''
Tests for the in-degree distribution of networks with fixed connection
probability for all possible connections, created by CSA.
'''
def __init__(self, N_s, N_t, p, e_min=5):
'''
Construct a test object.
Parameters
----------
N_s : Number of nodes in source population.
N_t : Number of nodes in target population.
p : Connection probability.
e_min: Minimum expected number of observations in each bin.
'''
self._degree = 'in'
CSA_FPCTester.__init__(self, N_s, N_t, p, e_min)
class OutDegreeTester(CSA_FPCTester):
'''
Tests for the out-degree distribution of networks with fixed connection
probability for all possible connections, created by CSA.
'''
def __init__(self, N_s, N_t, p, e_min=5):
'''
Construct a test object.
Parameters
----------
N_s : Number of nodes in source population.
N_t : Number of nodes in target population.
p : Connection probability.
e_min: Minimum expected number of observations in each bin.
'''
self._degree = 'out'
CSA_FPCTester.__init__(self, N_s, N_t, p, e_min)
if __name__ == '__main__':
test = InDegreeTester(N_s=30, N_t=100, p=0.5)
ks, p = test.two_level_test(n_runs=100, start_seed=0, control=False)
print 'p-value of KS-test of uniformity:', p
test.show_CDF()
test.show_histogram()