简体   繁体   English

填补角度列表(数字)之间的空白

[英]filling the gaps between list of angles (numbers)

i'll explain for simple example then go into the deep if i have a list of number consist of如果我有一个数字列表,我将用简单的例子进行解释,然后深入探讨

t_original = [180,174,168,166,162,94,70,80,128,131,160,180] t_original = [180,174,168,166,162,94,70,80,128,131,160,180]

if we graph this so it goes down from 180 to 70 then it ups to 180 again如果我们绘制它,它会从 180 下降到 70,然后它会再次上升到 180

在此处输入图像描述 but if we suddenly change the fourth value (166) by 450 then the list will be但如果我们突然将第四个值 (166) 更改为 450,那么列表将是

t = [180,174,168,700,162,94,70,80,128,131,160,180] t = [180,174,168,700,162,94,70,80,128,131,160,180]

which dose not make sense in the graph图中没有意义在此处输入图像描述

i wanna treat the fourth value (700) as a wrong value i want to replace it with a relative value even if not as the original value but relative to the previous two elements (168,174) i wanna do the same for the whole list if another wrong value appeared again我想将第四个值(700)视为错误值我想用相对值替换它,即使不是原始值而是相对于前两个元素(168,174)我想对整个列表做同样的事情如果另一个再次出现错误值

we can call that [Filling gaps between list of numbers]我们可以称之为[填补数字列表之间的空白]

so i'm tryig to do the same idea but for bigger example所以我尝试做同样的想法,但更大的例子在此处输入图像描述

the method i have tried我试过的方法

在此处输入图像描述

and i'll share my code with output , filtered means applied filling gap function我将与输出共享我的代码,过滤意味着应用填充间隙功能

my code我的代码

def preprocFN(*U):
prePlst=[] # after preprocessing list
#preprocessing Fc =| 2*LF1 prev by 1 - LF2 prev by 2 |
c0 = -2     #(previous) by 2
c1 =-1      #(previous)
c2 =0       #(current)
c3 = 1      #(next)
preP = U[0] # original list
if c2 == 0:
    prePlst.append(preP[0])
    prePlst.append(preP[1])
    c1+=2
    c2+=2
    c0+=2
oldlen = len(preP)
while oldlen > c2:
    Equ = abs(2*preP[c1] - preP[c0]) #fn of preprocessing #removed abs()
    formatted_float = "{:.2f}".format(Equ) #with .2 number only
    equu = float(formatted_float)          #from string float to float
    prePlst.insert(c2,equu)      # insert the preprocessed value to the List
    c1+=1
    c2+=1
    c0+=1

return prePlst

with my input : https://textuploader.com/t1py9我的输入: https ://textuploader.com/t1py9

the output will be : https://textuploader.com/t1pyk输出将是: https ://textuploader.com/t1pyk

and when printing the values higher than 180 (wrong values)以及打印高于 180 的值时(错误值)

result_list = [item for item in list if item > 180]

which dosen't make sense that any joint of human can pass the angle of 180人类的任何关节都可以通过 180 度角是没有意义的

the output was [183.6, 213.85, 221.62, 192.05, 203.39, 197.22, 188.45, 182.48, 180.41, 200.09, 200.67, 198.14, 199.44, 198.45, 200.55, 193.25, 204.19, 204.35, 200.59, 211.4, 180.51, 183.4, 217.91, 218.94, 213.79, 205.62, 221.35, 182.39, 180.62, 183.06, 180.78, 231.09, 227.33, 224.49, 237.02, 212.53, 207.0, 212.92, 182.28, 254.02, 232.49, 224.78, 193.92, 216.0, 184.82, 214.68, 182.04, 181.07, 234.68, 233.63, 182.84, 193.94, 226.8, 223.69, 222.77, 180.67, 184.72, 180.39, 183.99, 186.44, 233.35, 228.02, 195.31, 183.97, 185.26, 182.13, 207.09, 213.21, 238.41, 229.38, 181.57, 211.19, 180.05, 181.47, 199.69, 213.59, 191.99, 194.65, 190.75, 199.93, 221.43, 181.51, 181.42, 180.22] the output was [183.6, 213.85, 221.62, 192.05, 203.39, 197.22, 188.45, 182.48, 180.41, 200.09, 200.67, 198.14, 199.44, 198.45, 200.55, 193.25, 204.19, 204.35, 200.59, 211.4, 180.51, 183.4, 217.91, 218.94、213.79、205.62、221.35、182.39、180.62、183.06、180.78、231.09、227.33、224.49、237.49、237.02、212.53、212.53、207.0 234.68, 233.63, 182.84, 193.94, 226.8, 223.69, 222.77, 180.67, 184.72, 180.39, 183.99, 186.44, 233.35, 228.02, 195.31, 183.97, 185.26, 182.13, 207.09, 213.21, 238.41, 229.38, 181.57, 211.19, 180.05, 181.47、199.69、213.59、191.99、194.65、190.75、199.93、221.43、181.51、181.42、180.22]

