修改下面的c++代码计算mic系数这是将结果存储为长形矩阵的方式matrixdouble row_major calc_micconst matrixdouble row_major& mat int combination_num const stdvectorstdstring& col_names int threads 当样本量小于6个时终止程序 ifmatsize16 stdcer
#include
using namespace boost::numeric::ublas;
//计算mic系数,这是将结果存储为长形矩阵的方式 matrix<double, row_major> calc_mic(const matrix<double, row_major>& mat, int combination_num, const std::vectorstd::string& col_names, int threads) { //当样本量小于6个时,终止程序 if (mat.size1() < 6) { std::cerr << "error: the number of data rows should be greater than 5." << std::endl; return matrix<double, row_major>(0, 0); } if (mat.size2() < 2) { std::cerr << "error: the number of data columns should be greater than 1." << std::endl; return matrix<double, row_major>(0, 0); } // 创建空的3列矩阵 matrix<double, row_major> result(combination_num + 1, 3); // 创建MINE对象
// 计算每列两两之间的mic系数,并填充对称矩阵
omp_set_num_threads(threads);
#pragma omp parallel for
for (size_t i = 0; i < mat.size2(); i++) {
MINE mine(0.5, 15, EST_MIC_APPROX);
for (size_t j = i + 1; j < mat.size2(); j++) { // 计算上三角部分
double x[mat.size1()];
double y[mat.size1()];
for (size_t k = 0; k < mat.size1(); k++) {
x[k] = mat(k, i);
y[k] = mat(k, j);
}
mine.compute_score(x, y, mat.size1());
result(i + 1, 2) = mine.mic(); //第三列为mic系数
result(i + 1, 0) = i; // 第1列为变量
result(i + 1, 1) = j; // 第2列为变量
}
}
return result;
原文地址: https://www.cveoy.top/t/topic/iqWE 著作权归作者所有。请勿转载和采集!