[SciPy-User] Calculating (Conditional) Time Intervals

Lorenzo Isella lorenzo.isella@gmail....
Thu Oct 1 12:21:48 CDT 2009


Dear All,
Consider and array of this kind:

1      12    45
2      7       12
2      15     37
3      25     89
3      8       13
3      13     44
4      77     89
4      77     89
5      12     22
8      12     22
9      15     22
11    22     37
23    3       12
24    18     37
25    1      12



where the first column is time measured in some units. The other two 
columns are some ID's identifying  infected individuals establishing a 
contact at the corresponding time. As you can see, there may be 
time-gaps in my recorded times and there may be repeated times if 
several contacts take place simultaneously. The ID's are always sorted 
out in such a way the ID number of the 2nd column is always smaller than 
the corresponding entry of the third column (I am obviously indexing 
everything from 1).
Now, this is my problem: I want to look at a specific ID I will call A 
(let us say A is 12) and calculate all the time differences t_AC-t_AB 
for B!=C, i.e. all the time intervals between the most recent contact 
between A and B and the first subsequent contact between and A and C 
(which has to be different from B).
An example to fix the ideas: A=12, B=22, C=1, then
t_AB=8 (pick the most recent one before t_AC)
t_AC=25,
hence t_AC-t_AB=25-8=17. (but let me say it again: I want to be able to 
calculate all such intervals for any B and C on the fly).
It should be clear at this point that the calculated t_AC-t_AB != 
t_AB-t_AC as some time-ordering is implicit in the definition (in 
t_AC-t_AB, AC contacts have to always be more recent than AB contacts).
Even in the case of multiple disjointed AB and AC contacts, I always 
have to look for the closest time intervals in time. E.g. if I had

10    12       22
40    12       22
60    1         12
100  1         12
110  12       22
130  12       22
150  1         12 

then I would work out the time intervals 60-40=20 and 150-130=20.
Sorry for the long email, but any suggestion about how to calculate all 
this efficiently would help me a great deal.
Many thanks

Lorenzo


More information about the SciPy-User mailing list