#include "SampleData.h"#include <cmath> // 添加用于平方根等数学运算#include <iostream>#include <vector>#include <random>#include <numeric>#include <algorithm>namespace sample {Metric::Type SampleFrame::getColumnType(const std::string& metricName) const{auto it = data_.find(metricName);if (it == data_.end()) {std::cout << "Error: metric name not found" << std::endl;return Metric::TypeUnknown;}return it->first.type;}double SampleFrame::calculatePopulationStdDev(string& metricName) {// 计算标准差return sqrt(calculatePopulationVariance(metricName));}double SampleFrame::calculatePopulationVariance(string& metricName) {auto type = getColumnType(metricName);if (type != Metric::TypeInt && type != Metric::TypeDouble) {return 0.0;}ColumnData* c = getColumn(metricName);if (c == nullptr) {return 0.0;}std::vector<double> data;for (auto& d : *c) {if (type == Metric::TypeInt) {data.push_back(std::get<int>(d));}else if (type == Metric::TypeDouble) {data.push_back(std::get<double>(d));}}//std::vector<double> cd = getColumnData<double>(metricName);// 计算平均值double mean = std::accumulate(data.begin(), data.end(), 0.0) / data.size();//double sampleMean = boost::accumulators::mean(acc);//double sampleVariance = boost::accumulators::variance(acc);// 计算方差return std::accumulate(data.begin(), data.end(), 0.0,[&](double acc, double val) { return acc + pow(val - mean, 2); }) / data.size();}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。