Last active
September 27, 2017 02:37
-
-
Save pfmiles/c7145c5ebb9a0c269653d8797002fab9 to your computer and use it in GitHub Desktop.
增量计算扫描覆盖率的通用算法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 计算扫描覆盖率的通用算法 | |
* cover_rate递推公式为:fn = (1 - fn-1) * N/M + fn-1 ; 其中fn是本次迭代cover_rate, fn-1是上次迭代cover_rate, N是本次抽取数量,M是集合总数,f0=0; | |
*/ | |
public static BigDecimal scanCoverageRecur(BigDecimal fn1, int N, BigInteger M, int scale) { | |
if (fn1 == null) | |
fn1 = new BigDecimal(0); | |
BigDecimal one = new BigDecimal(1); | |
BigDecimal Nb = new BigDecimal(N); | |
BigDecimal Mb = new BigDecimal(M); | |
return one.subtract(fn1).multiply(Nb.divide(Mb, scale + 1, RoundingMode.HALF_UP)).add(fn1) | |
.setScale(scale, RoundingMode.HALF_UP); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
若希望通过“覆盖率”来决定抽样数量的话,最终抽样量可能会比较大;
对与给定的置信度和置信区间,这篇文章有工具可以计算出一个合理的抽样量: https://www.zhihu.com/question/23017185