• R/O
  • SSH

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

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

Commit MetaInfo

Revision3d3bd6336937f3c21376f7376bf57e1364e1f943 (tree)
Zeit2010-07-16 19:51:49
Autorlorenzo
Commiterlorenzo

Log Message

I updated the script; now it is on par with the un-branched version.
Be careful: I replaced a "<" with a "<=" in the role in the definition of time_list
in the main code (loop executed at the end of the code, NOT any function definition).
This is wrong as some slices would be counted twice, but I did that just as a test.

Ändern Zusammenfassung

Diff

diff -r 3b3765ab3ee7 -r 3d3bd6336937 Python-codes/iterate_tag_statistics_from_new_output_branch_1.py
--- a/Python-codes/iterate_tag_statistics_from_new_output_branch_1.py Tue Jul 13 16:35:39 2010 +0000
+++ b/Python-codes/iterate_tag_statistics_from_new_output_branch_1.py Fri Jul 16 10:51:49 2010 +0000
@@ -11,10 +11,18 @@
1111 #only with contact protocols
1212
1313 def generate_iteration_grid(boot_time_non_unique,\
14- number_intervals,interval_duration,ini_gap):
14+ number_intervals,interval_duration,t_ini,t_end):
1515 time_unique=s.unique1d(boot_time_non_unique)
1616
17- time_ini=time_unique[0]+ini_gap
17+ # time_ini=time_unique[0]+ini_gap
18+
19+
20+ if (t_ini>0):
21+ time_ini=t_ini
22+ else:
23+ time_ini=time_unique[0]
24+
25+
1826 print "time_ini is, ", time_ini
1927
2028 if (number_intervals<=0 and interval_duration<=0):
@@ -25,40 +33,22 @@
2533 print "Error in calling the function"
2634 #break
2735 if (number_intervals>0 and interval_duration<=0):
28- time_grid=s.linspace(time_ini,time_unique[-1],number_intervals+1)
36+ if (t_end<=0):
37+ time_grid=s.linspace(time_ini,time_unique[-1],number_intervals)
38+ elif (t_end>0):
39+ time_grid=s.linspace(time_ini,t_end,number_intervals)
40+
2941
3042 if (number_intervals<=0 and interval_duration>0):
31- time_grid=s.arange(time_ini,time_unique[-1],interval_duration)
43+ if (t_end<=0):
44+ time_grid=s.arange(time_ini,time_unique[-1],interval_duration)
45+ if (t_end>0):
46+ time_grid=s.arange(time_ini,t_end,interval_duration)
47+
3248
3349 return (time_grid.astype("int64"))
3450
3551
36-def decompose_hash_64(my_hashed_number,my_len):
37- #this function takes a 64-bit number and decomposes it into 4 16-bit
38- #integers, namely tag_id A, boot A, tag_id B, boot B.
39-
40- ini_arr=s.zeros(4).astype("int64")
41- arr_long=s.zeros(4*my_len).reshape(my_len,4).astype("int64")
42-
43- first_part = my_hashed_number >> 32 #to get back the 1st argument
44- second_part = my_hashed_number & 0xFFFFFFFF #to get back the second argument
45-
46- tag_A = first_part >> 16
47- boot_A= first_part & 0xFFFF
48-
49- tag_B=second_part >> 16
50- boot_B= second_part & 0xFFFF
51-
52- ini_arr[0]=tag_A
53- ini_arr[1]=boot_A
54- ini_arr[2]=tag_B
55- ini_arr[3]=boot_B
56-
57- for i in xrange(my_len):
58- arr_long[i, :]=ini_arr
59-
60- return (arr_long)
61-
6252
6353 def contact_duration_and_interval_single_couple(time_list, delta_slice):
6454 #this function is modelled on contact_duration_and_interval_single_tag.
@@ -73,10 +63,6 @@
7363
7464
7565 time_list=(time_list-time_list[0])/delta_slice
76-
77-
78-
79-
8066 gaps=s.diff(time_list) #a bit more efficient than the line above
8167
8268 #print "gaps is, ", gaps
@@ -89,9 +75,7 @@
8975
9076 #p.save("gaps.dat",gaps, fmt='%d')
9177
92- # find_gap=s.where(gaps != 1)[0]
93-
94- find_gap=s.where(gaps > 1)[0]
78+ find_gap=s.where(gaps != 1)[0]
9579
9680 gap_distr=(gaps[find_gap]-1)*delta_slice #so, this is really the list of the
9781 #time interval between two contacts for my tag. After the discussion with Ciro,
@@ -139,6 +123,9 @@
139123
140124 res=res*delta_slice
141125
126+ #Now I add some extra calculations. I also want to save the beginning and
127+ #end time of each contact
128+
142129 contact_begin=s.zeros(1)
143130 contact_end=s.zeros(1)
144131
@@ -168,11 +155,23 @@
168155 contact_begin=s.hstack((tag_times[0],tag_times[find_gap+1]))
169156 contact_end=s.hstack((tag_times[find_gap],tag_times[-1]))
170157
158+ # if (0 in contact_begin or 0 in contact_end):
159+ # print "error with a zero!"
160+
161+ # print "len(find_gap) is, ", len(find_gap)
162+ # print "len(res) is, ", len(res)
163+
164+ # print "res is, ", res
165+ # print "contact_begin is, ", contact_begin
166+ # print "contact_end is, ", contact_end
167+ # print "contact_end-contact_begin is, ",contact_end-contact_begin
168+ # print "tag_times is, ", tag_times
169+
171170
172171
173172 #print "the sum of all the durations is, ", res.sum()
174173
175- return [res,gap_distr,contact_begin,contact_end]
174+ return [res,gap_distr, contact_begin, contact_end]
176175
177176
178177
@@ -239,12 +238,11 @@
239238 print "The chosen tag does not exist hence no analysis can be performed on it"
240239 return
241240
241+ tag_times=s.copy(single_tag_no_rep)
242242
243243
244244 # delta_slice=int(delta_slice) #I do not need floating point arithmetic
245245
246- tag_times=s.copy(single_tag_no_rep)
247-
248246 single_tag_no_rep=(single_tag_no_rep-single_tag_no_rep[0])/delta_slice
249247 gaps=s.diff(single_tag_no_rep) #a bit more efficient than the line above
250248
@@ -266,6 +264,7 @@
266264 #from all the others when I see an increment larger than one in the
267265 #rescaled time.
268266
267+
269268 gap_distr=(gaps[find_gap]-1)*delta_slice #so, this is really the list of the
270269 #time interval between two contacts for my tag. After the discussion with Ciro,
271270 #I modified slightly the definition (now there is a -1) in the definition.
@@ -314,7 +313,9 @@
314313
315314 res=res*delta_slice
316315
317- #Now I add some extra calculations. I also want to save the beginning and
316+
317+
318+ #Now I add some extra calculations. I also want to save the beginning and
318319 #end time of each contact
319320
320321 contact_begin=s.zeros(1)
@@ -357,8 +358,12 @@
357358 # print "contact_end is, ", contact_end
358359 # print "contact_end-contact_begin is, ",contact_end-contact_begin
359360 # print "tag_times is, ", tag_times
360-
361361
362+
363+
364+ #print "the sum of all the durations is, ", res.sum()
365+
366+ # return [res,gap_distr]
362367 return [res,gap_distr, contact_begin, contact_end]
363368
364369 def contact_duration_and_interval_many_tags(sliced_interactions,\
@@ -375,6 +380,13 @@
375380 tag_ids= n.unique1d(s.ravel(sliced_interactions[:,1:3])) #to get a list of
376381 #all tag ID`s, which appear (repeated) on two rows of the matrix output by
377382 # time_binned_interaction
383+
384+ n.savetxt("list_interacting_tag_ids.dat", tag_ids , fmt='%d')
385+
386+
387+
388+ #n.savetxt("tag_IDs.dat", tag_ids , fmt='%d')
389+
378390
379391 # tag_ids=tag_ids.astype('int')
380392
@@ -395,7 +407,6 @@
395407 overall_end_contacts=s.zeros(0)
396408
397409
398-
399410 for i in xrange(len(tag_ids)):
400411 track_tag_id=tag_ids[i] #i.e. iterate on all tags
401412
@@ -404,25 +415,19 @@
404415
405416 #print "contact_times is, ", contact_times
406417
407- # if (i==0):
408- # p.save("contact_times_single_tag.dat",contact_times, fmt="%d")
409- # p.save("contact_times_single_tag_remapped.dat",\
410- # (contact_times-contact_times[0])/delta_slice, fmt="%d")
411-
412-
413418 results=contact_duration_and_interval_single_tag(contact_times, delta_slice)
414419
415420 tag_duration=results[0]
416- # if (i==0):
417- # p.save("duration_single_tag.dat",tag_duration, fmt="%d")
418421
419422
420423 tag_intervals=results[1] #get
421424 #an array with the time intervals between two contacts for a given tag
422425
426+
423427 tag_contact_begin=results[2]
424428 tag_contact_end=results[3]
425-
429+
430+
426431
427432 #print "tag_intervals is, ", tag_intervals
428433
@@ -434,42 +439,27 @@
434439 overall_end_contacts= \
435440 s.hstack((overall_end_contacts,tag_contact_end))
436441
442+
443+
444+
437445 #print "overall_gaps is, ", overall_gaps
438446
439447 overall_duration=s.hstack((overall_duration,tag_duration))
440448
441-
442- # print "overall_begin_contacts.shape is, ",overall_begin_contacts.shape
443- # print "overall_end_contacts.shape is, ",overall_end_contacts.shape
444- # print "overall_duration.shape is, ",overall_duration.shape
445-
446449 #overall_gaps=overall_gaps[s.where(overall_gaps !=0)]
447450 #overall_duration=overall_duration[s.where(overall_duration !=0)]
448451 filename="many_tags_contact_interval_distr2_%01d"%(counter+1)
449452 filename=filename+"_.dat"
450453
451- p.save(filename, overall_gaps , fmt='%d')
454+ n.savetxt(filename, overall_gaps , fmt='%d')
452455
453456 filename="many_tags_contact_duration_distr2_%01d"%(counter+1)
454457 filename=filename+"_.dat"
455458
456- p.save(filename, overall_duration , fmt='%d')
457-
458- # print "overall_duration,overall_begin_contacts,overall_end_contacts are, ",
459- # overall_duration,overall_begin_contacts, \
460- # overall_end_contacts
461459
462- overall_duration_and_start_end= \
463- s.vstack((overall_duration,overall_begin_contacts, \
464- overall_end_contacts))
460+ n.savetxt(filename, overall_duration , fmt='%d')
465461
466- filename="many_tags_contact_duration_distr_extended_%01d"%(counter+1)
467- filename=filename+"_.dat"
468-
469- p.save(filename, overall_duration_and_start_end.transpose() , fmt='%d')
470-
471-
472- return 0 #I have no need to return anythin else at this point
462+ return overall_duration, overall_gaps
473463
474464 # def my_hash(arr):
475465 # my_hash=hash((arr[0], arr[1]))
@@ -477,17 +467,20 @@
477467 # return my_hash
478468
479469
470+
471+
480472 def my_hash(arr): #this will operate on a similar function which
481473 #has already combined tag_id and bootcount (both taking 16 bites each)
482474
483475 # my_hash(arr) >> 32 to get back the 1st argument
484476 # my_hash(arr) & 0xFFFFFFFF to get back the second argument
485477
478+ arr=s.sort(arr) #maybe this is not needed at all; the rows of sliced data (which are arr)
479+ #are already sorted out elsewhere.
480+
486481 return (arr[0] << 32) | arr[1]
487482
488483
489-
490-
491484 def couple_hash_table(sliced_data,counter):
492485 hash_list=s.arange(len(sliced_data))
493486
@@ -501,13 +494,13 @@
501494 filename=filename+"_.dat"
502495
503496
504- p.save(filename, hash_and_time,fmt='%d')
497+ n.savetxt(filename, hash_and_time,fmt='%d')
505498
506499 #the aim of this function is to identify each reported binary contact with a single number.
507500 #then, instead of looking for couples of interacting tags, I will simply look for repeated
508501 #occurrences of a number
509502
510- return hash_and_time
503+ return hash_and_time.astype("int64")
511504
512505 def detect_binary_contacts_among_same_two_tags(hash_and_time,\
513506 delta_slice, counter):
@@ -521,28 +514,30 @@
521514 time_arr=hash_and_time[:,0] #important! Measure everything in units
522515 #of delta_slice
523516
524- couple_interaction_duration=s.zeros(0) #this array will store the times at which the SAME
517+ couple_interaction_duration=s.zeros(0).astype("int64") #this array will store the times at which the SAME
525518 #i-j tags interact.
526519
527- couple_interaction_interval=s.zeros(0)
520+ couple_interaction_interval=s.zeros(0).astype("int64")
521+
522+ record_hash=s.zeros(0).astype("int64")
523+
524+ hash_list_overall=s.zeros(0).astype("int64")
528525
529526
530- overall_begin_contacts=s.zeros(0)
531-
532- overall_end_contacts=s.zeros(0)
527+ overall_begin_contacts=s.zeros(0).astype("int64")
533528
534- overall_extended_info=-s.ones(4).astype("int64")
535-
529+ overall_end_contacts=s.zeros(0).astype("int64")
536530
537-
531+ # overall_extended_info=-s.ones(4).astype("int64")
532+
533+ overall_extended_info=-s.ones(2).astype("int64")
534+
538535
539536 for i in xrange(len(couple_list_unique)):
540537 chosen_couple=couple_list_unique[i]
541538 sel_chosen_couple_times=s.where(couple_list==chosen_couple)
542539 chosen_couple_times=time_arr[sel_chosen_couple_times]
543-
544-
545- # print "chosen_couple is, ", chosen_couple
540+ #print "i is, ", i
546541 #print "chosen_couple_times is, ", chosen_couple_times
547542 chosen_couple_contact_duration= \
548543 contact_duration_and_interval_single_couple(chosen_couple_times, delta_slice)[0]
@@ -550,44 +545,72 @@
550545 chosen_couple_contact_interval= \
551546 contact_duration_and_interval_single_couple(chosen_couple_times, delta_slice)[1]
552547
553-
548+ couple_interaction_duration=s.hstack((couple_interaction_duration,\
549+ chosen_couple_contact_duration))
550+
551+ couple_interaction_interval=s.hstack((couple_interaction_interval,\
552+ chosen_couple_contact_interval))
553+
554+ hash_in_iter=s.ones(len(chosen_couple_contact_duration)).astype("int64")\
555+ *chosen_couple
556+
557+ record_hash=s.hstack((record_hash,hash_in_iter))
558+
559+ interacting_couple_arr=s.ones(len(chosen_couple_contact_duration)).astype("int64")*chosen_couple
560+
561+ hash_list_overall=s.hstack((hash_list_overall,interacting_couple_arr))
562+
563+
554564 tag_contact_begin=\
555565 contact_duration_and_interval_single_couple(chosen_couple_times, delta_slice)[2]
556566 tag_contact_end=\
557567 contact_duration_and_interval_single_couple(chosen_couple_times, delta_slice)[3]
558568
559569
560- couple_interaction_duration=s.hstack((couple_interaction_duration,\
561- chosen_couple_contact_duration))
562570
563- couple_interaction_interval=s.hstack((couple_interaction_interval,\
564- chosen_couple_contact_interval))
565571
566572 overall_begin_contacts= \
567573 s.hstack((overall_begin_contacts,tag_contact_begin))
568574 overall_end_contacts= \
569575 s.hstack((overall_end_contacts,tag_contact_end))
570576
571- extended_info=decompose_hash_64(chosen_couple,len(tag_contact_begin))
577+ # extended_info=decompose_hash_64(chosen_couple,len(tag_contact_begin))
578+
579+ extended_info=decompose_hash_32_vec(chosen_couple,len(tag_contact_begin))
580+
581+
582+ # print "extended_info is, ", extended_info
583+
584+
585+
586+
587+
588+
572589
573590 overall_extended_info=s.vstack((overall_extended_info,extended_info))
574591
575592
576593
594+ filename="hashed_couples_corresponding_to_contact_duration_times_%01d"%(counter+1)
595+ filename=filename+"_.dat"
596+
597+
577598 filename="couple_interaction_duration_times_%01d"%(counter+1)
578599 filename=filename+"_.dat"
579600
580601
581- p.save(filename, couple_interaction_duration,fmt='%d')
602+ n.savetxt(filename, couple_interaction_duration,fmt='%d')
582603
583604 filename="couple_interaction_interval_times_%01d"%(counter+1)
584605 filename=filename+"_.dat"
585606
586607
587- p.save(filename, couple_interaction_interval,fmt='%d')
608+ n.savetxt(filename, couple_interaction_interval,fmt='%d')
588609
589- # print "couple_interaction_duration.shape is, ",\
590- # couple_interaction_duration.shape
610+ filename="hashed_couples_in_contact_durations_%01d"%(counter+1)
611+ filename=filename+"_.dat"
612+
613+ n.savetxt(filename, record_hash,fmt='%d')
591614
592615
593616
@@ -614,11 +637,98 @@
614637 filename="couple_interaction_duration_times_extended_%01d"%(counter+1)
615638 filename=filename+"_.dat"
616639
617- p.save(filename, overall_duration_and_start_end , fmt='%d')
640+ n.savetxt(filename, overall_duration_and_start_end , fmt='%d')
618641
619642
620643
621- return couple_interaction_duration
644+ return [couple_interaction_duration,hash_list_overall]
645+
646+
647+
648+def decompose_hash_64(my_hashed_number,my_len):
649+ #this function takes a 64-bit number and decomposes it into 4 16-bit
650+ #integers, namely tag_id A, boot A, tag_id B, boot B.
651+
652+ ini_arr=s.zeros(4).astype("int64")
653+ arr_long=s.zeros(4*my_len).reshape(my_len,4).astype("int64")
654+
655+ first_part = my_hashed_number >> 32 #to get back the 1st argument
656+ second_part = my_hashed_number & 0xFFFFFFFF #to get back the second argument
657+
658+ tag_A = first_part >> 16
659+ boot_A= first_part & 0xFFFF
660+
661+ tag_B=second_part >> 16
662+ boot_B= second_part & 0xFFFF
663+
664+ ini_arr[0]=tag_A
665+ ini_arr[1]=boot_A
666+ ini_arr[2]=tag_B
667+ ini_arr[3]=boot_B
668+
669+ for i in xrange(my_len):
670+ arr_long[i, :]=ini_arr
671+
672+ return (arr_long)
673+
674+
675+
676+
677+def decompose_hash_32(my_hashed_number):
678+ #this function takes a 64-bit number and decomposes it into 4 16-bit
679+ #integers, namely tag_id A, boot A, tag_id B, boot B.
680+
681+ ini_arr=s.zeros(2).astype("int64")
682+
683+ tag_A = my_hashed_number >> 32
684+ tag_B= my_hashed_number & 0xFFFFFFFF
685+
686+ ini_arr[0]=tag_A
687+ ini_arr[1]=tag_B
688+
689+ return (ini_arr)
690+
691+
692+
693+
694+def decompose_hash_32_vec(my_hashed_number,my_len):
695+ #this function takes a 64-bit number and decomposes it into 4 16-bit
696+ #integers, namely tag_id A, boot A, tag_id B, boot B.
697+
698+ ini_arr=s.zeros(2).astype("int64")
699+ arr_long=s.zeros(2*my_len).reshape(my_len,2).astype("int64")
700+
701+ # first_part = my_hashed_number >> 32 #to get back the 1st argument
702+ # second_part = my_hashed_number & 0xFFFFFFFF #to get back the second argument
703+
704+ # tag_A = first_part >> 16
705+ # boot_A= first_part & 0xFFFF
706+
707+ # tag_B=second_part >> 16
708+ # boot_B= second_part & 0xFFFF
709+
710+
711+ tag_A = my_hashed_number >> 32
712+ tag_B= my_hashed_number & 0xFFFFFFFF
713+
714+ ini_arr[0]=tag_A
715+ ini_arr[1]=tag_B
716+
717+
718+ # ini_arr[0]=tag_A
719+ # ini_arr[1]=boot_A
720+ # ini_arr[2]=tag_B
721+ # ini_arr[3]=boot_B
722+
723+ for i in xrange(my_len):
724+ arr_long[i, :]=ini_arr
725+
726+ # print "arr_long is, ", arr_long
727+
728+ return (arr_long)
729+
730+
731+
622732
623733
624734 def remove_self_loops_and_save(slice_lump):
@@ -647,10 +757,13 @@
647757 #sliced_interactions=p.load("sliced_dynamics.dat")
648758 #sliced_interactions=p.load("edge_list.dat")
649759
650-ini_gap=1240876800-1240092599 # 86400 #i.e. one day in seconds
760+t_ini=1254384000 # 86400 #i.e. one day in seconds
651761
652-number_intervals=-12
653-interval_duration= 86400 #i.e. one day in seconds
762+number_intervals=1
763+interval_duration= -86400 #i.e. 1 day #604800 #i.e. one week in seconds
764+t_end= 1254391200 #i.e. I choose when to end the time grid
765+#whereas with a negative value of time_end everything is as it used to be.
766+
654767
655768 f = open(sys.argv[1])
656769 sliced_interactions = [map(int, string.split(line)) for line in f.readlines()]
@@ -665,9 +778,12 @@
665778 time_non_unique=sliced_interactions[:,0]
666779
667780 time_grid= generate_iteration_grid(time_non_unique,\
668- number_intervals,interval_duration,ini_gap)
781+ (number_intervals+1),interval_duration,t_ini,t_end)
669782
670-p.save("time_grid.dat", time_grid, fmt="%d")
783+print "time_grid is, ", time_grid
784+
785+n.savetxt("time_grid.dat", time_grid, fmt="%d")
786+
671787
672788 file_list=-s.ones(len(time_grid))
673789
@@ -676,7 +792,7 @@
676792 print "m+1 is, ", m+1
677793
678794 time_sel=s.where((time_non_unique>= time_grid[m]) & \
679- (time_non_unique< time_grid[m+1]))[0]
795+ (time_non_unique<= time_grid[m+1]))[0]
680796
681797 sliced_interactions_sel=sliced_interactions[time_sel,:]
682798
@@ -684,13 +800,31 @@
684800 file_list[m]=m+1
685801
686802
803+ if (len(time_grid==2)): #then I just have a single interval I am going to save
804+ n.savetxt("raw_interactions_before_processing.dat", sliced_interactions_sel,fmt="%d")
805+
806+
687807 contact_duration_and_interval_many_tags(sliced_interactions_sel,\
688808 delta_slice,m)
689809
690810 hash_and_time=couple_hash_table(sliced_interactions_sel,m)
691811
692812
693- detect_binary_contacts_among_same_two_tags(hash_and_time, delta_slice,m)
813+ binary_statistics=detect_binary_contacts_among_same_two_tags(hash_and_time, delta_slice,m)
814+
815+ tag_couples=s.arange(2*len(binary_statistics[1])).reshape((len(binary_statistics[1]),2)).astype("int64")
816+
817+ for q in xrange(len(binary_statistics[1])):
818+ tag_couples[q,:]=decompose_hash_32(binary_statistics[1][q])
819+
820+ filename="decomposed_hashed_couples_corresponding_to_contact_duration_times_%01d"%(m+1)
821+ filename=filename+"_.dat"
822+
823+
824+ n.savetxt(filename,tag_couples ,fmt='%d')
825+
826+
827+
694828
695829
696830 sel=s.where(file_list>0)
@@ -700,7 +834,7 @@
700834 #print "file_list is, ", file_list
701835
702836
703-p.save("file_list.dat", file_list, fmt='%d')
837+n.savetxt("file_list.dat", file_list, fmt='%d')
704838
705839
706840