python中的可瘫痪系统模型

2024-05-14 20:57:12 发布

您现在位置:Python中文网/ 问答频道 /正文

作为更大模型的一部分,我需要几行代码来为我实现并行系统模型。你知道吗

整个模型都在探测器上。这个探测器可以根据到达的元素记录信号。这种探测器的效率很低,一个元素击中它后,它可能会在一定时间内失去灵敏度。你知道吗

在可瘫痪的模型中,当一个元素击中探测器时,即使它没有检测到它,探测器也会死机。这意味着,当另一个元素在这个时间内撞击探测器时,我们所拥有的死区时间,可能会改变,它会增加另一个死区时间。你知道吗

有一个链接,您可以阅读更多有关此主题的内容: Dead time

我用numpy做了一个随机的Poisson样本,这个样本可能和源有相同的行为(源是基于Poisson分布的元素),然后由于检测器一次只能检测一个元素,我们需要用一个替换所有不止一个的值。你知道吗

最后一步是实际应用并行死区效应的主要部分,它将根据检测值的死区距离来去除这些值。你知道吗

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

它没有犯任何错误,但它肯定没有做我所期待的。 有没有一个快速的方法让它工作?你知道吗

谢谢。你知道吗


Tags: 模型numpy元素indextimenp时间random
2条回答

我想出了一个非常简单的方法来解决这个问题,死区时间必须从元素击中探测器的位置开始计算,这意味着如果死区时间必须阻塞两个通道,第一个通道实际上就是元素在其中接收的通道。你知道吗

在这里,我只做了另一个向量,基本上是用numpy的,把主向量的d距离等于零,然后把它们相乘,最后在has to的位置上得到1,在blocked的位置上得到0。你知道吗

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)

据我所知,当传感器已经处于瘫痪状态时,您希望死区时间窗口在传感器每次被事件击中时增加(“一”)。我相信下面的代码可以做到这一点。这里的技巧是使用内部while循环,这样就可以动态地更改循环边界,因为在python中使用for循环是不可能的。我没有删除print语句,以便更容易看到后面给出的输出来自何处。你知道吗

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)

这将生成以下随机的\u集(对于一个可呈现的示例,我使用了不同的种子和长度)。在下面的列表中,i表示外循环的索引,j表示内循环的索引。这意味着,i表示将留在最后一组的‘一’,而j表示将要删除‘一’的范围。dt是自初始事件击中传感器以来“停滞时间”的大小。当在[j,i+dt+1]范围内发现一个“1”时,它就会增加。因此,i+dt+1表示麻痹停止后的外边界。你知道吗

###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]

我希望这能解决它。请让我知道,如果误解了问题的一个或另一个方式。你知道吗

相关问题 更多 >

    热门问题