Skip to content

Commit

Permalink
Merge branch 'main' of github.com:quantumish/leaf
Browse files Browse the repository at this point in the history
  • Loading branch information
quantumish committed Feb 3, 2024
2 parents f029f92 + 5bff2ce commit d121ce4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,25 @@ std::pair<double, double> record_baseline_conf_interval(int iterations, double c
double inv_norm_cdf = NormalCDFInverse(0.5 + confidence/2);
double conf_width = inv_norm_cdf * stdev / std::sqrt(iterations);
return std::pair<double, double>(mean_mj - conf_width, mean_mj + conf_width);
}

std::pair<double, double> conf_interval_from_samples(std::vector<uint32_t> samples, double confidence) {
size_t iterations = samples.size();
uint64_t mean_mj = 0;
for (size_t iteration = 0; iteration < iterations; iteration++) {
mean_mj += samples[iteration];
}
mean_mj /= samples.size();
double variance = 0;
for (size_t iteration_idx = 0; iteration_idx < iterations; iteration_idx++) {
variance += std::pow((mean_mj - samples[iteration_idx]), 2);
}
variance /= (iterations - 1);
double stdev = std::sqrt(variance);
// return degenerate interval in case confidence is invalid
if (confidence < 0 || confidence > 1) return std::pair<double, double>(0, 0);
// calculate inverse normal CDF (z*)
double inv_norm_cdf = NormalCDFInverse(0.5 + confidence/2);
double conf_width = inv_norm_cdf * stdev / std::sqrt(iterations);
return std::pair<double, double>(mean_mj - conf_width, mean_mj + conf_width);
}
4 changes: 3 additions & 1 deletion src/statistics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@

double NormalCDFInverse(double p);

std::pair<double, double> record_baseline_conf_interval(int iterations, double confidence);
std::pair<double, double> record_baseline_conf_interval(int iterations, double confidence, uint32_t& last_rapl);

std::pair<double, double> conf_interval_from_samples(std::vector<uint32_t> samples, double confidence);

0 comments on commit d121ce4

Please sign in to comment.