diff options
author | KatolaZ <katolaz@yahoo.it> | 2015-10-19 16:23:00 +0100 |
---|---|---|
committer | KatolaZ <katolaz@yahoo.it> | 2015-10-19 16:23:00 +0100 |
commit | df8386f75b0538075d72d52693836bb8878f505b (patch) | |
tree | 704c2a0836f8b9fd9f470c12b6ae05637c431468 /models/nullmodels/model_hypergeometric.py | |
parent | 363274e79eade464247089c105260bc34940da07 (diff) |
First commit of MAMMULT code
Diffstat (limited to 'models/nullmodels/model_hypergeometric.py')
-rw-r--r-- | models/nullmodels/model_hypergeometric.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/models/nullmodels/model_hypergeometric.py b/models/nullmodels/model_hypergeometric.py new file mode 100644 index 0000000..0a36237 --- /dev/null +++ b/models/nullmodels/model_hypergeometric.py @@ -0,0 +1,56 @@ +#### +## +## This is the hypergeometric model. Each layer has the same number of +## non-isolated nodes as the initial graph, but the nodes are +## activated at random. The input is a file of number of non-isolated +## nodes in each layer, and the total number of nodes in the multiplex. +## +## The output file is a node-layer participation file, in the format +## +## node_id1 layer_id1 +## node_id2 layer_id2 +## ..... +## + +import sys +import random + +if len(sys.argv) < 3: + print "Usage: %s <layer_N_file> <N>" % sys.argv[0] + sys.exit(1) + +N = int(sys.argv[2]) + +layer_degs = [] +node_layers = {} + +lines = open(sys.argv[1]).readlines() + +M = 0 + + +for l in lines: + if l[0] == "#": + continue + n = [int(x) for x in l.strip(" \n").split(" ")][0] + layer_degs.append(n) + M += 1 + +for i in range(M): + num = layer_degs[i] + added = [] + n = 0 + while n < num: + j = random.choice(range(N)) + if j not in added: + n += 1 + added.append(j) + if node_layers.has_key(j): + node_layers[j].append(i) + else: + node_layers[j] = [i] + +for n in node_layers.keys(): + for i in node_layers[n]: + print n,i + |