// // Created by lenovo on 2023/10/16. // #include "GreyClusterEvaluation.h" #include GreyClusterEvaluation::GreyClusterEvaluation(const GCEMat &mat, const GCERangeMat &ranges) : mat_(mat), ranges_(ranges) { sample_num_ = mat_.count(); if (sample_num_ == 0) { level_num_ = 0; } else { level_num_ = ranges_.at(0).count(); } for (int i = 0; i < sample_num_; ++i) { GCEMat cvtMat; cvtMat.append(QVector(level_num_, { 0.0, 0.0 })); ranges_cv_.append(cvtMat); } QVector cvrang_weights(level_num_, { 0.0, 0.0 }); ranges_weight_.append(cvrang_weights); } void GreyClusterEvaluation::evaluate(const QVector &weights) { for (int s = 0; s < sample_num_; ++s) { double val_front = mat_.at(s).front_val; double val_back = mat_.at(s).back_val; triangularwhiteningweight(s, val_front, val_back); } // QVector weights = {0.2, 0.15, 0.05, 0.4, 0.2}; evaluationlevel(weights); } void GreyClusterEvaluation::triangularwhiteningweight(int sam, double front_val, double back_val) { for (int i = 0; i < level_num_; ++i) { Q_ASSERT(ranges_.at(sam).at(i).level == i); // 计算前 double a1, a2, a3, a4; a1 = ranges_.at(sam).at(i).left_left; a2 = ranges_.at(sam).at(i).left_val; a3 = ranges_.at(sam).at(i).right_val; a4 = ranges_.at(sam).at(i).right_right; double lambda_k = (a2 + a3) / 2; if (front_val > a4 || front_val < a1) { ranges_cv_[sam][i].front_val = 0; } else if ((front_val >= a1) && (front_val < lambda_k)) { ranges_cv_[sam][i].front_val = (front_val - a1) / (lambda_k - a1); } else if ((front_val >= lambda_k) && (front_val <= a4)) { ranges_cv_[sam][i].front_val = (a4 - front_val) / (a4 - lambda_k); } if (back_val > a4 || back_val < a1) { ranges_cv_[sam][i].back_val = 0; } else if ((back_val >= a1) && (back_val < lambda_k)) { ranges_cv_[sam][i].back_val = (back_val - a1) / (lambda_k - a1); } else if ((back_val >= lambda_k) && (back_val <= a4)) { ranges_cv_[sam][i].back_val = (a4 - back_val) / (a4 - lambda_k); } } } void GreyClusterEvaluation::evaluationlevel(const QVector &weights) { for (int i = 0; i < level_num_; ++i) { double front_val = 0; double back_val = 0; for (int j = 0; j < sample_num_; ++j) { front_val = front_val + ranges_cv_.at(j).at(i).front_val * weights[j]; back_val = back_val + ranges_cv_.at(j).at(i).back_val * weights[j]; } ranges_weight_[i].front_val = front_val; ranges_weight_[i].back_val = back_val; } } BestIndex GreyClusterEvaluation::getBestIndex() const { BestIndex index = { 0, 0 }; double maxf_val = ranges_weight_.at(0).front_val; double maxb_val = ranges_weight_.at(0).back_val; for (int i = 1; i < ranges_weight_.count(); ++i) { if (ranges_weight_.at(i).front_val > maxf_val) { maxf_val = ranges_weight_.at(i).front_val; index.front_index = i; } if (ranges_weight_.at(i).back_val > maxb_val) { maxb_val = ranges_weight_.at(i).back_val; index.back_index = i; } } index.front_index = index.front_index + 1; index.back_index = index.back_index + 1; // for (auto &item : ranges_weight_) { // qDebug() << QString("前 %1 : 后 %2").arg(item.front_val).arg(item.back_val); // } for (int i = 0; i < ranges_cv_.size(); i++) { qDebug() << "指标" << i << " 深度" << ranges_cv_.at(i).count(); int n = 0; for (auto &item : ranges_cv_.at(i)) { qDebug() << QString(" 前 %1 : 后 %2").arg(item.front_val).arg(item.back_val); n++; if (n >= level_num_) break; } } return index; } const QVector &GreyClusterEvaluation::getRangeWeights() const { return ranges_weight_; } const QVector &GreyClusterEvaluation::getRangeCVT() const { return ranges_cv_; }