• R/O
  • SSH

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisionfeb0096336fc5b85e6e43481b48a74591cfc504a (tree)
Time2009-11-10 21:42:33
Authorlorenzo
Commiterlorenzo

Log Message

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).

Change Summary

Incremental Difference

diff -r 7c9e2f6d1666 -r feb0096336fc Python-codes/get_presence_duration.py
--- a/Python-codes/get_presence_duration.py Mon Nov 09 14:06:12 2009 +0000
+++ b/Python-codes/get_presence_duration.py Tue Nov 10 12:42:33 2009 +0000
@@ -2,14 +2,16 @@
22 import scipy as s
33 import pylab as p
44 import numpy as n
5+import sys
6+import string
57
68
7-def get_duration(presence_list):
9+def get_duration(presence_list, delta_slice):
810 tag_id_list=s.unique1d(presence_list[:,1])
911 duration_list=s.arange(len(tag_id_list))
1012 for i in xrange(len(tag_id_list)):
1113 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
1315
1416 #there may be problems with tags which are observed only once, hence the
1517 #corresponding visit duration would be 0, whereas I simply cannot define it
@@ -20,11 +22,56 @@
2022
2123 return (duration_list)
2224
23-presence_list=p.load("presence.dat")
24-presence_list=presence_list.astype("int")
25+def duplicate_and_mix_array(my_2d_arr):
2526
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))
2731
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+
2976
3077 print "So far so good"