|
@@ -97,38 +97,37 @@ public class ArticlePromotionService {
|
|
|
@Value("${topProducePlanId:}")
|
|
|
private String topProducePlanId;
|
|
|
|
|
|
- public static boolean abZTestCorrected(double readAvg, int fansA, double viewCount, int fansB, double confidence) {
|
|
|
- // 检查基础参数合法性
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param readAvg:对照组分子
|
|
|
+ * @param fansA:对照组分母
|
|
|
+ * @param viewCount: 实验组分子
|
|
|
+ * @param fansB: 实验组分母
|
|
|
+ * @param confidence=0.95
|
|
|
+ * @return boolean
|
|
|
+ */
|
|
|
+ public static boolean isExperimentGroupSuperior(double readAvg, int fansA, double viewCount, int fansB, double confidence) {
|
|
|
+
|
|
|
if (fansA <= 0 || fansB <= 0) {
|
|
|
throw new IllegalArgumentException("样本量必须大于零");
|
|
|
}
|
|
|
if (confidence <= 0 || confidence >= 1) {
|
|
|
throw new IllegalArgumentException("置信水平必须在 (0,1) 区间");
|
|
|
}
|
|
|
+ double pA = readAvg / fansA;
|
|
|
+ double pB = viewCount / fansB;
|
|
|
|
|
|
- // 计算比例 (使用浮点除法)
|
|
|
- double pA = (double) readAvg / fansA;
|
|
|
- double pB = (double) viewCount / fansB;
|
|
|
-
|
|
|
- // 防止除零错误
|
|
|
if (pA <= 0) {
|
|
|
throw new IllegalArgumentException("A组比例必须大于零");
|
|
|
}
|
|
|
-
|
|
|
- // 计算合并方差
|
|
|
double varA = pA * (1 - pA) / fansA;
|
|
|
double varB = pB * (1 - pB) / fansB;
|
|
|
double se = Math.sqrt(varA + varB);
|
|
|
|
|
|
- // 计算Z阈值 (双尾检验)
|
|
|
NormalDistribution normal = new NormalDistribution();
|
|
|
double alpha = (1 - confidence) / 2;
|
|
|
double zThreshold = normal.inverseCumulativeProbability(1 - alpha);
|
|
|
-
|
|
|
- // 计算置信区间下限
|
|
|
double ciLow = (pB - pA - zThreshold * se) / pA;
|
|
|
-
|
|
|
- // 判断是否拒绝原假设
|
|
|
return ciLow > 0;
|
|
|
}
|
|
|
|
|
@@ -150,7 +149,7 @@ public class ArticlePromotionService {
|
|
|
List<DatastatSortStrategy> listStrategy2 = list.stream()
|
|
|
.filter(o -> {
|
|
|
try {
|
|
|
- return abZTestCorrected(o.getAvgViewCount() * 1.1 * 30, o.getFans() * 30,
|
|
|
+ return isExperimentGroupSuperior(o.getAvgViewCount() * 1.1 * 30, o.getFans() * 30,
|
|
|
o.getViewCount(), o.getFans(), 0.95);
|
|
|
}
|
|
|
catch (Exception e) {
|