pmlpp/mlpp/outlier_finder/outlier_finder.cpp

42 lines
1.1 KiB
C++
Raw Normal View History

//
// OutlierFinder.cpp
//
// Created by Marc Melikyan on 11/13/20.
//
2023-01-24 18:12:23 +01:00
#include "outlier_finder.h"
#include "../stat/stat.h"
#include <iostream>
2023-01-24 19:20:18 +01:00
2023-01-25 00:54:50 +01:00
MLPPOutlierFinder::MLPPOutlierFinder(int threshold) :
2023-01-24 19:00:54 +01:00
threshold(threshold) {
}
2023-01-27 13:01:16 +01:00
std::vector<std::vector<real_t>> MLPPOutlierFinder::modelSetTest(std::vector<std::vector<real_t>> inputSet) {
MLPPStat stat;
2023-01-27 13:01:16 +01:00
std::vector<std::vector<real_t>> outliers;
2023-01-24 19:00:54 +01:00
outliers.resize(inputSet.size());
for (int i = 0; i < inputSet.size(); i++) {
for (int j = 0; j < inputSet[i].size(); j++) {
2023-01-27 13:01:16 +01:00
real_t z = (inputSet[i][j] - stat.mean(inputSet[i])) / stat.standardDeviation(inputSet[i]);
2023-01-24 19:00:54 +01:00
if (abs(z) > threshold) {
outliers[i].push_back(inputSet[i][j]);
}
}
}
return outliers;
}
2023-01-27 13:01:16 +01:00
std::vector<real_t> MLPPOutlierFinder::modelTest(std::vector<real_t> inputSet) {
MLPPStat stat;
2023-01-27 13:01:16 +01:00
std::vector<real_t> outliers;
2023-01-24 19:00:54 +01:00
for (int i = 0; i < inputSet.size(); i++) {
2023-01-27 13:01:16 +01:00
real_t z = (inputSet[i] - stat.mean(inputSet)) / stat.standardDeviation(inputSet);
2023-01-24 19:00:54 +01:00
if (abs(z) > threshold) {
outliers.push_back(inputSet[i]);
}
}
return outliers;
}