Revision | 3d3bd6336937f3c21376f7376bf57e1364e1f943 (tree) |
---|---|
Time | 2010-07-16 19:51:49 |
Author | lorenzo |
Commiter | lorenzo |
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.
@@ -11,10 +11,18 @@ | ||
11 | 11 | #only with contact protocols |
12 | 12 | |
13 | 13 | def generate_iteration_grid(boot_time_non_unique,\ |
14 | - number_intervals,interval_duration,ini_gap): | |
14 | + number_intervals,interval_duration,t_ini,t_end): | |
15 | 15 | time_unique=s.unique1d(boot_time_non_unique) |
16 | 16 | |
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 | + | |
18 | 26 | print "time_ini is, ", time_ini |
19 | 27 | |
20 | 28 | if (number_intervals<=0 and interval_duration<=0): |
@@ -25,40 +33,22 @@ | ||
25 | 33 | print "Error in calling the function" |
26 | 34 | #break |
27 | 35 | 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 | + | |
29 | 41 | |
30 | 42 | 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 | + | |
32 | 48 | |
33 | 49 | return (time_grid.astype("int64")) |
34 | 50 | |
35 | 51 | |
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 | - | |
62 | 52 | |
63 | 53 | def contact_duration_and_interval_single_couple(time_list, delta_slice): |
64 | 54 | #this function is modelled on contact_duration_and_interval_single_tag. |
@@ -73,10 +63,6 @@ | ||
73 | 63 | |
74 | 64 | |
75 | 65 | time_list=(time_list-time_list[0])/delta_slice |
76 | - | |
77 | - | |
78 | - | |
79 | - | |
80 | 66 | gaps=s.diff(time_list) #a bit more efficient than the line above |
81 | 67 | |
82 | 68 | #print "gaps is, ", gaps |
@@ -89,9 +75,7 @@ | ||
89 | 75 | |
90 | 76 | #p.save("gaps.dat",gaps, fmt='%d') |
91 | 77 | |
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] | |
95 | 79 | |
96 | 80 | gap_distr=(gaps[find_gap]-1)*delta_slice #so, this is really the list of the |
97 | 81 | #time interval between two contacts for my tag. After the discussion with Ciro, |
@@ -139,6 +123,9 @@ | ||
139 | 123 | |
140 | 124 | res=res*delta_slice |
141 | 125 | |
126 | + #Now I add some extra calculations. I also want to save the beginning and | |
127 | + #end time of each contact | |
128 | + | |
142 | 129 | contact_begin=s.zeros(1) |
143 | 130 | contact_end=s.zeros(1) |
144 | 131 |
@@ -168,11 +155,23 @@ | ||
168 | 155 | contact_begin=s.hstack((tag_times[0],tag_times[find_gap+1])) |
169 | 156 | contact_end=s.hstack((tag_times[find_gap],tag_times[-1])) |
170 | 157 | |
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 | + | |
171 | 170 | |
172 | 171 | |
173 | 172 | #print "the sum of all the durations is, ", res.sum() |
174 | 173 | |
175 | - return [res,gap_distr,contact_begin,contact_end] | |
174 | + return [res,gap_distr, contact_begin, contact_end] | |
176 | 175 | |
177 | 176 | |
178 | 177 |
@@ -239,12 +238,11 @@ | ||
239 | 238 | print "The chosen tag does not exist hence no analysis can be performed on it" |
240 | 239 | return |
241 | 240 | |
241 | + tag_times=s.copy(single_tag_no_rep) | |
242 | 242 | |
243 | 243 | |
244 | 244 | # delta_slice=int(delta_slice) #I do not need floating point arithmetic |
245 | 245 | |
246 | - tag_times=s.copy(single_tag_no_rep) | |
247 | - | |
248 | 246 | single_tag_no_rep=(single_tag_no_rep-single_tag_no_rep[0])/delta_slice |
249 | 247 | gaps=s.diff(single_tag_no_rep) #a bit more efficient than the line above |
250 | 248 |
@@ -266,6 +264,7 @@ | ||
266 | 264 | #from all the others when I see an increment larger than one in the |
267 | 265 | #rescaled time. |
268 | 266 | |
267 | + | |
269 | 268 | gap_distr=(gaps[find_gap]-1)*delta_slice #so, this is really the list of the |
270 | 269 | #time interval between two contacts for my tag. After the discussion with Ciro, |
271 | 270 | #I modified slightly the definition (now there is a -1) in the definition. |
@@ -314,7 +313,9 @@ | ||
314 | 313 | |
315 | 314 | res=res*delta_slice |
316 | 315 | |
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 | |
318 | 319 | #end time of each contact |
319 | 320 | |
320 | 321 | contact_begin=s.zeros(1) |
@@ -357,8 +358,12 @@ | ||
357 | 358 | # print "contact_end is, ", contact_end |
358 | 359 | # print "contact_end-contact_begin is, ",contact_end-contact_begin |
359 | 360 | # print "tag_times is, ", tag_times |
360 | - | |
361 | 361 | |
362 | + | |
363 | + | |
364 | + #print "the sum of all the durations is, ", res.sum() | |
365 | + | |
366 | + # return [res,gap_distr] | |
362 | 367 | return [res,gap_distr, contact_begin, contact_end] |
363 | 368 | |
364 | 369 | def contact_duration_and_interval_many_tags(sliced_interactions,\ |
@@ -375,6 +380,13 @@ | ||
375 | 380 | tag_ids= n.unique1d(s.ravel(sliced_interactions[:,1:3])) #to get a list of |
376 | 381 | #all tag ID`s, which appear (repeated) on two rows of the matrix output by |
377 | 382 | # 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 | + | |
378 | 390 | |
379 | 391 | # tag_ids=tag_ids.astype('int') |
380 | 392 |
@@ -395,7 +407,6 @@ | ||
395 | 407 | overall_end_contacts=s.zeros(0) |
396 | 408 | |
397 | 409 | |
398 | - | |
399 | 410 | for i in xrange(len(tag_ids)): |
400 | 411 | track_tag_id=tag_ids[i] #i.e. iterate on all tags |
401 | 412 |
@@ -404,25 +415,19 @@ | ||
404 | 415 | |
405 | 416 | #print "contact_times is, ", contact_times |
406 | 417 | |
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 | - | |
413 | 418 | results=contact_duration_and_interval_single_tag(contact_times, delta_slice) |
414 | 419 | |
415 | 420 | tag_duration=results[0] |
416 | - # if (i==0): | |
417 | - # p.save("duration_single_tag.dat",tag_duration, fmt="%d") | |
418 | 421 | |
419 | 422 | |
420 | 423 | tag_intervals=results[1] #get |
421 | 424 | #an array with the time intervals between two contacts for a given tag |
422 | 425 | |
426 | + | |
423 | 427 | tag_contact_begin=results[2] |
424 | 428 | tag_contact_end=results[3] |
425 | - | |
429 | + | |
430 | + | |
426 | 431 | |
427 | 432 | #print "tag_intervals is, ", tag_intervals |
428 | 433 |
@@ -434,42 +439,27 @@ | ||
434 | 439 | overall_end_contacts= \ |
435 | 440 | s.hstack((overall_end_contacts,tag_contact_end)) |
436 | 441 | |
442 | + | |
443 | + | |
444 | + | |
437 | 445 | #print "overall_gaps is, ", overall_gaps |
438 | 446 | |
439 | 447 | overall_duration=s.hstack((overall_duration,tag_duration)) |
440 | 448 | |
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 | - | |
446 | 449 | #overall_gaps=overall_gaps[s.where(overall_gaps !=0)] |
447 | 450 | #overall_duration=overall_duration[s.where(overall_duration !=0)] |
448 | 451 | filename="many_tags_contact_interval_distr2_%01d"%(counter+1) |
449 | 452 | filename=filename+"_.dat" |
450 | 453 | |
451 | - p.save(filename, overall_gaps , fmt='%d') | |
454 | + n.savetxt(filename, overall_gaps , fmt='%d') | |
452 | 455 | |
453 | 456 | filename="many_tags_contact_duration_distr2_%01d"%(counter+1) |
454 | 457 | filename=filename+"_.dat" |
455 | 458 | |
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 | |
461 | 459 | |
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') | |
465 | 461 | |
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 | |
473 | 463 | |
474 | 464 | # def my_hash(arr): |
475 | 465 | # my_hash=hash((arr[0], arr[1])) |
@@ -477,17 +467,20 @@ | ||
477 | 467 | # return my_hash |
478 | 468 | |
479 | 469 | |
470 | + | |
471 | + | |
480 | 472 | def my_hash(arr): #this will operate on a similar function which |
481 | 473 | #has already combined tag_id and bootcount (both taking 16 bites each) |
482 | 474 | |
483 | 475 | # my_hash(arr) >> 32 to get back the 1st argument |
484 | 476 | # my_hash(arr) & 0xFFFFFFFF to get back the second argument |
485 | 477 | |
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 | + | |
486 | 481 | return (arr[0] << 32) | arr[1] |
487 | 482 | |
488 | 483 | |
489 | - | |
490 | - | |
491 | 484 | def couple_hash_table(sliced_data,counter): |
492 | 485 | hash_list=s.arange(len(sliced_data)) |
493 | 486 |
@@ -501,13 +494,13 @@ | ||
501 | 494 | filename=filename+"_.dat" |
502 | 495 | |
503 | 496 | |
504 | - p.save(filename, hash_and_time,fmt='%d') | |
497 | + n.savetxt(filename, hash_and_time,fmt='%d') | |
505 | 498 | |
506 | 499 | #the aim of this function is to identify each reported binary contact with a single number. |
507 | 500 | #then, instead of looking for couples of interacting tags, I will simply look for repeated |
508 | 501 | #occurrences of a number |
509 | 502 | |
510 | - return hash_and_time | |
503 | + return hash_and_time.astype("int64") | |
511 | 504 | |
512 | 505 | def detect_binary_contacts_among_same_two_tags(hash_and_time,\ |
513 | 506 | delta_slice, counter): |
@@ -521,28 +514,30 @@ | ||
521 | 514 | time_arr=hash_and_time[:,0] #important! Measure everything in units |
522 | 515 | #of delta_slice |
523 | 516 | |
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 | |
525 | 518 | #i-j tags interact. |
526 | 519 | |
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") | |
528 | 525 | |
529 | 526 | |
530 | - overall_begin_contacts=s.zeros(0) | |
531 | - | |
532 | - overall_end_contacts=s.zeros(0) | |
527 | + overall_begin_contacts=s.zeros(0).astype("int64") | |
533 | 528 | |
534 | - overall_extended_info=-s.ones(4).astype("int64") | |
535 | - | |
529 | + overall_end_contacts=s.zeros(0).astype("int64") | |
536 | 530 | |
537 | - | |
531 | + # overall_extended_info=-s.ones(4).astype("int64") | |
532 | + | |
533 | + overall_extended_info=-s.ones(2).astype("int64") | |
534 | + | |
538 | 535 | |
539 | 536 | for i in xrange(len(couple_list_unique)): |
540 | 537 | chosen_couple=couple_list_unique[i] |
541 | 538 | sel_chosen_couple_times=s.where(couple_list==chosen_couple) |
542 | 539 | chosen_couple_times=time_arr[sel_chosen_couple_times] |
543 | - | |
544 | - | |
545 | - # print "chosen_couple is, ", chosen_couple | |
540 | + #print "i is, ", i | |
546 | 541 | #print "chosen_couple_times is, ", chosen_couple_times |
547 | 542 | chosen_couple_contact_duration= \ |
548 | 543 | contact_duration_and_interval_single_couple(chosen_couple_times, delta_slice)[0] |
@@ -550,44 +545,72 @@ | ||
550 | 545 | chosen_couple_contact_interval= \ |
551 | 546 | contact_duration_and_interval_single_couple(chosen_couple_times, delta_slice)[1] |
552 | 547 | |
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 | + | |
554 | 564 | tag_contact_begin=\ |
555 | 565 | contact_duration_and_interval_single_couple(chosen_couple_times, delta_slice)[2] |
556 | 566 | tag_contact_end=\ |
557 | 567 | contact_duration_and_interval_single_couple(chosen_couple_times, delta_slice)[3] |
558 | 568 | |
559 | 569 | |
560 | - couple_interaction_duration=s.hstack((couple_interaction_duration,\ | |
561 | - chosen_couple_contact_duration)) | |
562 | 570 | |
563 | - couple_interaction_interval=s.hstack((couple_interaction_interval,\ | |
564 | - chosen_couple_contact_interval)) | |
565 | 571 | |
566 | 572 | overall_begin_contacts= \ |
567 | 573 | s.hstack((overall_begin_contacts,tag_contact_begin)) |
568 | 574 | overall_end_contacts= \ |
569 | 575 | s.hstack((overall_end_contacts,tag_contact_end)) |
570 | 576 | |
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 | + | |
572 | 589 | |
573 | 590 | overall_extended_info=s.vstack((overall_extended_info,extended_info)) |
574 | 591 | |
575 | 592 | |
576 | 593 | |
594 | + filename="hashed_couples_corresponding_to_contact_duration_times_%01d"%(counter+1) | |
595 | + filename=filename+"_.dat" | |
596 | + | |
597 | + | |
577 | 598 | filename="couple_interaction_duration_times_%01d"%(counter+1) |
578 | 599 | filename=filename+"_.dat" |
579 | 600 | |
580 | 601 | |
581 | - p.save(filename, couple_interaction_duration,fmt='%d') | |
602 | + n.savetxt(filename, couple_interaction_duration,fmt='%d') | |
582 | 603 | |
583 | 604 | filename="couple_interaction_interval_times_%01d"%(counter+1) |
584 | 605 | filename=filename+"_.dat" |
585 | 606 | |
586 | 607 | |
587 | - p.save(filename, couple_interaction_interval,fmt='%d') | |
608 | + n.savetxt(filename, couple_interaction_interval,fmt='%d') | |
588 | 609 | |
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') | |
591 | 614 | |
592 | 615 | |
593 | 616 |
@@ -614,11 +637,98 @@ | ||
614 | 637 | filename="couple_interaction_duration_times_extended_%01d"%(counter+1) |
615 | 638 | filename=filename+"_.dat" |
616 | 639 | |
617 | - p.save(filename, overall_duration_and_start_end , fmt='%d') | |
640 | + n.savetxt(filename, overall_duration_and_start_end , fmt='%d') | |
618 | 641 | |
619 | 642 | |
620 | 643 | |
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 | + | |
622 | 732 | |
623 | 733 | |
624 | 734 | def remove_self_loops_and_save(slice_lump): |
@@ -647,10 +757,13 @@ | ||
647 | 757 | #sliced_interactions=p.load("sliced_dynamics.dat") |
648 | 758 | #sliced_interactions=p.load("edge_list.dat") |
649 | 759 | |
650 | -ini_gap=1240876800-1240092599 # 86400 #i.e. one day in seconds | |
760 | +t_ini=1254384000 # 86400 #i.e. one day in seconds | |
651 | 761 | |
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 | + | |
654 | 767 | |
655 | 768 | f = open(sys.argv[1]) |
656 | 769 | sliced_interactions = [map(int, string.split(line)) for line in f.readlines()] |
@@ -665,9 +778,12 @@ | ||
665 | 778 | time_non_unique=sliced_interactions[:,0] |
666 | 779 | |
667 | 780 | 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) | |
669 | 782 | |
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 | + | |
671 | 787 | |
672 | 788 | file_list=-s.ones(len(time_grid)) |
673 | 789 |
@@ -676,7 +792,7 @@ | ||
676 | 792 | print "m+1 is, ", m+1 |
677 | 793 | |
678 | 794 | 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] | |
680 | 796 | |
681 | 797 | sliced_interactions_sel=sliced_interactions[time_sel,:] |
682 | 798 |
@@ -684,13 +800,31 @@ | ||
684 | 800 | file_list[m]=m+1 |
685 | 801 | |
686 | 802 | |
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 | + | |
687 | 807 | contact_duration_and_interval_many_tags(sliced_interactions_sel,\ |
688 | 808 | delta_slice,m) |
689 | 809 | |
690 | 810 | hash_and_time=couple_hash_table(sliced_interactions_sel,m) |
691 | 811 | |
692 | 812 | |
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 | + | |
694 | 828 | |
695 | 829 | |
696 | 830 | sel=s.where(file_list>0) |
@@ -700,7 +834,7 @@ | ||
700 | 834 | #print "file_list is, ", file_list |
701 | 835 | |
702 | 836 | |
703 | -p.save("file_list.dat", file_list, fmt='%d') | |
837 | +n.savetxt("file_list.dat", file_list, fmt='%d') | |
704 | 838 | |
705 | 839 | |
706 | 840 |