|
@@ -1,10 +1,13 @@
|
|
|
package com.tzld.piaoquan.ad.engine.service.predict.container;
|
|
|
|
|
|
+import com.tdunning.math.stats.Centroid;
|
|
|
+import com.tdunning.math.stats.MergingDigest;
|
|
|
import com.tzld.piaoquan.ad.engine.service.predict.model.threshold.ThresholdPredictModel;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
@@ -16,6 +19,8 @@ public class ThresholdModelContainer {
|
|
|
private ApplicationContext applicationContext;
|
|
|
|
|
|
public static Map<String,ThresholdPredictModel> modelMap=new HashMap<>();
|
|
|
+ public static MergingDigest mergingDigest = new MergingDigest(100);
|
|
|
+
|
|
|
@PostConstruct
|
|
|
public void init() {
|
|
|
Map<String,ThresholdPredictModel> beanMap= applicationContext.getBeansOfType(ThresholdPredictModel.class);
|
|
@@ -31,4 +36,32 @@ public class ThresholdModelContainer {
|
|
|
public static ThresholdPredictModel getBasicPredictModel(){
|
|
|
return modelMap.get("basic");
|
|
|
}
|
|
|
+
|
|
|
+ public static void mergingDigestAddScore(Double score){
|
|
|
+ mergingDigest.add(score);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static double getThresholdByTDigest(Double sortPosition){
|
|
|
+ return mergingDigest.quantile(sortPosition);
|
|
|
+ }
|
|
|
+
|
|
|
+// public static void main(String[] args){
|
|
|
+// MergingDigest mergingDigest = new MergingDigest(100);
|
|
|
+// for(long i=0;i<1000;i++){
|
|
|
+// double newDataPoint = Math.random() * 100;
|
|
|
+// // 向MergingDigest中添加新数据
|
|
|
+// mergingDigest.add(newDataPoint);
|
|
|
+// }
|
|
|
+// System.out.println(mergingDigest.quantile(0.12));
|
|
|
+// System.out.println(mergingDigest.quantile(0.6));
|
|
|
+// Iterable<Centroid> centroids = mergingDigest.centroids();
|
|
|
+// Integer totalW=0;
|
|
|
+// Integer totalS=0;
|
|
|
+// // 遍历质点列表并输出
|
|
|
+// for (Centroid centroid : centroids) {
|
|
|
+// System.out.println("值: " + centroid.mean() + ", 权重: " + centroid.count());
|
|
|
+// }
|
|
|
+// System.out.println(totalW);
|
|
|
+// System.out.println(totalS);
|
|
|
+// }
|
|
|
}
|