4

As a part of a bigger model, I need to have couple of lines of code that could be implementing the Paralazable system model for me.

The whole model is on a detector. This detector could record signals based on the elements that are arriving. The detectors have this inefficiency that it could lose its sensitivity for a certain amount of time after one element hits it.

In Paralyzable models the detector will be dead when an element hits it, even if it did not detect it. It means that certain number that we have as the dead time, could be changed if another element hit the detector in that time and it will add another dead time to that.

There is this link that you could read a little more about this topic: Dead time

I have made a random Poisson sample using numpy as something that could have the same behavior as the source (The source is making the elements based on Poisson distribution), then due to the fact that the detector could only detect one element at a time, we need to replace all the values more than one with one.

Then the last step is the main part that is actually applying the Paralzable dead time effect, which will remove the values with the dead time distance of the detected values.

import numpy as np
np.random.seed(2)
random_set = np.random.poisson(lam=1, size = 500) #The source is making the elements with Poisson distribution
#lam could be any other value 
d = 2 #dead time, could be any other integers

#Saturation effect
#detector could not detect more than one elements at a time
random_set[random_set>1] = 1

index = 1 
#Paralyzable dead time effect
for i in range(1, (random_set.shape[0])):
    for j in range(index, index + d+1):

        if random_set[j]==1:
            index = j
            random_set[j]=0

It does not make any errors but it is certainly not doing what I am looking for. Is there a fast way to make it work?

Thanks.

Nikki
  • 195
  • 9
  • could you please provide an example input/output for the random set (say length 20-30)? That would help massively to understand what you are trying to achieve. Thanks. – user59271 Jun 01 '18 at 20:13

2 Answers2

2

I came up with this really easy way to solve for this problem, the dead time has to be counted from the position that the element hits the detector, which means that if the dead time has to block 2 channels, the first one is actually the one that the element is receiving in it.

In here, I just made another vector, which is basically using ones from numpy, and make the d distance from the main vector equal to zero, and then just multiply them together and it will end up giving ones on the positions in has to and zeros in the blocked positions.

import numpy as np
np.random.seed(2)
random_set = np.random.poisson(lam=1, size = 20) #The source is making the elements with Poisson distribution
#lam could be any other value 
d = 3 #dead time, could be any other integers

#Saturation effect
#detector could not detect more than one elements at a time
random_set[random_set>1] = 1
print(random_set) 
new_vec = np.ones(random_set.shape)
for i in range(random_set.shape[0]):
    if random_set[i]==1:
        new_vec[i+1:i+d]=0

result = new_vec*random_set 

print(result)
Nikki
  • 195
  • 9
1

As far as I understand, you want the dead time window to increase each time the sensor is hit by an event (a 'one'), when it's already in the paralyzed state. I believe the following code does that. The trick here is to use an inner while loop, so that you can dynamically change the loop boundaries, as it's not really possible to do so with a for loop in python. I did not delete the print statements so that it's easier to see where do the outputs given later come from.

import numpy as np

np.random.seed(468316)
random_set = np.random.poisson(lam=1, size = 30) #The source is making the elements with Poisson distribution
#lam could be any other value 
d = 2 #dead time, could be any other integers

#Saturation effect
#detector could not detect more than one elements at a time
random_set[random_set>1] = 1

print('###initial random set')
print(random_set)
#set max index
max_index = random_set.shape[0] - 1
print('i', '\t', 'j', '\t', 'dt', '\t',' i+dt+1')

#Paralyzable dead time effect
for i,val in enumerate(random_set):
    #see if current value is an event
    if val == 1:
        #if so, set next d elements to zero
        dt = d
        #emulate 'for j in range(i+1, i+dt+1):' with a while loop
        j = i+1 if i < max_index else max_index        
        while j < i+dt+1:
            print(i, '\t',j, '\t', dt, '\t', i+dt+1)
            #if an event is foud within the d window, increase dt by another d
            if random_set[j]==1:
                random_set[j]=0
                dt += d

           #dont let the i+dt+1 to get out of the bounds of the random_set 
            if i+dt+1 > max_index:
                dt =   max_index - i
            j += 1
print('###final random set')
print(random_set)

This produces the following random_set (i've used a different seed and lenght for a presentable example). In the list below, i indicates the index of the outer loop and j of the inner while loop. That means that i indicates the 'ones' that are going to stay in the final set and j's indicate the range within the which the 'ones' are going to be deleted. dt is the size of the 'dead time' since the initial event hit the sensor. It increases each time when a 'one' is found within the [j,i+dt+1] range. Hereby i+dt+1 indicates the outer boundary after which the paralyzation should stop.

###initial random set
[1 0 0 0 1 1 0 1 1 1 1 1 0 0 0 0 0 1 0 1 0 0 0 1 1 1 0 1 0 1]
i    j   dt  i+dt+1
0    1   2   3
0    2   2   3
4    5   2   7
4    6   4   9
4    7   4   9
4    8   6   11
4    9   8   13
4    10  10  15
4    11  12  17
4    12  14  19
4    13  14  19
4    14  14  19
4    15  14  19
4    16  14  19
4    17  14  19
4    18  16  21
4    19  16  21
4    20  18  23
4    21  18  23
4    22  18  23
23   24  2   26
23   25  4   28
23   26  6   30
23   27  6   30
23   28  6   30
23   29  6   30
###final random set
[1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0]

I hope that solves it. Please let me know if misunderstood the problem in one or another way.

user59271
  • 380
  • 2
  • 14
  • Thank you, this is a smart way to do this, but the only problem is that it doesn't go back to the initial dead time. It has to be going back to the default dead time after not getting hit by another element. In here, the one that is in 17th position has to be detected but it is been removed. – Nikki Jun 03 '18 at 23:31
  • If you have look at _dt_ values in the list above, then it gets reset at position 23 (_i_ = 23), once a new event is detected, and not once the dead time expires, since it does not need to be reset (or it's actual value known) until a new event is found to achieve same thing logically. The reason event at 17 is omitted is that dead time window at that point is 14, since 7 events have hit the sensor beforehand, with first event being detected at position 4. So at this point, instead of detecting an event,and resetting dt, it is increased by another 2. That's how I understood it. – user59271 Jun 04 '18 at 05:00