Revision | feb0096336fc5b85e6e43481b48a74591cfc504a (tree) |
---|---|
Zeit | 2009-11-10 21:42:33 |
Autor | lorenzo |
Commiter | lorenzo |
I modified this code which now provides an alternative (and equivalent) method
for the calculation of the distribution of visits duration given a time-
dependent edge-list which does not require any filtering. Also, I modified
the definition of visit duration adding an extra 20 seconds (the duration of
a timeslice).
@@ -2,14 +2,16 @@ | ||
2 | 2 | import scipy as s |
3 | 3 | import pylab as p |
4 | 4 | import numpy as n |
5 | +import sys | |
6 | +import string | |
5 | 7 | |
6 | 8 | |
7 | -def get_duration(presence_list): | |
9 | +def get_duration(presence_list, delta_slice): | |
8 | 10 | tag_id_list=s.unique1d(presence_list[:,1]) |
9 | 11 | duration_list=s.arange(len(tag_id_list)) |
10 | 12 | for i in xrange(len(tag_id_list)): |
11 | 13 | tag_sel=s.where(presence_list[:,1]==tag_id_list[i])[0] |
12 | - duration_list[i]=max(presence_list[tag_sel,0])-min(presence_list[tag_sel,0]) | |
14 | + duration_list[i]=max(presence_list[tag_sel,0])-min(presence_list[tag_sel,0])+delta_slice | |
13 | 15 | |
14 | 16 | #there may be problems with tags which are observed only once, hence the |
15 | 17 | #corresponding visit duration would be 0, whereas I simply cannot define it |
@@ -20,11 +22,56 @@ | ||
20 | 22 | |
21 | 23 | return (duration_list) |
22 | 24 | |
23 | -presence_list=p.load("presence.dat") | |
24 | -presence_list=presence_list.astype("int") | |
25 | +def duplicate_and_mix_array(my_2d_arr): | |
25 | 26 | |
26 | -visit_duration=get_duration(presence_list) | |
27 | + #this function is useful to cast the time-dependent edge list | |
28 | + #into a shape more similar to the bootcount list. | |
29 | + | |
30 | + new_arr=s.zeros(2*2*len(my_2d_arr)).reshape((2*len(my_2d_arr),2)) | |
27 | 31 | |
28 | -p.save("conference_visit_duration.dat",visit_duration,fmt='%d') | |
32 | + new_arr=new_arr.astype("int64") | |
33 | + sel_even=s.arange(0,len(new_arr),2) | |
34 | + | |
35 | + sel_odd=s.arange(1,len(new_arr),2) | |
36 | + | |
37 | + new_arr[sel_odd,0]=my_2d_arr[:,0] | |
38 | + new_arr[sel_even,0]=my_2d_arr[:,0] | |
39 | + | |
40 | + new_arr[sel_odd,1]=my_2d_arr[:,2] | |
41 | + | |
42 | + new_arr[sel_even,1]=my_2d_arr[:,1] | |
43 | + | |
44 | + return (new_arr) | |
45 | + | |
46 | + | |
47 | + | |
48 | +read_edgelist=1 #it tells whether the data are already in the form of an edgelist or not. | |
49 | + | |
50 | +filename=sys.argv[1] | |
51 | + | |
52 | +f = open(filename) | |
53 | +presence_list = [map(int, string.split(line)) for line in f.readlines()] | |
54 | +f.close() | |
55 | + | |
56 | +presence_list = s.array(presence_list, dtype="int64") | |
57 | + | |
58 | +delta_slice=20 #number of seconds | |
59 | + | |
60 | +if (read_edgelist!=1): | |
61 | + | |
62 | + visit_duration=get_duration(presence_list, delta_slice) | |
63 | + | |
64 | + n.savetxt("visit_duration_afresh.dat",visit_duration,fmt='%d') | |
65 | + | |
66 | +else: | |
67 | + presence_list =duplicate_and_mix_array(presence_list) | |
68 | + | |
69 | + n.savetxt("presence_list_afresh.dat",presence_list,fmt='%d') | |
70 | + | |
71 | + visit_duration=get_duration(presence_list, delta_slice) | |
72 | + | |
73 | + n.savetxt("visit_duration_afresh.dat",visit_duration,fmt='%d') | |
74 | + | |
75 | + | |
29 | 76 | |
30 | 77 | print "So far so good" |