46 lines
1.7 KiB
C++
46 lines
1.7 KiB
C++
#include <eqpalg/distribution/nd_test.h>
|
||
namespace distribution {
|
||
|
||
std::tuple<int, std::string> nd_test(std::vector<double> data,
|
||
dlib::running_stats<double> rs) {
|
||
std::stringstream sstream;
|
||
// 验证数据正态分布性,AD测试
|
||
std::sort(data.begin(), data.end());
|
||
double ad_value =
|
||
boost::math::statistics::anderson_darling_normality_statistic(
|
||
data, rs.mean(), rs.stddev()) /
|
||
data.size();
|
||
int test_result = 0;
|
||
if (ad_value > 2) {
|
||
sstream << "错误,该算法不属于正态分布,anderson_darling正态测试值为:"
|
||
<< ad_value << std::endl;
|
||
test_result = 2;
|
||
}
|
||
auto [test_result_2, erro_msg] = nd_test(rs);
|
||
sstream << erro_msg;
|
||
return std::make_tuple(test_result + test_result_2, sstream.str());
|
||
}
|
||
|
||
std::tuple<int, std::string> nd_test(dlib::running_stats<double> rs) {
|
||
std::stringstream sstream;
|
||
int test_result = 0;
|
||
// 对小范围数据正态分布进行估计
|
||
if (std::abs(rs.skewness()) > 1) {
|
||
sstream << "错误,偏态系数过大!请检查是否符合正态分布" << std::endl;
|
||
test_result = 5;
|
||
} else if (std::abs(rs.skewness()) > 0.6) {
|
||
sstream << "警告,偏态系数偏大!" << std::endl;
|
||
test_result = 3;
|
||
}
|
||
if (rs.ex_kurtosis() < -1) {
|
||
sstream << "警告,数据分布过于分散,可能导致中心数据数据异常" << std::endl;
|
||
test_result = test_result + 2;
|
||
} else if (rs.ex_kurtosis() > 1) {
|
||
sstream << "警告,数据分布过于集中,可能导致边缘数据报警异常" << std::endl;
|
||
test_result = test_result + 1;
|
||
}
|
||
return std::make_tuple(test_result, sstream.str());
|
||
}
|
||
|
||
} // namespace distribution
|