-
Notifications
You must be signed in to change notification settings - Fork 0
/
HybridAnomalyDetector.cpp
67 lines (56 loc) · 2.6 KB
/
HybridAnomalyDetector.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//Orpaz Sondhelm 206492324 Yarin Tzdaka 319091278
#include "HybridAnomalyDetector.h"
#define MINI_THRESHOLD 0.5
HybridAnomalyDetector::HybridAnomalyDetector() {
// TODO Auto-generated constructor stub
}
HybridAnomalyDetector::~HybridAnomalyDetector() {
// TODO Auto-generated destructor stub
}
void HybridAnomalyDetector::HowToLearn(float m, float c, int i, vector<pair<string, vector<float>>> columns, int sizeLines) {
if (c != -1 && m >= this->thresh) {
correlatedFeatures newCF;
newCF.corrlation = m;
newCF.feature1 = columns[i].first;
newCF.feature2 = columns[c].first;
newCF.lin_reg = linear_reg(&columns[i].second[0], &columns[c].second[0], sizeLines);
newCF.threshold = max_dev(&columns[i].second[0], &columns[c].second[0], newCF.lin_reg, sizeLines);
this->cf.push_back(newCF);
}
if (c!= -1 && m < this->thresh && m > MINI_THRESHOLD) {
correlatedFeatures newCF;
Point *points[sizeLines];
for (int j = 0; j < sizeLines; j++) {
points[j] = new Point(columns[i].second[j], columns[c].second[j]);
}
newCF.minCircle = findMinCircle(points,sizeLines);
newCF.corrlation = m;
newCF.feature1 = columns[i].first;
newCF.feature2 = columns[c].first;
newCF.threshold = newCF.minCircle.radius;
this->cf.push_back(newCF);
}
}
void HybridAnomalyDetector::HowToDetect(correlatedFeatures *currentCF, vector<float> *targetVector,
vector<float> *currentVector, string *currentFeature,
vector<AnomalyReport> *anomalyReportVector) {
Line regLine = currentCF->lin_reg;
float threshold = currentCF->threshold;
for (int k = 0; k < currentVector->size(); k++) {
Point p1(currentVector->at(k), targetVector->at(k));
if (currentCF->corrlation >= this->thresh) {
if (dev(p1, regLine) >= threshold * 1.1) {
AnomalyReport anomalyReport(*currentFeature + "-" + currentCF->feature2, k + 1);
anomalyReportVector->push_back(anomalyReport);
}
}
if (currentCF->corrlation < this->thresh && currentCF->corrlation > MINI_THRESHOLD) {
float distance = sqrt(pow(p1.x - currentCF->minCircle.center.x, 2) +
pow(p1.y - currentCF->minCircle.center.y, 2) * 1.0);
if (distance >= threshold * 1.1) {
AnomalyReport anomalyReport(*currentFeature + "-" + currentCF->feature2, k + 1);
anomalyReportVector->push_back(anomalyReport);
}
}
}
}