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_MSM.py | |
parent | 363274e79eade464247089c105260bc34940da07 (diff) |
First commit of MAMMULT code
Diffstat (limited to 'models/nullmodels/model_MSM.py')
-rw-r--r-- | models/nullmodels/model_MSM.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/models/nullmodels/model_MSM.py b/models/nullmodels/model_MSM.py new file mode 100644 index 0000000..2c30df5 --- /dev/null +++ b/models/nullmodels/model_MSM.py @@ -0,0 +1,65 @@ +#### +## +## +## Create a synthetic multiplex network in which a node $i$ appears at +## each layer $\alpha$ with a probability equal to $B_i$, which is the +## fraction of layers in which node $i$ participate in the original +## multiplex. +## +## Take a file of node binary participation indices, and sample a +## multiplex compatible with that distribution +## +## +## The input file is in the format: +## +## nodeID_i B_i +## +## 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 <filein> <M>" % sys.argv[0] + sys.exit(1) + +M = int(sys.argv[2]) + +bin_index = {} +node_ids = [] + +lines = open(sys.argv[1]).readlines() + + +for l in lines: + if l[0] == "#": + continue + elems = [int(x) for x in l.strip(" \n").split(" ")] + bin_index[elems[0]] = 1.0 * elems[1]/M + node_ids.append(elems[0]) + +N = len(node_ids) + +node_layers = {} + +for alpha in range (M): + for i in node_ids: + val = random.random() + if val < bin_index[i]: + if node_layers.has_key(i): + node_layers[i].append(alpha) + else: + node_layers[i] = [alpha] + + +for i in node_ids: + if node_layers.has_key(i): + for j in range(len(node_layers[i])): + print i, node_layers[i][j] + |