HierarchicalAnalysis.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "HierarchicalAnalysis.h"
  2. #include <QtMath>
  3. #include <QDebug>
  4. HierarchicalAnalysis::HierarchicalAnalysis(int columnCount, const QVector<qreal> &nxnValus)
  5. : m_columnCount(columnCount),
  6. m_sqartnValues(QVector<double>(m_columnCount, 0)),
  7. m_weights(QVector<double>(m_columnCount, 0)),
  8. m_averageWeights(QVector<double>(m_columnCount, 0)),
  9. m_CI(0),
  10. m_CR(0)
  11. {
  12. // qDebug() << "HierarchicalAnalysis nodes" << nodes;
  13. calc(nxnValus);
  14. }
  15. void HierarchicalAnalysis::calc(const QVector<qreal> &nxnValus)
  16. {
  17. // qDebug() << "HierarchicalAnalysis nxnValus" << nxnValus;
  18. QVector<qreal> nodeMul(m_columnCount, 1);
  19. for (int m = 0; m < m_columnCount; ++m) {
  20. for (int n = 0; n < m_columnCount; ++n) {
  21. nodeMul[m] *= nxnValus[m * m_columnCount + n];
  22. }
  23. }
  24. // qDebug() << "nodeMul" << nodeMul;
  25. qreal nSum = 0;
  26. for (int n = 0; n < m_sqartnValues.count(); ++n) {
  27. m_sqartnValues[n] = qPow(nodeMul[n], (qreal)1 / m_sqartnValues.count());
  28. nSum += m_sqartnValues[n];
  29. }
  30. // qDebug() << "sqartnValues" << m_sqartnValues;
  31. for (int w = 0; w < m_weights.count(); ++w) {
  32. m_weights[w] = m_sqartnValues[w] / nSum;
  33. }
  34. // qDebug() << "weights" << m_weights;
  35. // m0*w0+m1*w1+m2*w2+m3*w3...mn*wn
  36. for (int m = 0; m < m_columnCount; ++m) {
  37. for (int n = 0; n < m_columnCount; ++n) {
  38. m_averageWeights[m] += nxnValus[m * m_columnCount + n] * m_weights[n];
  39. }
  40. }
  41. // qDebug() << "averageWeights" << m_averageWeights;
  42. // Awi/Wi
  43. QVector<qreal> awiDividedWi(m_columnCount, 0);
  44. qreal awiDividedWiAverage = 0;
  45. for (int m = 0; m < m_columnCount; ++m) {
  46. awiDividedWi[m] = m_averageWeights[m] / m_weights[m];
  47. awiDividedWiAverage += awiDividedWi[m];
  48. }
  49. awiDividedWiAverage /= m_columnCount;
  50. // qDebug() << "awiDividedWi" << awiDividedWi;
  51. // CI=(λ-n)/(n-1)
  52. m_CI = (awiDividedWiAverage - m_columnCount) / (m_columnCount - 1);
  53. qreal result = m_columnCount <= 10 ? RI[m_columnCount - 1] : RI[9];
  54. if (qFuzzyCompare(result, 0)) {
  55. m_CR = 0;
  56. } else {
  57. m_CR = m_CI / result;
  58. }
  59. // qDebug() << RI[m_columnCount - 1] << "m_CI" << m_CI << "m_CR" << m_CR;
  60. }