你的中间计算逻辑讲的很清楚,还有一个疑问"总结:上面全部的文字为计算第三行f1的流程。 如果要计算下一行的f1,还是按照以上所有流程去计算",如果计算第四行的f1,因为第四行的barlen=2,既窗口长度为2,根据“按“第一个窗口的最后一行为本行”的原则”,去确定第四行的窗口序列,是吧?你的原始输入就是p值和barlen,输出为相应的f1?
p=3 4 4 3 5 7 6 8 6 7 8 7 8 7 9 8 9 8 9 8 7 6 6 5 4 3 2 barlen= 2 3 3 2 4 5 3 2 3 2 2 3 3 2 4 5 3 2 3 2 2 3 3 2 4 5 3 def select_Xvalue(MINARR,i){ if (i<2){ return MINARR[i] } count=0 res=int() for (k in sort(2..i,false) ){ if (MINARR[k]>MINARR[k-1]){ count=count+1 res=MINARR[k-1] } if (count>=2){ return res } } return res } def select_Pvalue(wind,X){ for (i in 1..size(wind)){ tmp=wind[i] if (sum(tmp<X[i-1])){ return tmp[tmp<X[i-1]][0] } } return int() } def f(p,barlen,i,select_Xvalue,select_Pvalue){ if (barlen[i]>(i+1)){ return int() } wind=cut(p[i+1-barlen[i]:],barlen[i]) MINARR=each(min,wind) X=each(select_Xvalue{MINARR,},0..(size(MINARR)-1)) return select_Pvalue(wind,X)-p[i+1] } f1=each(f{p,barlen,,select_Xvalue,select_Pvalue},0..(size(p)-12))