私は自分で開発したアルゴリズムをこのスレッドに投稿したいと思います:
これは、分散の原則に基づいています。新しいデータポイントが、移動平均から所定の x 数の標準偏差だけ離れている場合、アルゴリズムはシグナル ( z-scoreとも呼ばれます) を通知します。このアルゴリズムは、信号がしきい値を破損しないように、個別の移動平均と偏差を構築するため、非常に堅牢です。したがって、将来のシグナルは、以前のシグナルの量に関係なく、ほぼ同じ精度で識別されます。lag = the lag of the moving window
このアルゴリズムは、 、threshold = the z-score at which the algorithm signals
およびの 3 つの入力を受け取りますinfluence = the influence (between 0 and 1) of new signals on the mean and standard deviation
。たとえば、a lag
of 5 は、最後の 5 つの観測値を使用してデータを平滑化します。3.5の Athreshold
は、データポイントが移動平均から 3.5 標準偏差離れている場合に通知します。そして、influence
0.5 の an は信号を半分にします通常のデータポイントが持つ影響の。同様に、influence
0 の場合、新しいしきい値を再計算するために信号が完全に無視されます。したがって、0 の影響が最も堅牢なオプションです。
次のように機能します。
疑似コード
# Let y be a vector of timeseries data of at least length lag+2
# Let mean() be a function that calculates the mean
# Let std() be a function that calculates the standard deviaton
# Let absolute() be the absolute value function
# Settings (the ones below are examples: choose what is best for your data)
set lag to 5; # lag 5 for the smoothing functions
set threshold to 3.5; # 3.5 standard deviations for signal
set influence to 0.5; # between 0 and 1, where 1 is normal influence, 0.5 is half
# Initialise variables
set signals to vector 0,...,0 of length of y; # Initialise signal results
set filteredY to y(1,...,lag) # Initialise filtered series
set avgFilter to null; # Initialise average filter
set stdFilter to null; # Initialise std. filter
set avgFilter(lag) to mean(y(1,...,lag)); # Initialise first value
set stdFilter(lag) to std(y(1,...,lag)); # Initialise first value
for i=lag+1,...,t do
if absolute(y(i) - avgFilter(i-1)) > threshold*stdFilter(i-1) then
if y(i) > avgFilter(i-1)
set signals(i) to +1; # Positive signal
else
set signals(i) to -1; # Negative signal
end
# Adjust the filters
set filteredY(i) to influence*y(i) + (1-influence)*filteredY(i-1);
set avgFilter(i) to mean(filteredY(i-lag,i),lag);
set stdFilter(i) to std(filteredY(i-lag,i),lag);
else
set signals(i) to 0; # No signal
# Adjust the filters
set filteredY(i) to y(i);
set avgFilter(i) to mean(filteredY(i-lag,i),lag);
set stdFilter(i) to std(filteredY(i-lag,i),lag);
end
end
デモ