so the filling gaps fn from proposed method dosen't do it's job any suggestion for applying the same concept with a different way ?所以从提议的方法中填补空白 fn 并没有做任何建议以不同的方式应用相同的概念?

Extra Info may help额外信息可能会有所帮助

the filtered graph consists of filling gap function and then applying normalize function i don't think the problem is from the normalizing function since the output from the filling gaps function isn't correct in my opinion maybe i'm wrong but anyway i provide the normalize steps so you get how the final filtered graph has been made过滤后的图由填充间隙函数然后应用归一化函数组成标准化步骤,以便您了解最终过滤图的制作方式

fn : fn:

在此处输入图像描述

My Code :我的代码:

def outLiersFN(*U):
outliers=[] # after preprocessing list
#preprocessing Fc =| 2*LF1 prev by 1 - LF2 prev by 2 |
c0 = -2     #(previous) by 2 #from original
c1 =-1      #(previous)      #from original
c2 =0       #(current)       #from original
c3 = 1      #(next)          #from original
preP = U[0] # original list
if c2 == 0:
    outliers.append(preP[0])
    c1+=1
    c2+=1
    c0+=1
    c3+=1
oldlen = len(preP)
M_RangeOfMotion = 90
while oldlen > c2 :
    if c3 == oldlen:
        outliers.insert(c2, preP[c2]) #preP[c2] >> last element in old list
        break
    if (preP[c2] > M_RangeOfMotion and preP[c2] < (preP[c1] + preP[c3])/2) or (preP[c2] < M_RangeOfMotion and preP[c2] > (preP[c1] + preP[c3])/2): #Check Paper 3.3.1
        Equ = (preP[c1] + preP[c3])/2 #fn of preprocessing # From third index # ==== inserting current frame
        formatted_float = "{:.2f}".format(Equ) #with .2 number only
        equu = float(formatted_float)          #from string float to float
        outliers.insert(c2,equu)      # insert the preprocessed value to the List
        c1+=1
        c2+=1
        c0+=1
        c3+=1
    else :
        Equ = preP[c2] # fn of preprocessing #put same element (do nothing)
        formatted_float = "{:.2f}".format(Equ)  # with .2 number only
        equu = float(formatted_float)  # from string float to float
        outliers.insert(c2, equu)  # insert the preprocessed value to the List
        c1 += 1
        c2 += 1
        c0 += 1
        c3 += 1
return outliers

I suggest the following algorithm:我建议以下算法:

  • data point t[i] is considered an outlier if it deviates from the average of t[i-2], t[i-1], t[i], t[i+1], t[i+2] by more than the standard deviation of these 5 elements.如果数据点t[i]偏离t[i-2], t[i-1], t[i], t[i+1], t[i+2]的平均值,则认为它是异常值超过这5个元素的标准差。
  • outliers are replaced by the average of the two elements around them.异常值被它们周围的两个元素的平均值替换。
import matplotlib.pyplot as plt
from statistics import mean, stdev

t = [180,174,168,700,162,94,70,80,128,131,160,180]

def smooth(t):
    new_t = []
    for i, x in enumerate(t):
        neighbourhood = t[max(i-2,0): i+3]
        m = mean(neighbourhood)
        s = stdev(neighbourhood, xbar=m)
        if abs(x - m) > s:
            x = ( t[i - 1 + (i==0)*2] + t[i + 1 - (i+1==len(t))*2] ) / 2
        new_t.append(x)
    return new_t

new_t = smooth(t)

plt.plot(t)
plt.plot(new_t)
plt.show()

平滑异常值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM