// // Created by lenovo on 2023/10/16. // #include "GreyClusterEvaluation.h" 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; for (int j = 0; j < level_num_; ++j) { 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() { 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) { auto pFunc1 = [](double left, double right) { return (left + right) / 2; }; auto pFunc2 = [](double v, double left_left, double left_right) { return (v - left_left) / (left_right - left_left); }; auto pFunc3 = [](double v, double left_right, double right_right) { return (right_right - v) / (right_right - left_right); }; for (int i = 0; i < level_num_; ++i) { Q_ASSERT(ranges_.at(sam).at(i).level == i); double r1 = pFunc1(ranges_.at(sam).at(i).left_val, ranges_.at(sam).at(i).right_val); double r2 = pFunc2(front_val, ranges_.at(sam).at(i).left_left, r1); double r3 = pFunc3(front_val, r1, ranges_.at(sam).at(i).right_right); if ((front_val >= ranges_.at(sam).at(i).left_left) && (front_val <= r1)) ranges_cv_[sam][i].front_val = r2; else if ((front_val >= r1) && (front_val <= ranges_.at(sam).at(i).right_right)) ranges_cv_[sam][i].front_val = r3; else ranges_cv_[sam][i].front_val = 0; r2 = pFunc2(back_val, ranges_.at(sam).at(i).left_left, r1); r3 = pFunc3(back_val, r1, ranges_.at(sam).at(i).right_right); if ((back_val >= ranges_.at(sam).at(i).left_left) && (back_val <= r1)) ranges_cv_[sam][i].back_val = r2; else if ((back_val >= r1) && (back_val <= ranges_.at(sam).at(i).right_right)) ranges_cv_[sam][i].back_val = r3; else ranges_cv_[sam][i].back_val = 0; } } 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; return index; }