修改filter 参数

This commit is contained in:
yinjiangyi
2021-08-05 21:08:15 +08:00
parent d2171abbdb
commit b4957aa33f
4 changed files with 19 additions and 6 deletions

View File

@@ -44,8 +44,10 @@ public class ApplicationConfig {
public static final String HBASE_ZOOKEEPER_CLIENT_PORT= ConfigUtils.getStringProperty("hbase.zookeeper.client.port"); 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_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 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"); public static final Long DRUID_READ_BATCH_TIME_GRAD_HOUR = ConfigUtils.getLongProperty("druid.read.batch.time.grad.hour");

View File

@@ -95,11 +95,13 @@ public class BaselineSingleThread extends Thread {
Arrays.fill(baselineArr, (int)percentile); Arrays.fill(baselineArr, (int)percentile);
// KF // KF
baselineArr = baselineFunction(series); baselineArr = baselineFunction(series);
System.out.println("高频IP:" + ip + " origin:" + series + "\n baseline:" + Arrays.toString(baselineArr));
} else { } else {
// 判断周期性 // 判断周期性
if (SeriesUtils.isPeriod(series)){ if (SeriesUtils.isPeriod(series)){
// KF // KF
baselineArr = baselineFunction(series); baselineArr = baselineFunction(series);
System.out.println("低频周期IP:" + ip + " origin:" + series + "\n baseline:" + Arrays.toString(baselineArr));
} else { } else {
// 百分位数 // 百分位数
int ipPercentile = SeriesUtils.percentile( 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()), Integer.valueOf(i.get(ApplicationConfig.BASELINE_METRIC_TYPE).toString())).collect(Collectors.toList()),
ApplicationConfig.BASELINE_RATIONAL_PERCENTILE); ApplicationConfig.BASELINE_RATIONAL_PERCENTILE);
Arrays.fill(baselineArr, ipPercentile); Arrays.fill(baselineArr, ipPercentile);
System.out.println("其他IP:" + ip + " origin:" + series + "\n baseline:" + Arrays.toString(baselineArr));
} }
} }

View File

@@ -21,6 +21,7 @@ public class KalmanFilter {
private double mdelt; private double mdelt;
private double Gauss; private double Gauss;
private double kalmanGain; private double kalmanGain;
private final static double Q = ApplicationConfig.BASELINE_KALMAN_Q;
private final static double R = ApplicationConfig.BASELINE_KALMAN_R; private final static double R = ApplicationConfig.BASELINE_KALMAN_R;
public KalmanFilter() { public KalmanFilter() {
@@ -29,21 +30,23 @@ public class KalmanFilter {
public void initial(){ public void initial(){
pdelt = ApplicationConfig.BASELINE_KALMAN_P; pdelt = ApplicationConfig.BASELINE_KALMAN_P;
mdelt = ApplicationConfig.BASELINE_KALMAN_M;
} }
private ArrayList<Integer> smoothSeries; private ArrayList<Integer> smoothSeries;
private ArrayList<Integer> forecastSeries; private ArrayList<Integer> forecastSeries;
public Integer calSingleKalPoint(Integer oldValue, Integer value){ public Integer calSingleKalPoint(Integer oldValue, Integer value){
//第一个估计值
predict = oldValue; predict = oldValue;
current = value; 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); estimate = (int) (kalmanGain * (current - predict) + predict);
//新的估计方差 //新的估计方差
mdelt = (1-kalmanGain) * pdelt ; mdelt = Math.sqrt((1-kalmanGain) * Gauss * Gauss);
return estimate; return estimate;
} }
@@ -68,6 +71,9 @@ public class KalmanFilter {
} }
forecastSeries.add((int)sum/partitonNum); forecastSeries.add((int)sum/partitonNum);
} }
System.out.println("KF test: origin:" + historicalSeries + "\n smooth:" + smoothSeries + "\n baseline:" + forecastSeries);
} }
public ArrayList<Integer> getSmoothSeries() { public ArrayList<Integer> getSmoothSeries() {

View File

@@ -47,8 +47,10 @@ baseline.historical.ratio.threshold=0.1
baseline.historical.sparse.fill.percentile=0.95 baseline.historical.sparse.fill.percentile=0.95
baseline.rational.percentile=0.95 baseline.rational.percentile=0.95
#Kalman Filter #Kalman Filter
baseline.kalman.p=2 baseline.kalman.q=0.00001
baseline.kalman.r=4 baseline.kalman.r=0.1
baseline.kalman.p=1
baseline.kalman.m=1
# FOR TEST # FOR TEST
baseline.generate.batch.size=100 baseline.generate.batch.size=100