ts-aggregator/project_template/Normalization.cpp
2022-12-13 12:36:06 +04:00

57 lines
1.4 KiB
C++

#include "stdafx.h"
#include "Math.h"
#include "Normalization.h"
using namespace std;
Normalization::Normalization() {
timeSeriaShiftValue = 0;
maxTimePoint = 0;
}
vector<double> Normalization::shift(vector<double> timeSeria){
double timeSeriaShiftValue = timeSeria[0];
for (int i = 0; i < timeSeria.size(); i++){
if (timeSeria[i] < timeSeriaShiftValue && timeSeria[i] < 0){
timeSeriaShiftValue = timeSeria[i];
}
}
if (timeSeriaShiftValue < 0){
timeSeriaShiftValue = fabs(timeSeriaShiftValue);
for (int i = 0; i < timeSeria.size(); i++){
timeSeria[i] += timeSeriaShiftValue;
}
}
return timeSeria;
}
vector<double> Normalization::deShift(vector<double> timeSeria){
if (timeSeriaShiftValue < 0){
for (int i = 0; i < timeSeria.size(); i++){
timeSeria[i] -= timeSeriaShiftValue;
}
}
return timeSeria;
}
vector<double> Normalization::normalizeTimeSeria(vector<double> timeSeria){
shift(timeSeria);
maxTimePoint = timeSeria[0];
for (int i = 0; i < timeSeria.size(); i++){
if (timeSeria[i] > maxTimePoint)
maxTimePoint = timeSeria[i];
}
for (int i = 0; i < timeSeria.size(); i++){
timeSeria[i] /= maxTimePoint;
}
return timeSeria;
}
vector<double> Normalization::deNormalizeTimeSeria(vector<double> timeSeria){
//shift(timeSeria);
for (int i = 0; i < timeSeria.size(); i++){
timeSeria[i] *= maxTimePoint;
}
timeSeria = deShift(timeSeria);
return timeSeria;
}