#include "HierarchicalAnalysis.h" #include #include HierarchicalAnalysis::HierarchicalAnalysis(int columnCount, const QVector &nxnValus) : m_columnCount(columnCount), m_sqartnValues(QVector(m_columnCount, 0)), m_weights(QVector(m_columnCount, 0)), m_averageWeights(QVector(m_columnCount, 0)), m_CI(0), m_CR(0) { // qDebug() << "HierarchicalAnalysis nodes" << nodes; calc(nxnValus); } void HierarchicalAnalysis::calc(const QVector &nxnValus) { // qDebug() << "HierarchicalAnalysis nxnValus" << nxnValus; QVector nodeMul(m_columnCount, 1); for (int m = 0; m < m_columnCount; ++m) { for (int n = 0; n < m_columnCount; ++n) { nodeMul[m] *= nxnValus[m * m_columnCount + n]; } } // qDebug() << "nodeMul" << nodeMul; qreal nSum = 0; for (int n = 0; n < m_sqartnValues.count(); ++n) { m_sqartnValues[n] = qPow(nodeMul[n], (qreal)1 / m_sqartnValues.count()); nSum += m_sqartnValues[n]; } // qDebug() << "sqartnValues" << m_sqartnValues; for (int w = 0; w < m_weights.count(); ++w) { m_weights[w] = m_sqartnValues[w] / nSum; } // qDebug() << "weights" << m_weights; // m0*w0+m1*w1+m2*w2+m3*w3...mn*wn for (int m = 0; m < m_columnCount; ++m) { for (int n = 0; n < m_columnCount; ++n) { m_averageWeights[m] += nxnValus[m * m_columnCount + n] * m_weights[n]; } } // qDebug() << "averageWeights" << m_averageWeights; // Awi/Wi QVector awiDividedWi(m_columnCount, 0); qreal awiDividedWiAverage = 0; for (int m = 0; m < m_columnCount; ++m) { awiDividedWi[m] = m_averageWeights[m] / m_weights[m]; awiDividedWiAverage += awiDividedWi[m]; } awiDividedWiAverage /= m_columnCount; // qDebug() << "awiDividedWi" << awiDividedWi; // CI=(λ-n)/(n-1) m_CI = (awiDividedWiAverage - m_columnCount) / (m_columnCount - 1); qreal result = m_columnCount <= 10 ? RI[m_columnCount - 1] : RI[9]; if (qFuzzyCompare(result, 0)) { m_CR = 0; } else { m_CR = m_CI / result; } // qDebug() << RI[m_columnCount - 1] << "m_CI" << m_CI << "m_CR" << m_CR; }