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_layer_growth.py | |
parent | 363274e79eade464247089c105260bc34940da07 (diff) |
First commit of MAMMULT code
Diffstat (limited to 'models/nullmodels/model_layer_growth.py')
-rw-r--r-- | models/nullmodels/model_layer_growth.py | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/models/nullmodels/model_layer_growth.py b/models/nullmodels/model_layer_growth.py new file mode 100644 index 0000000..46b4c0f --- /dev/null +++ b/models/nullmodels/model_layer_growth.py @@ -0,0 +1,121 @@ +#### +## +## layer-by-layer multiplex growth +## +## - We start from a multiplex with M_0 layers, with a certain number of +## active nodes each +## +## - Each new layer arrives with a certain number N\lay{\alpha} of nodes +## to be activated (this number is sampled from the observed distribution +## of N\lay{\alpha}, like in the airlines multiplex) +## +## - Each node $i$ is activated with a probability proportional to the +## number of existing layers in which it is already active, added to an +## attractivity A : +## +## P_i(t) \propto A + B_i(t) +## +## - the hope is that A might tune the exponent of the resulting distribution +## of B_i..... +## +## +## This script takes as input a file which contains the degrees of the +## layers, the total number of nodes in the multiplex, the initial +## number M0 of layers in the multiplex and the attractiveness +## parameter A. If "RND" is specified as a third parameter, then the +## sequence of N\lay{\alpha} is shuffled +## +## Gives as output a list of node-layer participation +## + +import sys +import random + +if len(sys.argv) < 5: + print "Usage: %s <layers_N> <N> <M0> <A> [RND]" % sys.argv[0] + sys.exit(1) + +N = int(sys.argv[2]) +M0 = int(sys.argv[3]) +A = int(sys.argv[4]) + +layer_degs = [] + + +if len(sys.argv) > 5 and sys.argv[5] == "RND": + randomize = True +else: + randomize = False + +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 + + +if randomize: + random.shuffle(layer_degs) + +## the list node_Bi contains, at each time, the attachment +## probabilities, i.e. it is a list which contains each node $i$ +## exactly $A + B_i$ times + +node_Bi = [] + +# +# initialize the distribution of attachment proibabilities, giving to +# all nodes an attachment probability equal to A +# + +for i in range(N): + for j in range(A): + node_Bi.append(i) + +layers = [] + + +for i in range(M0): + N_alpha = layer_degs.pop() + node_list = [] + num_nodes = 0 + while num_nodes < N_alpha: + val = random.choice(range(N)) + if val not in node_list: + node_list.append(val) + num_nodes += 1 + for n in node_list: + node_Bi.append(n) + layers.append(node_list) + i += 1 + + +#sys.exit(1) + +while i < M: + N_alpha = layer_degs.pop() + node_list = [] + num_nodes = 0 + while num_nodes < N_alpha: + val = random.choice(node_Bi) + if val not in node_list: + node_list.append(val) + num_nodes += 1 + for n in node_list: + node_Bi.append(n) + layers.append(node_list) + i += 1 + +#print layers + +for i in range(M): + node_list = layers[i] + for n in node_list: + print n, i + |