私は株式市場データの時系列分析を行っており、区分線形セグメンテーションのアルゴリズムを実装しようとしています。これは次のとおりです。
split(T [ta, tb ]) – split a time series T of length
n from time ta to time tb where 0 ≤ a < b ≤ n
1: Ttemp = ∅
2: εmin = ∞;
3: εtotal = 0;
4: for i = a to b do
5:εi = (pi − pi )^2 ;
6:if εmin > εi then
7: εmin = εi ;
8: tk = ti ;
9:end if
10:εtotal = εtotal + εi ;
11: end for
12: ε = εtotal /(tb − ta );
13: if t-test.reject(ε) then
14:Ttemp = Ttemp ∪ split(T [ta , tk ]);
15:Ttemp = Ttemp ∪ split(T [tk , tb ]);
16: end if
17: return Ttemp ;
私の時系列クラスは次のとおりです。
class MySeries{
ArrayList<Date> time;
Double[] value;
}
上記のアルゴリズムでは、Ttemp は時系列の別のインスタンスです。4 行目から 12 行目までの計算は、誤差を計算するためのものです。
問題は、上記の再帰部分と結合部分 (14 行目と 15 行目) を実装できないことです。再帰して MySeries オブジェクトの結合を作成する方法がわかりません。
** * ** * ** * ***編集* ** * ** * ** * ** * ** * **
class Segmentation{
static MySeries series1 = new MySeries(); //contains the complete time series
static HashSet<MySeries> series_set = new HashSet<MySeries>();
public static MySeries split(MySeries series, int start, int limit) throws ParseException{
if(limit-start < 3){ //get min of 3 readings atleast
return null;
}
tTemp = MySeries.createSegment(series1, start, limit);
double emin = 999999999, e,etotal=0, p, pcap;
DescriptiveStatistics errors = new DescriptiveStatistics();
for(int i=start;i<limit;i++){
p = series1.y[i];
pcap = series1.regress.predict(series1.x[i]);
e = (p-pcap)*(p-pcap);
errors.addValue(e);
if(emin > e){
emin = e;
splitPoint = i;
}
etotal = etotal + e;
}
e = etotal/(limit-start);
double std_dev_error = errors.getStandardDeviation();
double tTstatistic = e/(std_dev_error/Math.sqrt(errors.getN()));
if(ttest.tTest(tTstatistic, errors, 0.10)){
union(split(series1, start, splitPoint));
union(split(series1, splitPoint+1, limit));
}
return tTemp;
}
static void union(MySeries ms){
series_set.add(ms);
}
}
私は与えられたアルゴリズムのために上記のコードを書きました..しかし、なぜそれが無限ループに陥るのかわかりません..誰かが他のデザインやコードの変更を私に提供してくれれば感謝します.