EntropyWeights.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //
  2. // Created by Austin on 2023/10/10.
  3. //
  4. #ifndef ALGORITHM__ENTROPYWEIGHTS_H_
  5. #define ALGORITHM__ENTROPYWEIGHTS_H_
  6. #include <QVector>
  7. typedef QVector<QVector<double>> EntropyMat;
  8. /**
  9. * @brief 熵权法
  10. */
  11. class EntropyWeights
  12. {
  13. public:
  14. /**
  15. * @param mat: 输入矩阵,一行代表一个指标, 每列对应一个样本
  16. * @param direction,定正向指标true,负向指标false
  17. */
  18. EntropyWeights(const EntropyMat &mat, const QVector<bool> &direction = QVector<bool>());
  19. void setYMin(double ymin);
  20. void setYMax(double ymax);
  21. void compute(QVector<double> &weights, QVector<double> &score);
  22. // 若归一化到[0,1], 0会出问题
  23. double ymin_;
  24. double ymax_;
  25. int sample_num_; // 样本数
  26. int index_num_; // 指标数
  27. private:
  28. void normalization();
  29. void getMinMax(const QVector<double> &in, double &min, double &max);
  30. void getWeights(QVector<double> &weights, QVector<double> &score);
  31. EntropyMat mat_;
  32. QVector<bool> direction_;
  33. };
  34. #endif // ALGORITHM__ENTROPYWEIGHTS_H_