ts-aggregator/project_template/TrackingControlSignal.h

88 lines
2.1 KiB
C
Raw Permalink Normal View History

2022-12-13 12:36:06 +04:00
#ifndef TCS_H
#define TCS_H
#include "math.h"
#include <iostream>
#include <map>
using namespace std;
class TrackingControlSignal {
private:
map<double, double> Quant;
double AlphaQuant(double alpha){
return alpha;
}
double Eps;
double Eps1;
double Eps2;
double alpha; // 0~1
double gamma; //0.05 ~ 0.1
bool estimateTCS(double TCS){
return ((-1.2 * AlphaQuant(alpha / 2) * sqrt(gamma / (2 - gamma)) < TCS) &&
(1.2 * AlphaQuant(1 - alpha / 2) * sqrt(gamma / (2 - gamma)) > TCS));
}
public:
TrackingControlSignal::TrackingControlSignal(){
}
bool TrackingControlSignal::calcTCS(double realData, double forecastedData){
//calcEps
Eps = realData - forecastedData;
//eps^ n eps~
Eps1 = gamma * Eps + (1 - gamma) * Eps1;
Eps2 = gamma * fabs(Eps) + (1 - gamma) * Eps2;
return estimateTCS(Eps1 / Eps2);
}
vector<bool> TrackingControlSignal::HistoricalExpertControl(Method** values, double tsdiffval, int expertsCount){
//init
double diff = 0.0;
vector<bool> res;
vector<double> diffs;
int activeExperts = expertsCount;
for (int i = 0; i < expertsCount; i++){
res.push_back(true);
diffs.push_back(0.0);
}
int indMaxDiff = 0;
bool isExcluded = true;
//main algo
while (isExcluded){
//set exit flag
isExcluded = false;
//calc diffs between experts
for (int i = 0; i < expertsCount; i++){
for (int j = 0; j < expertsCount; j++){
if ((i != j) && res[i] && res[j]){
diffs[j] += fabs(values[j]->value - values[i]->value);
if (diffs[j] > diffs[indMaxDiff]){
indMaxDiff = j;
}
}
}
}
//check max diff on trashhold
if ((diffs[indMaxDiff] / activeExperts - 1) > tsdiffval){
res[indMaxDiff] = false;
isExcluded = true;
activeExperts--;
for (int i = 0; i < expertsCount; i++){
diffs[i] = 0.0;
}
}
if (activeExperts - 1 == 0){
cout << "Something went wrong, all experts exept one was filltered." << endl;
cout << "Hight probability that last expert wasn't correct!" << endl;
cout << "See logs" << endl;
return res;
}
}
return res;
}
};
#endif