HierarchyWeighting.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // Created by lenovo on 2023/10/18.
  3. //
  4. #ifndef ALGORITHM_HIERARCHYWEIGHTING_H
  5. #define ALGORITHM_HIERARCHYWEIGHTING_H
  6. #include <QVector>
  7. #include <QString>
  8. #include <QDebug>
  9. #include <QtMath>
  10. typedef QVector<QVector<qreal>> HWMat;
  11. typedef QVector<QVector<qreal>> SMat;
  12. struct HWWeight
  13. {
  14. QString node;
  15. QString name;
  16. QVector<qreal> weights;
  17. QVector<int> node_number;
  18. };
  19. struct HWNode
  20. {
  21. QString node; // 1.1 , 1.1.1
  22. QString name;
  23. HWMat mat;
  24. QVector<int> node_number; // [1, 1] , [1, 1, 1]
  25. };
  26. /**
  27. * @brief 层次加权法
  28. */
  29. class HierarchyWeighting
  30. {
  31. public:
  32. HierarchyWeighting(const SMat &smat); //
  33. void evaluate();
  34. void push(const QString &node, const QString &name, const HWMat &value);
  35. bool isFull() const;
  36. const QVector<double> &getsampleweight() const { return smat_cv_; }
  37. int getBestIndex() const { return best_index_; }
  38. private:
  39. void EvaluateNodeWeight(const HWNode &hwnode);
  40. void LastLevelWeight();
  41. void BestSample();
  42. const qreal RI[10] = { 0, 0, 0.58, 0.90, 1.12, 1.24, 1.32, 1.41, 1.45, 1.49 };
  43. const qreal thd = 0.1;
  44. qreal m_CI;
  45. qreal m_CR;
  46. QVector<HWNode> mat_; // 各节点
  47. QVector<HWWeight> weights_node_; // 各节点计算出的权重
  48. SMat smat_; // 样本
  49. int sam_num_; // 样本数量
  50. int best_index_; // 最好的样本索引
  51. QVector<double> smat_cv_;
  52. QVector<double> weights_; // 最后一层综合权重
  53. };
  54. #endif // ALGORITHM_HIERARCHYWEIGHTING_H