123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- //
- // Created by lenovo on 2023/10/16.
- //
- #include "GreyClusterEvaluation.h"
- #include <QDebug>
- 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<GCEmat>(level_num_, { 0.0, 0.0 }));
- }
- ranges_cv_.append(cvtMat);
- }
- QVector<GCEmat> cvrang_weights(level_num_, { 0.0, 0.0 });
- ranges_weight_.append(cvrang_weights);
- }
- void GreyClusterEvaluation::evaluate(const QVector<double> &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<double> 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) {
- if (left_left == left_right) {
- return 0.0;
- }
- return (v - left_left) / (left_right - left_left);
- };
- auto pFunc3 = [](double v, double left_right, double right_right) {
- if (right_right == left_right) {
- return 0.0;
- }
- 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<double> &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;
- 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 >= 4)
- break;
- }
- }
- return index;
- }
- const QVector<GCEmat> &GreyClusterEvaluation::getRangeWeights() const
- {
- return ranges_weight_;
- }
- const QVector<GCEMat> &GreyClusterEvaluation::getRangeCVT() const
- {
- return ranges_cv_;
- }
|