2023-01-23 21:13:26 +01:00
|
|
|
//
|
|
|
|
// 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"
|
2023-01-23 21:13:26 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
2023-01-24 19:20:18 +01:00
|
|
|
|
2023-01-24 19:00:54 +01:00
|
|
|
OutlierFinder::OutlierFinder(int threshold) :
|
|
|
|
threshold(threshold) {
|
|
|
|
}
|
2023-01-23 21:13:26 +01:00
|
|
|
|
2023-01-24 19:00:54 +01:00
|
|
|
std::vector<std::vector<double>> OutlierFinder::modelSetTest(std::vector<std::vector<double>> inputSet) {
|
|
|
|
Stat stat;
|
|
|
|
std::vector<std::vector<double>> outliers;
|
|
|
|
outliers.resize(inputSet.size());
|
|
|
|
for (int i = 0; i < inputSet.size(); i++) {
|
|
|
|
for (int j = 0; j < inputSet[i].size(); j++) {
|
|
|
|
double z = (inputSet[i][j] - stat.mean(inputSet[i])) / stat.standardDeviation(inputSet[i]);
|
|
|
|
if (abs(z) > threshold) {
|
|
|
|
outliers[i].push_back(inputSet[i][j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return outliers;
|
|
|
|
}
|
2023-01-23 21:13:26 +01:00
|
|
|
|
2023-01-24 19:00:54 +01:00
|
|
|
std::vector<double> OutlierFinder::modelTest(std::vector<double> inputSet) {
|
|
|
|
Stat stat;
|
|
|
|
std::vector<double> outliers;
|
|
|
|
for (int i = 0; i < inputSet.size(); i++) {
|
|
|
|
double z = (inputSet[i] - stat.mean(inputSet)) / stat.standardDeviation(inputSet);
|
|
|
|
if (abs(z) > threshold) {
|
|
|
|
outliers.push_back(inputSet[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return outliers;
|
|
|
|
}
|