MCPcopy Create free account
hub / github.com/Tencent/embedx / HypothesisTesting

Function HypothesisTesting

src/sampler/sampling/sampling_validator.cc:86–113  ·  view source on GitHub ↗

Let Phi(Z_a) be the CDF of the variable x. Find the smallest Z_{a/2}, such that Phi(Z_{a/2}) >= 1 - a/2. mean : N * prob confidence interval : [N * prob - Z_{a/2} * sqrt(N * prob * (1-prob)), N * prob + Z_{a/2} * sqrt(N * prob * (1-prob))]

Source from the content-addressed store, hash-verified

84// confidence interval : [N * prob - Z_{a/2} * sqrt(N * prob * (1-prob)),
85// N * prob + Z_{a/2} * sqrt(N * prob * (1-prob))]
86bool HypothesisTesting(int trails, const vec_pair_t& distribution_to_validate,
87 const index_map_t& node_count_map) {
88 int_t count = 0;
89 float_t prob = 0;
90 float_t mean = 0;
91 float_t interval = 0;
92 int failure_time = 0;
93 for (const auto& entry : distribution_to_validate) {
94 auto it = node_count_map.find(entry.first);
95 if (it == node_count_map.end()) {
96 count = 0;
97 } else {
98 count = it->second;
99 }
100 prob = entry.second;
101 mean = trails * prob;
102 interval = QUANTILE * std::sqrt(trails * prob * (1 - prob));
103
104 if (count < mean - interval || count > mean + interval) {
105 DXINFO("The sampling result of node: %" PRIu64 "(%" PRIu64
106 ") is out of the expect range [%f,%f]",
107 entry.first, count, mean - interval, mean + interval);
108 failure_time += 1;
109 }
110 }
111
112 return failure_time <= MAX_FAILURE_TIME;
113}
114
115} // namespace
116

Callers 1

TestMethod · 0.85

Calls

no outgoing calls

Tested by 1

TestMethod · 0.68