123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #include "AverageMethod.h"
- #include <QDebug>
- #include <QtMath>
- AverageMethod::AverageMethod(const QVector<AverageMethod::EvaluateIndex> &rMat, const QVector<qreal> &wMat,
- const QVector<qreal> &maxMat, const QVector<qreal> &minMat, const QVector<qreal> &sumMat,
- int type)
- : m_rMat(rMat), m_wMat(wMat), m_maxMat(maxMat), m_minMat(minMat), m_sumMat(sumMat)
- {
- Q_ASSERT(rMat.count() != 0);
- Q_ASSERT(rMat.at(0).count() != 0);
- if (type == MethodType::Max) {
- for (auto &r : m_rMat) {
- for (int i = 0; i < r.count(); ++i) {
- r[i] = r[i] / m_maxMat.at(i);
- }
- }
- } else if (type == MethodType::Min) {
- for (auto &r : m_rMat) {
- for (int i = 0; i < r.count(); ++i) {
- r[i] = r[i] / m_minMat.at(i);
- }
- }
- } else {
- // Z-Score 需要求方差和均值
- QVector<qreal> aMat;
- QVector<qreal> sMat;
- int count = m_rMat.count();
- for (auto s : m_sumMat) {
- aMat.append(s / count);
- }
- //方差
- int rCount = m_sumMat.count();
- for (int i = 0; i < rCount; ++i) {
- qreal s2 = 0;
- for (auto r : m_rMat) {
- s2 += pow(r.at(i) - aMat.at(i), 2);
- }
- sMat.append(sqrt(s2 / count));
- }
- for (auto &r : m_rMat) {
- for (int i = 0; i < r.count(); ++i) {
- r[i] = (r[i] - aMat.at(i)) / sMat.at(i);
- }
- }
- }
- }
- AverageMethod::Relations AverageMethod::getRelations() const
- {
- Relations uMat;
- for (auto r : m_rMat) {
- qreal ui = 0;
- for (int i = 0; i < r.count(); ++i) {
- ui += r.at(i) * m_wMat.at(i);
- }
- uMat << ui;
- }
- return uMat;
- }
|