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

104 lines
2.0 KiB
C++

#include "StdAfx.h"
#include <iostream>
#include "sMAPE.h"
#include "RMSE.h"
#include "BIC.h"
#include "Math.h"
#include <vector>
Bic::Bic(algoritm versionBIC, int paramCount) {
pc = paramCount;
this->versionBIC = versionBIC;
}
Bic::~Bic() {
}
double Bic::getValue(vector<double> original, vector<double> model) {
double valueBIC;
switch (versionBIC)
{
case algoritm::Classic:
valueBIC = classicBIC(original, model, pc);
break;
case algoritm::RMSE:
valueBIC = rmseBIC(original, model, pc);
break;
case algoritm::sMAPE:
valueBIC = smapeBIC(original, model, pc);
break;
}
return valueBIC;
}
double Bic::getValue(int paramCount, vector<double> original, vector<double> model) {
double valueBIC;
switch (versionBIC)
{
case algoritm::Classic:
valueBIC = classicBIC(original, model, paramCount);
break;
case algoritm::RMSE:
valueBIC = rmseBIC(original, model, paramCount);
break;
case algoritm::sMAPE:
valueBIC = smapeBIC(original, model, paramCount);
break;
}
return valueBIC;
}
double Bic::classicBIC(vector<double> original, vector<double> model, int paramCount)
{
double valueBIC;
double sumLik = 0;
double logLik;
int sampleSize = original.size();
for (int i = 0; i < sampleSize; i++) {
sumLik += pow(original[i] - model[i], 2);
}
logLik = log(sumLik) * sampleSize;
valueBIC = logLik + log((double)sampleSize) * paramCount;
return valueBIC;
}
double Bic::rmseBIC(vector<double> original, vector<double> model, int paramCount)
{
double valueBIC;
int sampleSize = original.size();
Estimation *RMSE = new Rmse();
double valueRMSE = RMSE->getValue(original, model);
valueBIC = valueRMSE * pow((double)sampleSize, paramCount / (2 * sampleSize));
return valueBIC;
}
double Bic::smapeBIC(vector<double> original, vector<double> model, int paramCount)
{
double valueBIC;
int sampleSize = original.size();
Estimation *sMAPE = new SMape();
double value_sMAPE = sMAPE->getValue(original, model);
valueBIC = value_sMAPE * pow((double)sampleSize, paramCount / (2 * sampleSize));
return valueBIC;
}