Revision | 31c3e30fd22f0a0ad951b5ffe92b2b1c7c590050 (tree) |
---|---|
Time | 2010-06-07 21:45:40 |
Author | lorenzo |
Commiter | lorenzo |
Some improvements to the code: I can now remove self-interactions in
the time-dependent edge list.
@@ -23,6 +23,16 @@ | ||
23 | 23 | return new_info |
24 | 24 | |
25 | 25 | |
26 | +def remove_self_loops(clean_data): | |
27 | + sel=s.where(clean_data[:,1]!=clean_data[:,2])[0] | |
28 | + | |
29 | + clean_data_no_int=clean_data[sel,:] | |
30 | + | |
31 | + return (clean_data_no_int.astype("int64")) | |
32 | + | |
33 | + | |
34 | + | |
35 | +no_self=1 | |
26 | 36 | |
27 | 37 | #NB: this code should be used on an edgelist without self-interactions |
28 | 38 |
@@ -30,6 +40,13 @@ | ||
30 | 40 | info = [map(int, string.split(line)) for line in f.readlines()] |
31 | 41 | f.close() |
32 | 42 | |
43 | +if (no_self==1): | |
44 | + | |
45 | + info=s.array(info, dtype="int64") | |
46 | + | |
47 | + info=remove_self_loops(info) | |
48 | + | |
49 | + info=info.tolist() | |
33 | 50 | |
34 | 51 | new = get_times(info) |
35 | 52 | contacts = new.keys() |
@@ -70,11 +87,21 @@ | ||
70 | 87 | |
71 | 88 | all_times=s.asarray(all_times, dtype="int64") |
72 | 89 | |
73 | -n.savetxt("t_ab_t_ac.dat",all_times, fmt='%d') | |
90 | +if (no_self==1): | |
74 | 91 | |
75 | -sel=s.where(all_times>0) | |
92 | + n.savetxt("t_ab_t_ac_no_self.dat",all_times, fmt='%d') | |
76 | 93 | |
77 | -n.savetxt("t_ab_t_ac_no_zero.dat",all_times[sel], fmt='%d') | |
94 | + sel=s.where(all_times>0) | |
95 | + | |
96 | + n.savetxt("t_ab_t_ac_no_self_no_zero.dat",all_times[sel], fmt='%d') | |
97 | + | |
98 | +else : | |
99 | + | |
100 | + n.savetxt("t_ab_t_ac.dat",all_times, fmt='%d') | |
101 | + | |
102 | + sel=s.where(all_times>0) | |
103 | + | |
104 | + n.savetxt("t_ab_t_ac_no_zero.dat",all_times[sel], fmt='%d') | |
78 | 105 | |
79 | 106 | |
80 | 107 | print ("So far so good") |