修改filter 参数
This commit is contained in:
@@ -44,8 +44,10 @@ public class ApplicationConfig {
|
||||
public static final String HBASE_ZOOKEEPER_CLIENT_PORT= ConfigUtils.getStringProperty("hbase.zookeeper.client.port");
|
||||
|
||||
|
||||
public static final Double BASELINE_KALMAN_P = ConfigUtils.getDoubleProperty("baseline.kalman.p");
|
||||
public static final Double BASELINE_KALMAN_Q = ConfigUtils.getDoubleProperty("baseline.kalman.q");
|
||||
public static final Double BASELINE_KALMAN_R = ConfigUtils.getDoubleProperty("baseline.kalman.r");
|
||||
public static final Double BASELINE_KALMAN_P = ConfigUtils.getDoubleProperty("baseline.kalman.p");
|
||||
public static final Double BASELINE_KALMAN_M = ConfigUtils.getDoubleProperty("baseline.kalman.m");
|
||||
|
||||
public static final Integer BASELINE_GENERATE_BATCH_SIZE = ConfigUtils.getIntProperty("baseline.generate.batch.size");
|
||||
public static final Long DRUID_READ_BATCH_TIME_GRAD_HOUR = ConfigUtils.getLongProperty("druid.read.batch.time.grad.hour");
|
||||
|
||||
@@ -95,11 +95,13 @@ public class BaselineSingleThread extends Thread {
|
||||
Arrays.fill(baselineArr, (int)percentile);
|
||||
// KF
|
||||
baselineArr = baselineFunction(series);
|
||||
System.out.println("高频IP:" + ip + " origin:" + series + "\n baseline:" + Arrays.toString(baselineArr));
|
||||
} else {
|
||||
// 判断周期性
|
||||
if (SeriesUtils.isPeriod(series)){
|
||||
// KF
|
||||
baselineArr = baselineFunction(series);
|
||||
System.out.println("低频周期IP:" + ip + " origin:" + series + "\n baseline:" + Arrays.toString(baselineArr));
|
||||
} else {
|
||||
// 百分位数
|
||||
int ipPercentile = SeriesUtils.percentile(
|
||||
@@ -107,6 +109,7 @@ public class BaselineSingleThread extends Thread {
|
||||
Integer.valueOf(i.get(ApplicationConfig.BASELINE_METRIC_TYPE).toString())).collect(Collectors.toList()),
|
||||
ApplicationConfig.BASELINE_RATIONAL_PERCENTILE);
|
||||
Arrays.fill(baselineArr, ipPercentile);
|
||||
System.out.println("其他IP:" + ip + " origin:" + series + "\n baseline:" + Arrays.toString(baselineArr));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ public class KalmanFilter {
|
||||
private double mdelt;
|
||||
private double Gauss;
|
||||
private double kalmanGain;
|
||||
private final static double Q = ApplicationConfig.BASELINE_KALMAN_Q;
|
||||
private final static double R = ApplicationConfig.BASELINE_KALMAN_R;
|
||||
|
||||
public KalmanFilter() {
|
||||
@@ -29,21 +30,23 @@ public class KalmanFilter {
|
||||
|
||||
public void initial(){
|
||||
pdelt = ApplicationConfig.BASELINE_KALMAN_P;
|
||||
mdelt = ApplicationConfig.BASELINE_KALMAN_M;
|
||||
}
|
||||
|
||||
private ArrayList<Integer> smoothSeries;
|
||||
private ArrayList<Integer> forecastSeries;
|
||||
|
||||
public Integer calSingleKalPoint(Integer oldValue, Integer value){
|
||||
//第一个估计值
|
||||
predict = oldValue;
|
||||
current = value;
|
||||
//高斯噪声方差
|
||||
Gauss = Math.sqrt(pdelt * pdelt + mdelt * mdelt) + Q;
|
||||
//估计方差
|
||||
kalmanGain = pdelt/(pdelt + R);
|
||||
kalmanGain = Math.sqrt((Gauss * Gauss)/(Gauss * Gauss + pdelt * pdelt)) + R;
|
||||
//估计值
|
||||
estimate = (int) (kalmanGain * (current - predict) + predict);
|
||||
//新的估计方差
|
||||
mdelt = (1-kalmanGain) * pdelt ;
|
||||
mdelt = Math.sqrt((1-kalmanGain) * Gauss * Gauss);
|
||||
|
||||
return estimate;
|
||||
}
|
||||
@@ -68,6 +71,9 @@ public class KalmanFilter {
|
||||
}
|
||||
forecastSeries.add((int)sum/partitonNum);
|
||||
}
|
||||
|
||||
System.out.println("KF test: origin:" + historicalSeries + "\n smooth:" + smoothSeries + "\n baseline:" + forecastSeries);
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<Integer> getSmoothSeries() {
|
||||
|
||||
@@ -47,8 +47,10 @@ baseline.historical.ratio.threshold=0.1
|
||||
baseline.historical.sparse.fill.percentile=0.95
|
||||
baseline.rational.percentile=0.95
|
||||
#Kalman Filter
|
||||
baseline.kalman.p=2
|
||||
baseline.kalman.r=4
|
||||
baseline.kalman.q=0.00001
|
||||
baseline.kalman.r=0.1
|
||||
baseline.kalman.p=1
|
||||
baseline.kalman.m=1
|
||||
|
||||
# FOR TEST
|
||||
baseline.generate.batch.size=100
|
||||
|
||||
Reference in New Issue
Block a user