1

在数据流中,我尝试检测是否满足某个阈值(条件)。此外,阈值不应适用于自发噪声(尖峰),在满足条件下自发的低值也不应阻止我检测上述值的区域X

数据在数据流中逐个样本地出现,我仍在寻找 pythonic/fast 解决方案。下图直观地解释了我的问题: 在此处输入图像描述 目的是保存满足超过某个阈值X次数条件的检测到的部分的起始索引和结束索引。

我正在努力处理一次输入一个数据的问题,在整个数据集上这不是问题。我想到了这样的事情:

threshold = 5
start_index_list = []

while i < len(data):  # just to show that it's one datapoint at a time
    if data(i) > threshold:
         threshold_counter +=1 
         if threshold_counter > threshold_counter_level:  # consecutive true conditions
             start_index = i - threshold_counter_level
             start_index_list.append(start_index)
    else:
         threshold_counter = 0  # if condition breaks, counter is reset

    i += 1  # increment iteration variable

这里的问题是,如果计数器开始增加单个错误事件会停止它。但是我想检测例如窗口中 90% 的值是否为真,比如说 50 个连续值,在前 3 个值之后是否有一个低于阈值的值并不重要,我仍然需要starting_index整个end_index区域。

对于相当复杂的描述感到抱歉,在数据流的情况下找不到解决方案真是令人沮丧。如果还有问题或不清楚的地方,我会编辑我的答案。

4

0 回答 0