This commit is contained in:
Anton Romanov 2022-12-13 12:36:06 +04:00
commit 1bf1657b93
103 changed files with 9853 additions and 0 deletions

BIN
Debug/project_template.exe Normal file

Binary file not shown.

BIN
Debug/project_template.ilk Normal file

Binary file not shown.

BIN
Debug/project_template.pdb Normal file

Binary file not shown.

51
Debug/test/1.txt Normal file
View File

@ -0,0 +1,51 @@
5520
3940
4490
5030
5660
4790
5520
5560
5200
6670
5900
5280
6490
5560
5090
7090
6570
5890
6640
6360
5640
6630
5330
5540
7100
5410
5800
6110
6870
6560
6120
6540
5810
6300
6270
6900
6310
5330
5700
6680
5510
6690
5870
7140
6680
6520
6020
6190
6690
6330
7620

View File

@ -0,0 +1,30 @@
5780
5780
5780
5780
5780
5780
4860
5780
5780
5780
4860
5780
5780
5780
5780
5780
6700
5780
5780
5166,67
6393,33
5780
5780
5166,67
5780
5780
5780
6393,33
5780
6393,33

View File

@ -0,0 +1 @@
Smape for 15 method: 11.2282 alpha: 0 delta 0 gamma: 0 phi: 0 countRulesIn: 1 countFuzzyParts: 2 sizeLabels: 1 p: 1

Binary file not shown.

Binary file not shown.

BIN
libnlopt-0.dll Normal file

Binary file not shown.

BIN
libnlopt-0.lib Normal file

Binary file not shown.

BIN
project_template.ncb Normal file

Binary file not shown.

26
project_template.sln Normal file
View File

@ -0,0 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "project_template", "project_template\project_template.vcproj", "{D68B91E2-1169-4096-AC00-5992226D29DF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Элементы решения", "Элементы решения", "{33699718-6D46-4936-8061-0EF2D6A27D62}"
ProjectSection(SolutionItems) = preProject
C:\Users\orion\Desktop\project_template.vsd = C:\Users\orion\Desktop\project_template.vsd
project_template.vsd = project_template.vsd
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D68B91E2-1169-4096-AC00-5992226D29DF}.Debug|Win32.ActiveCfg = Debug|Win32
{D68B91E2-1169-4096-AC00-5992226D29DF}.Debug|Win32.Build.0 = Debug|Win32
{D68B91E2-1169-4096-AC00-5992226D29DF}.Release|Win32.ActiveCfg = Release|Win32
{D68B91E2-1169-4096-AC00-5992226D29DF}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

BIN
project_template.suo Normal file

Binary file not shown.

BIN
project_template.vsd Normal file

Binary file not shown.

35
project_template/A.cpp Normal file
View File

@ -0,0 +1,35 @@
#include "StdAfx.h"
#include "A.h"
A::A() {
}
A::A(double left, double right) {
this->left = left;
this->right = right;
}
double A::getValue(double value) {
if (value == (right + left) / 2) {
return 1;
} else if ((value >= right) || (value <= left)) {
return 0;
} else if (value < (right + left) / 2) {
return (double)(value - left) / ((right + left) / 2 - left);
} else if (value > (right + left) / 2) {
return (double) -(value - right) / (right - (right + left) / 2);
}
}
double A::getValueAtTop() {
return (right + left) / 2;
}
double A::getLeft() {
return left;
}
double A::getRight() {
return right;
}

20
project_template/A.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef A_H
#define A_H
//using namespace std;
// класс, отвечающий описывающий функции принадлежности
class A {
private:
double left; // левая граница
double right; // правая граница
public:
A();
A(double, double);
double getLeft();
double getRight();
double getValue(double); // получить значение функции принадлежности в указанной точке
double getValueAtTop(); // получить четкое значение при чначении функции принадлежности = 1
};
#endif

View File

@ -0,0 +1,142 @@
//
// Ìåòîä ýêñïîíåíöèàëüíîãî ñãëàæèâàíèÿ è ïðîãíîçèðîâàíèÿ:
// àääèòèâíûé òðåíä, àääèòèâíàÿ ñåçîííîñòü
//
#include "StdAfx.h"
#include <iostream>
#include "AddTrendAddSeasonality.h"
#include "Param.h"
// êîíñòðóêòîð ñ çàäàííûìè íåïîñðåäñòâåííî ïàðàìåòðàìè
AddTrendAddSeasonality::AddTrendAddSeasonality(vector<double> timeSeries, int countPointForecast) {
this->x = timeSeries;
this->countPointForecast = countPointForecast;
this->partition();
}
AddTrendAddSeasonality::~AddTrendAddSeasonality() {
// îñâîáîæäàåòñÿ ïàìÿòü
std::vector<double> ().swap(S);
std::vector<double> ().swap(x);
std::vector<double> ().swap(T);
std::vector<double> ().swap(I);
std::vector<double> ().swap(forecast);
}
// èíèöèàëèçàöèÿ ìîäåëè, çàäàíèå ïåðâîíà÷àëüíûõ çíà÷åíèé
void AddTrendAddSeasonality::init() {
S.clear();
T.clear();
I.clear();
forecast.clear();
double sumS = 0;
double sumT = 0;
for (unsigned int t = 0; t < p; t++) {
sumS += x[t];
sumT += x[t+p];
}
S.push_back(sumS / p);
T.push_back((sumT/ p - S[0]) / p);
for (unsigned int t = 0; t < p; t++) {
I.push_back(x[t] - S[0]);
}
forecast.push_back(S[0] + T[0] + I[0]);
}
// Çàäàòü ïàðàìåòð
void AddTrendAddSeasonality::setParam(string paramName, double value) {
if (paramName.compare("alpha") == 0) {
this->alpha = value;
} else if (paramName.compare("gamma") == 0) {
this->gamma = value;
} else if (paramName.compare("p") == 0) {
this->p = value;
} else if (paramName.compare("delta") == 0) {
this->delta = value;
}
}
// ñôîðìèðîâàòü ìîäåëü
void AddTrendAddSeasonality::createModel() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < x.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < x.size()) {
e = x[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] + T[t] + alpha * e); // óðîâåíü
T.push_back(T[t] + alpha * gamma * e); // òðåíä
I.push_back(I[t] + delta * e); // ñåçîííîñòü
forecast.push_back(S[t+1] + T[t+1] + I[t+1]); // ïðîãíîç
}
}
// ñôîðìèðîâàòü ìîäåëü
void AddTrendAddSeasonality::createModelForEstimation() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < xLearning.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < xLearning.size()) {
e = xLearning[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] + T[t] + alpha * e); // óðîâåíü
T.push_back(T[t] + alpha * gamma * e); // òðåíä
I.push_back(I[t] + delta * e); // ñåçîííîñòü
forecast.push_back(S[t+1] + T[t+1] + I[t+1]); // ïðîãíîç
}
}
// ìåòîä ïîëó÷åíèÿ ïðîãíîçà
vector<double> AddTrendAddSeasonality::getForecast() {
vector<double> result;
for (unsigned int i = forecast.size() - countPointForecast; i < forecast.size(); i++) {
result.push_back(forecast[i]);
}
return result;
}
// ìåòîä ïîëó÷åíèÿ îöåíêè ìîäåëè
double AddTrendAddSeasonality::calcEstimation(Aic *aic) {
return aic->getValue(3, this->xEstimation, this->forecast);
}
// ìåòîä ïîëó÷åíèÿ îïòèìèçèðîâàííîãî çíà÷åíèÿ îäíîãî ïàðàìåòðà
// TODO: ðåàëèçîâàòü
Param* AddTrendAddSeasonality::optimize(Estimation *est) {
Param *optimal = new Param();
double minSmape = 99999;
for (double al = 0.1; al < 1; al+= 0.01) {
for (double del = 0.1; del < 1; del+= 0.01) {
this->setParam("alpha", al);
this->setParam("delta", del);
this->createModelForEstimation();
double smapeValue = est->getValue(getXEstimation(), getForecast());
if (minSmape > smapeValue) {
minSmape = smapeValue;
optimal->alpha = al;
}
}
}
return optimal;
}

View File

@ -0,0 +1,35 @@
#ifndef ADDTRENDADDSEASONALITY_H
#define ADDTRENDADDSEASONALITY_H
#include "Method.h"
#include "Aic.h"
#include "Param.h"
using namespace std;
// êîíêðåòíàÿ ðåàëèçàöèÿ àáñòðàêòíîãî êëàññà Method
// ðåàëèçóåò ìåòîä ýêñïîíåíöèàëüíîãî ñ àääèòèâíûì òðåíäîì, àääèòèâíîé ñåçîííîñòüþ
class AddTrendAddSeasonality : public Method {
public:
double alpha; // ïàðàìåòð ñãëàæèâàíèÿ
vector<double> S; // ñãëàæåííûé äàííûì ìåòîäîì ðÿä
double gamma; // ïàðàìåòð ñãëàæèâàíèÿ òðåíäà
double delta; // ïàðàìåòð ñãëàæèâàíèÿ ñåçîííîé êîìïîíåíòû
vector<double> T; // ñãëàæåííûé òðåíä
vector<double> I; // ñåçîííàÿ êîìïîíåíòà
int p; // ïåðèîä ñåçîííîñòè
AddTrendAddSeasonality(vector<double>, int);
~AddTrendAddSeasonality();
vector<double> getForecast();
void init();
void createModel();
void createModelForEstimation();
void setParam(string, double);
double calcEstimation(Aic *);
Param* optimize(Estimation *); // ìåòîä îïòèìèçàöèè îäíîãî ïàðàìåòðà
vector<double> getS();
};
#endif

View File

@ -0,0 +1,145 @@
//
// Ìåòîä ýêñïîíåíöèàëüíîãî ñãëàæèâàíèÿ è ïðîãíîçèðîâàíèÿ:
// àääèòèâíûé òðåíä, ìóëüòèïëèêàòèâíàÿ ñåçîííîñòü
//
#include "StdAfx.h"
#include <iostream>
#include "AddTrendMultSeasonality.h"
#include "Param.h"
// êîíñòðóêòîð ñ çàäàííûìè íåïîñðåäñòâåííî ïàðàìåòðàìè
AddTrendMultSeasonality::AddTrendMultSeasonality(vector<double> timeSeries, int countPointForecast) {
this->x = timeSeries;
this->countPointForecast = countPointForecast;
this->partition();
}
AddTrendMultSeasonality::~AddTrendMultSeasonality() {
// îñâîáîæäàåòñÿ ïàìÿòü
std::vector<double> ().swap(S);
std::vector<double> ().swap(x);
std::vector<double> ().swap(T);
std::vector<double> ().swap(I);
std::vector<double> ().swap(forecast);
}
// èíèöèàëèçàöèÿ ìîäåëè, çàäàíèå ïåðâîíà÷àëüíûõ çíà÷åíèé
void AddTrendMultSeasonality::init() {
S.clear();
T.clear();
I.clear();
forecast.clear();
double sumS = 0;
double sumT = 0;
for (unsigned int t = 0; t < p; t++) {
sumS += x[t];
sumT += x[t+p];
}
S.push_back(sumS / p);
T.push_back((sumT/ p - S[0]) / p);
for (unsigned int t = 0; t < p; t++) {
I.push_back(x[t] / S[0]);
}
forecast.push_back((S[0] + T[0]) * I[0]);
}
// Çàäàòü ïàðàìåòð
void AddTrendMultSeasonality::setParam(string paramName, double value) {
if (paramName.compare("alpha") == 0) {
this->alpha = value;
} else if (paramName.compare("gamma") == 0) {
this->gamma = value;
} else if (paramName.compare("p") == 0) {
this->p = value;
} else if (paramName.compare("delta") == 0) {
this->delta = value;
}
}
// ñôîðìèðîâàòü ìîäåëü
void AddTrendMultSeasonality::createModel() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < x.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < x.size()) {
e = x[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] + T[t] + alpha * e / I[t]); // óðîâåíü
T.push_back(T[t] + alpha * gamma * e / I[t]); // òðåíä
I.push_back(I[t] + delta * e / (S[t] + T[t])); // ñåçîííîñòü
forecast.push_back((S[t+1] + T[t+1]) * I[t+1]); // ïðîãíîç
}
}
// ñôîðìèðîâàòü ìîäåëü ñ íîâûì çíà÷åíèåì ïàðàìåòðà. ïåðåãðóæåííûé ìåòîä
void AddTrendMultSeasonality::createModelForEstimation() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < xLearning.size()-1 +this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < xLearning.size()) {
e = xLearning[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] + T[t] + alpha * e / I[t]); // óðîâåíü
T.push_back(T[t] + alpha * gamma * e / I[t]); // òðåíä
I.push_back(I[t] + delta * e / (S[t] + T[t])); // ñåçîííîñòü
forecast.push_back((S[t+1] + T[t+1]) * I[t+1]); // ïðîãíîç
}
}
// ìåòîä ïîëó÷åíèÿ ïðîãíîçà
vector<double> AddTrendMultSeasonality::getForecast() {
vector<double> result;
for (unsigned int i = forecast.size() - countPointForecast; i < forecast.size(); i++) {
result.push_back(forecast[i]);
}
return result;
}
// ìåòîä ïîëó÷åíèÿ îöåíêè ìîäåëè
double AddTrendMultSeasonality::calcEstimation(Aic *aic) {
return aic->getValue(3, this->xEstimation, this->forecast);
}
// ìåòîä ïîëó÷åíèÿ îïòèìèçèðîâàííîãî çíà÷åíèÿ îäíîãî ïàðàìåòðà
// TODO: ðåàëèçîâàòü
Param* AddTrendMultSeasonality::optimize(Estimation *est) {
Param *optimal = new Param();
double minSmape = 99999;
for (double al = 0.1; al < 1; al+= 0.01) {
for (double gam = 0.1; gam < 1; gam+= 0.01) {
for (double del = 0.1; del < 1;del+= 0.01) {
this->setParam("alpha", al);
this->setParam("gamma", gam);
this->setParam("delta", del);
this->createModelForEstimation();
double smapeValue = est->getValue(getXEstimation(), getForecast());
if (minSmape > smapeValue) {
minSmape = smapeValue;
optimal->alpha = al;
optimal->gamma = gam;
optimal->delta = del;
}
}
}
}
return optimal;
}

View File

@ -0,0 +1,34 @@
#ifndef ADDTRENDMULTSEASONALITY_H
#define ADDTRENDMULTSEASONALITY_H
#include "Method.h"
#include "Aic.h"
#include "Param.h"
using namespace std;
// êîíêðåòíàÿ ðåàëèçàöèÿ àáñòðàêòíîãî êëàññà Method
// ðåàëèçóåò ìåòîä ýêñïîíåíöèàëüíîãî ñ àääèòèâíûì òðåíäîì, ìóëüòèïëèêàòèâíîé ñåçîííîñòüþ
class AddTrendMultSeasonality : public Method {
public:
double alpha; // ïàðàìåòð ñãëàæèâàíèÿ
vector<double> S; // ñãëàæåííûé äàííûì ìåòîäîì ðÿä
double gamma; // ïàðàìåòð ñãëàæèâàíèÿ òðåíäà
double delta; // ïàðàìåòð ñãëàæèâàíèÿ ñåçîííîé êîìïîíåíòû
vector<double> T; // ñãëàæåííûé òðåíä
vector<double> I; // ñåçîííàÿ êîìïîíåíòà
int p; // ïåðèîä ñåçîííîñòè
AddTrendMultSeasonality(vector<double>, int);
~AddTrendMultSeasonality();
vector<double> getForecast();
void init();
void createModel();
void createModelForEstimation();
void setParam(string, double);
double calcEstimation(Aic *);
Param* optimize(Estimation *); // ìåòîä îïòèìèçàöèè îäíîãî ïàðàìåòðà
};
#endif

View File

@ -0,0 +1,126 @@
//
// Ìåòîä ýêñïîíåíöèàëüíîãî ñãëàæèâàíèÿ è ïðîãíîçèðîâàíèÿ:
// àääèòèâíûé òðåíä, áåç ñåçîííîñòè
//
#include "StdAfx.h"
#include <iostream>
#include "AddTrendNoSeasonality.h"
#include "Aic.h"
#include "Param.h"
// êîíñòðóêòîð ñ çàäàííûìè íåïîñðåäñòâåííî ïàðàìåòðàìè
AddTrendNoSeasonality::AddTrendNoSeasonality(vector<double> timeSeries, int countPointForecast) {
this->x = timeSeries;
this->countPointForecast = countPointForecast;
this->partition();
this->alpha = 0;
this->gamma = 0;
}
AddTrendNoSeasonality::~AddTrendNoSeasonality() {
// îñâîáîæäàåòñÿ ïàìÿòü
std::vector<double> ().swap(S);
std::vector<double> ().swap(x);
std::vector<double> ().swap(T);
std::vector<double> ().swap(forecast);
}
// Çàäàòü ïàðàìåòð
void AddTrendNoSeasonality::setParam(string paramName, double value) {
if (paramName.compare("alpha") == 0) {
this->alpha = value;
} else if (paramName.compare("gamma") == 0) {
this->gamma = value;
}
}
// èíèöèàëèçàöèÿ ìîäåëè, çàäàíèå ïåðâîíà÷àëüíûõ çíà÷åíèé
void AddTrendNoSeasonality::init() {
S.clear();
T.clear();
forecast.clear();
T.push_back(x[1] - x[0]);
S.push_back(x[0]);
forecast.push_back(S[0] + T[0]);
}
// ñôîðìèðîâàòü ìîäåëü
void AddTrendNoSeasonality::createModel() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t <x.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < x.size()) {
e = x[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] + T[t] + alpha * e); // óðîâåíü
T.push_back(T[t] + alpha * gamma * e); // òðåíä
forecast.push_back(S[t+1] + T[t+1]); // ïðîãíîç
}
}
// ñôîðìèðîâàòü ìîäåëü
void AddTrendNoSeasonality::createModelForEstimation() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < xLearning.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < xLearning.size()) {
e = xLearning[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] + T[t] + alpha * e); // óðîâåíü
T.push_back(T[t] + alpha * gamma * e); // òðåíä
forecast.push_back(S[t+1] + T[t+1]); // ïðîãíîç
}
}
// ìåòîä ïîëó÷åíèÿ ïðîãíîçà
vector<double> AddTrendNoSeasonality::getForecast() {
vector<double> result;
for (unsigned int i = forecast.size() - countPointForecast; i < forecast.size(); i++) {
result.push_back(forecast[i]);
}
return result;
}
// ìåòîä ïîëó÷åíèÿ îöåíêè ìîäåëè
double AddTrendNoSeasonality::calcEstimation(Aic *aic) {
return aic->getValue(3, this->xEstimation, this->forecast);
}
// ìåòîä ïîëó÷åíèÿ îïòèìèçèðîâàííîãî çíà÷åíèÿ îäíîãî ïàðàìåòðà
// TODO: ðåàëèçîâàòü
Param* AddTrendNoSeasonality::optimize(Estimation *est) {
Param *optimal = new Param();
double minSmape = 99999;
for (double al = 0.1; al < 1; al+= 0.01) {
for (double gam = 0.1; gam < 1; gam+= 0.01) {
this->setParam("alpha", al);
this->setParam("gamma", gam);
this->createModelForEstimation();
double smapeValue = est->getValue(getXEstimation(), getForecast());
if (minSmape > smapeValue) {
minSmape = smapeValue;
optimal->alpha = al;
optimal->gamma = gam;
}
}
}
return optimal;
}

View File

@ -0,0 +1,31 @@
#ifndef ADDTRENDNOSEASONALITY_H
#define ADDTRENDNOSEASONALITY_H
#include "Method.h"
#include "Aic.h"
#include "Param.h"
using namespace std;
// êîíêðåòíàÿ ðåàëèçàöèÿ àáñòðàêòíîãî êëàññà Method
// ðåàëèçóåò ìåòîä ýêñïîíåíöèàëüíîãî ñ àääèòèâíûì òðåíäîì, áåç ñåçîííîñòè
class AddTrendNoSeasonality : public Method {
public:
double alpha; // ïàðàìåòð ñãëàæèâàíèÿ
vector<double> S; // ñãëàæåííûé äàííûì ìåòîäîì ðÿä
double gamma; // ïàðàìåòð ñãëàæèâàíèÿ òðåíäà
vector<double> T; // ñãëàæåííûé òðåíä
AddTrendNoSeasonality(vector<double>, int);
~AddTrendNoSeasonality();
vector<double> getForecast();
void init();
void createModel();
void createModelForEstimation();
void setParam(string, double);
double calcEstimation(Aic *);
Param* optimize(Estimation *); // ìåòîä îïòèìèçàöèè îäíîãî ïàðàìåòðà
};
#endif

202
project_template/Aic.cpp Normal file
View File

@ -0,0 +1,202 @@
#include "StdAfx.h"
#include <iostream>
#include <math.h>
#include "Aic.h"
# define M_PI 3.14159265358979323846 /* pi */
using namespace std;
// критерий Акаике. Наследуется от класса Estimation.
// реализует метод "получить значение критерия"
Aic::Aic() {
}
Aic::~Aic(){
}
/*
paramsCount - count of model params,
количество параетров модели
tsLen - lenght of forecasted estimated time seria,
длина оцениваемого спрогнозированного временного ряда
isSecondOrder - AIC second order modification,
модифицированный АИК второго порядка
original - values of the predicted time series,
известные значения прогнозируемого временного ряда
model - forecasted values of the predicted time series,
прогнозированные значения прогнозируемого временного ряда
*/
//Надо перенести в интерфейс модели, логично если модели будут в последствии
//разных типов
//Функция правдоподобия для не линейной модели
double Aic::logLikNLS(vector<double> forecast, vector<double> weights){
int n = forecast.size();
if (weights.size() == 0){
for (int i = 0; i < n; i++){
weights.push_back(1);
}
}
//summ log(w)
double wls = 0;
//wetghted forecasts
double wfor = 0;
for (int i = 0; i < n; i++){
//zero weights hack
if (weights[i] != 0){
wls += log(weights[i]);
}
else{
wls += log((double)1);
}
wfor += weights[i] * forecast[i] * forecast[i];
}
double res = -n * (log((double)2 * M_PI) + 1 - log((double)n) - wls + log((double)wfor)) / 2;
return res;
}
//Функция правдоподобия для линейной модели
double Aic::logLikLM(vector<double> forecast, vector<double> weights){
int n = forecast.size();
if (weights.size() == 0){
for (int i = 0; i < n; i++){
weights.push_back(1);
}
}
else{
int i = 0;
while (i < n){
if (weights[i] == 0){
forecast.erase(forecast.begin() + i);
weights.erase(weights.begin() + i);
n = forecast.size();
}
i++;
}
}
//summ log(w)
double wls = 0;
//wetghted forecasts
double wfor = 0;
for (int i = 0; i < n; i++){
wls += log(weights[i]);
wfor += weights[i] * forecast[i] * forecast[i];
}
double res = 0.5 * (wls - n * (log((double)2 * M_PI) + 1 - log((double)n) + log((double)wfor)));
return res;
}
//Свойство класса модели
int Aic::getParamsCount(vector<double> model){
#pragma message ("Need solve where is it must do")
cout << "log-likelihood function calculate";
return 0;
}
/*
models with special methods:
glm, multinom
+- maxlikeFit, merMod, unmarkedFit, vglm
*/
double Aic::getBicValue(int paramsCount,
vector<double> original, vector<double> model){
int n = (original.size() > model.size() ? model.size() : original.size());
double res = 0;
double lik = 0;
double lik2 = 0;
vector<double> e;
cout << "Bicc " << endl;
cout << " e sum(lik) sum(lik2)" << endl;
for (int i = 0; i < n; i++){
//adderror
e.push_back(original[i] - model[i]);
cout << " " << e[i];
lik += e[i] * e[i];
cout << " " << lik;
lik2 += log(fabs(model[i]));
cout << " " << lik2 << endl;
// MULT lik += (original[i] - model[i])/ model[i];
}
lik = n * log(lik);
//MULT lik +=2 *lik2;
res = lik + log((double)n) * paramsCount;
cout << " " << res << " " << endl;
return res;
}
double Aic::getAiccValue(int paramsCount,
vector<double> original, vector<double> model){
int n = (original.size() > model.size() ? model.size() : original.size());
double res = 0;
double lik = 0;
double lik2 = 0;
vector<double> e;
cout << "Aicc " << endl;
cout << " e sum(lik) sum(lik2)" << endl;
for (int i = 0; i < n; i++){
//adderror
e.push_back(original[i] - model[i]);
cout << " " << e[i];
lik += e[i] * e[i];
cout << " " << lik;
lik2 += log(fabs(model[i]));
cout << " " << lik2 << endl;
// MULT lik += (original[i] - model[i])/ model[i];
}
lik = n * log(lik);
//MULT lik +=2 *lik2;
res = lik + (2 * paramsCount* n)/( n - paramsCount - 1);
cout << " " << res << " " << endl;
return res;
}
/*
valide for next models by package:
aov, clm, clmm, coxme, coxph, gls, lm, lme, lmeik, mer, merMod,
multinom, nlme, nls, polr, rlm, zeroinfl
*/
double Aic::getValue(int paramsCount, // bool isSecondOrder,
vector<double> original, vector<double> model) {
//Validate(original, model);
int n = (original.size() > model.size() ? model.size() : original.size());
////// R default package
//double logLik = Aic::logLikNLS(model, RSSweights(original, model));//Aic::logLikLM(model, RSSweights(original, model));
////R-package version
//if (true){//isSecondOrder){
// return -2 * logLik + 2 * paramsCount;
//}
//else
//{
// return -2 * logLik + 2 * paramsCount *(n / (n - paramsCount - 1));
//}
//lm version from paper
/*double rss = RSS(original, model);
double res = 2 * paramsCount + n * log(rss / (n - 2));
return res;*/
///forecast 5.6 R package
double res = 0;
double lik = 0;
double lik2 = 0;
vector<double> e;
//cout << "Aic " << endl;
//cout << " e sum(lik) sum(lik2)" << endl;
for (int i = 0; i < n; i++){
//adderror
e.push_back(original[i] - model[i]);
//cout << " " << e[i];
lik += e[i] * e[i];
//cout << " " << lik;
lik2 += log(fabs(model[i]));
//cout << " " << lik2 << endl;
// MULT lik += (original[i] - model[i])/ model[i];
}
lik = n * log(lik);
//MULT lik +=2 *lik2;
res = lik + 2 * paramsCount;
//cout << " " << res << " " << endl;
return res;
}
double Aic::getValue(vector<double> original, vector<double> model) {
return this->getValue(4, original, model);
}

40
project_template/Aic.h Normal file
View File

@ -0,0 +1,40 @@
#ifndef AIC_H
#define AIC_H
#include "Estimation.h"
#include <vector>
using namespace std;
// êðèòåðèé Àêàèêå. Íàñëåäóåòñÿ îò êëàññà Estimation.
// ðåàëèçóåò ìåòîä "ïîëó÷èòü çíà÷åíèå êðèòåðèÿ"
class Aic : public Estimation {
private:
static double getMinValue(vector<double> AicWeights); // Íàéòè ìèíèìàëüíûé ýëåìåíò âåêòîðà
//For fuzzy adoptive weights calculate
//Delta koeff
static double delta;
static double N;
static double relativeError(double value, double forecastedValue);
static double forecastedTendency(vector<double> realSeria);
static double grayTendency(double forecastedTendency, vector<double> timeSeria, vector<vector<double>> forecastedSeries);
static double grayBasicWeight(double relativeError, vector<double> timeSeria, vector<vector<double>> forecastedSeries);
static double adaptiveControlCoefficient(int i);
static double beta(vector<double> timeSeria, vector<vector<double>> forecastedSeries);
static double alpha(vector<double> timeSeria, vector<vector<double>> forecastedSeries);
public:
Aic();
~Aic();
static int getParamsCount(vector<double> model);
static double logLikNLS(vector<double> model, vector<double> weights);
static double logLikLM(vector<double> model, vector<double> weights);
static vector<double> calculateWeights(vector<double> AicWeights); //Ðàññ÷èòàòü çíà÷åíèÿ âåñîâ
static vector<double> calculateFuzzyAdaptiveWeights(vector<double> timeSeria, vector<vector<double>> forecastedSeries); //Ðàññ÷èòàòü çíà÷åíèÿ âåñîâ
double getBicValue(int paramsCount, vector<double> original, vector<double> model);
double getAiccValue(int paramsCount, vector<double> original, vector<double> model);
double getValue(int paramsCount,// int tsLen, bool isSecondOrder,
vector<double> original, vector<double> model); //ïîëó÷èòü çíà÷åíèå îöåíêè ìîäåëè
double getValue(// int tsLen, bool isSecondOrder,
vector<double> original, vector<double> model); //ïîëó÷èòü çíà÷åíèå îöåíêè ìîäåëè
};
#endif

View File

@ -0,0 +1,126 @@
#include "StdAfx.h"
#include <iostream>
#include <math.h>
#include "AicWeights.h"
using namespace std;
AicWeights::AicWeights(){
delta = 0.5;
N = 0.5;
}
AicWeights::~AicWeights(){
}
double AicWeights::getMinValue(vector<double> AicValues){
double res = AicValues[0];
for (int i = 0; i < AicValues.size(); i++){
if (AicValues[i] < res){
res = AicValues[i];
}
}
return res;
}
vector<double> AicWeights::calculateWeights(vector<double> AicValues){
vector<double> diffs;
double minWeight = getMinValue(AicValues);
double sum = 0;
for (int i = 0; i < AicValues.size(); i++){
diffs.push_back(AicValues[i] - minWeight);
sum += exp(-0.5 * (AicValues[i] - minWeight));
}
vector<double> res;
for (int i = 0; i < AicValues.size(); i++){
res.push_back(exp(-0.5 *diffs[i]) / sum);
}
double check = 0;
for (int i = 0; i < res.size(); i++){
check += res[i];
}
return res;
}
//timeSeria - Real process time seria value vector.
//forecastedSeries - Vector of vectors of the forecasted values.
//Inner vectors must have the same length that timeSeria. Usually need cut timeSeria.
double AicWeights::alpha(vector<double> timeSeria, vector<vector<double>> forecastedSeries){
double alphaRes = abs(timeSeria[0] - forecastedSeries[0][0]);
for (int j = 0; j < forecastedSeries.size(); j++){
for (int i = 0; i < forecastedSeries[j].size(); i++){
if (alphaRes < abs(timeSeria[i] - forecastedSeries[j][i])){
alphaRes = abs(timeSeria[i] - forecastedSeries[j][i]);
}
}
}
return alphaRes;
}
double AicWeights::beta(vector<double> timeSeria, vector<vector<double>> forecastedSeries){
double betaRes = abs(timeSeria[0] - forecastedSeries[0][0]);
for (int j = 0; j < forecastedSeries.size(); j++){
for (int i = 0; i < forecastedSeries[j].size(); i++){
if (betaRes > abs(timeSeria[i] - forecastedSeries[j][i])){
betaRes = abs(timeSeria[i] - forecastedSeries[j][i]);
}
}
}
return betaRes;
}
double AicWeights::grayBasicWeight(double relativeError, vector<double> timeSeria, vector<vector<double>> forecastedSeries){
return (alpha(timeSeria, forecastedSeries) + beta(timeSeria, forecastedSeries) * delta) / abs(relativeError)
+ beta(timeSeria, forecastedSeries) * delta;
}
double AicWeights::grayTendency(double forecastedTendency, vector<double> timeSeria, vector<vector<double>> forecastedSeries){
return (alpha(timeSeria, forecastedSeries) + beta(timeSeria, forecastedSeries) * delta) / abs(forecastedTendency)
+ beta(timeSeria, forecastedSeries) * delta;
}
double AicWeights::delta;
double AicWeights::N;
//e(i)
double AicWeights::relativeError(double value, double forecastedValue){
return (value - forecastedValue) / value;
}
//c(i)
double AicWeights::forecastedTendency(vector<double> realSeria){
double sum = 0;
for (int i = 0; i < realSeria.size() - 1; i++){
sum += realSeria[i];
}
return (realSeria[realSeria.size() - 1] - (1 / (realSeria.size() - 2)) * sum) / realSeria[realSeria.size() - 1];
}
//n - positive number,usually n = 0.5
//i - forecasted value number
double AicWeights::adaptiveControlCoefficient(int i){
double acc = 0;
acc = 1 - pow(((i - 1) / i), N);
return acc;
}
vector<double> AicWeights::calculateFuzzyAdaptiveWeights(vector<double> timeSeria, vector<vector<double>> forecastedSeries){
vector<double> fweights;
for (int i = 0; i < forecastedSeries.size(); i++){
fweights.push_back(adaptiveControlCoefficient(timeSeria.size())* grayBasicWeight(relativeError(timeSeria[timeSeria.size() - 1], forecastedSeries[i][forecastedSeries[i].size() - 1]), timeSeria, forecastedSeries)
+ (1 - adaptiveControlCoefficient(timeSeria.size())) * grayTendency(forecastedTendency(timeSeria), timeSeria, forecastedSeries));
}
//normalization
double sum = 0;
for (int i = 0; i < fweights.size(); i++){
sum += fweights[i];
}
for (int i = 0; i < fweights.size(); i++){
fweights[i] = fweights[i] / sum;
}
double check = 0;
for (int i = 0; i < fweights.size(); i++){
check += fweights[i];
}
return fweights;
}

View File

@ -0,0 +1,29 @@
#ifndef AICWEIGHTS_H
#define AICWEIGHTS_H
#include <vector>
using namespace std;
// êðèòåðèé Àêàèêå. Íàñëåäóåòñÿ îò êëàññà Estimation.
// ðåàëèçóåò ìåòîä "ïîëó÷èòü çíà÷åíèå êðèòåðèÿ"
class AicWeights {
private:
static double getMinValue(vector<double> AicWeights); // Íàéòè ìèíèìàëüíûé ýëåìåíò âåêòîðà
//For fuzzy adoptive weights calculate
//Delta koeff
static double delta;
static double N;
static double relativeError(double value, double forecastedValue);
static double forecastedTendency(vector<double> realSeria);
static double grayTendency(double forecastedTendency, vector<double> timeSeria, vector<vector<double>> forecastedSeries);
static double grayBasicWeight(double relativeError, vector<double> timeSeria, vector<vector<double>> forecastedSeries);
static double adaptiveControlCoefficient(int i);
static double beta(vector<double> timeSeria, vector<vector<double>> forecastedSeries);
static double alpha(vector<double> timeSeria, vector<vector<double>> forecastedSeries);
public:
AicWeights();
~AicWeights();
static vector<double> calculateWeights(vector<double> AicWeights); //Ðàññ÷èòàòü çíà÷åíèÿ âåñîâ
static vector<double> calculateFuzzyAdaptiveWeights(vector<double> timeSeria, vector<vector<double>> forecastedSeries); //Ðàññ÷èòàòü çíà÷åíèÿ âåñîâ
};
#endif

104
project_template/BIC.cpp Normal file
View File

@ -0,0 +1,104 @@
#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;
}

30
project_template/BIC.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef BIC_H
#define BIC_H
#include "Estimation.h"
#include <vector>
using namespace std;
enum algoritm {
RMSE,
sMAPE,
Classic
};
class Bic : public Estimation {
private:
algoritm versionBIC;
double classicBIC(vector<double>, vector<double>, int);
double rmseBIC(vector<double>, vector<double>, int);
double smapeBIC(vector<double>, vector<double>, int);
public:
Bic(algoritm, int);
~Bic();
int pc;
double getValue(vector<double>, vector<double>);
double getValue(int, vector<double>, vector<double>);
};
#endif

View File

@ -0,0 +1,373 @@
<?xml version="1.0" encoding="utf-8"?>
<ClassDiagram MajorVersion="1" MinorVersion="1" GroupingSetting="Alphabetical">
<Class Name="Estimation">
<Position X="61.5" Y="6.75" Width="2" />
<TypeIdentifier>
<HashCode>IAAAAAAAAACAACAAAAAAAAAAAAAAACAAAAAAAAAAAAA=</HashCode>
<FileName>Estimation.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="File">
<Position X="38.25" Y="4.75" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAggAAAAAAAQg=</HashCode>
<FileName>File.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="Method">
<Position X="12.75" Y="0.5" Width="2" />
<TypeIdentifier>
<HashCode>AAQAAAAEAgAAAABAAAAAABAAAIBEACAkDEBEAAAAACI=</HashCode>
<FileName>Method.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="Normalization">
<Position X="34.75" Y="7.5" Width="1.5" />
<TypeIdentifier>
<HashCode>AABgAAAACAABAAoAAABAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Normalization.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="Param">
<Position X="36.5" Y="8.75" Width="1.5" />
<TypeIdentifier>
<HashCode>AAEAAAIAAAAAAAAAAAQABAAAAAAAAGCAAAgQAEAAAAA=</HashCode>
<FileName>Param.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="TrackingControlSignal">
<Position X="40" Y="4.75" Width="1.5" />
<TypeIdentifier>
<HashCode>AAEAAEAABAAAAAAEAAAAAAAAAAADAAAAAABQDAACAAA=</HashCode>
<FileName>TrackingControlSignal.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="Vovk">
<Position X="33" Y="4.75" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAABEAECAQAIAIhAIhUAABAAhAAAEIAAQEwAMAAA=</HashCode>
<FileName>Vovk.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="Preparator">
<Position X="38.25" Y="7" Width="1.5" />
<TypeIdentifier>
<HashCode>AABgCAAACAABFAJAiQBABBACACAAAAEACQgAAAIAACA=</HashCode>
<FileName>Preparator.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="AddTrendAddSeasonality">
<Position X="8.25" Y="6" Width="2.25" />
<TypeIdentifier>
<HashCode>AAUAAAAEAgAAAAAAAAAAAAAAAIIAAAYACEAQAGCEAAI=</HashCode>
<FileName>AddTrendAddSeasonality.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="AddTrendMultSeasonality">
<Position X="8.25" Y="10.75" Width="2.25" />
<InheritanceLine Type="Method" ManuallyRouted="true">
<Path>
<Point X="13.75" Y="4.873" />
<Point X="13.75" Y="5.242" />
<Point X="10.922" Y="5.242" />
<Point X="10.922" Y="10.461" />
<Point X="9.375" Y="10.461" />
<Point X="9.375" Y="10.75" />
</Path>
</InheritanceLine>
<TypeIdentifier>
<HashCode>AAUAAAAEAgAAAAQAAAAAAAAAAIAAAAIACEAQCGCEAAI=</HashCode>
<FileName>AddTrendMultSeasonality.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="AddTrendNoSeasonality">
<Position X="8.5" Y="15.25" Width="2" />
<InheritanceLine Type="Method" ManuallyRouted="true">
<Path>
<Point X="13.75" Y="4.873" />
<Point X="13.75" Y="5.313" />
<Point X="10.935" Y="5.313" />
<Point X="10.935" Y="15.058" />
<Point X="9.5" Y="15.058" />
<Point X="9.5" Y="15.25" />
</Path>
</InheritanceLine>
<TypeIdentifier>
<HashCode>AAUAAAAEAgAAAABAAgAAAAAAAIAAAAIACAAQAACEAAI=</HashCode>
<FileName>AddTrendNoSeasonality.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="DATrendAddSeasonality">
<Position X="11.5" Y="6" Width="2" />
<InheritanceLine Type="Method" ManuallyRouted="true">
<Path>
<Point X="13.75" Y="4.873" />
<Point X="13.75" Y="5.249" />
<Point X="12.5" Y="5.249" />
<Point X="12.5" Y="6" />
</Path>
</InheritanceLine>
<TypeIdentifier>
<HashCode>AAUAAAAEAgAAAAAAAAAAAAAAAIAAAEIACEAQAGCEAGI=</HashCode>
<FileName>DATrendAddSeasonality.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="DATrendMultSeasonality">
<Position X="11.5" Y="10.75" Width="2" />
<InheritanceLine Type="Method" ManuallyRouted="true">
<Path>
<Point X="13.75" Y="4.873" />
<Point X="13.801" Y="5.214" />
<Point X="13.801" Y="10.485" />
<Point X="12.5" Y="10.485" />
<Point X="12.5" Y="10.75" />
</Path>
</InheritanceLine>
<TypeIdentifier>
<HashCode>AAUgAAAEAgAAAAAAAAAAAEAAAIAAAEIACEAQAGCEAAI=</HashCode>
<FileName>DATrendMultSeasonality.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="DATrendNoSeasonality">
<Position X="11.5" Y="15.5" Width="2" />
<TypeIdentifier>
<HashCode>AAUEAAAEAgAAAAQAAAAAAAAAAIAAAEIACAAQAACEAAI=</HashCode>
<FileName>DATrendNoSeasonality.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="DMTrendAddSeasonality">
<Position X="17.5" Y="6" Width="2.25" />
<InheritanceLine Type="Method" ManuallyRouted="true">
<Path>
<Point X="13.75" Y="4.873" />
<Point X="13.75" Y="5.213" />
<Point X="18.625" Y="5.213" />
<Point X="18.625" Y="6" />
</Path>
</InheritanceLine>
<TypeIdentifier>
<HashCode>AAUAAAAEAgAAAAAAAAAAAAAABIAAAEIACEAQAGCEACI=</HashCode>
<FileName>DMTrendAddSeasonality.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="DMTrendMultSeasonality">
<Position X="17.5" Y="11" Width="2.25" />
<InheritanceLine Type="Method" ManuallyRouted="true">
<Path>
<Point X="13.75" Y="4.873" />
<Point X="13.75" Y="5.249" />
<Point X="17.069" Y="5.249" />
<Point X="17.069" Y="10.562" />
<Point X="18.625" Y="10.562" />
<Point X="18.625" Y="11" />
</Path>
</InheritanceLine>
<TypeIdentifier>
<HashCode>AAUgAAAEAgAEAAAAAAAAAAAAAIAAAEIACEAQAGCEAQI=</HashCode>
<FileName>DMTrendMultSeasonality.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="DMTrendNoSeasonality">
<Position X="17.5" Y="16" Width="2" />
<InheritanceLine Type="Method" ManuallyRouted="true">
<Path>
<Point X="13.75" Y="4.873" />
<Point X="13.75" Y="5.251" />
<Point X="16.991" Y="5.251" />
<Point X="16.991" Y="15.649" />
<Point X="18.5" Y="15.649" />
<Point X="18.5" Y="16" />
</Path>
</InheritanceLine>
<TypeIdentifier>
<HashCode>AAUAAAAEBgAAAAQAAAAAAAAAAIAAAEIACAAQAACEAAI=</HashCode>
<FileName>DMTrendNoSeasonality.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="Dsa">
<Position X="5.25" Y="19.25" Width="2" />
<InheritanceLine Type="Method" ManuallyRouted="true">
<Path>
<Point X="13.75" Y="4.873" />
<Point X="13.75" Y="5.313" />
<Point X="7.983" Y="5.313" Type="JumpStart" />
<Point X="7.816" Y="5.313" Type="JumpEnd" />
<Point X="4.88" Y="5.313" />
<Point X="4.88" Y="18.875" />
<Point X="6.25" Y="18.875" />
<Point X="6.25" Y="19.25" />
</Path>
</InheritanceLine>
<TypeIdentifier>
<HashCode>AAQAAAAEAgACAAAAAAAAAAAAAIAAAAKACAAAAQIAAAI=</HashCode>
<FileName>Dsa.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="MultTrendAddSeasonality">
<Position X="14.25" Y="10.75" Width="2.25" />
<InheritanceLine Type="Method" ManuallyRouted="true">
<Path>
<Point X="13.75" Y="4.873" />
<Point X="13.75" Y="5.244" />
<Point X="17.024" Y="5.244" />
<Point X="17.024" Y="10.426" />
<Point X="15.375" Y="10.426" />
<Point X="15.375" Y="10.75" />
</Path>
</InheritanceLine>
<TypeIdentifier>
<HashCode>AAUAAAAEAgAQAAAAAAAAAAAAAIAAAAJACEAQAGCEAAI=</HashCode>
<FileName>MultTrendAddSeasonality.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="MultTrendMultSeasonality">
<Position X="14.25" Y="6" Width="2.25" />
<TypeIdentifier>
<HashCode>AAUAAAAEAgAAAAAAAAAAAAAAAIAAAAIACEARAGCFAAI=</HashCode>
<FileName>MultTrendMultSeasonality.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="MultTrendNoSeasonality">
<Position X="14.5" Y="15.5" Width="2" />
<InheritanceLine Type="Method" ManuallyRouted="true">
<Path>
<Point X="13.75" Y="4.873" />
<Point X="13.75" Y="5.222" />
<Point X="17.056" Y="5.222" />
<Point X="17.056" Y="15.219" />
<Point X="15.5" Y="15.219" />
<Point X="15.5" Y="15.5" />
</Path>
</InheritanceLine>
<TypeIdentifier>
<HashCode>AAUAAAAEAgAAAIAAAAAAAAAAAIAAAAIACAAQAACEABI=</HashCode>
<FileName>MultTrendNoSeasonality.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="NoTrendAddSeasonality">
<Position X="5.25" Y="10" Width="2" />
<InheritanceLine Type="Method" ManuallyRouted="true">
<Path>
<Point X="13.75" Y="4.873" />
<Point X="13.75" Y="5.239" />
<Point X="7.835" Y="5.239" />
<Point X="7.835" Y="9.584" />
<Point X="6.25" Y="9.584" />
<Point X="6.25" Y="10" />
</Path>
</InheritanceLine>
<TypeIdentifier>
<HashCode>AAwAAAAEAgBAAAAAAAAAAAAAAIAAAAIACEAQAGCAAAI=</HashCode>
<FileName>NoTrendAddSeasonality.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="NoTrendMultSeasonality">
<Position X="5.25" Y="14.5" Width="2" />
<InheritanceLine Type="Method" ManuallyRouted="true">
<Path>
<Point X="13.75" Y="4.873" />
<Point X="13.75" Y="5.166" />
<Point X="7.9" Y="5.166" />
<Point X="7.9" Y="14.2" />
<Point X="6.25" Y="14.2" />
<Point X="6.25" Y="14.5" />
</Path>
</InheritanceLine>
<TypeIdentifier>
<HashCode>AAQAAAAEAgIAAABAAAAAAAAAAIAAAAIACEAQAGCAAAI=</HashCode>
<FileName>NoTrendMultSeasonality.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="NoTrendNoSeasonality">
<Position X="5.25" Y="6" Width="2" />
<InheritanceLine Type="Method" ManuallyRouted="true">
<Path>
<Point X="13.75" Y="4.873" />
<Point X="13.75" Y="5.249" />
<Point X="6.25" Y="5.249" />
<Point X="6.25" Y="6" />
</Path>
</InheritanceLine>
<TypeIdentifier>
<HashCode>AAQAAAAEAgAAAAAAAAAAAAAAAIAAAANACAAQAACAAAI=</HashCode>
<FileName>NoTrendNoSeasonality.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="Aic">
<Position X="58.5" Y="9.5" Width="2.5" />
<TypeIdentifier>
<HashCode>AIAAAAAACwAAACIAAQCAFAAEAEAAoBAAQAAQAFCAAAA=</HashCode>
<FileName>Aic.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="AicWeights">
<Position X="36.5" Y="4.75" Width="1.5" />
<TypeIdentifier>
<HashCode>ABAAAQAACwAAAAAAAACABAAAAAAAoAAAQAAQAFCAAAA=</HashCode>
<FileName>AicWeights.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="Mape">
<Position X="61.75" Y="9.5" Width="2" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAIQAAA=</HashCode>
<FileName>Mape.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="SMape">
<Position X="64.5" Y="9.5" Width="2" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAACAAgAAAAAABAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>SMape.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="A">
<Position X="34.75" Y="4.75" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAgAAAACAAAAAAAAAACAAICAAAAAAAIAAAgAA=</HashCode>
<FileName>A.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="Fuzzy">
<Position X="2.5" Y="6" Width="2" />
<InheritanceLine Type="Method" ManuallyRouted="true">
<Path>
<Point X="13.75" Y="4.873" />
<Point X="13.75" Y="5.191" />
<Point X="3.5" Y="5.191" />
<Point X="3.5" Y="6" />
</Path>
</InheritanceLine>
<TypeIdentifier>
<HashCode>AAUAAAAEFgIGAgAEAAQkAAAAAIBEAGIhCEiQAEAAAAI=</HashCode>
<FileName>Fuzzy.h</FileName>
</TypeIdentifier>
</Class>
<Class Name="FuzzyWithSets">
<Position X="2.5" Y="13.75" Width="2.25" />
<InheritanceLine Type="Method" ManuallyRouted="true">
<Path>
<Point X="13.75" Y="4.873" />
<Point X="13.75" Y="5.25" />
<Point X="7.983" Y="5.25" Type="JumpStart" />
<Point X="7.816" Y="5.25" Type="JumpEnd" />
<Point X="4.88" Y="5.25" />
<Point X="4.88" Y="13.501" />
<Point X="3.625" Y="13.501" />
<Point X="3.625" Y="13.75" />
</Path>
</InheritanceLine>
<TypeIdentifier>
<HashCode>AAcQAAIEBgIKAgAEQIQgAAAAAIQEAEIhCEkQAGCEAAI=</HashCode>
<FileName>FuzzyWithSets.h</FileName>
</TypeIdentifier>
</Class>
<Struct Name="AggModel">
<Position X="40" Y="8" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAQAEACAgAAAAAAAAAAA=</HashCode>
<FileName>Vovk.h</FileName>
</TypeIdentifier>
</Struct>
<Font Name="Segoe UI" Size="9" />
</ClassDiagram>

View File

@ -0,0 +1,152 @@
//
// Ìåòîä ýêñïîíåíöèàëüíîãî ñãëàæèâàíèÿ è ïðîãíîçèðîâàíèÿ:
// äåìïèíã àääèòèâíûé òðåíä, àääèòèâíàÿ ñåçîííîñòü
//
#include "StdAfx.h"
#include <iostream>
#include "DATrendAddSeasonality.h"
#include "Param.h"
// êîíñòðóêòîð ñ çàäàííûìè íåïîñðåäñòâåííî ïàðàìåòðàìè
DATrendAddSeasonality::DATrendAddSeasonality(vector<double> timeSeries, int countPointForecast) {
this->x = timeSeries;
this->countPointForecast = countPointForecast;
this->partition();
}
DATrendAddSeasonality::~DATrendAddSeasonality() {
// îñâîáîæäàåòñÿ ïàìÿòü
std::vector<double> ().swap(S);
std::vector<double> ().swap(x);
std::vector<double> ().swap(T);
std::vector<double> ().swap(I);
std::vector<double> ().swap(forecast);
}
// èíèöèàëèçàöèÿ ìîäåëè, çàäàíèå ïåðâîíà÷àëüíûõ çíà÷åíèé
void DATrendAddSeasonality::init() {
S.clear();
T.clear();
I.clear();
forecast.clear();
double sumS = 0;
double sumT = 0;
for (unsigned int t = 0; t < p; t++) {
sumS += x[t];
sumT += x[t+p];
}
S.push_back(sumS / p);
T.push_back((sumT/ p - S[0]) / p);
for (unsigned int t = 0; t < p; t++) {
I.push_back(x[t] - S[0]);
}
forecast.push_back(S[0] + T[0] * phi + I[0]);
}
// Çàäàòü ïàðàìåòð
void DATrendAddSeasonality::setParam(string paramName, double value) {
if (paramName.compare("alpha") == 0) {
this->alpha = value;
} else if (paramName.compare("gamma") == 0) {
this->gamma = value;
} else if (paramName.compare("p") == 0) {
this->p = value;
} else if (paramName.compare("delta") == 0) {
this->delta = value;
} else if (paramName.compare("phi") == 0) {
this->phi = value;
}
}
// ñôîðìèðîâàòü ìîäåëü
void DATrendAddSeasonality::createModel() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < x.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < x.size()) {
e = x[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] + T[t] * phi + alpha * e); // óðîâåíü
T.push_back(T[t] * phi + alpha * gamma * e); // òðåíä
I.push_back(I[t] + delta * e); // ñåçîííîñòü
forecast.push_back(S[t+1] + T[t+1] * phi + I[t+1]); // ïðîãíîç
}
}
// ñôîðìèðîâàòü ìîäåëü
void DATrendAddSeasonality::createModelForEstimation() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < xLearning.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < xLearning.size()) {
e = xLearning[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] + T[t] * phi + alpha * e); // óðîâåíü
T.push_back(T[t] * phi + alpha * gamma * e); // òðåíä
I.push_back(I[t] + delta * e); // ñåçîííîñòü
forecast.push_back(S[t+1] + T[t+1] * phi + I[t+1]); // ïðîãíîç
}
}
// ìåòîä ïîëó÷åíèÿ ïðîãíîçà
vector<double> DATrendAddSeasonality::getForecast() {
vector<double> result;
for (unsigned int i = forecast.size() - countPointForecast; i < forecast.size(); i++) {
result.push_back(forecast[i]);
}
return result;
}
// ìåòîä ïîëó÷åíèÿ îöåíêè ìîäåëè
double DATrendAddSeasonality::calcEstimation(Aic *aic) {
return aic->getValue(3, this->xEstimation, this->forecast);
}
// ìåòîä ïîëó÷åíèÿ îïòèìèçèðîâàííîãî çíà÷åíèÿ îäíîãî ïàðàìåòðà
// TODO: ðåàëèçîâàòü
Param* DATrendAddSeasonality::optimize(Estimation *est) {
Param *optimal = new Param();
double minSmape = 99999;
for (double al = 0.1; al < 1; al+= 0.05) {
for (double gam = 0.1; gam < 1; gam+= 0.05) {
for (double del = 0.1; del < 1;del+= 0.05) {
for (double ph = 0.1; ph < 1;ph+= 0.05) {
this->setParam("alpha", al);
this->setParam("gamma", gam);
this->setParam("delta", del);
this->setParam("ph", ph);
this->createModelForEstimation();
double smapeValue = est->getValue(getXEstimation(), getForecast());
if (minSmape > smapeValue) {
minSmape = smapeValue;
optimal->alpha = al;
optimal->gamma = gam;
optimal->delta = del;
optimal->phi = ph;
}
}
}
}
}
return optimal;
}

View File

@ -0,0 +1,35 @@
#ifndef DATRENDADDSEASONALITY_H
#define DATRENDADDSEASONALITY_H
#include "Method.h"
#include "Aic.h"
#include "Param.h"
using namespace std;
// êîíêðåòíàÿ ðåàëèçàöèÿ àáñòðàêòíîãî êëàññà Method
// ðåàëèçóåò ìåòîä ýêñïîíåíöèàëüíîãî ñ äåìïèíã àääèòèâíûì òðåíäîì, àääèòèâíàÿ ñåçîííîñòü
class DATrendAddSeasonality : public Method {
public:
double alpha; // ïàðàìåòð ñãëàæèâàíèÿ
vector<double> S; // ñãëàæåííûé äàííûì ìåòîäîì ðÿä
double gamma; // ïàðàìåòð ñãëàæèâàíèÿ òðåíäà
double delta; // ïàðàìåòð ñãëàæèâàíèÿ ñåçîííîé êîìïîíåíòû
vector<double> T; // ñãëàæåííûé òðåíä
vector<double> I; // ñåçîííàÿ êîìïîíåíòà
int p; // ïåðèîä ñåçîííîñòè
double phi; // ïàðàìåòð äåìïèíãà
DATrendAddSeasonality(vector<double>, int);
~DATrendAddSeasonality();
vector<double> getForecast();
void init();
void createModel();
void createModelForEstimation();
void setParam(string, double);
double calcEstimation(Aic *);
Param* optimize(Estimation *); // ìåòîä îïòèìèçàöèè îäíîãî ïàðàìåòðà
};
#endif

View File

@ -0,0 +1,150 @@
//
// Ìåòîä ýêñïîíåíöèàëüíîãî ñãëàæèâàíèÿ è ïðîãíîçèðîâàíèÿ:
// äåìïèíã àääèòèâíûé òðåíä, ìóëüòèïëèêàòâíàÿ ñåçîííîñòü
//
#include "StdAfx.h"
#include <iostream>
#include "DATrendMultSeasonality.h"
#include "Param.h"
// êîíñòðóêòîð ñ çàäàííûìè íåïîñðåäñòâåííî ïàðàìåòðàìè
DATrendMultSeasonality::DATrendMultSeasonality(vector<double> timeSeries, int countPointForecast) {
this->x = timeSeries;
this->countPointForecast = countPointForecast;
this->partition();
}
DATrendMultSeasonality::~DATrendMultSeasonality() {
// îñâîáîæäàåòñÿ ïàìÿòü
std::vector<double> ().swap(S);
std::vector<double> ().swap(x);
std::vector<double> ().swap(T);
std::vector<double> ().swap(I);
std::vector<double> ().swap(forecast);
}
// èíèöèàëèçàöèÿ ìîäåëè, çàäàíèå ïåðâîíà÷àëüíûõ çíà÷åíèé
void DATrendMultSeasonality::init() {
S.clear();
T.clear();
I.clear();
forecast.clear();
double sumS = 0;
double sumT = 0;
for (unsigned int t = 0; t < p; t++) {
sumS += x[t];
sumT += x[t+p];
}
S.push_back(sumS / p);
T.push_back((sumT/ p - S[0]) / p);
for (unsigned int t = 0; t < p; t++) {
I.push_back(x[t] / S[0]);
}
forecast.push_back((S[0] + T[0] * phi) * I[0]);
}
// Çàäàòü ïàðàìåòð
void DATrendMultSeasonality::setParam(string paramName, double value) {
if (paramName.compare("alpha") == 0) {
this->alpha = value;
} else if (paramName.compare("gamma") == 0) {
this->gamma = value;
} else if (paramName.compare("p") == 0) {
this->p = value;
} else if (paramName.compare("delta") == 0) {
this->delta = value;
} else if (paramName.compare("phi") == 0) {
this->phi = value;
}
}
// ñôîðìèðîâàòü ìîäåëü
void DATrendMultSeasonality::createModel() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < x.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < x.size()) {
e = x[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] + T[t] * phi + alpha * e / I[t]); // óðîâåíü
T.push_back(T[t] * phi + alpha * gamma * e / I[t]); // òðåíä
I.push_back(I[t] + delta * e / (S[t] + T[t] * phi)); // ñåçîííîñòü
forecast.push_back((S[t+1] + T[t+1] * phi ) * I[t+1]); // ïðîãíîç
}
}
// ñôîðìèðîâàòü ìîäåëü
void DATrendMultSeasonality::createModelForEstimation() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < xLearning.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < xLearning.size()) {
e = xLearning[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] + T[t] * phi + alpha * e / I[t]); // óðîâåíü
T.push_back(T[t] * phi + alpha * gamma * e / I[t]); // òðåíä
I.push_back(I[t] + delta * e / (S[t] + T[t] * phi)); // ñåçîííîñòü
forecast.push_back((S[t+1] + T[t+1] * phi ) * I[t+1]); // ïðîãíîç
}
}
// ìåòîä ïîëó÷åíèÿ ïðîãíîçà
vector<double> DATrendMultSeasonality::getForecast() {
vector<double> result;
for (unsigned int i = forecast.size() - countPointForecast; i < forecast.size(); i++) {
result.push_back(forecast[i]);
}
return result;
}
// ìåòîä ïîëó÷åíèÿ îöåíêè ìîäåëè
double DATrendMultSeasonality::calcEstimation(Aic *aic) {
return aic->getValue(3, this->xEstimation, this->forecast);
}
// ìåòîä ïîëó÷åíèÿ îïòèìèçèðîâàííîãî çíà÷åíèÿ îäíîãî ïàðàìåòðà
// TODO: ðåàëèçîâàòü
Param* DATrendMultSeasonality::optimize(Estimation *est) {
Param *optimal = new Param();
double minSmape = 99999;
for (double al = 0.1; al < 1; al+= 0.05) {
for (double gam = 0.1; gam < 1; gam+= 0.05) {
for (double del = 0.1; del < 1;del+= 0.05) {
for (double ph = 0.1; ph < 1;ph+= 0.05) {
this->setParam("alpha", al);
this->setParam("gamma", gam);
this->setParam("delta", del);
this->setParam("ph", ph);
this->createModelForEstimation();
double smapeValue = est->getValue(getXEstimation(), getForecast());
if (minSmape > smapeValue) {
minSmape = smapeValue;
optimal->alpha = al;
optimal->gamma = gam;
optimal->delta = del;
optimal->phi = ph;
}
}
}
}
}
return optimal;
}

View File

@ -0,0 +1,35 @@
#ifndef DATRENDMULTSEASONALITY_H
#define DATRENDMULTSEASONALITY_H
#include "Method.h"
#include "Aic.h"
#include "Param.h"
using namespace std;
// êîíêðåòíàÿ ðåàëèçàöèÿ àáñòðàêòíîãî êëàññà Method
// ðåàëèçóåò ìåòîä ýêñïîíåíöèàëüíîãî ñ äåìïèíã àääèòèâíûì òðåíäîì, àääèòèâíàÿ ñåçîííîñòü
class DATrendMultSeasonality : public Method {
public:
double alpha; // ïàðàìåòð ñãëàæèâàíèÿ
vector<double> S; // ñãëàæåííûé äàííûì ìåòîäîì ðÿä
double gamma; // ïàðàìåòð ñãëàæèâàíèÿ òðåíäà
double delta; // ïàðàìåòð ñãëàæèâàíèÿ ñåçîííîé êîìïîíåíòû
vector<double> T; // ñãëàæåííûé òðåíä
vector<double> I; // ñåçîííàÿ êîìïîíåíòà
int p; // ïåðèîä ñåçîííîñòè
double phi; // ïàðàìåòð äåìïèíãà
DATrendMultSeasonality(vector<double>, int);
~DATrendMultSeasonality();
vector<double> getForecast();
void init();
void createModel();
void createModelForEstimation();
void setParam(string, double);
double calcEstimation(Aic *);
Param* optimize(Estimation *); // ìåòîä îïòèìèçàöèè îäíîãî ïàðàìåòðà
};
#endif

View File

@ -0,0 +1,125 @@
//
// Ìåòîä ýêñïîíåíöèàëüíîãî ñãëàæèâàíèÿ è ïðîãíîçèðîâàíèÿ:
// äåìïèíã àääèòèâíûé òðåíä, áåç ñåçîííîñòè
//
#include "StdAfx.h"
#include <iostream>
#include "DATrendNoSeasonality.h"
#include "Param.h"
// êîíñòðóêòîð ñ çàäàííûìè íåïîñðåäñòâåííî ïàðàìåòðàìè
DATrendNoSeasonality::DATrendNoSeasonality(vector<double> timeSeries, int countPointForecast) {
this->x = timeSeries;
this->countPointForecast = countPointForecast;
this->partition();
}
DATrendNoSeasonality::~DATrendNoSeasonality() {
// îñâîáîæäàåòñÿ ïàìÿòü
std::vector<double> ().swap(S);
std::vector<double> ().swap(x);
std::vector<double> ().swap(T);
std::vector<double> ().swap(forecast);
}
// èíèöèàëèçàöèÿ ìîäåëè, çàäàíèå ïåðâîíà÷àëüíûõ çíà÷åíèé
void DATrendNoSeasonality::init() {
S.clear();
T.clear();
forecast.clear();
T.push_back(x[1] - x[0]);
S.push_back(x[0]);
forecast.push_back(S[0] + T[0] * phi);
}
// Çàäàòü ïàðàìåòð
void DATrendNoSeasonality::setParam(string paramName, double value) {
if (paramName.compare("alpha") == 0) {
this->alpha = value;
} else if (paramName.compare("gamma") == 0) {
this->gamma = value;
} else if (paramName.compare("phi") == 0) {
this->phi = value;
}
}
// ñôîðìèðîâàòü ìîäåëü
void DATrendNoSeasonality::createModel() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < x.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < x.size()) {
e = x[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] + phi * T[t] + alpha * e); // óðîâåíü
T.push_back(phi * T[t] + alpha * gamma * e); // çàòóõàþùèé òðåíä
forecast.push_back(S[t+1] + phi * T[t+1]); // ïðîãíîç
}
}
// ñôîðìèðîâàòü ìîäåëü
void DATrendNoSeasonality::createModelForEstimation() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < xLearning.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < xLearning.size()) {
e = xLearning[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] + phi * T[t] + alpha * e); // óðîâåíü
T.push_back(phi * T[t] + alpha * gamma * e); // çàòóõàþùèé òðåíä
forecast.push_back(S[t+1] + phi * T[t+1]); // ïðîãíîç
}
}
// ìåòîä ïîëó÷åíèÿ ïðîãíîçà
vector<double> DATrendNoSeasonality::getForecast() {
vector<double> result;
for (unsigned int i = forecast.size() - countPointForecast; i < forecast.size(); i++) {
result.push_back(forecast[i]);
}
return result;
}
// ìåòîä ïîëó÷åíèÿ îöåíêè ìîäåëè
double DATrendNoSeasonality::calcEstimation(Aic *aic) {
return aic->getValue(2, this->xEstimation, this->forecast);
}
// ìåòîä ïîëó÷åíèÿ îïòèìèçèðîâàííîãî çíà÷åíèÿ îäíîãî ïàðàìåòðà
// TODO: ðåàëèçîâàòü
Param* DATrendNoSeasonality::optimize(Estimation *est) {
Param *optimal = new Param();
double minSmape = 99999;
for (double al = 0.1; al < 1; al+= 0.05) {
for (double gam = 0.1; gam < 1; gam+= 0.05) {
for (double ph = 0.1; ph < 1; ph+= 0.05) {
this->setParam("alpha", al);
this->setParam("gamma", gam);
this->setParam("phi", ph);
this->createModelForEstimation();
double smapeValue = est->getValue(getXEstimation(), getForecast());
if (minSmape > smapeValue) {
minSmape = smapeValue;
optimal->alpha = al;
optimal->gamma = gam;
optimal->phi = phi;
}
}
}
}
return optimal;
}

View File

@ -0,0 +1,32 @@
#ifndef DATRENDNOSEASONALITY_H
#define DATRENDNOSEASONALITY_H
#include "Method.h"
#include "Aic.h"
#include "Param.h"
using namespace std;
// êîíêðåòíàÿ ðåàëèçàöèÿ àáñòðàêòíîãî êëàññà Method
// ðåàëèçóåò ìåòîä ýêñïîíåíöèàëüíîãî ñ äåìïèíã àääèòèâíûì òðåíäîì, áåç ñåçîííîñòè
class DATrendNoSeasonality : public Method {
public:
double alpha; // ïàðàìåòð ñãëàæèâàíèÿ
vector<double> S; // ñãëàæåííûé äàííûì ìåòîäîì ðÿä
double gamma; // ïàðàìåòð ñãëàæèâàíèÿ òðåíäà
vector<double> T; // ñãëàæåííûé òðåíä
double phi; // ïàðàìåòð äåìïèíãà
DATrendNoSeasonality(vector<double>, int);
~DATrendNoSeasonality();
vector<double> getForecast();
void init();
void createModel();
void createModelForEstimation();
void setParam(string, double);
double calcEstimation(Aic *);
Param* optimize(Estimation *); // ìåòîä îïòèìèçàöèè îäíîãî ïàðàìåòðà
};
#endif

View File

@ -0,0 +1,155 @@
//
// Ìåòîä ýêñïîíåíöèàëüíîãî ñãëàæèâàíèÿ è ïðîãíîçèðîâàíèÿ:
// äåìïèíã ìóëüòèïëèêàòèâíûé òðåíä, àääèòèâíàÿ ñåçîííîñòü
//
#include "StdAfx.h"
#include "math.h"
#include <iostream>
#include "DMTrendAddSeasonality.h"
#include "Param.h"
// êîíñòðóêòîð ñ çàäàííûìè íåïîñðåäñòâåííî ïàðàìåòðàìè
DMTrendAddSeasonality::DMTrendAddSeasonality(vector<double> timeSeries, int countPointForecast) {
this->x = timeSeries;
this->countPointForecast = countPointForecast;
this->partition();
}
DMTrendAddSeasonality::~DMTrendAddSeasonality() {
// îñâîáîæäàåòñÿ ïàìÿòü
std::vector<double> ().swap(S);
std::vector<double> ().swap(x);
std::vector<double> ().swap(T);
std::vector<double> ().swap(I);
std::vector<double> ().swap(forecast);
}
// èíèöèàëèçàöèÿ ìîäåëè, çàäàíèå ïåðâîíà÷àëüíûõ çíà÷åíèé
void DMTrendAddSeasonality::init() {
S.clear();
T.clear();
I.clear();
forecast.clear();
double sumS = 0;
double sumT = 0;
for (unsigned int t = 0; t < p; t++) {
sumS += x[t];
sumT += x[t+p];
}
S.push_back(sumS / p);
T.push_back((sumT/ p - S[0]) / p);
for (unsigned int t = 0; t < p; t++) {
I.push_back(x[t] - S[0]);
}
forecast.push_back(S[0] * pow(T[0], phi) + I[0]);
}
// Çàäàòü ïàðàìåòð
void DMTrendAddSeasonality::setParam(string paramName, double value) {
if (paramName.compare("alpha") == 0) {
this->alpha = value;
} else if (paramName.compare("gamma") == 0) {
this->gamma = value;
} else if (paramName.compare("p") == 0) {
this->p = value;
} else if (paramName.compare("delta") == 0) {
this->delta = value;
} else if (paramName.compare("phi") == 0) {
this->phi = value;
}
}
// ñôîðìèðîâàòü ìîäåëü
void DMTrendAddSeasonality::createModel() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < x.size()-1 +this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < x.size()) {
e = x[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] * pow(T[t], phi) + alpha * e); // óðîâåíü
T.push_back(pow(T[t], phi) + alpha * gamma * e / S[t]); // òðåíä
I.push_back(I[t] + delta * e); // ñåçîííîñòü
forecast.push_back(S[t+1] * pow(T[t+1], phi) + I[t+1]); // ïðîãíîç
}
}
// ñôîðìèðîâàòü ìîäåëü
void DMTrendAddSeasonality::createModelForEstimation() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < xLearning.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < xLearning.size()) {
e = xLearning[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] * pow(T[t], phi) + alpha * e); // óðîâåíü
T.push_back(pow(T[t], phi) + alpha * gamma * e / S[t]); // òðåíä
I.push_back(I[t] + delta * e); // ñåçîííîñòü
forecast.push_back(S[t+1] * pow(T[t+1], phi) + I[t+1]); // ïðîãíîç
}
}
// ìåòîä ïîëó÷åíèÿ ïðîãíîçà
vector<double> DMTrendAddSeasonality::getForecast() {
vector<double> result;
for (unsigned int i = forecast.size() - countPointForecast; i < forecast.size(); i++) {
result.push_back(forecast[i]);
}
return result;
}
// ìåòîä ïîëó÷åíèÿ îöåíêè ìîäåëè
double DMTrendAddSeasonality::calcEstimation(Aic *aic) {
return aic->getValue(3, this->xEstimation, this->forecast);
}
// ìåòîä ïîëó÷åíèÿ îïòèìèçèðîâàííîãî çíà÷åíèÿ îäíîãî ïàðàìåòðà
// TODO: ðåàëèçîâàòü
Param* DMTrendAddSeasonality::optimize(Estimation *est) {
Param *optimal = new Param();
double minSmape = 99999;
for (double al = 0.1; al < 1; al+= 0.05) {
for (double gam = 0.1; gam < 1; gam+= 0.05) {
for (double del = 0.1; del < 1;del+= 0.05) {
for (double ph = 0.1; ph < 1;ph+= 0.05) {
this->setParam("alpha", al);
this->setParam("gamma", gam);
this->setParam("delta", del);
this->setParam("ph", ph);
this->createModelForEstimation();
double smapeValue = est->getValue(getXEstimation(), getForecast());
if (minSmape > smapeValue) {
minSmape = smapeValue;
optimal->alpha = al;
optimal->gamma = gam;
optimal->delta = del;
optimal->phi = ph;
}
}
}
}
}
return optimal;
}

View File

@ -0,0 +1,35 @@
#ifndef DMTRENDADDSEASONALITY_H
#define DMTRENDADDSEASONALITY_H
#include "Method.h"
#include "Aic.h"
#include "Param.h"
using namespace std;
// êîíêðåòíàÿ ðåàëèçàöèÿ àáñòðàêòíîãî êëàññà Method
// ðåàëèçóåò ìåòîä ýêñïîíåíöèàëüíîãî ñ äåìïèíã ìóëüòèïëèêàòèâíûì òðåíäîì, àääèòèâíàÿ ñåçîííîñòü
class DMTrendAddSeasonality : public Method {
public:
double alpha; // ïàðàìåòð ñãëàæèâàíèÿ
vector<double> S; // ñãëàæåííûé äàííûì ìåòîäîì ðÿä
double gamma; // ïàðàìåòð ñãëàæèâàíèÿ òðåíäà
double delta; // ïàðàìåòð ñãëàæèâàíèÿ ñåçîííîé êîìïîíåíòû
vector<double> T; // ñãëàæåííûé òðåíä
vector<double> I; // ñåçîííàÿ êîìïîíåíòà
int p; // ïåðèîä ñåçîííîñòè
double phi; // ïàðàìåòð äåìïèíãà
DMTrendAddSeasonality(vector<double>, int);
~DMTrendAddSeasonality();
vector<double> getForecast();
void init();
void createModel();
void createModelForEstimation();
void setParam(string, double);
double calcEstimation(Aic *);
Param* optimize(Estimation *); // ìåòîä îïòèìèçàöèè îäíîãî ïàðàìåòðà
};
#endif

View File

@ -0,0 +1,149 @@
//
// Ìåòîä ýêñïîíåíöèàëüíîãî ñãëàæèâàíèÿ è ïðîãíîçèðîâàíèÿ:
// äåìïèíã ìóëüòèïëèêàòèâíûé òðåíä, ìóëüòèïëèêàòâíàÿ ñåçîííîñòü
//
#include "StdAfx.h"
#include "math.h"
#include <iostream>
#include "DMTrendMultSeasonality.h"
#include "Param.h"
// êîíñòðóêòîð ñ çàäàííûìè íåïîñðåäñòâåííî ïàðàìåòðàìè
DMTrendMultSeasonality::DMTrendMultSeasonality(vector<double> timeSeries, int countPointForecast) {
this->x = timeSeries;
this->countPointForecast = countPointForecast;
this->partition();
}
DMTrendMultSeasonality::~DMTrendMultSeasonality() {
// îñâîáîæäàåòñÿ ïàìÿòü
std::vector<double> ().swap(S);
std::vector<double> ().swap(x);
std::vector<double> ().swap(T);
std::vector<double> ().swap(I);
std::vector<double> ().swap(forecast);
}
// èíèöèàëèçàöèÿ ìîäåëè, çàäàíèå ïåðâîíà÷àëüíûõ çíà÷åíèé
void DMTrendMultSeasonality::init() {
S.clear();
T.clear();
I.clear();
forecast.clear();
double sumS = 0;
double sumT = 0;
for (unsigned int t = 0; t < p; t++) {
sumS += x[t];
sumT += x[t+p];
}
S.push_back(sumS / p);
T.push_back((sumT/ p - S[0]) / p);
for (unsigned int t = 0; t < p; t++) {
I.push_back(x[t] / S[0]);
}
forecast.push_back(S[0] * pow(T[0], phi) * I[0]);
}
// Çàäàòü ïàðàìåòð
void DMTrendMultSeasonality::setParam(string paramName, double value) {
if (paramName.compare("alpha") == 0) {
this->alpha = value;
} else if (paramName.compare("gamma") == 0) {
this->gamma = value;
} else if (paramName.compare("p") == 0) {
this->p = value;
} else if (paramName.compare("delta") == 0) {
this->delta = value;
} else if (paramName.compare("phi") == 0) {
this->phi = value;
}
}
// ñôîðìèðîâàòü ìîäåëü
void DMTrendMultSeasonality::createModel() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < x.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < x.size()) {
e = x[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] * pow(T[t], phi) + alpha * e / I[t]); // óðîâåíü
T.push_back(pow(T[t], phi) + alpha * gamma * e / (I[t] * S[t])); // òðåíä
I.push_back(I[t] + delta * e / (S[t] * pow(T[t], phi))); // ñåçîííîñòü
forecast.push_back(S[t+1] * pow(T[t+1], phi) * I[t+1]); // ïðîãíîç
}
}
// ñôîðìèðîâàòü ìîäåëü ñ íîâûì çíà÷åíèåì ïàðàìåòðà. ïåðåãðóæåííûé ìåòîä
void DMTrendMultSeasonality::createModelForEstimation() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < xLearning.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < xLearning.size()) {
e = xLearning[t]-forecast[t];
} else {
e = 0;
}
`
S.push_back(S[t] * pow(T[t], phi) + alpha * e / I[t]); // óðîâåíü
T.push_back(pow(T[t], phi) + alpha * gamma * e / (I[t] * S[t])); // òðåíä
I.push_back(I[t] + delta * e / (S[t] * pow(T[t], phi))); // ñåçîííîñòü
forecast.push_back(S[t+1] * pow(T[t+1], phi) * I[t+1]); // ïðîãíîç
}
}
// ìåòîä ïîëó÷åíèÿ ïðîãíîçà
vector<double> DMTrendMultSeasonality::getForecast() {
vector<double> result;
for (unsigned int i = forecast.size() - countPointForecast; i < forecast.size(); i++) {
result.push_back(forecast[i]);
}
return result;
}
// ìåòîä ïîëó÷åíèÿ îöåíêè ìîäåëè
double DMTrendMultSeasonality::calcEstimation(Aic *aic) {
return aic->getValue(3, this->xEstimation, this->forecast);
}
// ìåòîä ïîëó÷åíèÿ îïòèìèçèðîâàííîãî çíà÷åíèÿ îäíîãî ïàðàìåòðà
// TODO: ðåàëèçîâàòü
Param* DMTrendMultSeasonality::optimize(Estimation *est) {
Param *optimal = new Param();
double minSmape = 99999;
for (double al = 0.1; al < 1; al+= 0.05) {
for (double gam = 0.1; gam < 1; gam+= 0.05) {
for (double del = 0.1; del < 1;del+= 0.05) {
for (double ph = 0.1; ph < 1;ph+= 0.05) {
this->setParam("alpha", al);
this->setParam("gamma", gam);
this->setParam("delta", del);
this->setParam("phi", ph);
this->createModelForEstimation();
double smapeValue = est->getValue(getXEstimation(), getForecast());
if (minSmape > smapeValue) {
minSmape = smapeValue;
optimal->alpha = al;
optimal->gamma = gam;
optimal->delta = del;
optimal->phi = ph;
}
}
}
}
}
return optimal;
}

View File

@ -0,0 +1,36 @@
#ifndef DMTRENDMULTSEASONALITY_H
#define DMTRENDMULTSEASONALITY_H
#include "Method.h"
#include "Aic.h"
#include "Param.h"
using namespace std;
// êîíêðåòíàÿ ðåàëèçàöèÿ àáñòðàêòíîãî êëàññà Method
// ðåàëèçóåò ìåòîä ýêñïîíåíöèàëüíîãî ñ äåìïèíã ìóëüòèïëèêàòèâíûì òðåíäîì, àääèòèâíàÿ ñåçîííîñòü
class DMTrendMultSeasonality : public Method {
public:
double alpha; // ïàðàìåòð ñãëàæèâàíèÿ
vector<double> S; // ñãëàæåííûé äàííûì ìåòîäîì ðÿä
double gamma; // ïàðàìåòð ñãëàæèâàíèÿ òðåíäà
double delta; // ïàðàìåòð ñãëàæèâàíèÿ ñåçîííîé êîìïîíåíòû
vector<double> T; // ñãëàæåííûé òðåíä
vector<double> I; // ñåçîííàÿ êîìïîíåíòà
vector<double> R; // äåìïèíã
int p; // ïåðèîä ñåçîííîñòè
double phi; // ïàðàìåòð äåìïèíãà
DMTrendMultSeasonality(vector<double>, int);
~DMTrendMultSeasonality();
vector<double> getForecast();
void init();
void createModel();
void createModelForEstimation();
void setParam(string, double);
double calcEstimation(Aic *);
Param* optimize(Estimation *); // ìåòîä îïòèìèçàöèè îäíîãî ïàðàìåòðà
};
#endif

View File

@ -0,0 +1,127 @@
//
// Ìåòîä ýêñïîíåíöèàëüíîãî ñãëàæèâàíèÿ è ïðîãíîçèðîâàíèÿ:
// äåìïèíã ìóëüòèïëèêàòèâíûé òðåíä, áåç ñåçîííîñòè
//
#include "StdAfx.h"
#include <iostream>
#include <math.h>
#include "DMTrendNoSeasonality.h"
#include "Param.h"
// êîíñòðóêòîð ñ çàäàííûìè íåïîñðåäñòâåííî ïàðàìåòðàìè
DMTrendNoSeasonality::DMTrendNoSeasonality(vector<double> timeSeries, int countPointForecast) {
this->x = timeSeries;
this->countPointForecast = countPointForecast;
this->partition();
}
DMTrendNoSeasonality::~DMTrendNoSeasonality() {
// îñâîáîæäàåòñÿ ïàìÿòü
std::vector<double> ().swap(S);
std::vector<double> ().swap(x);
std::vector<double> ().swap(T);
std::vector<double> ().swap(forecast);
}
// èíèöèàëèçàöèÿ ìîäåëè, çàäàíèå ïåðâîíà÷àëüíûõ çíà÷åíèé
void DMTrendNoSeasonality::init() {
S.clear();
T.clear();
forecast.clear();
T.push_back(x[1] / x[0]);
S.push_back(x[0]);
forecast.push_back(S[0] * pow(T[0], phi));
}
// Çàäàòü ïàðàìåòð
void DMTrendNoSeasonality::setParam(string paramName, double value) {
if (paramName.compare("alpha") == 0) {
this->alpha = value;
} else if (paramName.compare("gamma") == 0) {
this->gamma = value;
} else if (paramName.compare("phi") == 0) {
this->phi = value;
}
}
// ñôîðìèðîâàòü ìîäåëü
void DMTrendNoSeasonality::createModel() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < x.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < x.size()) {
e = x[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] * pow(T[t], phi) + alpha * e); // óðîâåíü
T.push_back(pow(T[t], phi) + alpha * gamma * e / S[t]); // çàòóõàþùèé òðåíä
forecast.push_back(S[t+1] * pow(T[t+1], phi)); // ïðîãíîç
}
}
// ñôîðìèðîâàòü ìîäåëü
void DMTrendNoSeasonality::createModelForEstimation() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < xLearning.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < xLearning.size()) {
e = xLearning[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] * pow(T[t], phi) + alpha * e); // óðîâåíü
T.push_back(pow(T[t], phi) + alpha * gamma * e / S[t]); // çàòóõàþùèé òðåíä
forecast.push_back(S[t+1] * pow(T[t+1], phi)); // ïðîãíîç
}
}
// ìåòîä ïîëó÷åíèÿ ïðîãíîçà
vector<double> DMTrendNoSeasonality::getForecast() {
vector<double> result;
for (unsigned int i = forecast.size() - countPointForecast; i < forecast.size(); i++) {
result.push_back(forecast[i]);
}
return result;
}
// ìåòîä ïîëó÷åíèÿ îöåíêè ìîäåëè
double DMTrendNoSeasonality::calcEstimation(Aic *aic) {
return aic->getValue(3, this->xEstimation, this->forecast);
}
// ìåòîä ïîëó÷åíèÿ îïòèìèçèðîâàííîãî çíà÷åíèÿ îäíîãî ïàðàìåòðà
// TODO: ðåàëèçîâàòü
Param* DMTrendNoSeasonality::optimize(Estimation *est) {
Param *optimal = new Param();
double minSmape = 99999;
for (double al = 0.1; al < 1; al+= 0.05) {
for (double gam = 0.1; gam < 1; gam+= 0.05) {
for (double ph = 0.1; ph < 1; ph+= 0.05) {
this->setParam("alpha", al);
this->setParam("gamma", gam);
this->setParam("phi", ph);
this->createModelForEstimation();
double smapeValue = est->getValue(getXEstimation(), getForecast());
if (minSmape > smapeValue) {
minSmape = smapeValue;
optimal->alpha = al;
optimal->gamma = gam;
optimal->phi = phi;
}
}
}
}
return optimal;
}

View File

@ -0,0 +1,32 @@
#ifndef DMTRENDNOSEASONALITY_H
#define DMTRENDNOSEASONALITY_H
#include "Method.h"
#include "Aic.h"
#include "Param.h"
using namespace std;
// êîíêðåòíàÿ ðåàëèçàöèÿ àáñòðàêòíîãî êëàññà Method
// ðåàëèçóåò ìåòîä ýêñïîíåíöèàëüíîãî ñ äåìïèíã ìóëüòèïëèêàòèâíûì òðåíäîì, áåç ñåçîííîñòè
class DMTrendNoSeasonality : public Method {
public:
double alpha; // ïàðàìåòð ñãëàæèâàíèÿ
vector<double> S; // ñãëàæåííûé äàííûì ìåòîäîì ðÿä
double gamma; // ïàðàìåòð ñãëàæèâàíèÿ òðåíäà
vector<double> T; // ñãëàæåííûé òðåíä
double phi; // ïàðàìåòð äåìïèíãà
DMTrendNoSeasonality(vector<double>, int);
~DMTrendNoSeasonality();
vector<double> getForecast();
void init();
void createModel();
void createModelForEstimation();
void setParam(string, double);
double calcEstimation(Aic *);
Param* optimize(Estimation *); // ìåòîä îïòèìèçàöèè îäíîãî ïàðàìåòðà
};
#endif

307
project_template/Dsa.cpp Normal file
View File

@ -0,0 +1,307 @@
#include "StdAfx.h"
#include "Dsa.h"
#include <iostream>
#include "Param.h"
Dsa::Dsa(vector<double> timeSeries, int countPointForecast){
this->countPointForecast = countPointForecast;
this->x = timeSeries;
this->partition();
}
Dsa::~Dsa(void) {
}
void Dsa::init() {
defineUniversum();
fuzzyTs.clear();
}
// îïðåäåëèòü óíèâåðñóì äëÿ âðåìåííîãî ðÿäà
// èùåì ìàêñèìóì, ìèíèìóì, ïðîèçâîäèì ðàçáèåíèå íà çàäàííûå èíòåðâàëû
void Dsa::defineUniversum() {
this->universumMax = x[0];
this->universumMin = x[0];
for (int i = 1; i < x.size(); i++) {
if (universumMax < x[i]) {
universumMax = x[i];
}
if (universumMin > x[i]) {
universumMin = x[i];
}
}
// ñîçäàåì ôóíêöèè ïðèíàäëåæíîñòè
// ïðèíèìàåì ïî óìîë÷àíèþ, ÷òî ñîñåäíèå ïåðåêðûâàþòñÿ íà ïîëîâèíó ìåæäó ñîáîé
// ðàç åñòü êîëè÷åñòâî èíòåðâàëîâ, òî âû÷èñëÿåì ðàçìåð îñíîâàíèÿ òðåóãîëüíèêà
double baseSize = (universumMax - universumMin) / countFuzzyParts;
a.resize(countFuzzyParts + 1);
for (int i=0; i < countFuzzyParts + 1;i++){
a[i] = (A(universumMin + (i-sizeLabels) * baseSize, universumMin + (i+sizeLabels)*baseSize));
}
}
// ôàççèôèöèðîâàòü òîëüêî îäíó òî÷êó
// âîçâðàùàåò èíäåêñ ôóíêöèè ïðèíàäëåæíîñòè ñ ìàêñèìàëüíûì çíà÷åíèåì
int Dsa::fuzzyfication(double value) {
// ïåðåáèðàåì âñå ôóíêöèè ïðèíàäëåæíîñòè,
// åñëè íàøëè íàèáîëüøóþ ñòåïåíü ïðèíàäëåæíîñòè, òî ôèêñèðóåì èíäåêñ ôóíêöèè
int indMax = 0;
double max = a[0].getValue(value);
for (int j =0; j < a.size(); j++) {
if (a[j].getValue(value) > max) {
indMax = j;
max = a[j].getValue(value);
}
}
return indMax;
}
void Dsa::createRules() {
rulesIn.clear();
rulesIn.resize(fuzzyTs.size() - countRulesIn);
rulesOut.clear();
rulesOut.resize(fuzzyTs.size() - countRulesIn);
for (int i=0; i < fuzzyTs.size() - countRulesIn; i ++) {
vector<int> v;
v.resize(countRulesIn);
for (int j=i; j < i + countRulesIn; j++) {
v[j-i] = fuzzyTs[j];
}
rulesIn[i] = v;
rulesOut[i] = fuzzyTs[i+countRulesIn];
}
}
vector<int> Dsa::searchRules(vector<int> inPart) {
vector<int> res;
for (int i = 0; i < rulesIn.size(); i++) {
bool isRuleFound = true;
for (int j = 0; j < rulesIn[i].size(); j++) {
if (rulesIn[i][j] != inPart[j]) {
isRuleFound = false;
}
}
if (isRuleFound) {
res.push_back(rulesOut[i]);
}
}
return res;
}
vector<int> Dsa::searchRulesForSeason(int index) {
vector<int> res;
int i =index - p;
while (i > 0) {
res.push_back(fuzzyfication(x[i]));
i -= p;
}
return res;
}
void Dsa::createModelForEstimation() {
init();
fuzzyTs.resize(xLearning.size());
for (int t = 0; t < xLearning.size(); t++) {
fuzzyTs[t] = fuzzyfication(xLearning[t]);
}
createRules();
forecast.clear();
forecast.resize(fuzzyTs.size()+countPointForecast);
for (int i=0; i < fuzzyTs.size();i++) {
forecast[i] = defuzzyfication(fuzzyTs[i]);
}
int k = fuzzyTs.size();
for (int i=0; i < countPointForecast;i++) {
vector<int> lastPoints;
lastPoints.resize(countRulesIn);
for (int j = countRulesIn; j > 0; j--) {
lastPoints[countRulesIn -j] = (fuzzyTs[fuzzyTs.size() - j]);
}
double sum = 0;
// ñåçîííàÿ êîìïîíåíòà
vector<int> foundSeasonFuncs = searchRulesForSeason(fuzzyTs.size());
for (int j =0; j < foundSeasonFuncs.size(); j++) {
sum += a[foundSeasonFuncs[j]].getValueAtTop();
}
double valueAtSeason = sum / foundSeasonFuncs.size();
forecast[i+k] = (valueAtSeason);
int index = fuzzyfication(forecast[i+k]);
// äîáàâèòü ïðîãíîçóþ òî÷êó â êîíåö ðÿäà
fuzzyTs.push_back(index);
xLearning.push_back(forecast[i+k]);
createRules();
}
for (int i=0; i < countPointForecast;i++) {
if (fuzzyTs.size() > 0)
fuzzyTs.pop_back();
if (rulesIn.size() > 0)
rulesIn.pop_back();
if (rulesOut.size() > 0)
rulesOut.pop_back();
xLearning.pop_back();
}
}
// ôàççèèêàöèÿ, ñîçäàòü ñïèñîê ôóíêöèé ïðèíàäëåæíîñòè ïî âñåìó ðÿäó
void Dsa::createModel() {
init();
fuzzyTs.resize(x.size());
for (int i = 0; i < x.size(); i++) {
fuzzyTs[i] = fuzzyfication(x[i]);
}
createRules();
forecast.clear();
forecast.resize(fuzzyTs.size()+countPointForecast);
for (int i=0; i < fuzzyTs.size();i++) {
forecast[i] = defuzzyfication(fuzzyTs[i]);
}
int k = fuzzyTs.size();
for (int i=0; i < countPointForecast;i++) {
vector<int> lastPoints;
lastPoints.resize(countRulesIn);
for (int j = countRulesIn; j > 0; j--) {
lastPoints[countRulesIn -j] = (fuzzyTs[fuzzyTs.size() - j]);
}
double sum = 0;
// ñåçîííàÿ êîìïîíåíòà
vector<int> foundSeasonFuncs = searchRulesForSeason(fuzzyTs.size());
for (int j =0; j < foundSeasonFuncs.size(); j++) {
sum += a[foundSeasonFuncs[j]].getValueAtTop();
}
double valueAtSeason = sum / foundSeasonFuncs.size();
forecast[i+k] = (valueAtSeason);
int index = fuzzyfication(forecast[i+k]);
// äîáàâèòü ïðîãíîçóþ òî÷êó â êîíåö ðÿäà
fuzzyTs.push_back(index);
x.push_back(forecast[i+k]);
createRules();
}
for (int i=0; i < countPointForecast;i++) {
if (fuzzyTs.size() > 0)
fuzzyTs.pop_back();
if (rulesIn.size() > 0)
rulesIn.pop_back();
if (rulesOut.size() > 0)
rulesOut.pop_back();
x.pop_back();
}
}
vector<double> Dsa::getForecast() {
vector<double> result;
for (unsigned int i = forecast.size() - countPointForecast; i < forecast.size(); i++) {
result.push_back(forecast[i]);
}
return forecast;
}
double Dsa::defuzzyfication(int index) {
return this->a[index].getValueAtTop();
}
void Dsa::setParam(string paramName, double value) {
if (paramName.compare("countFuzzyParts") == 0) {
this->countFuzzyParts = value;
} else if (paramName.compare("countRulesIn") == 0) {
if (this->xLearning.size() < value) {
this->countRulesIn = this->xLearning.size();
} else {
this->countRulesIn = value;
}
} else if (paramName.compare("p") == 0) {
if (value <= 0) {
this->p = 1;
} else {
this->p = value;
}
} else if (paramName.compare("sizeLabels") == 0) {
this->sizeLabels = value;
}
if (paramName.compare("0") == 0) {
this->countFuzzyParts = value * 100;
} else if (paramName.compare("1") == 0) {
if (this->xLearning.size() < value * 5) {
this->countRulesIn = this->xLearning.size();
} else {
this->countRulesIn = value * 5;
}
} else if (paramName.compare("2") == 0) {
this->sizeLabels = value * 100;
}
}
// ìåòîä ïîëó÷åíèÿ îöåíêè ìîäåëè
double Dsa::calcEstimation(Aic *aic) {
return aic->getValue(3, this->xEstimation, this->forecast);
}
// ìåòîä ïîëó÷åíèÿ îïòèìèçèðîâàííîãî çíà÷åíèÿ îäíîãî ïàðàìåòðà
// TODO: ðåàëèçîâàòü
Param* Dsa::optimize(Estimation *est) {
Param *optimal = new Param();
double minSmape = 99999;
for (double cfp = 2; cfp < 50;cfp+= 1) {
cout << "DSA " << cfp << " èç 50" <<"\n";;
for (double cri = 1; cri < 5;cri+=1) {
for (double sizeLabels = 1; sizeLabels < 50; sizeLabels+= 1) {
this->setParam("countRulesIn", cri);
this->setParam("countFuzzyParts", cfp);
this->setParam("sizeLabels", sizeLabels);
double smapeValue = 0;
int maxShift = 5;
if (maxShift > this->countPointForecast) {
maxShift = this->countPointForecast-1;
}
this->countPointForecast -= maxShift;
for (int shift=0; shift <= maxShift; shift++) {
this->partition();
this->createModelForEstimation();
smapeValue += est->getValue(x, getForecast());
this->countPointForecast++;
}
this->countPointForecast--;
smapeValue = smapeValue / maxShift;
if (minSmape > smapeValue) {
minSmape = smapeValue;
optimal->countFuzzyParts = cfp;
optimal->countRulesIn = cri;
optimal->estim = smapeValue;
optimal->sizeLabels = sizeLabels;
}
}
}
}
return optimal;
}
int Dsa::getNamberParam() {
return 3;
}

48
project_template/Dsa.h Normal file
View File

@ -0,0 +1,48 @@
#ifndef DSA_H
#define DSA_H
#include <vector>
#include "A.h"
#include "Method.h"
#include "Param.h"
using namespace std;
class Dsa : public Method {
private:
vector<A> a; // íàáîð ôóíêöèé ïðèíàäëåæíîñòè
int countFuzzyParts;// êîëè÷åñòâî èíòåðâàëîâ óíèâåðñóìà
vector<vector<int>> rulesIn; // âõîäíàÿ ÷àñòü ïðàâèë
vector<int> rulesOut; // âûõîäíàÿ ÷àñòü
int countRulesIn; // êîëè÷åñòâî âõîäíûõ ïåðåìåííûõ
double universumMin;
double universumMax;
double sizeLabels;
vector<int> fuzzyTs; // íå÷åòêèé âðåìåííîé ðÿä
double alpha; // ïàðàìåòð ñãëàæèâàíèÿ
double gamma; // ïàðàìåòð ñãëàæèâàíèÿ òðåíäà
double delta; // ïàðàìåòð ñãëàæèâàíèÿ ñåçîííîé êîìïîíåíòû
int p; // ïåðèîä ñåçîííîñòè
double phi; // ïàðàìåòð äåìïèíãà
void defineUniversum(); // îïðåäåëèòü óíèåðñóì äëÿ âðåìåííîãî ðÿäà
void createRules(); // ñîçäàòü ïðàâèëà, ïàðàìåòð çàäàåò êîëè÷åñòâî âõîäíûõ ïåðåìåííûõ
int fuzzyfication(double); // ïîëó÷èòü íå÷åòêèé âðåìåííîé ðÿä â âèäå ïîñëåäîâàòåëüíîñòè íå÷åòêèõ ìíîæåñòâ
double defuzzyfication(int); // ïîëó÷èòü íå÷åòêèé âðåìåííîé ðÿä â âèäå ïîñëåäîâàòåëüíîñòè íå÷åòêèõ ìíîæåñòâ
vector<int> searchRules(vector<int>);
vector<int> searchRulesForSeason(int);
public:
Dsa(vector<double>, int);
~Dsa(void);
vector<double> getForecast();
void init();
void createModel();
void createModelForEstimation();
void setParam(string, double);
double calcEstimation(Aic *);
Param* optimize(Estimation *); // ìåòîä îïòèìèçàöèè îäíîãî ïàðàìåòðà
int getNamberParam();
};
#endif

View File

@ -0,0 +1,33 @@
#ifndef ESTIMATION_H
#define ESTIMATION_H
#include <vector>
using namespace std;
// àáñòðàêòíûé êëàññ îöåíêè âðåìåííûõ ðÿäîâ
// ïîêà ÷òî èñïîëüçóåòñÿ äëÿ õðàíåíèÿ òîëüêî ïîëÿ "çíà÷åíèå"
// íóæíî áóäåò äîïîëíèòü íåîáõîäèìûìè ó÷àñòêàìè âðåìåííîãî ðÿäà äëÿ ïðîåäåíèÿ îöåíêè
// îò íåãî íàñëåäóþòñÿ êîíêðåòíûå ðåàëèçàöèè êðèòåðèåâ, ðåàëèçóþùèå ñîîòâåòñòâóþùèå ìåòîäèêè
// èñõîäèì èç òîãî, ÷òî âñå êðèòåðèè â êà÷åñòâå ðåçóëüòàòà âîçâðàùàþò double
class Estimation {
public:
double value; // çíà÷åíèå îöåíêè ìîäåëè
virtual double getValue(int paramsCount, vector<double>, vector<double>) = 0; // ïîëó÷èòü çíà÷åíèå îöåíêè ìîäåëè
virtual double getValue(vector<double>, vector<double>) = 0; // ïîëó÷èòü çíà÷åíèå îöåíêè ìîäåëè
protected:
double RSS(vector<double> original, vector<double> model){
double res = 0.0;
int commonElemsCount = original.size() > model.size() ? original.size() : model.size();
for (int i = 0; i < commonElemsCount; i++) {
res += (original[i] - model[i]) * (original[i] - model[i]);
}
return res;
}
virtual void Validate(vector<double> original, vector<double> model){
if (original.size() == 0)
throw exception("Original time seria is empty");
if (model.size() == 0)
throw exception("Model time seria is empty");
}
};
#endif

117
project_template/File.cpp Normal file
View File

@ -0,0 +1,117 @@
//
// Êëàññ äëÿ ðàáîòû ñ ôàéëàìè: ÷òåíèÿ âðåìåííîãî ðÿäà, çàïèñü ðåçóëüòàòîâ
//
#include "stdafx.h"
#include <string.h>
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <fstream>
#include "File.h"
#include <math.h>
using namespace std;
// ïðî÷èòàòü âðåìåííîé ðÿä èç ôàéëà
// ôîðìàò ôàéëà: âåùåñòâåííûå ÷èñëà, êàæäîå íàõîäèòñÿ íà íîâîé ñòðîêå, ðàçäåëèòåëü äðîáíîé ÷àñòè - çàïÿòàÿ
vector<double> File::readFile(string tsFileName) {
vector<double> x; // ñþäà óïàäåò çàãðóæåííûé âðåìåííîé ðÿä
std::ifstream inFile; // ïîòîê äëÿ ÷òåíèÿ ôàéëà
inFile.open(tsFileName.c_str());
string tsString = "";
while(inFile >> tsString) {
string str = tsString;
int pos = tsString.find(".");
if (pos > 0) {
str = tsString.replace(tsString.find("."), 1, ",");
}
x.push_back(atof(str.c_str()));
}
inFile.close();
return x;
}
vector<double> File::readKonfFile(string tsFileName) {
vector<double> x; // ñþäà óïàäåò çàãðóæåííûé âðåìåííîé ðÿä
int forecastCountDots = 1;
string TSPeriod = "daily"; // day, mounth, year....? êàê ïðåäñêàçàíèå çàâèñèò îò âðåìåííîãî ïåðèîäà
string TSName = ""; // day, mounth, year....? êàê ïðåäñêàçàíèå çàâèñèò îò âðåìåííîãî ïåðèîäà
std::ifstream inFile; // ïîòîê äëÿ ÷òåíèÿ ôàéëà
inFile.open(tsFileName.c_str());
string tsString = "";
while (inFile >> tsString) {
int endpos = tsString.find(';');
int startpos = 0;
if (endpos > 0){
if (TSName == ""){
//first string with params
//endpos = tsString.find(';');
//set ts name
TSName = tsString.substr(0, endpos);
startpos = endpos;
//set ts name
endpos = tsString.find(';', startpos + 1);
forecastCountDots = atoi(tsString.substr(startpos + 1, endpos - startpos - 1).c_str());
startpos = endpos;
//set ts name
endpos = tsString.find(';', startpos + 1);
TSPeriod = tsString.substr(startpos + 1 , endpos - startpos - 1);
startpos = endpos;
endpos = tsString.find(';', startpos + 1);
}
//parse ts data
while (endpos > 0){
x.push_back(atof(tsString.substr(startpos + 1, endpos - startpos -1).c_str()));
startpos = endpos;
endpos = tsString.find(';', startpos + 1);
}
}
/*string str = tsString;
int pos = tsString.find(".");
if (pos > 0) {
str = tsString.replace(tsString.find("."), 1, ",");
}
x.push_back(atof(str.c_str()));*/
}
inFile.close();
return x;
}
double File::round (double value) {
return floor(value + 0.5);
}
//îêðóãëèòü äî äâóõ çíàêîâ ïîñëå çàïÿòîé
string File::myRound(double num) {
double n = ((double) round(num * 100)) / 100;
std::ostringstream sstream;
sstream << n;
string s = sstream.str();
// çàìåíèòü ðàçäåëèòåëü äðîáíîé ÷àñòè íà çàïÿòóþ
int commaIndex = s.find(".");
if (commaIndex > 0) {
s = s.replace(commaIndex, 1, ",");
}
return s;
}
// ñîõðàíèòü â ôàéë âåêòîð ñ ðåçóëüòàòîì ïðîãíîçà
void File::writeFile(string outFileName, vector<double> result) {
ofstream outFile(outFileName.c_str(), std::ofstream::out | std::ofstream::trunc);
for (unsigned int i = 0; i < result.size(); i++) {
outFile << myRound(result[i]) << "\n";
}
outFile.close();
}
// ñîõðàíèòü â ôàéë ïðî÷èå ðåçóëüòàòû ïðîãíîçèðîâàíèÿ, íàïðèìåð îöåíêè
void File::writeFile(string outFileName, string key, double value) {
ofstream outFile(outFileName.c_str(), ios::app);
outFile << key << ";" << myRound(value) << "\n";
outFile.close();
}

23
project_template/File.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef FILE_H
#define FILE_H
//
// Êëàññ äëÿ ðàáîòû ñ ôàéëàìè:
// çàãðóçêà âðåìåííûõ ðÿäîâ, ñîõðàíåíèå ðåçóëüòàòîâ ïðîãíîçà
//
#include <string>
#include <vector>
using namespace std;
class File {
private:
static double round(double); // ðåàëèçàöèÿ îêðóãëåíèÿ ÷èñëà
static string myRound(double num); // îêðóãëåíèå ñ òî÷íîñòüþ äî òðåõ çíàêîâ ïîñëå çàïÿòîé
public:
static vector<double> readFile (string); // çàãðóçèòü âðåìåííîé ðÿä
static vector<double> readKonfFile(string); // çàãðóçèòü ðÿä â ôîðìàòå êîíôåðåíöèè
static void writeFile (string, vector<double>); // ñîõðàíèòü ðåçóëüòàò ïðîãíîçà
static void writeFile (string, string, double); // ñîõðàíèòü ïðî÷èå ðåçóëüòàòû
};
#endif

354
project_template/Fuzzy.cpp Normal file
View File

@ -0,0 +1,354 @@
#include "StdAfx.h"
#include "Fuzzy.h"
#include <iostream>
#include "Param.h"
#include <time.h>
Fuzzy::Fuzzy(string trendType, string seasonType, vector<double> timeSeries, int countPointForecast){
this->countPointForecast = countPointForecast;
this->trendType = trendType;
this->seasonType = seasonType;
this->x = timeSeries;
this->partition();
}
Fuzzy::~Fuzzy(void) {
}
void Fuzzy::init() {
defineUniversum();
fuzzyTs.clear();
}
// îïðåäåëèòü óíèâåðñóì äëÿ âðåìåííîãî ðÿäà
// èùåì ìàêñèìóì, ìèíèìóì, ïðîèçâîäèì ðàçáèåíèå íà çàäàííûå èíòåðâàëû
void Fuzzy::defineUniversum() {
this->universumMax = x[0];
this->universumMin = x[0];
for (int i = 1; i < x.size(); i++) {
if (universumMax < x[i]) {
universumMax = x[i];
}
if (universumMin > x[i]) {
universumMin = x[i];
}
}
// ñîçäàåì ôóíêöèè ïðèíàäëåæíîñòè
// ïðèíèìàåì ïî óìîë÷àíèþ, ÷òî ñîñåäíèå ïåðåêðûâàþòñÿ íà ïîëîâèíó ìåæäó ñîáîé
// ðàç åñòü êîëè÷åñòâî èíòåðâàëîâ, òî âû÷èñëÿåì ðàçìåð îñíîâàíèÿ òðåóãîëüíèêà
double baseSize = (universumMax - universumMin) / countFuzzyParts;
a.resize(countFuzzyParts + 1);
for (int i=0; i < countFuzzyParts + 1;i++){
a[i] = (A(universumMin + (i-1) * baseSize, universumMin + (i+1)*baseSize));
}
}
// ôàççèôèöèðîâàòü òîëüêî îäíó òî÷êó
// âîçâðàùàåò èíäåêñ ôóíêöèè ïðèíàäëåæíîñòè ñ ìàêñèìàëüíûì çíà÷åíèåì
int Fuzzy::fuzzyfication(double value) {
// ïåðåáèðàåì âñå ôóíêöèè ïðèíàäëåæíîñòè,
// åñëè íàøëè íàèáîëüøóþ ñòåïåíü ïðèíàäëåæíîñòè, òî ôèêñèðóåì èíäåêñ ôóíêöèè
int indMax = 0;
double max = a[0].getValue(value);
for (int j =0; j < a.size(); j++) {
if (a[j].getValue(value) > max) {
indMax = j;
max = a[j].getValue(value);
}
}
return indMax;
}
void Fuzzy::createRules() {
rulesIn.clear();
rulesIn.resize(fuzzyTs.size() - countRulesIn);
rulesOut.clear();
rulesOut.resize(fuzzyTs.size() - countRulesIn);
for (int i=0; i < fuzzyTs.size() - countRulesIn; i ++) {
vector<int> v;
v.resize(countRulesIn);
for (int j=i; j < i + countRulesIn; j++) {
v[j-i] = fuzzyTs[j];
}
rulesIn[i] = v;
rulesOut[i] = fuzzyTs[i+countRulesIn];
}
}
vector<int> Fuzzy::searchRules(vector<int> inPart) {
vector<int> res(rulesOut.size());
int countRes = 0;
for (int i = 0; i < rulesIn.size(); i++) {
bool isRuleFound = true;
for (int j = 0; j < rulesIn[i].size(); j++) {
if (rulesIn[i][j] != inPart[j]) {
isRuleFound = false;
}
}
if (isRuleFound) {
res[countRes++] = rulesOut[i];
}
}
res.resize(countRes);
return res;
}
vector<int> Fuzzy::searchRulesForSeason(int index) {
vector<int> res;
int i =index - p;
while (i > 0) {
res.push_back(fuzzyfication(x[i]));
i -= p;
}
return res;
}
void Fuzzy::createModelForEstimation() {
init();
fuzzyTs.resize(xLearning.size());
for (int t = 0; t < xLearning.size(); t++) {
fuzzyTs[t] = fuzzyfication(xLearning[t]);
}
createRules();
forecast.clear();
forecast.resize(fuzzyTs.size()+countPointForecast);
for (int i=0; i < fuzzyTs.size();i++) {
forecast[i] = defuzzyfication(fuzzyTs[i]);
}
int k = fuzzyTs.size();
for (int i=0; i < countPointForecast;i++) {
vector<int> lastPoints;
lastPoints.resize(countRulesIn);
for (int j = countRulesIn; j > 0; j--) {
lastPoints[countRulesIn -j] = (fuzzyTs[fuzzyTs.size() - j]);
}
vector<int> foundFuncs = searchRules(lastPoints);
if (foundFuncs.size() == 0) {
foundFuncs.push_back(fuzzyTs[fuzzyTs.size()-1]);
}
double sum = 0;
for (int j =0; j < foundFuncs.size(); j++) {
sum += a[foundFuncs[j]].getValueAtTop();
}
// òðåíäîâàÿ ñîñòàâëÿþùàÿ
double globInfo = sum / foundFuncs.size();
A at = this->a[fuzzyTs[fuzzyTs.size()-1]];
A atPrev = this->a[fuzzyTs[fuzzyTs.size()-2]];
double localInfo = at.getLeft() + (at.getRight() - at.getLeft())/2 + (at.getValueAtTop() - atPrev.getValueAtTop()) / (at.getValueAtTop() + atPrev.getValueAtTop());
// ñåçîííàÿ êîìïîíåíòà
vector<int> foundSeasonFuncs = searchRulesForSeason(fuzzyTs.size());
sum = 0;
for (int j =0; j < foundSeasonFuncs.size(); j++) {
sum += a[foundSeasonFuncs[j]].getValueAtTop();
}
double valueAtSeason = sum / foundSeasonFuncs.size();
if (trendType.compare("None") == 0) {
if (seasonType.compare("None") == 0) {
forecast[i+k] = (localInfo);
} else if (seasonType.compare("Add") == 0) {
forecast[i+k] = (gamma * localInfo + (1-gamma) * valueAtSeason);
}
} else if (trendType.compare("Add") == 0) {
if (seasonType.compare("None") == 0) {
forecast[i+k] = (delta * localInfo + (1-delta) * globInfo);
} else if (seasonType.compare("Add") == 0) {
forecast[i+k] = (gamma * delta * localInfo + (1-gamma) * valueAtSeason + (1-delta) * globInfo);
}
}
int index = fuzzyfication(forecast[i+k]);
// äîáàâèòü ïðîãíîçóþ òî÷êó â êîíåö ðÿäà
fuzzyTs.push_back(index);
xLearning.push_back(forecast[i+k]);
createRules();
}
for (int i=0; i < countPointForecast;i++) {
fuzzyTs.pop_back();
rulesIn.pop_back();
rulesOut.pop_back();
xLearning.pop_back();
}
}
// ôàççèèêàöèÿ, ñîçäàòü ñïèñîê ôóíêöèé ïðèíàäëåæíîñòè ïî âñåìó ðÿäó
void Fuzzy::createModel() {
init();
fuzzyTs.resize(x.size());
for (int i = 0; i < x.size(); i++) {
fuzzyTs[i] = fuzzyfication(x[i]);
}
createRules();
forecast.clear();
forecast.resize(fuzzyTs.size()+countPointForecast);
for (int i=0; i < fuzzyTs.size();i++) {
forecast[i] = defuzzyfication(fuzzyTs[i]);
}
int k = fuzzyTs.size();
for (int i=0; i < countPointForecast;i++) {
vector<int> lastPoints;
lastPoints.resize(countRulesIn);
for (int j = countRulesIn; j > 0; j--) {
lastPoints[countRulesIn -j] = (fuzzyTs[fuzzyTs.size() - j]);
}
vector<int> foundFuncs = searchRules(lastPoints);
if (foundFuncs.size() == 0) {
foundFuncs.push_back(fuzzyTs[fuzzyTs.size()-1]);
}
double sum = 0;
for (int j =0; j < foundFuncs.size(); j++) {
sum += a[foundFuncs[j]].getValueAtTop();
}
// òðåíäîâàÿ ñîñòàâëÿþùàÿ
double globInfo = sum / foundFuncs.size();
A at = this->a[fuzzyTs[fuzzyTs.size()-1]];
A atPrev = this->a[fuzzyTs[fuzzyTs.size()-2]];
double localInfo = at.getLeft() + (at.getRight() - at.getLeft())/2 + (at.getValueAtTop() - atPrev.getValueAtTop()) / (at.getValueAtTop() + atPrev.getValueAtTop());
// ñåçîííàÿ êîìïîíåíòà
vector<int> foundSeasonFuncs = searchRulesForSeason(fuzzyTs.size());
sum = 0;
for (int j =0; j < foundSeasonFuncs.size(); j++) {
sum += a[foundSeasonFuncs[j]].getValueAtTop();
}
double valueAtSeason = sum / foundSeasonFuncs.size();
if (trendType.compare("None") == 0) {
if (seasonType.compare("None") == 0) {
forecast[i+k] = (localInfo);
} else if (seasonType.compare("Add") == 0) {
forecast[i+k] = (gamma * localInfo + (1-gamma) * valueAtSeason);
}
} else if (trendType.compare("Add") == 0) {
if (seasonType.compare("None") == 0) {
forecast[i+k] = (delta * localInfo + (1-delta) * globInfo);
} else if (seasonType.compare("Add") == 0) {
forecast[i+k] = (gamma * delta * localInfo + (1-gamma) * valueAtSeason + (1-delta) * globInfo);
}
}
int index = fuzzyfication(forecast[i+k]);
// äîáàâèòü ïðîãíîçóþ òî÷êó â êîíåö ðÿäà
fuzzyTs.push_back(index);
x.push_back(forecast[i+k]);
createRules();
}
for (int i=0; i < countPointForecast;i++) {
fuzzyTs.pop_back();
rulesIn.pop_back();
rulesOut.pop_back();
x.pop_back();
}
}
vector<double> Fuzzy::getForecast() {
vector<double> result;
for (unsigned int i = forecast.size() - countPointForecast; i < forecast.size(); i++) {
result.push_back(forecast[i]);
}
return forecast;
}
double Fuzzy::defuzzyfication(int index) {
return this->a[index].getValueAtTop();
}
void Fuzzy::setParam(string paramName, double value) {
if (paramName.compare("countFuzzyParts") == 0) {
this->countFuzzyParts = value;
} else if (paramName.compare("countRulesIn") == 0) {
if (this->xLearning.size() < value) {
this->countRulesIn = this->xLearning.size();
} else {
this->countRulesIn = value;
}
} else if (paramName.compare("p") == 0) {
this->p = value;
} else if (paramName.compare("gamma") == 0) {
this->gamma = value;
} else if (paramName.compare("delta") == 0) {
this->delta = value;
}
if (paramName.compare("0") == 0) {
this->countFuzzyParts = value * 100;
} else if (paramName.compare("1") == 0) {
if (this->xLearning.size() < value * 5) {
this->countRulesIn = this->xLearning.size();
} else {
this->countRulesIn = value * 5;
}
} else if (paramName.compare("2") == 0) {
this->gamma = value;
} else if (paramName.compare("3") == 0) {
this->delta = value;
}
}
// ìåòîä ïîëó÷åíèÿ îöåíêè ìîäåëè
double Fuzzy::calcEstimation(Aic *aic) {
return aic->getValue(3, this->xEstimation, this->forecast);
}
// ìåòîä ïîëó÷åíèÿ îïòèìèçèðîâàííîãî çíà÷åíèÿ îäíîãî ïàðàìåòðà
// TODO: ðåàëèçîâàòü
Param* Fuzzy::optimize(Estimation *est) {
Param *optimal = new Param();
double minSmape = 99999;
for (double gam = 0; gam < 1; gam+= 0.1) {
cout << "fuzzy " << gam << " èç 1" <<"\n";;
for (double del = 0; del < 1;del+= 0.1) {
for (double cri = 1; cri < 5;cri+= 1) {
for (double cfp = 2; cfp < 50;cfp+= 2) {
this->setParam("gamma", gam);
this->setParam("delta", del);
this->setParam("countRulesIn", cri);
this->setParam("countFuzzyParts", cfp);
double smapeValue = 0;
int maxShift = 5;
if (maxShift > this->countPointForecast) {
maxShift = this->countPointForecast-1;
}
this->countPointForecast -= maxShift;
for (int shift=0; shift <= maxShift; shift++) {
this->partition();
this->createModelForEstimation();
smapeValue += est->getValue(x, getForecast());
this->countPointForecast++;
}
this->countPointForecast--;
smapeValue = smapeValue / maxShift;
if (minSmape > smapeValue) {
minSmape = smapeValue;
optimal->gamma = gam;
optimal->delta = del;
optimal->estim = smapeValue;
optimal->countFuzzyParts = cfp;
optimal->countRulesIn = cri;
}
}
}
}
}
return optimal;
}
int Fuzzy::getNamberParam() {
return 4;
}

49
project_template/Fuzzy.h Normal file
View File

@ -0,0 +1,49 @@
#ifndef FUZZY_H
#define FUZZY_H
#include <vector>
#include "A.h"
#include "Method.h"
#include "Param.h"
using namespace std;
class Fuzzy : public Method {
private:
vector<A> a; // íàáîð ôóíêöèé ïðèíàäëåæíîñòè
int countFuzzyParts;// êîëè÷åñòâî èíòåðâàëîâ óíèâåðñóìà
vector<vector<int>> rulesIn; // âõîäíàÿ ÷àñòü ïðàâèë
vector<int> rulesOut; // âûõîäíàÿ ÷àñòü
int countRulesIn; // êîëè÷åñòâî âõîäíûõ ïåðåìåííûõ
double universumMin;
double universumMax;
vector<int> fuzzyTs; // íå÷åòêèé âðåìåííîé ðÿä
string trendType;
string seasonType;
double alpha; // ïàðàìåòð ñãëàæèâàíèÿ
double gamma; // ïàðàìåòð ñãëàæèâàíèÿ òðåíäà
double delta; // ïàðàìåòð ñãëàæèâàíèÿ ñåçîííîé êîìïîíåíòû
int p; // ïåðèîä ñåçîííîñòè
double phi; // ïàðàìåòð äåìïèíãà
void defineUniversum(); // îïðåäåëèòü óíèåðñóì äëÿ âðåìåííîãî ðÿäà
void createRules(); // ñîçäàòü ïðàâèëà, ïàðàìåòð çàäàåò êîëè÷åñòâî âõîäíûõ ïåðåìåííûõ
int fuzzyfication(double); // ïîëó÷èòü íå÷åòêèé âðåìåííîé ðÿä â âèäå ïîñëåäîâàòåëüíîñòè íå÷åòêèõ ìíîæåñòâ
double defuzzyfication(int); // ïîëó÷èòü íå÷åòêèé âðåìåííîé ðÿä â âèäå ïîñëåäîâàòåëüíîñòè íå÷åòêèõ ìíîæåñòâ
vector<int> searchRules(vector<int>);
vector<int> searchRulesForSeason(int);
public:
Fuzzy(string, string, vector<double>, int);
~Fuzzy(void);
vector<double> getForecast();
void init();
void createModel();
void createModelForEstimation();
void setParam(string, double);
double calcEstimation(Aic *);
Param* optimize(Estimation *); // ìåòîä îïòèìèçàöèè îäíîãî ïàðàìåòðà
int getNamberParam();
};
#endif

View File

@ -0,0 +1,498 @@
#include "StdAfx.h"
#include "FuzzyWithSets.h"
#include <iostream>
#include <sstream>
#include "Param.h"
#include "float.h"
FuzzyWithSets::FuzzyWithSets(string trendType, string seasonType, vector<double> timeSeries, int countPointForecast){
this->countPointForecast = countPointForecast;
this->trendType = trendType;
this->seasonType = seasonType;
this->x = timeSeries;
this->partition();
}
FuzzyWithSets::~FuzzyWithSets(void) {
}
void FuzzyWithSets::init() {
S.clear();
T.clear();
I.clear();
if (trendType.compare("None") == 0) {
if (seasonType.compare("None") == 0) {
S.push_back(fuzzyTs[0]);
fuzzyForecast.push_back(fuzzyTs[0]);
} else if (seasonType.compare("Add") == 0) {
A sumS = fuzzyTs[0];
for (unsigned int t = 1; t < p; t++) {
sumS = plusSet(sumS, fuzzyTs[t]);
}
S.push_back(divSet(sumS, p));
I.resize(p);
for (unsigned int t = 0; t < p; t++) {
I[t] = minusSet(fuzzyTs[t], S[0]);
}
fuzzyForecast.push_back(plusSet(S[0], I[0]));
} else if (seasonType.compare("Mult") == 0) {
A sumS = fuzzyTs[0];
for (unsigned int t = 1; t < p; t++) {
sumS = plusSet(sumS, fuzzyTs[t]);
}
S.push_back(divSet(sumS, p));
I.resize(p);
for (unsigned int t = 0; t < p; t++) {
I[t] = divSet(fuzzyTs[t], S[0]);
}
fuzzyForecast.push_back(multSet(S[0], I[0]));
}
} else if (trendType.compare("Add") == 0) {
if (seasonType.compare("None") == 0) {
T.push_back(minusSet(fuzzyTs[1], fuzzyTs[0]));
S.push_back(fuzzyTs[0]);
fuzzyForecast.push_back(plusSet(S[0], T[0]));
} else if (seasonType.compare("Add") == 0) {
A sumS = fuzzyTs[0];
A sumT = fuzzyTs[0];
for (unsigned int t = 1; t < p; t++) {
sumS = plusSet(sumS, fuzzyTs[t]);
sumT = plusSet(sumT, fuzzyTs[t+p]);
}
S.push_back(divSet(sumS, p));
T.push_back(divSet(minusSet(divSet(sumT, p), S[0]), p));
I.resize(p);
for (unsigned int t = 0; t < p; t++) {
I[t] = minusSet(fuzzyTs[t], S[0]);
}
fuzzyForecast.push_back(plusSet(S[0], plusSet(T[0], I[0])));
} else if (seasonType.compare("Mult") == 0) {
A sumS = fuzzyTs[0];
A sumT = fuzzyTs[0];
for (unsigned int t = 1; t < p; t++) {
sumS = plusSet(sumS, fuzzyTs[t]);
sumT = plusSet(sumT, fuzzyTs[t+p]);
}
S.push_back(divSet(sumS, p));
T.push_back(divSet(minusSet(divSet(sumT, p), S[0]), p));
I.resize(p);
for (unsigned int t = 0; t < p; t++) {
I[t] = divSet(fuzzyTs[t], S[0]);
}
fuzzyForecast.push_back(multSet(plusSet(S[0],T[0]), I[0]));
}
} else if (trendType.compare("Mult") == 0) {
if (seasonType.compare("None") == 0) {
T.push_back(divSet(fuzzyTs[1], fuzzyTs[0]));
S.push_back(fuzzyTs[0]);
fuzzyForecast.push_back(multSet(S[0], T[0]));
} else if (seasonType.compare("Add") == 0) {
A sumS = fuzzyTs[0];
A sumT = fuzzyTs[0];
for (unsigned int t = 1; t < p; t++) {
sumS = plusSet(sumS, fuzzyTs[t]);
sumT = plusSet(sumT, fuzzyTs[t+p]);
}
S.push_back(divSet(sumS, p));
T.push_back(divSet(minusSet(divSet(sumT, p), S[0]), p));
I.resize(p);
for (unsigned int t = 0; t < p; t++) {
I[t] = minusSet(fuzzyTs[t], S[0]);
}
fuzzyForecast.push_back(plusSet(multSet(S[0], T[0]), I[0]));
} else if (seasonType.compare("Mult") == 0) {
A sumS = fuzzyTs[0];
A sumT = fuzzyTs[0];
for (unsigned int t = 1; t < p; t++) {
sumS = plusSet(sumS, fuzzyTs[t]);
sumT = plusSet(sumT, fuzzyTs[t+p]);
}
S.push_back(divSet(sumS, p));
T.push_back(divSet(minusSet(divSet(sumT, p), S[0]), p));
I.resize(p);
for (unsigned int t = 0; t < p; t++) {
I[t] = divSet(fuzzyTs[t], S[0]);
}
fuzzyForecast.push_back(multSet(multSet(S[0],T[0]), I[0]));
}
}
}
// îïðåäåëèòü óíèâåðñóì äëÿ âðåìåííîãî ðÿäà
// èùåì ìàêñèìóì, ìèíèìóì, ïðîèçâîäèì ðàçáèåíèå íà çàäàííûå èíòåðâàëû
void FuzzyWithSets::defineUniversum() {
this->universumMax = x[0];
this->universumMin = x[0];
for (int i = 1; i < x.size(); i++) {
if (universumMax < x[i]) {
universumMax = x[i];
}
if (universumMin > x[i]) {
universumMin = x[i];
}
}
// ñîçäàåì ôóíêöèè ïðèíàäëåæíîñòè
// ïðèíèìàåì ïî óìîë÷àíèþ, ÷òî ñîñåäíèå ïåðåêðûâàþòñÿ íà ïîëîâèíó ìåæäó ñîáîé
// ðàç åñòü êîëè÷åñòâî èíòåðâàëîâ, òî âû÷èñëÿåì ðàçìåð îñíîâàíèÿ òðåóãîëüíèêà
double baseSize = (universumMax - universumMin) / countFuzzyParts;
a.resize(countFuzzyParts + 1);
for (int i=0; i < countFuzzyParts + 1;i++){
a[i] = (A(universumMin + (i-1) * baseSize, universumMin + (i+1)*baseSize));
}
}
// îïåðàöèÿ âû÷èòàíèÿ ìíîæåñòâ
A FuzzyWithSets::minusSet(A a, A b) {
return A(a.getLeft()- b.getLeft(), a.getRight() - b.getRight());
}
// îïåðàöèÿ äåëåíèÿ ìíîæåñòâ
A FuzzyWithSets::divSet(A a, A b) {
return A(a.getLeft()/b.getLeft(), a.getRight()/b.getRight());
}
// îïåðàöèÿ äåëåíèÿ ìíîæåñòâ
A FuzzyWithSets::divSet(A a, double b) {
return A(a.getLeft()/b, a.getRight()/b);
}
// îïåðàöèÿ óìíîæåíèå ìíîæåñòâà íà ÷èñëî
A FuzzyWithSets::multSetNum(double num, A a) {
return A(a.getLeft() * num, a.getRight() * num);
}
// îïåðàöèÿ ñëîæåíèÿ ìíîæåñòâ
A FuzzyWithSets::plusSet(A a, A b) {
return A(a.getLeft()+ b.getLeft(), a.getRight() + b.getRight());
}
// îïåðàöèÿ óìíîæåíèÿ ìíîæåñòâ
A FuzzyWithSets::multSet(A a, A b) {
return A(a.getLeft()* b.getLeft(), a.getRight() * b.getRight());
}
// ôàççèôèöèðîâàòü òîëüêî îäíó òî÷êó
// âîçâðàùàåò èíäåêñ ôóíêöèè ïðèíàäëåæíîñòè ñ ìàêñèìàëüíûì çíà÷åíèåì
A FuzzyWithSets::fuzzyfication(double value) {
// ïåðåáèðàåì âñå ôóíêöèè ïðèíàäëåæíîñòè,
// åñëè íàøëè íàèáîëüøóþ ñòåïåíü ïðèíàäëåæíîñòè, òî ôèêñèðóåì èíäåêñ ôóíêöèè
A aMax = a[0];
for (int j = 0; j < a.size(); j++) {
if (a[j].getValue(value) > aMax.getValue(value)) {
aMax = a[j];
}
}
return aMax;
}
void FuzzyWithSets::createModelForEstimation() {
fuzzyTs.clear();
fuzzyForecast.clear();
defineUniversum();
// ôàççèôèêàöèÿ
fuzzyTs.resize(xLearning.size());
for (int i = 0; i < xLearning.size();i++) {
fuzzyTs[i] = (fuzzyfication(xLearning[i]));
}
init();
A fuzzyLast = fuzzyTs[fuzzyTs.size()-1];
A e;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < xLearning.size()-1+this->countPointForecast; t++) {
if (trendType.compare("None") == 0) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < fuzzyTs.size()) {
e = minusSet(fuzzyTs[t], fuzzyForecast[t]);
} else {
e = A(0,0);
}
if (seasonType.compare("None") == 0) {
S.push_back(plusSet(S[t],multSetNum(alpha, e)));
fuzzyForecast.push_back(S[t+1]);
} else if (seasonType.compare("Add") == 0) {
S.push_back(plusSet(S[t], multSetNum(alpha, e)));
I.push_back(plusSet(I[t], multSetNum(delta, e)));
fuzzyForecast.push_back(plusSet(S[t+1], I[t+1]));
} else if (seasonType.compare("Mult") == 0) {
S.push_back(plusSet(S[t], divSet(multSetNum(alpha, e), I[t])));
I.push_back(plusSet(I[t], divSet(multSetNum(delta, e), S[t])));
fuzzyForecast.push_back(multSet(S[t+1], I[t+1]));
}
} else if (trendType.compare("Add") == 0) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < fuzzyTs.size()) {
e = minusSet(fuzzyTs[t], fuzzyForecast[t]);
} else {
e = A(0,0);
}
if (seasonType.compare("None") == 0) {
S.push_back(plusSet(S[t], plusSet(T[t], multSetNum(alpha, e))));
T.push_back(plusSet(T[t], multSetNum(alpha, multSetNum(gamma, e))));
fuzzyForecast.push_back(plusSet(S[t+1], T[t+1]));
} else if (seasonType.compare("Add") == 0) {
S.push_back(plusSet(S[t], plusSet(T[t], multSetNum(alpha, e))));
T.push_back(plusSet(T[t], multSetNum(alpha, multSetNum(gamma, e))));
I.push_back(plusSet(I[t], multSetNum(delta, e)));
fuzzyForecast.push_back(plusSet(S[t+1], plusSet(T[t+1], I[t+1])));
} else if (seasonType.compare("Mult") == 0) {
S.push_back(plusSet(S[t], plusSet(T[t], divSet(multSetNum(alpha, e), I[t]))));
T.push_back(plusSet(T[t], divSet(multSetNum(alpha, multSetNum(gamma, e)), I[t])));
I.push_back(plusSet(I[t], divSet(multSetNum(delta, e), plusSet(S[t], T[t]))));
fuzzyForecast.push_back(multSet(plusSet(S[t+1], T[t+1]), I[t+1]));
}
} else if (trendType.compare("Mult") == 0) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < fuzzyTs.size()) {
e = minusSet(fuzzyTs[t], fuzzyForecast[t]);
} else {
e = A(0,0);
}
if (seasonType.compare("None") == 0) {
S.push_back(plusSet(multSet(S[t], T[t]), multSetNum(alpha, e)));
T.push_back(plusSet(T[t], divSet(multSetNum(alpha, multSetNum(gamma, e)), S[t])));
fuzzyForecast.push_back(multSet(S[t+1], T[t+1]));
} else if (seasonType.compare("Add") == 0) {
S.push_back(plusSet(multSet(S[t], T[t]), multSetNum(alpha, e)));
T.push_back(plusSet(T[t], divSet(multSetNum(alpha, multSetNum(gamma, e)), S[t])));
I.push_back(plusSet(I[t], multSetNum(delta, e)));
fuzzyForecast.push_back(plusSet(multSet(S[t+1], T[t+1]), I[t]));
} else if (seasonType.compare("Mult") == 0) {
S.push_back(plusSet(multSet(S[t], T[t]), divSet(multSetNum(alpha, e), I[t])));
T.push_back(plusSet(
T[t],
divSet(
divSet(
multSetNum(
alpha,
multSetNum(
gamma,
e)
),
S[t]),
I[t])
)
);
I.push_back(plusSet(I[t], divSet(divSet(multSetNum(delta, e), S[t]), T[t])));
fuzzyForecast.push_back(multSet(S[t+1], multSet(T[t+1], I[t])));
}
}
}
}
// ôàççèèêàöèÿ, ñîçäàòü ñïèñîê ôóíêöèé ïðèíàäëåæíîñòè ïî âñåìó ðÿäó
void FuzzyWithSets::createModel() {
fuzzyTs.clear();
fuzzyForecast.clear();
defineUniversum();
// ôàççèôèêàöèÿ
fuzzyTs.resize(x.size());
for (int i = 0; i < x.size();i++) {
fuzzyTs[i] = (fuzzyfication(x[i]));
}
init();
A fuzzyLast = fuzzyTs[fuzzyTs.size()-1];
A e;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < x.size()-1+this->countPointForecast; t++) {
if (trendType.compare("None") == 0) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < fuzzyTs.size()) {
e = minusSet(fuzzyTs[t], fuzzyForecast[t]);
} else {
e = A(0,0);
}
if (seasonType.compare("None") == 0) {
S.push_back(plusSet(S[t],multSetNum(alpha, e)));
fuzzyForecast.push_back(S[t+1]);
} else if (seasonType.compare("Add") == 0) {
S.push_back(plusSet(S[t], multSetNum(alpha, e)));
I.push_back(plusSet(I[t], multSetNum(delta, e)));
fuzzyForecast.push_back(plusSet(S[t+1], I[t+1]));
} else if (seasonType.compare("Mult") == 0) {
S.push_back(plusSet(S[t], divSet(multSetNum(alpha, e), I[t])));
I.push_back(plusSet(I[t], divSet(multSetNum(delta, e), S[t])));
fuzzyForecast.push_back(multSet(S[t+1], I[t+1]));
}
} else if (trendType.compare("Add") == 0) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < fuzzyTs.size()) {
e = minusSet(fuzzyTs[t], fuzzyForecast[t]);
} else {
e = A(0,0);
}
if (seasonType.compare("None") == 0) {
S.push_back(plusSet(S[t], plusSet(T[t], multSetNum(alpha, e))));
T.push_back(plusSet(T[t], multSetNum(alpha, multSetNum(gamma, e))));
fuzzyForecast.push_back(plusSet(S[t+1], T[t+1]));
} else if (seasonType.compare("Add") == 0) {
S.push_back(plusSet(S[t], plusSet(T[t], multSetNum(alpha, e))));
T.push_back(plusSet(T[t], multSetNum(alpha, multSetNum(gamma, e))));
I.push_back(plusSet(I[t], multSetNum(delta, e)));
fuzzyForecast.push_back(plusSet(S[t+1], plusSet(T[t+1], I[t+1])));
} else if (seasonType.compare("Mult") == 0) {
S.push_back(plusSet(S[t], plusSet(T[t], divSet(multSetNum(alpha, e), I[t]))));
T.push_back(plusSet(T[t], divSet(multSetNum(alpha, multSetNum(gamma, e)), I[t])));
I.push_back(plusSet(I[t], divSet(multSetNum(delta, e), plusSet(S[t], T[t]))));
fuzzyForecast.push_back(multSet(plusSet(S[t+1], T[t+1]), I[t+1]));
}
} else if (trendType.compare("Mult") == 0) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < fuzzyTs.size()) {
e = minusSet(fuzzyTs[t], fuzzyForecast[t]);
} else {
e = A(0,0);
}
if (seasonType.compare("None") == 0) {
S.push_back(plusSet(multSet(S[t], T[t]), multSetNum(alpha, e)));
T.push_back(plusSet(T[t], divSet(multSetNum(alpha, multSetNum(gamma, e)), S[t])));
fuzzyForecast.push_back(multSet(S[t+1], T[t+1]));
} else if (seasonType.compare("Add") == 0) {
S.push_back(plusSet(multSet(S[t], T[t]), multSetNum(alpha, e)));
T.push_back(plusSet(T[t], divSet(multSetNum(alpha, multSetNum(gamma, e)), S[t])));
I.push_back(plusSet(I[t], multSetNum(delta, e)));
fuzzyForecast.push_back(plusSet(multSet(S[t+1], T[t+1]), I[t]));
} else if (seasonType.compare("Mult") == 0) {
S.push_back(plusSet(multSet(S[t], T[t]), divSet(multSetNum(alpha, e), I[t])));
T.push_back(plusSet(
T[t],
divSet(
divSet(
multSetNum(
alpha,
multSetNum(
gamma,
e)
),
S[t]),
I[t])
)
);
I.push_back(plusSet(I[t], divSet(divSet(multSetNum(delta, e), S[t]), T[t])));
fuzzyForecast.push_back(multSet(S[t+1], multSet(T[t+1], I[t])));
}
}
}
}
vector<double> FuzzyWithSets::getForecast() {
vector<double> result;
/* result.resize(countPointForecast);
for (unsigned int i = fuzzyForecast.size() - countPointForecast; i < fuzzyForecast.size(); i++) {
if (_finite(defuzzyfication(fuzzyForecast[i])) == 0){
result[i - (fuzzyForecast.size() - countPointForecast)] = (x[x.size()-1]);
} else {
result[i - (fuzzyForecast.size() - countPointForecast)] = (defuzzyfication(fuzzyForecast[i]));
}
}*/
result.resize(fuzzyForecast.size());
for (unsigned int i = 0; i < fuzzyForecast.size(); i++) {
if (_finite(defuzzyfication(fuzzyForecast[i])) == 0){
result[i] = (x[x.size()-1]);
} else {
result[i] = (defuzzyfication(fuzzyForecast[i]));
}
}
return result;
}
double FuzzyWithSets::defuzzyfication(A a) {
return a.getValueAtTop();
}
vector<double> FuzzyWithSets::defuzzyfication(vector<A> fuz) {
vector<double> result;
for (int i =0; i < fuz.size(); i++) {
result.push_back(defuzzyfication(fuz[i]));
}
return result;
}
void FuzzyWithSets::setParam(string paramName, double value) {
if (paramName.compare("countFuzzyParts") == 0) {
this->countFuzzyParts = value;
} else if (paramName.compare("p") == 0) {
this->p = value;
} else if (paramName.compare("gamma") == 0) {
this->gamma = value;
} else if (paramName.compare("alpha") == 0) {
this->alpha = value;
} else if (paramName.compare("delta") == 0) {
this->delta = value;
}
if (paramName.compare("0") == 0) {
this->countFuzzyParts = value * 100;
} else if (paramName.compare("1") == 0) {
this->alpha = value;
} else if (paramName.compare("2") == 0) {
this->gamma = value;
} else if (paramName.compare("3") == 0) {
this->delta = value;
} else if (paramName.compare("4") == 0) {
this->alpha = value;
}
}
// ìåòîä ïîëó÷åíèÿ îöåíêè ìîäåëè
double FuzzyWithSets::calcEstimation(Aic *aic) {
return aic->getValue(3, this->xEstimation, this->forecast);
}
// ìåòîä ïîëó÷åíèÿ îïòèìèçèðîâàííîãî çíà÷åíèÿ îäíîãî ïàðàìåòðà
// TODO: ðåàëèçîâàòü
Param* FuzzyWithSets::optimize(Estimation *est) {
Param *optimal = new Param();
double minSmape = 99999;
for (double al = 0; al < 1; al+= 0.1) {
cout << "FWS " << al << " èç 1" <<"\n";
for (double gam = 0; gam < 1; gam+= 0.1) {
for (double del = 0; del < 1;del+= 0.1) {
for (double cfp = 2; cfp < 50;cfp+= 2) {
this->setParam("alpha", al);
this->setParam("gamma", gam);
this->setParam("delta", del);
this->setParam("countFuzzyParts", cfp);
double smapeValue = 0;
int maxShift = 5;
if (maxShift > this->countPointForecast) {
maxShift = this->countPointForecast-1;
}
this->countPointForecast -= maxShift;
for (int shift=0; shift <= maxShift; shift++) {
this->partition();
this->createModelForEstimation();
smapeValue += est->getValue(x, getForecast());
this->countPointForecast++;
}
this->countPointForecast--;
smapeValue = smapeValue / maxShift;
if (minSmape > smapeValue) {
minSmape = smapeValue;
optimal->alpha = al;
optimal->gamma = gam;
optimal->delta = del;
optimal->estim = smapeValue;
optimal->countFuzzyParts = cfp;
}
}
}
}
}
return optimal;
}
int FuzzyWithSets::getNamberParam() {
return 5;
}

View File

@ -0,0 +1,55 @@
#ifndef FUZZYWITHSETS_H
#define FUZZYWITHSETS_H
#include <vector>
#include "A.h"
#include "Method.h"
#include "Param.h"
using namespace std;
class FuzzyWithSets : public Method {
private:
vector<A> a; // íàáîð ôóíêöèé ïðèíàäëåæíîñòè
int countFuzzyParts;// êîëè÷åñòâî èíòåðâàëîâ óíèâåðñóìà
double universumMin;
double universumMax;
vector<A> fuzzyTs; // íå÷åòêèé âðåìåííîé ðÿä
vector<A> fuzzyForecast; // íå÷åòêèé âðåìåííîé ðÿä
double w;
string trendType;
string seasonType;
double alpha; // ïàðàìåòð ñãëàæèâàíèÿ
double gamma; // ïàðàìåòð ñãëàæèâàíèÿ òðåíäà
double delta; // ïàðàìåòð ñãëàæèâàíèÿ ñåçîííîé êîìïîíåíòû
int p; // ïåðèîä ñåçîííîñòè
double phi; // ïàðàìåòð äåìïèíãà
vector<A> S; // ñãëàæåííûé äàííûì ìåòîäîì ðÿä
vector<A> I;
vector<A> T;
void defineUniversum(); // îïðåäåëèòü óíèåðñóì äëÿ âðåìåííîãî ðÿäà
A fuzzyfication(double);
double defuzzyfication(A);
vector<double> defuzzyfication(vector<A>);
A minusSet(A, A);
A plusSet(A, A);
A divSet(A, A);
A divSet(A, double);
A multSet(A, A);
A multSetNum(double, A);
public:
FuzzyWithSets(string, string, vector<double>, int);
~FuzzyWithSets(void);
vector<double> getForecast();
void init();
void createModel();
void createModelForEstimation();
void setParam(string, double);
double calcEstimation(Aic *);
Param* optimize(Estimation *); // ìåòîä îïòèìèçàöèè îäíîãî ïàðàìåòðà
int getNamberParam();
};
#endif

29
project_template/Mape.cpp Normal file
View File

@ -0,0 +1,29 @@
#include "StdAfx.h"
#include <iostream>
#include "Mape.h"
#include "Math.h"
#include <vector>
// êðèòåðèé Mape. Íàñëåäóåòñÿ îò êëàññà Estimation.
// ðåàëèçóåò ìåòîä "ïîëó÷èòü çíà÷åíèå êðèòåðèÿ"
Mape::Mape() {
}
Mape::~Mape() {
}
double Mape::getValue(int paramCount, vector<double> original, vector<double> model) {
return 0;
}
double Mape::getValue(vector<double> original, vector<double> model) {
double mape = 0;
for (int i = 0; i < original.size(); i++) {
mape += fabs((fabs(original[i] - model[i])) / original[i]);
}
mape = mape / original.size();
mape = mape * 100;
return mape;
}

15
project_template/Mape.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef MAPE_H
#define MAPE_H
#include "Estimation.h"
using namespace std;
// êðèòåðèé Mape. Íàñëåäóåòñÿ îò êëàññà Estimation.
// ðåàëèçóåò ìåòîä "ïîëó÷èòü çíà÷åíèå êðèòåðèÿ"
class Mape : public Estimation {
public:
Mape();
~Mape();
double getValue(vector<double>, vector<double>);
double getValue(int, vector<double>, vector<double>);
};
#endif

View File

@ -0,0 +1,65 @@
#include "StdAfx.h"
#include "Median.h"
#include <vector>
#include <algorithm>
Median::Median() {
}
Median::~Median() {
}
double Median::getValue(int, vector<double>, vector<double>){
return 0;
}
double Median::getValue(vector<double>, vector<double>){
return 0;
}
double Median::getValue(vector<double> ts){
double median;
int size = ts.size();
sort(ts.begin(), ts.end());
if (size % 2 == 0)
{
median = (ts[size % 2 - 1] + ts[size % 2 + 1]) / 2;
}
else
{
median = ts[size / 2];
}
return median;
}
vector<double> Median::getValue(vector<double> ts, int period){
int size = ts.size();
int amtPeriod = size / period;
int shift = size - amtPeriod * period;
vector <double> median(amtPeriod);
vector <double> temp(period);
int begin;
int end;
for (int i = 0; i < amtPeriod; i++)
{
begin = shift + i * period;
end = begin + period;
std::copy(ts.begin() + begin, ts.begin() + end, temp.begin());
median[i] = getValue(temp);
}
return median;
}

20
project_template/Median.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef MEDIAN_H
#define MEDIAN_H
#include "Estimation.h"
using namespace std;
//
//
class Median :public Estimation {
public:
Median();
~Median();
double getValue(vector<double>);
vector<double> getValue(vector<double>, int);
double getValue(int, vector<double>, vector<double>);
double getValue(vector<double>, vector<double>);
};
#endif

View File

@ -0,0 +1,34 @@
//
// Ìåòîä ýêñïîíåíöèàëüíîãî ñãëàæèâàíèÿ è ïðîãíîçèðîâàíèÿ:
// àääèòèâíûé òðåíä, àääèòèâíàÿ ñåçîííîñòü
//
#include "StdAfx.h"
#include <iostream>
#include "Method.h"
void Method::partition() {
this->xLearning.clear();
this->xEstimation.clear();
this->xLearning.resize(x.size() - countPointForecast);
this->xEstimation.resize(this->countPointForecast);
//ñîõðàíÿåì ÷àñòü äëÿ òåñòèðîâàíèÿ
for (unsigned int i = 0; i < x.size() - countPointForecast; i++) {
this->xLearning[i] = x[i];
}
// ñîõðàíÿåì ÷àñòü ÂÐ äëÿ òåñòèðîâàíèÿ
int j=0;
for (unsigned int i = x.size() - countPointForecast; i < x.size(); i++) {
this->xEstimation[j++] = x[i];
}
}
vector<double> Method::getXEstimation() {
return this->xEstimation;
}
int Method::getNamberParam() {
return 1;
}

45
project_template/Method.h Normal file
View File

@ -0,0 +1,45 @@
#ifndef METHOD_H
#define METHOD_H
#include "Estimation.h"
#include "Aic.h"
#include "Param.h"
#include <vector>
using namespace std;
// абстрактный класс метода сглаживания и прогнозирования временных рядов
// хранит в себе поля, отвечающие за части ряда для обучения, тестирования, прогнозную часть
//
class Method {
public:
vector<double> x; // первоначальный временной ряд
vector<double> xLearning; // временной ряд для обучения
vector<double> xEstimation; // временной ряд для тестирования
vector<double> forecast; // прогноз ряда
unsigned int countPointForecast; // количеcтво прогнозируемых точек
//Vovks variables
char * name;
//double weight = 0.5; //start weight
//double value = 0; //last forecast
double weight; //start weight
double value; //last forecast
//bool isActive = true;
bool isActive;
//Vovks variables
virtual vector<double> getForecast() = 0; // виртуальный метод получения прогноза
virtual void createModel() = 0; // виртуальный метод для формирования модели
virtual void createModelForEstimation() = 0; // виртуальный метод для формирования модели на участке для обучения
virtual double calcEstimation(Aic *) = 0; // виртуальный метод получения оценки модели
//virtual double calcEstimation(Aicc *) = 0; // виртуальный метод получения оценки модели
//virtual double calcEstimation(Bic *) = 0; // виртуальный метод получения оценки модели
virtual Param* optimize(Estimation *) = 0; // виртуальный метод оптимизации одного параметра
virtual void setParam(string, double) = 0; // виртуальный метод оптимизации задания параметров
void partition(); // разделить временной ряд на части для обучения и тестирования
void partition(int); // разделить временной ряд на части для обучения и тестирования
vector<double> getXLearning(); // метод получения части временного ряда для обучения
vector<double> getXEstimation(); // метод получения части временного ряда для тестирования
virtual int getNamberParam();
};
#endif

View File

@ -0,0 +1,146 @@
//
// Ìåòîä ýêñïîíåíöèàëüíîãî ñãëàæèâàíèÿ è ïðîãíîçèðîâàíèÿ:
// àääèòèâíûé òðåíä, àääèòèâíàÿ ñåçîííîñòü
//
#include "StdAfx.h"
#include <iostream>
#include "MultTrendAddSeasonality.h"
#include <math.h>
#include "Param.h"
// êîíñòðóêòîð ñ çàäàííûìè íåïîñðåäñòâåííî ïàðàìåòðàìè
MultTrendAddSeasonality::MultTrendAddSeasonality(vector<double> timeSeries, int countPointForecast) {
this->x = timeSeries;
this->countPointForecast = countPointForecast;
this->partition();
}
MultTrendAddSeasonality::~MultTrendAddSeasonality() {
// îñâîáîæäàåòñÿ ïàìÿòü
std::vector<double> ().swap(S);
std::vector<double> ().swap(x);
std::vector<double> ().swap(T);
std::vector<double> ().swap(I);
std::vector<double> ().swap(forecast);
}
// èíèöèàëèçàöèÿ ìîäåëè, çàäàíèå ïåðâîíà÷àëüíûõ çíà÷åíèé
void MultTrendAddSeasonality::init() {
S.clear();
T.clear();
I.clear();
forecast.clear();
double sumS = 0;
double sumT = 0;
for (unsigned int t = 0; t < p; t++) {
sumS += x[t];
sumT += x[t+p];
}
S.push_back(sumS / p);
T.push_back((sumT/ p - S[0]) / p);
for (unsigned int t = 0; t < p; t++) {
I.push_back(x[t] - S[0]);
}
forecast.push_back(S[0] * T[0] + I[0]);
}
// Çàäàòü ïàðàìåòð
void MultTrendAddSeasonality::setParam(string paramName, double value) {
if (paramName.compare("alpha") == 0) {
this->alpha = value;
} else if (paramName.compare("gamma") == 0) {
this->gamma = value;
} else if (paramName.compare("p") == 0) {
this->p = value;
} else if (paramName.compare("delta") == 0) {
this->delta = value;
}
}
// ñôîðìèðîâàòü ìîäåëü
void MultTrendAddSeasonality::createModel() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < x.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < x.size()) {
e = x[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] * T[t] + alpha * e); // óðîâåíü
T.push_back(T[t] + alpha * gamma * e / S[t]); // òðåíä
I.push_back(I[t] + delta * e); // ñåçîííîñòü
forecast.push_back(S[t+1] * T[t+1] + I[t+1]); // ïðîãíîç
}
}
// ñôîðìèðîâàòü ìîäåëü
void MultTrendAddSeasonality::createModelForEstimation() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < xLearning.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < xLearning.size()) {
e = xLearning[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] * T[t] + alpha * e); // óðîâåíü
T.push_back(T[t] + alpha * gamma * e / S[t]); // òðåíä
I.push_back(I[t] + delta * e); // ñåçîííîñòü
forecast.push_back(S[t+1] * T[t+1] + I[t+1]); // ïðîãíîç
}
}
// ìåòîä ïîëó÷åíèÿ ïðîãíîçà
vector<double> MultTrendAddSeasonality::getForecast() {
vector<double> result;
for (unsigned int i = forecast.size() - countPointForecast; i < forecast.size(); i++) {
result.push_back(forecast[i]);
}
return result;
}
// ìåòîä ïîëó÷åíèÿ îöåíêè ìîäåëè
double MultTrendAddSeasonality::calcEstimation(Aic *aic) {
return aic->getValue(3, this->xEstimation, this->forecast);
}
// ìåòîä ïîëó÷åíèÿ îïòèìèçèðîâàííîãî çíà÷åíèÿ îäíîãî ïàðàìåòðà
// TODO: ðåàëèçîâàòü
Param* MultTrendAddSeasonality::optimize(Estimation *est) {
Param *optimal = new Param();
double minSmape = 99999;
for (double al = 0.1; al < 1; al+= 0.01) {
for (double gam = 0.1; gam < 1; gam+= 0.01) {
for (double del = 0.1; del < 1;del+= 0.01) {
this->setParam("alpha", al);
this->setParam("gamma", gam);
this->setParam("delta", del);
this->createModelForEstimation();
double smapeValue = est->getValue(getXEstimation(), getForecast());
if (minSmape > smapeValue) {
minSmape = smapeValue;
optimal->alpha = al;
optimal->gamma = gam;
optimal->delta = del;
}
}
}
}
return optimal;
}

View File

@ -0,0 +1,34 @@
#ifndef MULTTRENDADDSEASONALITY_H
#define MULTTRENDADDSEASONALITY_H
#include "Method.h"
#include "Aic.h"
#include "Param.h"
using namespace std;
// êîíêðåòíàÿ ðåàëèçàöèÿ àáñòðàêòíîãî êëàññà Method
// ðåàëèçóåò ìåòîä ýêñïîíåíöèàëüíîãî ñãëàæèâàíèÿ ñ ìóëüòèïëèêàòâíûì òðåíäîì, àääèòèâíîé ñåçîííîñòüþ
class MultTrendAddSeasonality : public Method {
public:
double alpha; // ïàðàìåòð ñãëàæèâàíèÿ
vector<double> S; // ñãëàæåííûé äàííûì ìåòîäîì ðÿä
double gamma; // ïàðàìåòð ñãëàæèâàíèÿ òðåíäà
double delta; // ïàðàìåòð ñãëàæèâàíèÿ ñåçîííîé êîìïîíåíòû
vector<double> T; // ñãëàæåííûé òðåíä
vector<double> I; // ñåçîííàÿ êîìïîíåíòà
int p; // ïåðèîä ñåçîííîñòè
MultTrendAddSeasonality(vector<double>, int);
~MultTrendAddSeasonality();
vector<double> getForecast();
void init();
void createModel();
void createModelForEstimation();
void setParam(string, double);
double calcEstimation(Aic *);
Param* optimize(Estimation *); // ìåòîä îïòèìèçàöèè îäíîãî ïàðàìåòðà
};
#endif

View File

@ -0,0 +1,145 @@
//
// Ìåòîä ýêñïîíåíöèàëüíîãî ñãëàæèâàíèÿ è ïðîãíîçèðîâàíèÿ:
// àääèòèâíûé òðåíä, ìóëüòèïëèêàòèâíàÿ ñåçîííîñòü
//
#include "StdAfx.h"
#include <iostream>
#include "MultTrendMultSeasonality.h"
#include <math.h>
#include "Param.h"
// êîíñòðóêòîð ñ çàäàííûìè íåïîñðåäñòâåííî ïàðàìåòðàìè
MultTrendMultSeasonality::MultTrendMultSeasonality(vector<double> timeSeries, int countPointForecast) {
this->x = timeSeries;
this->countPointForecast = countPointForecast;
this->partition();
}
MultTrendMultSeasonality::~MultTrendMultSeasonality() {
// îñâîáîæäàåòñÿ ïàìÿòü
std::vector<double> ().swap(S);
std::vector<double> ().swap(x);
std::vector<double> ().swap(T);
std::vector<double> ().swap(I);
std::vector<double> ().swap(forecast);
}
// èíèöèàëèçàöèÿ ìîäåëè, çàäàíèå ïåðâîíà÷àëüíûõ çíà÷åíèé
void MultTrendMultSeasonality::init() {
S.clear();
T.clear();
I.clear();
forecast.clear();
double sumS = 0;
double sumT = 0;
for (unsigned int t = 0; t < p; t++) {
sumS += x[t];
sumT += x[t+p];
}
S.push_back(sumS / p);
T.push_back((sumT/ p - S[0]) / p);
for (unsigned int t = 0; t < p; t++) {
I.push_back(x[t] / S[0]);
}
forecast.push_back(S[0] * T[0] * I[0]);
}
// Çàäàòü ïàðàìåòð
void MultTrendMultSeasonality::setParam(string paramName, double value) {
if (paramName.compare("alpha") == 0) {
this->alpha = value;
} else if (paramName.compare("gamma") == 0) {
this->gamma = value;
} else if (paramName.compare("p") == 0) {
this->p = value;
} else if (paramName.compare("delta") == 0) {
this->delta = value;
}
}
// ñôîðìèðîâàòü ìîäåëü
void MultTrendMultSeasonality::createModel() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < x.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < x.size()) {
e = x[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] * T[t] + alpha * e / I[t]); // óðîâåíü
T.push_back(T[t] + alpha * gamma * e / (I[t] * S[t])); // òðåíä
I.push_back(I[t] + delta * e / (S[t] * T[t])); // ñåçîííîñòü
forecast.push_back(S[t+1] * T[t+1] * I[t+1]); // ïðîãíîç
}
}
// ñôîðìèðîâàòü ìîäåëü ñ íîâûì çíà÷åíèåì ïàðàìåòðà. ïåðåãðóæåííûé ìåòîä
void MultTrendMultSeasonality::createModelForEstimation() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < xLearning.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < xLearning.size()) {
e = xLearning[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] * T[t] + alpha * e / I[t]); // óðîâåíü
T.push_back(T[t] + alpha * gamma * e / (I[t] * S[t])); // òðåíä
I.push_back(I[t] + delta * e / (S[t] * T[t])); // ñåçîííîñòü
forecast.push_back(S[t+1] * T[t+1] * I[t+1]); // ïðîãíîç
}
}
// ìåòîä ïîëó÷åíèÿ ïðîãíîçà
vector<double> MultTrendMultSeasonality::getForecast() {
vector<double> result;
for (unsigned int i = forecast.size() - countPointForecast; i < forecast.size(); i++) {
result.push_back(forecast[i]);
}
return result;
}
// ìåòîä ïîëó÷åíèÿ îöåíêè ìîäåëè
double MultTrendMultSeasonality::calcEstimation(Aic *aic) {
return aic->getValue(3, this->xEstimation, this->forecast);
}
// ìåòîä ïîëó÷åíèÿ îïòèìèçèðîâàííîãî çíà÷åíèÿ îäíîãî ïàðàìåòðà
// TODO: ðåàëèçîâàòü
Param* MultTrendMultSeasonality::optimize(Estimation *est) {
Param *optimal = new Param();
double minSmape = 99999;
for (double al = 0.1; al < 1; al+= 0.01) {
for (double gam = 0.1; gam < 1; gam+= 0.01) {
for (double del = 0.1; del < 1;del+= 0.01) {
this->setParam("alpha", al);
this->setParam("gamma", gam);
this->setParam("delta", del);
this->createModelForEstimation();
double smapeValue = est->getValue(getXEstimation(), getForecast());
if (minSmape > smapeValue) {
minSmape = smapeValue;
optimal->alpha = al;
optimal->gamma = gam;
optimal->delta = del;
}
}
}
}
return optimal;
}

View File

@ -0,0 +1,34 @@
#ifndef MULTTRENDMULTSEASONALITY_H
#define MULTTRENDMULTSEASONALITY_H
#include "Method.h"
#include "Aic.h"
#include "Param.h"
using namespace std;
// êîíêðåòíàÿ ðåàëèçàöèÿ àáñòðàêòíîãî êëàññà Method
// ðåàëèçóåò ìåòîä ýêñïîíåíöèàëüíîãî ñãëàæèâàíèÿ ñ ìóëüòèïëèêàòâíûì òðåíäîì, ìóëüòèïëèêàòèâíîé ñåçîííîñòüþ
class MultTrendMultSeasonality : public Method {
public:
double alpha; // ïàðàìåòð ñãëàæèâàíèÿ
vector<double> S; // ñãëàæåííûé äàííûì ìåòîäîì ðÿä
double gamma; // ïàðàìåòð ñãëàæèâàíèÿ òðåíäà
vector<double> T; // ñãëàæåííûé òðåíä
double delta; // ïàðàìåòð ñãëàæèâàíèÿ ñåçîííîé êîìïîíåíòû
vector<double> I; // ñåçîííàÿ êîìïîíåíòà
int p; // ïåðèîä ñåçîííîñòè
MultTrendMultSeasonality(vector<double>, int);
~MultTrendMultSeasonality();
vector<double> getForecast();
void init();
void createModel();
void createModelForEstimation();
void setParam(string, double);
double calcEstimation(Aic *);
Param* optimize(Estimation *); // ìåòîä îïòèìèçàöèè îäíîãî ïàðàìåòðà
};
#endif

View File

@ -0,0 +1,121 @@
//
// Ìåòîä ýêñïîíåíöèàëüíîãî ñãëàæèâàíèÿ è ïðîãíîçèðîâàíèÿ:
// ìóëüòèïëèêàòèâíûé òðåíä, áåç ñåçîííîñòè
//
#include "StdAfx.h"
#include <iostream>
#include "MultTrendNoSeasonality.h"
#include "Param.h"
// êîíñòðóêòîð ñ çàäàííûìè íåïîñðåäñòâåííî ïàðàìåòðàìè
MultTrendNoSeasonality::MultTrendNoSeasonality(vector<double> timeSeries, int countPointForecast) {
this->x = timeSeries;
this->countPointForecast = countPointForecast;
this->partition();
}
MultTrendNoSeasonality::~MultTrendNoSeasonality() {
// îñâîáîæäàåòñÿ ïàìÿòü
std::vector<double> ().swap(S);
std::vector<double> ().swap(x);
std::vector<double> ().swap(T);
std::vector<double> ().swap(forecast);
}
// èíèöèàëèçàöèÿ ìîäåëè, çàäàíèå ïåðâîíà÷àëüíûõ çíà÷åíèé
void MultTrendNoSeasonality::init() {
S.clear();
T.clear();
forecast.clear();
T.push_back(x[1] / x[0]);
S.push_back(x[0]);
forecast.push_back(S[0] * T[0]);
}
// Çàäàòü ïàðàìåòð
void MultTrendNoSeasonality::setParam(string paramName, double value) {
if (paramName.compare("alpha") == 0) {
this->alpha = value;
} else if (paramName.compare("gamma") == 0) {
this->gamma = value;
}
}
// ñôîðìèðîâàòü ìîäåëü
void MultTrendNoSeasonality::createModel() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < x.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < x.size()) {
e = x[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] * T[t] + alpha * e); // óðîâåíü
T.push_back(T[t] + alpha * gamma * e / S[t]); // òðåíä
forecast.push_back(S[t+1] * T[t+1]); // ïðîãíîç
}
}
// ñôîðìèðîâàòü ìîäåëü
void MultTrendNoSeasonality::createModelForEstimation() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < xLearning.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < xLearning.size()) {
e = xLearning[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] * T[t] + alpha * e); // óðîâåíü
T.push_back(T[t] + alpha * gamma * e / S[t]); // òðåíä
forecast.push_back(S[t+1] * T[t+1]); // ïðîãíîç
}
}
// ìåòîä ïîëó÷åíèÿ ïðîãíîçà
vector<double> MultTrendNoSeasonality::getForecast() {
vector<double> result;
for (unsigned int i = forecast.size() - countPointForecast; i < forecast.size(); i++) {
result.push_back(forecast[i]);
}
return result;
}
// ìåòîä ïîëó÷åíèÿ îöåíêè ìîäåëè
double MultTrendNoSeasonality::calcEstimation(Aic *aic) {
return aic->getValue(2, this->xEstimation, this->forecast);
}
// ìåòîä ïîëó÷åíèÿ îïòèìèçèðîâàííîãî çíà÷åíèÿ îäíîãî ïàðàìåòðà
// TODO: ðåàëèçîâàòü
Param* MultTrendNoSeasonality::optimize(Estimation *est) {
Param *optimal = new Param();
double minSmape = 99999;
for (double al = 0.1; al < 1; al+= 0.01) {
for (double gam = 0.1; gam < 1; gam+= 0.01) {
this->setParam("alpha", al);
this->setParam("gamma", gam);
this->createModelForEstimation();
double smapeValue = est->getValue(getXEstimation(), getForecast());
if (minSmape > smapeValue) {
minSmape = smapeValue;
optimal->alpha = al;
optimal->gamma = gam;
}
}
}
return optimal;
}

View File

@ -0,0 +1,32 @@
#ifndef MULTTRENDNOSEASONALITY_H
#define MULTTRENDNOSEASONALITY_H
#include "Method.h"
#include "Aic.h"
#include "Param.h"
using namespace std;
// êîíêðåòíàÿ ðåàëèçàöèÿ àáñòðàêòíîãî êëàññà Method
// ðåàëèçóåò ìåòîä ýêñïîíåíöèàëüíîãî ñ ìóëüòèïëèêàòèâíûì òðåíäîì, áåç ñåçîííîñòè
class MultTrendNoSeasonality : public Method {
public:
double alpha; // ïàðàìåòð ñãëàæèâàíèÿ
vector<double> S; // ñãëàæåííûé äàííûì ìåòîäîì ðÿä
double gamma; // ïàðàìåòð ñãëàæèâàíèÿ òðåíäà
vector<double> T; // ñãëàæåííûé òðåíä
MultTrendNoSeasonality(vector<double>, int);
~MultTrendNoSeasonality();
vector<double> getForecast();
void init();
void createModel();
void createModelForEstimation();
void setParam(string, double);
double calcEstimation(Aic *);
Param* optimize(Estimation *); // ìåòîä îïòèìèçàöèè îäíîãî ïàðàìåòðà
};
#endif

View File

@ -0,0 +1,130 @@
//
// Ìåòîä ýêñïîíåíöèàëüíîãî ñãëàæèâàíèÿ è ïðîãíîçèðîâàíèÿ:
// áåç òðåíäà, àääèòèâíàÿ ñåçîííîñòü
//
#include "StdAfx.h"
#include <iostream>
#include "NoTrendAddSeasonality.h"
// êîíñòðóêòîð ñ çàäàííûìè íåïîñðåäñòâåííî ïàðàìåòðàìè
NoTrendAddSeasonality::NoTrendAddSeasonality(vector<double> timeSeries, int countPointForecast) {
this->x = timeSeries;
this->countPointForecast = countPointForecast;
this->partition();
}
NoTrendAddSeasonality::~NoTrendAddSeasonality() {
// îñâîáîæäàåòñÿ ïàìÿòü
std::vector<double> ().swap(S);
std::vector<double> ().swap(I);
std::vector<double> ().swap(x);
std::vector<double> ().swap(forecast);
}
// èíèöèàëèçàöèÿ ìîäåëè, çàäàíèå ïåðâîíà÷àëüíûõ çíà÷åíèé
void NoTrendAddSeasonality::init() {
S.clear();
I.clear();
forecast.clear();
double sumS = 0;
for (unsigned int t = 0; t < p; t++) {
sumS += x[t];
}
S.push_back(sumS / p);
for (unsigned int t = 0; t < p; t++) {
I.push_back(x[t] - S[0]);
}
forecast.push_back(S[0] + I[0]);
}
// ñôîðìèðîâàòü ìîäåëü
void NoTrendAddSeasonality::createModel() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < x.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < x.size()) {
e = x[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] + alpha * e); // óðîâåíü
I.push_back(I[t] + delta * e); // ñåçîííîñòü
forecast.push_back(S[t+1] + I[t+1]); // ïðîãíîç
}
}
// ñôîðìèðîâàòü ìîäåëü
void NoTrendAddSeasonality::createModelForEstimation() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < xLearning.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < xLearning.size()) {
e = xLearning[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] + alpha * e); // óðîâåíü
I.push_back(I[t] + delta * e); // ñåçîííîñòü
forecast.push_back(S[t+1] + I[t+1]); // ïðîãíîç
}
}
// ìåòîä çàäàíèÿ ïàðàìåòðîâ
void NoTrendAddSeasonality::setParam(string paramName, double value) {
if (paramName.compare("alpha") == 0) {
this->alpha = value;
} else if (paramName.compare("delta") == 0) {
this->delta = value;
} else if (paramName.compare("p") == 0) {
this->p = (int) value;
}
}
// ìåòîä ïîëó÷åíèÿ ïðîãíîçà
vector<double> NoTrendAddSeasonality::getForecast() {
vector<double> result;
for (unsigned int i = forecast.size() - countPointForecast; i < forecast.size(); i++) {
result.push_back(forecast[i]);
}
return result;
}
// ìåòîä ïîëó÷åíèÿ îöåíêè ìîäåëè
double NoTrendAddSeasonality::calcEstimation(Aic *aic) {
return aic->getValue(2, this->xEstimation, this->forecast);
}
// ìåòîä ïîëó÷åíèÿ îïòèìèçèðîâàííîãî çíà÷åíèÿ îäíîãî ïàðàìåòðà
// TODO: ðåàëèçîâàòü
Param* NoTrendAddSeasonality::optimize(Estimation *est) {
Param *optimal = new Param();
double minSmape = 99999;
for (double al = 0.1; al < 1; al+= 0.01) {
for (double del = 0.1; del < 1; del+= 0.01) {
this->setParam("alpha", al);
this->setParam("delta", del);
this->createModelForEstimation();
double smapeValue = est->getValue(getXEstimation(), getForecast());
if (minSmape > smapeValue) {
minSmape = smapeValue;
optimal->alpha = al;
optimal->delta = del;
}
}
}
return optimal;
}

View File

@ -0,0 +1,33 @@
#ifndef NOTRENDADDSEASONALITY_H
#define NOTRENDADDSEASONALITY_H
#include "Method.h"
#include "Aic.h"
#include "Param.h"
using namespace std;
// êîíêðåòíàÿ ðåàëèçàöèÿ àáñòðàêòíîãî êëàññà Method
// ðåàëèçóåò ìåòîä ýêñïîíåíöèàëüíîãî ñãëàæèâàíèÿ áåç òðåíäà c àääèòèâíîé ñåçîííîñòüþ
class NoTrendAddSeasonality : public Method {
public:
double alpha; // ïàðàìåòð ñãëàæèâàíèÿ
vector<double> S; // ñãëàæåííûé äàííûì ìåòîäîì ðÿä
double delta; // ïàðàìåòð ñãëàæèâàíèÿ ñåçîííîñòè
vector<double> I; // ñåçîííàÿ êîìïîíåíòà
int p; // ïåðèîä ñåçîííîñòè
NoTrendAddSeasonality(vector<double>, int);
~NoTrendAddSeasonality();
vector<double> getForecast();
void init();
void createModel();
void createModelForEstimation();
void setParam(string, double);
double calcEstimation(Aic *);
Param* optimize(Estimation *); // ìåòîä îïòèìèçàöèè îäíîãî ïàðàìåòðà
vector<double> getS();
};
#endif

View File

@ -0,0 +1,132 @@
//
// Ìåòîä ýêñïîíåíöèàëüíîãî ñãëàæèâàíèÿ è ïðîãíîçèðîâàíèÿ:
// áåç òðåíäà, ìóëüòèïëèêàòèâíàÿ ñåçîííîñòü
//
#include "StdAfx.h"
#include <iostream>
#include "NoTrendMultSeasonality.h"
// êîíñòðóêòîð ñ çàäàííûìè íåïîñðåäñòâåííî ïàðàìåòðàìè
NoTrendMultSeasonality::NoTrendMultSeasonality(vector<double> timeSeries, int countPointForecast) {
this->x = timeSeries;
this->countPointForecast = countPointForecast;
this->partition();
}
NoTrendMultSeasonality::~NoTrendMultSeasonality() {
// îñâîáîæäàåòñÿ ïàìÿòü
std::vector<double> ().swap(S);
std::vector<double> ().swap(I);
std::vector<double> ().swap(x);
std::vector<double> ().swap(forecast);
}
// ìåòîä çàäàíèÿ ïàðàìåòðîâ
void NoTrendMultSeasonality::setParam(string paramName, double value) {
if (paramName.compare("alpha") == 0) {
this->alpha = value;
} else if (paramName.compare("delta") == 0) {
this->delta = value;
} else if (paramName.compare("p") == 0) {
this->p = (int) value;
}
}
// èíèöèàëèçàöèÿ ìîäåëè, çàäàíèå ïåðâîíà÷àëüíûõ çíà÷åíèé
void NoTrendMultSeasonality::init() {
S.clear();
I.clear();
forecast.clear();
double sumS = 0;
for (int t = 0; t < p; t++) {
sumS += x[t];
}
S.push_back(sumS / p);
for (unsigned int t = 0; t < p; t++) {
I.push_back(x[t] / S[0]);
}
forecast.push_back(S[0] * I[0]);
}
// ñôîðìèðîâàòü ìîäåëü
void NoTrendMultSeasonality::createModel() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < x.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < x.size()) {
e = x[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] + alpha * e / I[t]); // óðîâåíü
I.push_back(I[t] + delta * e / S[t]); // ñåçîííîñòü
forecast.push_back(S[t+1] * I[t+1]); // ïðîãíîç
}
}
// ñôîðìèðîâàòü ìîäåëü
void NoTrendMultSeasonality::createModelForEstimation() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < xLearning.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < xLearning.size()) {
e = xLearning[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t] + alpha * e / I[t]); // óðîâåíü
I.push_back(I[t] + delta * e / S[t]); // ñåçîííîñòü
forecast.push_back(S[t+1] * I[t+1]); // ïðîãíîç
}
}
// ìåòîä ïîëó÷åíèÿ ïðîãíîçà
vector<double> NoTrendMultSeasonality::getForecast() {
vector<double> result;
for (unsigned int i = forecast.size() - countPointForecast; i < forecast.size(); i++) {
result.push_back(forecast[i]);
}
return result;
}
// ìåòîä ïîëó÷åíèÿ îöåíêè ìîäåëè
double NoTrendMultSeasonality::calcEstimation(Aic *aic) {
return aic->getValue(3, this->xEstimation, this->getForecast());
}
// ìåòîä ïîëó÷åíèÿ îïòèìèçèðîâàííîãî çíà÷åíèÿ îäíîãî ïàðàìåòðà
// TODO: ðåàëèçîâàòü
Param* NoTrendMultSeasonality::optimize(Estimation *est) {
Param *optimal = new Param();
double minSmape = 99999;
for (double al = 0.1; al < 1; al+= 0.01) {
for (double del = 0.1; del < 1; del+= 0.01) {
this->setParam("alpha", al);
this->setParam("delta", del);
this->createModelForEstimation();
double smapeValue = est->getValue(getXEstimation(), getForecast());
if (minSmape > smapeValue) {
minSmape = smapeValue;
optimal->alpha = al;
optimal->delta = del;
}
}
}
return optimal;
}

View File

@ -0,0 +1,30 @@
#ifndef NOTRENDMULTSEASONALITY_H
#define NOTRENDMULTSEASONALITY_H
#include "Method.h"
using namespace std;
// êîíêðåòíàÿ ðåàëèçàöèÿ àáñòðàêòíîãî êëàññà Method
// ðåàëèçóåò ìåòîä ýêñïîíåíöèàëüíîãî ñãëàæèâàíèÿ áåç òðåíäà c àääèòèâíîé ñåçîííîñòüþ
class NoTrendMultSeasonality : public Method {
public:
double alpha; // ïàðàìåòð ñãëàæèâàíèÿ
vector<double> S; // ñãëàæåííûé äàííûì ìåòîäîì ðÿä
double delta; // ïàðàìåòð ñãëàæèâàíèÿ ñåçîííîñòè
vector<double> I; // ñåçîííàÿ êîìïîíåíòà
int p; // ïåðèîä ñåçîííîñòè
NoTrendMultSeasonality(vector<double>, int);
~NoTrendMultSeasonality();
vector<double> getForecast();
void init();
void createModel();
void createModelForEstimation();
void setParam(string, double);
double calcEstimation(Aic *); // âèðòóàëüíûé ìåòîä ïîëó÷åíèÿ îöåíêè ìîäåëè
Param* optimize(Estimation *); // ìåòîä îïòèìèçàöèè îäíîãî ïàðàìåòðà
};
#endif

View File

@ -0,0 +1,109 @@
//
// Ìåòîä ýêñïîíåíöèàëüíîãî ñãëàæèâàíèÿ è ïðîãíîçèðîâàíèÿ:
// áåç òðåíäà, áåç ñåçîííîñòè
//
#include "StdAfx.h"
#include <iostream>
#include "NoTrendNoSeasonality.h"
#include "Aic.h"
#include "Param.h"
// êîíñòðóêòîð ñ çàäàííûìè íåïîñðåäñòâåííî ïàðàìåòðàìè
NoTrendNoSeasonality::NoTrendNoSeasonality(vector<double> timeSeries, int countPointForecast) {
this->x = timeSeries;
this->countPointForecast = countPointForecast;
this->partition();
}
NoTrendNoSeasonality::~NoTrendNoSeasonality() {
// îñâîáîæäàåòñÿ ïàìÿòü
std::vector<double> ().swap(S);
std::vector<double> ().swap(x);
std::vector<double> ().swap(forecast);
}
// èíèöèàëèçàöèÿ ìîäåëè, çàäàíèå ïåðâîíà÷àëüíûõ çíà÷åíèé
void NoTrendNoSeasonality::init() {
S.clear();
forecast.clear();
S.push_back(x[0]);
forecast.push_back(S[0]);
}
// ìåòîä çàäàíèÿ ïàðàìåòðîâ
void NoTrendNoSeasonality::setParam(string paramName, double value) {
if (paramName.compare("alpha") == 0) {
this->alpha = value;
}
}
// ñôîðìèðîâàòü ìîäåëü
void NoTrendNoSeasonality::createModel() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < x.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < x.size()) {
e = x[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t]+alpha * e); // óðîâåíü
forecast.push_back(S[t+1]); // ïðîãíîç
}
}
// ñôîðìèðîâàòü ìîäåëü
void NoTrendNoSeasonality::createModelForEstimation() {
this->init(); // èíèöèàëèçèðîâàòü ìîäåëü
double e = 0;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < xLearning.size()-1 + this->countPointForecast; t++) {
// ïîêà íå äîøëè äî êîíöà ðÿäà - ñãëàæèâàåì, èíà÷å ñòðîèì ïðîãíîç
if (t < xLearning.size()) {
e = xLearning[t]-forecast[t];
} else {
e = 0;
}
S.push_back(S[t]+alpha * e); // óðîâåíü
forecast.push_back(S[t+1]); // ïðîãíîç
}
}
// ìåòîä ïîëó÷åíèÿ ïðîãíîçà
vector<double> NoTrendNoSeasonality::getForecast() {
vector<double> result;
for (unsigned int i = forecast.size() - countPointForecast; i < forecast.size(); i++) {
result.push_back(forecast[i]);
}
return result;
}
// ìåòîä ïîëó÷åíèÿ îöåíêè ìîäåëè
double NoTrendNoSeasonality::calcEstimation(Aic *aic) {
return aic->getValue(2, this->xEstimation, this->getForecast());
}
// ìåòîä ïîëó÷åíèÿ îïòèìèçèðîâàííîãî çíà÷åíèÿ îäíîãî ïàðàìåòðà
// TODO: ðåàëèçîâàòü
Param* NoTrendNoSeasonality::optimize(Estimation *est) {
Param *optimal = new Param();
double minSmape = 99999;
for (double al = 0.1; al < 1; al+= 0.01) {
this->setParam("alpha", al);
this->createModelForEstimation();
double smapeValue = est->getValue(getXEstimation(), getForecast());
if (minSmape > smapeValue) {
minSmape = smapeValue;
optimal->alpha = al;
}
}
return optimal;
}

View File

@ -0,0 +1,30 @@
#ifndef NOTRENDNOSEASONALITY_H
#define NOTRENDNOSEASONALITY_H
#include "Method.h"
#include "Aic.h"
#include "Param.h"
using namespace std;
// êîíêðåòíàÿ ðåàëèçàöèÿ àáñòðàêòíîãî êëàññà Method
// ðåàëèçóåò ìåòîä ýêñïîíåíöèàëüíîãî ñãëàæèâàíèÿ áåç òðåíäà è ñåçîííîñòè
class NoTrendNoSeasonality : public Method {
public:
double alpha; // ïàðàìåòð ñãëàæèâàíèÿ
vector<double> S; // ñãëàæåííûé äàííûì ìåòîäîì ðÿä
NoTrendNoSeasonality(vector<double>, int);
~NoTrendNoSeasonality();
vector<double> getForecast();
void init();
void createModel();
void createModelForEstimation();
void setParam(string, double); // âèðòóàëüíûé ìåòîä çàäàíèÿ ïàðàìåòðîâ
double calcEstimation(Aic *); // âèðòóàëüíûé ìåòîä ïîëó÷åíèÿ îöåíêè ìîäåëè
Param* optimize(Estimation *); // ìåòîä îïòèìèçàöèè îäíîãî ïàðàìåòðà
vector<double> getS();
};
#endif

View File

@ -0,0 +1,57 @@
#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;
}

View File

@ -0,0 +1,17 @@
#ifndef NORMALIZATION_H
#define NORMALIZATION_H
#include "Method.h"
#include <vector>
using namespace std;
class Normalization {
private:
double timeSeriaShiftValue;
double maxTimePoint;
vector<double> shift(vector<double>); // ñäâèã âðåìåííîãî ðÿäà èç îòðèöàòåëüíîé îáëàñòè
vector<double> deShift(vector<double>); // ñäâèã âðåìåííîãî ðÿäà â îáðàòíóþ ñòîðîíó
public:
Normalization();
vector<double> normalizeTimeSeria(vector<double>); // íîðìàëèçàöèÿ âðåìåííîãî ðÿäà
vector<double> deNormalizeTimeSeria(vector<double>); // äåíîðìàëèçàöèÿ âðåìåííîãî ðÿäà
};
#endif

View File

@ -0,0 +1,36 @@
#include "StdAfx.h"
#include "Param.h"
#include "string.h"
#include <sstream>
Param::Param() {
alpha =0;
delta =0;
gamma =0;
phi =0;
countRulesIn =0;
countFuzzyParts =0;
sizeLabels =1;
lb1 = 0;
rb1 = 0;
lb2 = 0;
rb2 = 0;
}
string Param::toString() {
stringstream ss1;
ss1 << "alpha: " <<alpha <<
" delta " << delta <<
" gamma: " << gamma <<
" phi: " << phi <<
" countRulesIn: " << countRulesIn <<
" countFuzzyParts: " << countFuzzyParts <<
" sizeLabels: " << sizeLabels <<
" lb1: " << lb1 <<
" rb1: " << rb1 <<
" lb2: " << lb2 <<
" rb2: " << rb2;
return ss1.str();
}

24
project_template/Param.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef PARAM_H
#define PARAM_H
#include <string>
using namespace std;
class Param {
public:
double alpha;
double delta;
double gamma;
double phi;
int countRulesIn;
int countFuzzyParts;
double sizeLabels;
double lb1;
double rb1;
double lb2;
double rb2;
double estim;
Param();
string toString(void);
};
#endif

View File

@ -0,0 +1,181 @@
#include "stdafx.h"
#include "Preparator.h"
#include <iostream>
#include <math.h>
using namespace std;
int Preparator::sgn(double val){
if (val > 0)
return 1;
if (val == 0)
return 0;
return -1;
}
void Preparator::setLog(bool log){
IsLogarithm = log;
}
void Preparator::setBoxCox(bool boxcox){
IsBoxCox = boxcox;
}
void Preparator::setBoxCoxGamma(double gamma){
if (gamma > 0 && gamma < 1){
boxCoxGamma = gamma;
}
}
vector<double> Preparator::boxcox(vector<double> timeSeria){
for (int i = 0; i < timeSeria.size(); i++){
timeSeria[i] = (pow(timeSeria[i], boxCoxGamma) - 1) / boxCoxGamma;
}
return timeSeria;
}
vector<double> Preparator::deboxcox(vector<double> timeSeria){
for (int i = 0; i < timeSeria.size(); i++){
timeSeria[i] = sgn(boxCoxGamma * timeSeria[i] + 1) *
pow((abs(boxCoxGamma * timeSeria[i] + 1)), 1 / boxCoxGamma);
}
return timeSeria;
}
Preparator::Preparator(bool _IsLogarithm, bool _IsBoxCox){
IsBoxCox = _IsBoxCox;
IsLogarithm = _IsLogarithm;
}
vector<double> Preparator::logarithm(vector<double> timeSeria){
for (int i = 0; i < timeSeria.size(); i++){
timeSeria[i] = log(timeSeria[i]);
}
return timeSeria;
}
vector<double> Preparator::delogarithm(vector<double> timeSeria){
for (int i = 0; i < timeSeria.size(); i++){
timeSeria[i] = exp(timeSeria[i]);
}
return timeSeria;
}
vector<double> Preparator::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> Preparator::deShift(vector<double> timeSeria){
if (timeSeriaShiftValue < 0){
for (int i = 0; i < timeSeria.size(); i++){
timeSeria[i] -= timeSeriaShiftValue;
}
}
return timeSeria;
}
vector<double> Preparator::normalizeTimeSeria(vector<double> timeSeria){
timeSeria = shift(timeSeria);
if (IsLogarithm)
timeSeria = logarithm(timeSeria);
if (IsBoxCox)
timeSeria = boxcox(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> Preparator::deNormalizeTimeSeria(vector<double> timeSeria){
//shift(timeSeria);
for (int i = 0; i < timeSeria.size(); i++){
timeSeria[i] *= maxTimePoint;
}
if (IsLogarithm)
timeSeria = delogarithm(timeSeria);
if (IsBoxCox)
timeSeria = deboxcox(timeSeria);
deShift(timeSeria);
return timeSeria;
}
//bool Preparator::TestCommon(vector<double> timeSeria, vector<double>(*direct)(vector<double>),
// vector<double>(*inverse)(vector<double>)){
// vector<double> initTimeSeria = timeSeria;
// timeSeria = direct(inverse(timeSeria));
// double res = 0;
// for (int i = 0; i < timeSeria.size(); i++){
// res += initTimeSeria[i] - timeSeria[i];
// }
// return res == 0;
//}
double Preparator::TestPreparator(vector<double> timeSeria){
double resLog = TestLogarithm(timeSeria);
cout << "log func works with " << resLog << " error" << endl;
double resBoxCox = TestBoxCox(timeSeria);
cout << "BoxCox func works with " << resBoxCox << " error" << endl;
double resShift = TestShift(timeSeria);
cout << "Shift func works with " << resShift << " error" << endl;
double resNormalize = TestNormalize(timeSeria);
cout << "Normalize func works with " << resShift << " error" << endl;
return resNormalize + resLog + resBoxCox + resShift;
}
double Preparator::TestLogarithm(vector<double> timeSeria){
vector<double> initTimeSeria = timeSeria;
timeSeria = delogarithm(logarithm(timeSeria));
double res = 0;
for (int i = 0; i < timeSeria.size(); i++){
res += initTimeSeria[i] - timeSeria[i];
}
return res;
}
double Preparator::TestBoxCox(vector<double> timeSeria){
vector<double> initTimeSeria = timeSeria;
timeSeria = deboxcox(boxcox(timeSeria));
double res = 0;
for (int i = 0; i < timeSeria.size(); i++){
res += initTimeSeria[i] - timeSeria[i];
}
return res;
}
double Preparator::TestShift(vector<double> timeSeria){
vector<double> initTimeSeria = timeSeria;
timeSeria = deboxcox(boxcox(timeSeria));
double res = 0;
for (int i = 0; i < timeSeria.size(); i++){
res += initTimeSeria[i] - timeSeria[i];
}
return res;
}
double Preparator::TestNormalize(vector<double> timeSeria){
timeSeriaShiftValue = 0;
maxTimePoint = 0;
IsLogarithm = false;
IsBoxCox = false;
boxCoxGamma = 0.5;
vector<double> initTimeSeria = timeSeria;
timeSeria = deboxcox(boxcox(timeSeria));
double res = 0;
for (int i = 0; i < timeSeria.size(); i++){
res += initTimeSeria[i] - timeSeria[i];
}
return res;
}

View File

@ -0,0 +1,35 @@
#ifndef PREPARATOR_H
#define PREPARATOR_H
#include "Method.h"
#include <vector>
using namespace std;
class Preparator {
private:
/*bool TestCommon(vector<double> timeSeria, vector<double>(*)(vector<double>),
vector<double>(*)(vector<double>)){}*/
double timeSeriaShiftValue;
double maxTimePoint;
bool IsLogarithm;
bool IsBoxCox;
double boxCoxGamma;
int sgn(double);
vector<double> logarithm(vector<double>); //ëîăîđčôěčđîâŕíčĺ ÂĐ
vector<double> delogarithm(vector<double>);
vector<double> boxcox(vector<double>); // áîęń-ęîęń ďđĺáđŕçîâŕíčĺ ÂĐ
vector<double> deboxcox(vector<double>);
vector<double> shift(vector<double>); // ńäâčă âđĺěĺííîăî đ˙äŕ čç îňđčöŕňĺëüíîé îáëŕńňč
vector<double> deShift(vector<double>); // ńäâčă âđĺěĺííîăî đ˙äŕ â îáđŕňíóţ ńňîđîíó
public:
double TestPreparator(vector<double> timeSeria);
double TestLogarithm(vector<double> timeSeria);
double TestBoxCox(vector<double> timeSeria);
double TestShift(vector<double> timeSeria);
double TestNormalize(vector<double>);
Preparator(bool IsLogarithm, bool IsBoxCox);
void setBoxCoxGamma(double gamma);
void setLog(bool log);
void setBoxCox(bool boxcox);
vector<double> normalizeTimeSeria(vector<double> timeSeria); // íîđěŕëčçŕöč˙ âđĺěĺííîăî đ˙äŕ
vector<double> deNormalizeTimeSeria(vector<double> timeSeria); // äĺíîđěŕëčçŕöč˙ âđĺěĺííîăî đ˙äŕ
};
#endif

29
project_template/RMSE.cpp Normal file
View File

@ -0,0 +1,29 @@
#include "StdAfx.h"
#include "RMSE.h"
#include <vector>
#include <math.h>
Rmse::Rmse() {
}
Rmse::~Rmse() {
}
double Rmse::getValue(int paramCount, vector<double> original, vector<double> model) {
return 0;
}
double Rmse::getValue(vector<double> original, vector<double> model) {
double valueRMSE = 0;
int sampleSize = original.size();
for (int i = 0; i < sampleSize; i++) {
valueRMSE += pow(original[i] - model[i], 2);
}
valueRMSE = sqrt(valueRMSE / sampleSize);
return valueRMSE;
}

14
project_template/RMSE.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef RMSE_H
#define RMSE_H
#include "Estimation.h"
using namespace std;
class Rmse : public Estimation {
public:
Rmse();
~Rmse();
double getValue(vector<double>, vector<double>);
double getValue(int, vector<double>, vector<double>);
};
#endif

View File

@ -0,0 +1,33 @@
========================================================================
CONSOLE APPLICATION : project_template Project Overview
========================================================================
AppWizard has created this project_template application for you.
This file contains a summary of what you will find in each of the files that
make up your project_template application.
project_template.vcproj
This is the main project file for VC++ projects generated using an Application Wizard.
It contains information about the version of Visual C++ that generated the file, and
information about the platforms, configurations, and project features selected with the
Application Wizard.
project_template.cpp
This is the main application source file.
/////////////////////////////////////////////////////////////////////////////
Other standard files:
StdAfx.h, StdAfx.cpp
These files are used to build a precompiled header (PCH) file
named project_template.pch and a precompiled types file named StdAfx.obj.
/////////////////////////////////////////////////////////////////////////////
Other notes:
AppWizard uses "TODO:" comments to indicate parts of the source code you
should add to or customize.
/////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,35 @@
#include "StdAfx.h"
#include <iostream>
#include "SMape.h"
#include "Math.h"
#include <vector>
// êðèòåðèé SMape. Íàñëåäóåòñÿ îò êëàññà Estimation.
// ðåàëèçóåò ìåòîä "ïîëó÷èòü çíà÷åíèå êðèòåðèÿ"
SMape::SMape() {
}
SMape::~SMape() {
}
double SMape::getValue(int countParams, vector<double> original, vector<double> model) {
return 0;
}
double SMape::getValue(vector<double> original, vector<double> model) {
double smape = 0;
for (int i = 0; i < original.size(); i++) {
/*double a = original[i] - model[i];
double b = (original[i] + model[i]) / 2;
double c = fabs(a);
double d = fabs(b);*/
smape += (fabs((double)original[i] - model[i])) /
(((fabs((double)(original[i])) + fabs((double)model[i]))) / 2);
}
smape = smape / original.size();
smape = smape * 100;
return smape;
}

15
project_template/SMape.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef SMAPE_H
#define SMAPE_H
#include "Estimation.h"
using namespace std;
// êðèòåðèé SMape. Íàñëåäóåòñÿ îò êëàññà Estimation.
// ðåàëèçóåò ìåòîä "ïîëó÷èòü çíà÷åíèå êðèòåðèÿ"
class SMape :public Estimation {
public:
SMape();
~SMape();
double getValue(int, vector<double>, vector<double>);
double getValue(vector<double>, vector<double>);
};
#endif

View File

@ -0,0 +1,88 @@
#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

View File

@ -0,0 +1,559 @@
#include "stdafx.h"
#include "Transformation.h"
#include "Median.h"
#include <math.h>
#include <vector>
#include <iostream>
#include <limits>
Transformation::Transformation(vector <double> ts)
{
setTimeSeries(ts);
INFINITY = std::numeric_limits<double>::infinity();
}
Transformation::~Transformation()
{
}
void Transformation::setTimeSeries(vector<double> ts){
TimeSeries = ts;
tsSizeValue = ts.size();
tsShiftValue = 0;
GeometricAverage = 1;
valueMean = 0;
double min = 0;
for (int i = 0; i < tsSizeValue; i++)
{
if ((TimeSeries[i] < 0) && (TimeSeries[i] < min))
{
min = TimeSeries[i];
}
GeometricAverage = GeometricAverage * TimeSeries[i];
valueMean += TimeSeries[i];
}
if (min != 0)
{
tsShiftValue = abs(min) + 1;
}
if (tsSizeValue != 0)
{
GeometricAverage = pow(GeometricAverage, 1 / tsSizeValue);
valueMean /= tsSizeValue;
}
}
int Transformation::sign(double value)
{
if (value >= 0)
return 1;
else
return -1;
}
double Transformation::lambdaEstimationGuerrero(double param){
double result;
int begin; // iterator
int end; // iterator
double sumRow; // sum row matrix
double sumSd; // sum for estimation standard deviation
double meanRat;
int lengthPeriod = 2;
if (seasonalPeriod > lengthPeriod)
{
lengthPeriod = seasonalPeriod;
}
int amtlengthPeriod = floor((double)tsSizeValue / lengthPeriod);
int shift = tsSizeValue - floor((double)amtlengthPeriod * lengthPeriod);
vector <double> mean(amtlengthPeriod); // mean row matrix
vector <double> sd(amtlengthPeriod); // standard deviation
vector <double> rat(amtlengthPeriod);
for (int i = 0; i < amtlengthPeriod; i++)
{
begin = shift + i * lengthPeriod;
end = begin + lengthPeriod;
sumRow = 0;
for (int row = begin; row < end; row++)
{
sumRow += TimeSeries[row];
}
mean[i] = sumRow / lengthPeriod;
sumSd = 0;
for (int row = begin; row < end; row++)
{
sumSd += pow(TimeSeries[row] - mean[i], 2);
}
sd[i] = sqrt(sumSd / (lengthPeriod - 1));
}
for (int i = 0; i < amtlengthPeriod; i++)
{
rat[i] = sd[i] / (pow(mean[i], 1 - param));
}
meanRat = 0;
for (int i = 0; i < amtlengthPeriod; i++)
{
meanRat += rat[i];
}
meanRat /= amtlengthPeriod;
sumSd = 0;
for (int i = 0; i < amtlengthPeriod; i++)
{
sumSd += pow(rat[i] - meanRat, 2);
}
result = sqrt(sumSd / (amtlengthPeriod - 1)) / meanRat;
return result;
}
void Transformation::lambdaEstimation(){
double cv = INFINITY; //cv - coefficient of variation
for (double i = -1; i <= 2; i += 0.01)
{
//double i = 0.7;
double result = lambdaEstimationGuerrero(i);
if (result < cv)
{
cv = result;
lambda = i;
}
}
}
vector<double> Transformation::BoxCox(){
vector <double> tsTransformation(tsSizeValue);
if (lambda == 0)
{
for (int i = 0; i < tsSizeValue; i++)
{
tsTransformation[i] = log(TimeSeries[i] + tsShiftValue);
}
}
else
{
for (int i = 0; i < TimeSeries.size(); i++)
{
tsTransformation[i] = (pow(TimeSeries[i] + tsShiftValue, lambda) - 1) / lambda;
}
}
return tsTransformation;
}
vector<double> Transformation::invBoxCox(){
vector <double> tsTransformation(tsSizeValue);
if (lambda == 0)
{
for (int i = 0; i < tsSizeValue; i++)
{
tsTransformation[i] = exp(TimeSeries[i]) - tsShiftValue;
}
}
else
{
for (int i = 0; i < TimeSeries.size(); i++)
{
tsTransformation[i] = pow((lambda * TimeSeries[i] + 1), 1 / lambda) - tsShiftValue;
}
}
return tsTransformation;
}
vector<double> Transformation::ExponentialTransformation(){
vector <double> tsTransformation(tsSizeValue);
if (lambda != 0)
{
for (int i = 0; i < tsSizeValue; i++)
{
tsTransformation[i] = (exp(TimeSeries[i] * lambda) - 1) / lambda;
}
}
return tsTransformation;
}
vector<double> Transformation::invExponentialTransformation(){
vector <double> tsTransformation(tsSizeValue);
if (lambda != 0)
{
for (int i = 0; i < tsSizeValue; i++)
{
tsTransformation[i] = log(1 + TimeSeries[i] * lambda) / lambda;
}
}
return tsTransformation;
}
vector<double> Transformation::ModulusTransformation(){
vector <double> tsTransformation(tsSizeValue);
if (lambda == 0)
{
for (int i = 0; i < tsSizeValue; i++)
{
tsTransformation[i] = sign(TimeSeries[i]) * log(abs(TimeSeries[i]) + 1);
}
}
else
{
for (int i = 0; i < tsSizeValue; i++)
{
tsTransformation[i] = sign(TimeSeries[i]) * (pow(abs(TimeSeries[i]) + 1, lambda) - 1) / lambda;
}
}
return tsTransformation;
}
vector<double> Transformation::invModulusTransformation(){
vector <double> tsTransformation(tsSizeValue);
if (lambda == 0)
{
for (int i = 0; i < tsSizeValue; i++)
{
tsTransformation[i] = sign(TimeSeries[i]) * (exp(abs(TimeSeries[i])) - 1);
}
}
else
{
for (int i = 0; i < tsSizeValue; i++)
{
tsTransformation[i] = pow(TimeSeries[i] * lambda / sign(TimeSeries[i]) + 1, 1 / lambda) - 1;
}
}
return tsTransformation;
}
vector<double> Transformation::AsymptoticBoxCox(){
vector <double> tsTransformation(tsSizeValue);
if (lambda > 0)
{
for (int i = 0; i < tsSizeValue; i++)
{
tsTransformation[i] = (sign(TimeSeries[i]) * pow(abs(TimeSeries[i]), lambda) - 1) / lambda;
}
}
return tsTransformation;
}
vector<double> Transformation::invAsymptoticBoxCox(){
vector <double> tsTransformation(tsSizeValue);
if (lambda > 0)
{
for (int i = 0; i < tsSizeValue; i++)
{
tsTransformation[i] = pow((TimeSeries[i] * lambda - 1) / sign(TimeSeries[i]), 1 / lambda);
}
}
return tsTransformation;
}
vector<double> Transformation::ModifiedBoxCox(){
vector <double> tsTransformation(tsSizeValue);
for (int i = 0; i < tsSizeValue; i++)
{
if ((TimeSeries[i] >= 0) && (lambda != 0))
{
tsTransformation[i] = (pow(TimeSeries[i] + 1, lambda) - 1) / lambda;
}
else if ((TimeSeries[i] >= 0) && (lambda == 0))
{
tsTransformation[i] = log(TimeSeries[i] + 1);
}
else if ((TimeSeries[i] < 0) && (lambda != 0))
{
tsTransformation[i] = -(pow(-TimeSeries[i] + 1, 2 - lambda) - 1) / (2 - lambda);
}
else if ((TimeSeries[i] < 0) && (lambda == 0))
{
tsTransformation[i] = -log(-TimeSeries[i] + 1);
}
}
return tsTransformation;
}
vector<double> Transformation::invModifiedBoxCox(){
vector <double> tsTransformation(tsSizeValue);
for (int i = 0; i < tsSizeValue; i++)
{
if ((TimeSeries[i] >= 0) && (lambda != 0))
{
tsTransformation[i] = pow(TimeSeries[i] * lambda + 1, 1 / lambda) - 1;
}
else if ((TimeSeries[i] >= 0) && (lambda == 0))
{
tsTransformation[i] = exp(TimeSeries[i]) - 1;
}
else if ((TimeSeries[i] < 0) && (lambda != 2))
{
tsTransformation[i] = -(pow(-(TimeSeries[i] * (2 - lambda) - 1), 1 / (2 - lambda)) - 1);
}
else if ((TimeSeries[i] < 0) && (lambda == 2))
{
tsTransformation[i] = -exp(-TimeSeries[i]) + 1;
}
}
return tsTransformation;
}
vector<double> Transformation::NormalizedBoxCox(){
vector <double> tsTransformation(tsSizeValue);
if (lambda == 0)
{
for (int i = 0; i < tsSizeValue; i++)
{
tsTransformation[i] = GeometricAverage * log(TimeSeries[i]);
}
}
else
{
for (int i = 0; i < tsSizeValue; i++)
{
tsTransformation[i] = (pow(TimeSeries[i], lambda) - 1) / (lambda * pow(GeometricAverage, lambda - 1));
}
}
return tsTransformation;
}
vector<double> Transformation::invNormalizedBoxCox(){
vector <double> tsTransformation(tsSizeValue);
if (lambda == 0)
{
for (int i = 0; i < tsSizeValue; i++)
{
tsTransformation[i] = exp(TimeSeries[i] / GeometricAverage);
}
}
else
{
for (int i = 0; i < tsSizeValue; i++)
{
tsTransformation[i] = pow(TimeSeries[i] * lambda * pow(GeometricAverage, lambda - 1) + 1, 1 / lambda);
}
}
return tsTransformation;
}
vector<double> Transformation::Deseasonalization(int seasonalPeriod){
vector <double> tsDeseasonalization(tsSizeValue);
SeasonalIndex.resize(seasonalPeriod - 1);
int tsShift = 0;
int amtSeasonalPeriod = tsSizeValue / seasonalPeriod;
if (tsSizeValue % seasonalPeriod != 0)
{
tsShift = tsSizeValue - amtSeasonalPeriod * seasonalPeriod;
}
// считаем средние сезоанальные индексы
Median *est = new Median();
SeasonalIndex = est->getValue(TimeSeries, seasonalPeriod);
// получаем итог
for (int i = 0; i < amtSeasonalPeriod; i++)
{
int begin = tsShift + i * seasonalPeriod;
int end = begin + seasonalPeriod;
for (int ii = begin; ii < end; ii++)
{
tsDeseasonalization[ii] = TimeSeries[ii] / SeasonalIndex[i];
}
}
return tsDeseasonalization;
}
vector<double> Transformation::invDeseasonalization(){
vector <double> tsDeseasonalization(tsSizeValue);
int tsShift = 0;
int amtSeasonalPeriod = tsSizeValue / seasonalPeriod;
if (tsSizeValue % seasonalPeriod != 0)
{
tsShift = tsSizeValue - amtSeasonalPeriod * seasonalPeriod - 1;
}
for (int i = 0; i < amtSeasonalPeriod; i++)
{
int begin = tsShift + i * seasonalPeriod;
int end = begin + seasonalPeriod;
for (int ii = begin; ii < end; ii++)
{
tsDeseasonalization[ii] = TimeSeries[ii] * SeasonalIndex[i];
}
}
return tsDeseasonalization;
}
vector<double> Transformation::getSeasonalIndex(){
return SeasonalIndex;
}
vector <double> Transformation::Aggregation(int seasonalPeriod){
int tsShift = 0;
int amtSeasonalPeriod = tsSizeValue / seasonalPeriod;
vector <double> tsAggregation(amtSeasonalPeriod);
if (tsSizeValue % seasonalPeriod != 0)
{
tsShift = tsSizeValue - amtSeasonalPeriod * seasonalPeriod;
}
// получаем итог
for (int i = 0; i < amtSeasonalPeriod; i++)
{
int begin = tsShift + i * seasonalPeriod;
int end = begin + seasonalPeriod;
for (int ii = begin; ii < end; ii++)
{
tsAggregation[i] += TimeSeries[ii];
}
}
return tsAggregation;
}
vector <double> Transformation::invAggregation(){
int sumSeasonalPeriod = tsSizeValue * seasonalPeriod;
vector <double> tsDeaggregation(sumSeasonalPeriod);
// получаем итог
for (int i = 0; i < tsSizeValue; i++)
{
int begin = i * seasonalPeriod;
int end = begin + seasonalPeriod;
for (int ii = begin; ii < end; ii++)
{
tsDeaggregation[ii] = TimeSeries[i] / seasonalPeriod;
}
}
return tsDeaggregation;
}
vector<double> Transformation::Normalization(){
vector <double> tsNormalization(tsSizeValue);
valueSd = 0;
for (int i = 0; i < tsSizeValue; i++)
{
valueSd += pow(TimeSeries[i] - valueMean, 2);
}
valueSd = sqrt(valueSd / (tsSizeValue - 1));
for (int i = 0; i < tsSizeValue; i++)
{
tsNormalization[i] = (TimeSeries[i] - valueMean) / valueSd;
}
return tsNormalization;
}
vector <double> Transformation::invNormalization()
{
vector <double> tsNormalization(tsSizeValue);
for (int i = 0; i < tsSizeValue; i++)
{
tsNormalization[i] = TimeSeries[i] * valueSd + valueMean;
}
return tsNormalization;
}

View File

@ -0,0 +1,96 @@
#ifndef TRANSFORMATION_H
#define TRANSFORMATION_H
#include <vector>
using namespace std;
class Transformation
{
private:
vector <double> SeasonalIndex;
double GeometricAverage;
double valueMean;
double valueSd;
int tsSizeValue;
public:
vector <double> TimeSeries;
double INFINITY;
Transformation(vector<double>);
~Transformation();
// период сезонности для использования в Deseasonalization
int seasonalPeriod;
// параметр трансформации
double lambda;
// параметр сдвига значений вектора при наличии в нем отрицательных значений
double tsShiftValue;
// обрабатываемый временной ряд
void setTimeSeries(vector<double>);
int sign(double);
// auto lambda estimation
void lambdaEstimation();
//Guerrero(1993)
//Time-series analysis supported by Power Transformations
double lambdaEstimationGuerrero(double);
//Box-Cox(1964)
vector<double> BoxCox();
vector<double> invBoxCox();
//Manly(1976)
// -- Negative ys could be allowed
// -- The transformation was reported to be successful in transform
// unimodal skewed distribution into normal distribution, but is
// not quite useful for bimodal or U - shaped distribution
vector<double> ExponentialTransformation();
vector<double> invExponentialTransformation();
//John and Draper(1980)
// -- Negative ys could be allowed.
// -- It works best at those distribution that is somewhat symmetric.
// A power transformation on a symmetric distribution is likel
// y going to introduce some degree of skewness.
vector<double> ModulusTransformation();
vector<double> invModulusTransformation();
//Bickel and Doksum(1981)
// --Negative ys could be allowed.
vector<double> AsymptoticBoxCox();
vector<double> invAsymptoticBoxCox();
//Yeo and Johnson (2000)
// --Negative ys could be allowed.
// --When estimating the transformation parameter, found the value of
// λ that minimizes the Kullback - Leibler distance between
// the normal distribution and the transformed distribution.
vector<double> ModifiedBoxCox();
vector<double> invModifiedBoxCox();
// Atkinson(1973)
// --Negative ys could be allowed.
vector<double> NormalizedBoxCox();
vector<double> invNormalizedBoxCox();
// очистка вектора TimeSeries от сезонности
vector<double> Deseasonalization(int);
vector<double> invDeseasonalization();
// получение средних сезоональных индексов
vector<double> getSeasonalIndex();
// Aggregation time series
vector <double> Aggregation(int);
vector <double> invAggregation();
// Normalization time series: mean = 0, Sd (Standard deviation) = 1
vector <double> Normalization();
vector <double> invNormalization();
};
#endif

271
project_template/Tsaur.cpp Normal file
View File

@ -0,0 +1,271 @@
#include "StdAfx.h"
#include "Tsaur.h"
#include "Param.h"
#include "float.h"
#include <iostream>
Tsaur::Tsaur(vector<double> timeSeries, int countPointForecast){
this->countPointForecast = countPointForecast;
this->trendType = trendType;
this->seasonType = seasonType;
this->x = timeSeries;
this->partition();
}
void Tsaur::init() {
S.clear();
T.clear();
T.push_back(fuzzyfication(x[1]-x[0]));
S.push_back(fuzzyfication(x[0]));
fuzzyForecast.push_back(plusSet(S[0], T[0]));
}
// îïðåäåëèòü óíèâåðñóì äëÿ âðåìåííîãî ðÿäà
// èùåì ìàêñèìóì, ìèíèìóì, ïðîèçâîäèì ðàçáèåíèå íà çàäàííûå èíòåðâàëû
void Tsaur::defineUniversum() {
this->universumMax = x[0];
this->universumMin = x[0];
for (int i = 1; i < x.size(); i++) {
if (universumMax < x[i]) {
universumMax = x[i];
}
if (universumMin > x[i]) {
universumMin = x[i];
}
}
// ñîçäàåì ôóíêöèè ïðèíàäëåæíîñòè
// ïðèíèìàåì ïî óìîë÷àíèþ, ÷òî ñîñåäíèå ïåðåêðûâàþòñÿ íà ïîëîâèíó ìåæäó ñîáîé
// ðàç åñòü êîëè÷åñòâî èíòåðâàëîâ, òî âû÷èñëÿåì ðàçìåð îñíîâàíèÿ òðåóãîëüíèêà
double baseSize = (universumMax - universumMin) / countFuzzyParts;
a.resize(countFuzzyParts + 1);
for (int i=0; i < countFuzzyParts + 1;i++){
a[i] = (A(universumMin + (i-1) * baseSize, universumMin + (i+1)*baseSize));
}
}
// îïåðàöèÿ âû÷èòàíèÿ ìíîæåñòâ
A Tsaur::minusSet(A a, A b) {
//if ((a.getLeft()- b.getLeft()) < (a.getRight() - b.getRight())) {
return A(a.getLeft()- b.getLeft(), a.getRight() - b.getRight());
//} else {
// return A(a.getRight() - b.getRight(), a.getLeft()- b.getLeft());
//}
}
// îïåðàöèÿ âû÷èòàíèÿ ìíîæåñòâ
A Tsaur::numMinusSet(double num, A a) {
//if ((num - a.getLeft()) < (num - a.getRight())) {
return A(num - a.getLeft(), num - a.getRight());
//} else {
// return A(num - a.getRight(), num - a.getLeft());
//}
}
// îïåðàöèÿ äåëåíèÿ ìíîæåñòâ
A Tsaur::divSet(A a, A b) {
return A(a.getLeft()/b.getLeft(), a.getRight()/b.getRight());
}
// îïåðàöèÿ äåëåíèÿ ìíîæåñòâ
A Tsaur::divSet(A a, double b) {
return A(a.getLeft()/b, a.getRight()/b);
}
// îïåðàöèÿ óìíîæåíèå ìíîæåñòâà íà ÷èñëî
A Tsaur::multSetNum(double num, A a) {
//if ((a.getLeft() * num) < (a.getRight() * num)) {
return A(a.getLeft() * num, a.getRight() * num);
//} else {
// return A(a.getRight() * num, a.getLeft() * num);
//}
}
// îïåðàöèÿ ñëîæåíèÿ ìíîæåñòâ
A Tsaur::plusSet(A a, A b) {
return A(a.getLeft()+ b.getLeft(), a.getRight() + b.getRight());
}
// îïåðàöèÿ óìíîæåíèÿ ìíîæåñòâ
A Tsaur::multSet(A a, A b) {
//if ((a.getLeft()* b.getLeft()) < (a.getRight() * b.getRight())) {
return A(a.getLeft()* b.getLeft(), a.getRight() * b.getRight());
//} else {
// return A(a.getLeft()* b.getLeft(), a.getRight() * b.getRight());
//}
}
// ôàççèôèöèðîâàòü òîëüêî îäíó òî÷êó
// âîçâðàùàåò èíäåêñ ôóíêöèè ïðèíàäëåæíîñòè ñ ìàêñèìàëüíûì çíà÷åíèåì
A Tsaur::fuzzyfication(double value) {
// ïåðåáèðàåì âñå ôóíêöèè ïðèíàäëåæíîñòè,
// åñëè íàøëè íàèáîëüøóþ ñòåïåíü ïðèíàäëåæíîñòè, òî ôèêñèðóåì èíäåêñ ôóíêöèè
A aMax = a[0];
for (int j = 0; j < a.size(); j++) {
if (a[j].getValue(value) > aMax.getValue(value)) {
aMax = a[j];
}
}
return aMax;
}
void Tsaur::createModelForEstimation() {
defineUniversum();
A fuzzyBetta0 = fuzzyfication(xLearning[1]- xLearning[0]);
A fuzzyBetta1 = A(lb1,rb1);
A fuzzyBetta2 = A(lb2,rb2);
A fuzzyAlpha = A(0, 1);
fuzzyTs.clear();
fuzzyForecast.clear();
// ôàççèôèêàöèÿ
fuzzyTs.resize(xLearning.size());
init();
A e;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < xLearning.size()-1+this->countPointForecast; t++) {
if (t < xLearning.size()) {
e = minusSet(fuzzyfication(xLearning[t]), fuzzyForecast[t]);
} else {
e = A(0,0);
}
S.push_back(plusSet(S[t], multSet(e, fuzzyAlpha)));
T.push_back(plusSet(plusSet(fuzzyBetta0, multSetNum(t, fuzzyBetta1)), multSetNum(t*t, fuzzyBetta2)));
fuzzyForecast.push_back(plusSet(multSetNum(alpha, S[t+1]), multSetNum((1-alpha), T[t+1])));
//fuzzyForecast.push_back(S[t+1]);
}
forecast.clear();
forecast.resize(fuzzyForecast.size());
for (unsigned int i = 0; i < fuzzyForecast.size(); i++) {
if (_finite(defuzzyfication(fuzzyForecast[i])) == 0){
forecast[i] = (x[x.size()-1]);
} else {
forecast[i] = (defuzzyfication(fuzzyForecast[i]));
}
}
}
void Tsaur::createModel() {
defineUniversum();
A fuzzyBetta0 = fuzzyfication(x[1]- x[0]);
A fuzzyBetta1 = A(lb1,rb1);
A fuzzyBetta2 = A(lb2,rb2);
A fuzzyAlpha = A(0, 1);
fuzzyTs.clear();
fuzzyForecast.clear();
// ôàççèôèêàöèÿ
fuzzyTs.resize(x.size());
init();
A e;
//âûïîëíÿåòñÿ ïðîõîä ìîäåëè ïî ñãëàæèâàíèþ è ïðîãíîçèðîâàíèþ countPointForecast òî÷åê
for (unsigned int t = 0; t < x.size()-1+this->countPointForecast; t++) {
if (t < x.size()) {
e = minusSet(fuzzyfication(x[t]), fuzzyForecast[t]);
} else {
e = A(0,0);
}
S.push_back(plusSet(S[t], multSet(e, fuzzyAlpha)));
T.push_back(plusSet(plusSet(fuzzyBetta0, multSetNum(t, fuzzyBetta1)), multSetNum(t*t, fuzzyBetta2)));
fuzzyForecast.push_back(plusSet(multSetNum(alpha, S[t+1]), multSetNum((1-alpha), T[t+1])));
//fuzzyForecast.push_back(S[t+1]);
}
forecast.clear();
forecast.resize(fuzzyForecast.size());
for (unsigned int i = 0; i < fuzzyForecast.size(); i++) {
if (_finite(defuzzyfication(fuzzyForecast[i])) == 0){
forecast[i] = (x[x.size()-1]);
} else {
forecast[i] = (defuzzyfication(fuzzyForecast[i]));
}
}
}
// ìåòîä ïîëó÷åíèÿ îöåíêè ìîäåëè
double Tsaur::calcEstimation(Aic *aic) {
return aic->getValue(3, this->xEstimation, this->forecast);
}
Tsaur::~Tsaur(void) {
}
double Tsaur::defuzzyfication(A a) {
return a.getValueAtTop();
}
vector<double> Tsaur::defuzzyfication(vector<A> fuz) {
vector<double> result;
for (int i =0; i < fuz.size(); i++) {
result.push_back(defuzzyfication(fuz[i]));
}
return result;
}
vector<double> Tsaur::getForecast() {
vector<double> result;
for (unsigned int i = forecast.size() - countPointForecast; i < forecast.size(); i++) {
result.push_back(forecast[i]);
}
return result;
}
void Tsaur::setParam(string paramName, double value) {
if (paramName.compare("countFuzzyParts") == 0) {
this->countFuzzyParts = value;
} else if (paramName.compare("alpha") == 0) {
this->alpha = value;
} else if (paramName.compare("lb1") == 0) {
this->lb1 = value;
} else if (paramName.compare("rb1") == 0) {
this->rb1 = value;
} else if (paramName.compare("lb2") == 0) {
this->lb2 = value;
} else if (paramName.compare("rb2") == 0) {
this->rb2 = value;
}
}
// ìåòîä ïîëó÷åíèÿ îïòèìèçèðîâàííîãî çíà÷åíèÿ îäíîãî ïàðàìåòðà
// TODO: ðåàëèçîâàòü
Param* Tsaur::optimize(Estimation *est) {
Param *optimal = new Param();
double minSmape = 99999;
for (double a = 0; a < 1; a+= 0.1) {
cout << "TSAUR " << a << " èç 1" <<"\n";;
for (double _lb1 = -10; _lb1 < 1; _lb1 += 0.2) {
for (double _rb1 = _lb1; _rb1 < 1; _rb1 += 0.2) {
for (double _lb2 = -1; _lb2 < 1; _lb2 += 0.2) {
for (double _rb2 = _lb2; _rb2 < 1; _rb2 += 0.2) {
for (double cfp = 2; cfp < 20;cfp+= 1) {
this->setParam("countFuzzyParts", cfp);
this->setParam("alpha", a);
this->setParam("lb1", _lb1);
this->setParam("rb1", _rb1);
this->setParam("lb2", _lb2);
this->setParam("rb2", _rb2);
this->createModelForEstimation();
double smapeValue = est->getValue(getXEstimation(), getForecast());
if (minSmape > smapeValue) {
minSmape = smapeValue;
optimal->countFuzzyParts = cfp;
optimal->alpha = a;
optimal->lb1 = _lb1;
optimal->lb2 = _lb2;
optimal->rb1 = _rb1;
optimal->rb2 = _rb2;
}
}
}
}
}
}
}
return optimal;
}

59
project_template/Tsaur.h Normal file
View File

@ -0,0 +1,59 @@
#ifndef TSAUR_H
#define TSAUR_H
#include <vector>
#include "Method.h"
#include "A.h"
using namespace std;
class Tsaur : public Method{
private:
vector<A> a; // íàáîð ôóíêöèé ïðèíàäëåæíîñòè
int countFuzzyParts;// êîëè÷åñòâî èíòåðâàëîâ óíèâåðñóìà
double universumMin;
double universumMax;
vector<A> fuzzyTs; // íå÷åòêèé âðåìåííîé ðÿä
vector<A> fuzzyForecast; // íå÷åòêèé âðåìåííîé ðÿä
double w;
string trendType;
string seasonType;
double alpha; // ïàðàìåòð ñãëàæèâàíèÿ
double gamma; // ïàðàìåòð ñãëàæèâàíèÿ òðåíäà
double delta; // ïàðàìåòð ñãëàæèâàíèÿ ñåçîííîé êîìïîíåíòû
int p; // ïåðèîä ñåçîííîñòè
double phi; // ïàðàìåòð äåìïèíãà
vector<A> S; // ñãëàæåííûé äàííûì ìåòîäîì ðÿä
vector<A> I;
vector<A> T;
double lb1;
double rb1;
double lb2;
double rb2;
void defineUniversum(); // îïðåäåëèòü óíèåðñóì äëÿ ïàðàìåòðîâ
A fuzzyfication(double);
double defuzzyfication(A);
vector<double> defuzzyfication(vector<A>);
A minusSet(A, A);
A numMinusSet(double, A);
A plusSet(A, A);
A divSet(A, A);
A divSet(A, double);
A multSet(A, A);
A multSetNum(double, A);
public:
Tsaur(vector<double>, int);
~Tsaur(void);
vector<double> getForecast();
void init();
void createModel();
void createModelForEstimation();
void setParam(string, double);
double calcEstimation(Aic *);
Param* optimize(Estimation *); // ìåòîä îïòèìèçàöèè îäíîãî ïàðàìåòðà
};
#endif

216
project_template/Vovk.cpp Normal file
View File

@ -0,0 +1,216 @@
#include "StdAfx.h"
#include "Vovk.h"
#include "Dsa.h"
#include "Fuzzy.h"
#include "FuzzyWithSets.h"
#include "NoTrendNoSeasonality.h"
#include "NoTrendNoSeasonality.h"
#include "NoTrendAddSeasonality.h"
#include "NoTrendMultSeasonality.h"
#include "AddTrendNoSeasonality.h"
#include "AddTrendAddSeasonality.h"
#include "AddTrendMultSeasonality.h"
#include "MultTrendNoSeasonality.h"
#include "MultTrendAddSeasonality.h"
#include "MultTrendMultSeasonality.h"
#include "DATrendNoSeasonality.h"
#include "DATrendAddSeasonality.h"
#include "DATrendMultSeasonality.h"
#include "DMTrendNoSeasonality.h"
#include "DMTrendAddSeasonality.h"
#include "DMTrendMultSeasonality.h"
#include "TrackingControlSignal.h"
#include <iostream>
//Set ts at constructor, get first forecast
//add value(update) ts
//recalculate weights
Vovk::Vovk(vector<double> _timeSeria, int _forecastHorizont, Method **m) {
prep = new Preparator(true, true);
useSingleTrashhold = false;
forecastHorizont = 1;
singleTrashhold = 0.35;
useModelTrashhold = false;
modelTrashhold = 0;
activeExpertsCount = 0;
beta = 0.5;
step = 0;
forecast = 0;
addWeightFromSleepEx = 0.0;
timeSeria = _timeSeria;
calculateTimeSeriaDiff(_timeSeria);
int n = 29; // êîëè÷åñòâî ìåòîäîâ, ÷òîá ëèøíåãî ïàìÿòè íå æðàòü
expertsCount = n;
forecastHorizont = _forecastHorizont;
/*int p = 1;
double alpha = 0.4;
double delta = 0.9;
double gamma = 0.4;
double phi = 0.1;*/
int countRulesIn = 1;
int countFuzzyParts = 40;
models = m;
//models[0] = new NoTrendNoSeasonality(_timeSeria, _forecastHorizont);
//models[1] = new NoTrendAddSeasonality(_timeSeria, _forecastHorizont);
//models[2] = new NoTrendMultSeasonality(_timeSeria, _forecastHorizont);
//models[3] = new AddTrendNoSeasonality(_timeSeria, _forecastHorizont);
//models[4] = new MultTrendNoSeasonality(_timeSeria, _forecastHorizont);
//models[5] = new DATrendNoSeasonality(_timeSeria, _forecastHorizont);
//models[6] = new DMTrendNoSeasonality(_timeSeria, _forecastHorizont);
//models[7] = new AddTrendAddSeasonality(_timeSeria, _forecastHorizont);
//models[8] = new MultTrendAddSeasonality(_timeSeria, _forecastHorizont);
//models[9] = new DATrendAddSeasonality(_timeSeria, _forecastHorizont);
//models[10] = new DMTrendAddSeasonality(_timeSeria, _forecastHorizont);
//models[11] = new AddTrendMultSeasonality(_timeSeria, _forecastHorizont);
//models[12] = new MultTrendMultSeasonality(_timeSeria, _forecastHorizont);
//models[13] = new DATrendMultSeasonality(_timeSeria, _forecastHorizont);
//models[14] = new DMTrendMultSeasonality(_timeSeria, _forecastHorizont);
//models[15] = new Dsa(_timeSeria, _forecastHorizont);
//models[16] = new Fuzzy("None", "None", _timeSeria, _forecastHorizont);
//models[17] = new Fuzzy("Add", "None", _timeSeria, _forecastHorizont);
//models[18] = new Fuzzy("None", "Add", _timeSeria, _forecastHorizont);
//models[19] = new Fuzzy("Add", "Add", _timeSeria, _forecastHorizont);
//models[20] = new FuzzyWithSets("None", "None", _timeSeria, _forecastHorizont);
//models[21] = new FuzzyWithSets("None", "Add", _timeSeria, _forecastHorizont);
//models[22] = new FuzzyWithSets("None", "Mult", _timeSeria, _forecastHorizont);
//models[23] = new FuzzyWithSets("Add", "None", _timeSeria, _forecastHorizont);
//models[24] = new FuzzyWithSets("Add", "Add", _timeSeria, _forecastHorizont);
//models[25] = new FuzzyWithSets("Add", "Mult", _timeSeria, _forecastHorizont);
//models[26] = new FuzzyWithSets("Mult", "None", _timeSeria, _forecastHorizont);
//models[27] = new FuzzyWithSets("Mult", "Add", _timeSeria, _forecastHorizont);
//models[28] = new FuzzyWithSets("Mult", "Mult", _timeSeria, _forecastHorizont);
////add models
//for (int i = 0; i < 29; i++) {
// // ñîçäàåì ìîäåëü äëÿ òåñòèðîâàíèÿ ïðè ïîìîùè âûáðàííîãî ìåòîäà
// // çàäàåì ïàðàìåòðû
// models[i]->setParam("alpha", alpha);
// models[i]->setParam("gamma", gamma);
// models[i]->setParam("delta", delta);
// models[i]->setParam("p", p);
// models[i]->setParam("phi", phi);
// models[i]->setParam("countRulesIn", countRulesIn);
// models[i]->setParam("countFuzzyParts", countFuzzyParts);
// models[i]->setParam("w", 0.5);
// // ñ íóæíî îïðåäåëÿòü êàê îòíîñèòåëüíóþ âåëè÷èíó, áåç ïðèâÿçêè ê çíà÷åíèÿì ðÿäà
// // ëèøü ïîòîì ìàñøòàáèðîâàòü
// // íàïðèìåð ìîæíî ðàññ÷èòàòü òàê: ïðè êîëè÷åñòâå èíòåðâàëîâ ðàçáèåíèÿ = 20, åñëè çàäàòü c = 20
// // òî òðåóãîëüíèêè áóäóò ïåðåêðûâàòü äðóã äðóãà ðîâíî íà ïîëîâèíó
// models[i]->setParam("c", 20);
// // ñîçäàåì ìîäåëü
// models[i]->createModelForEstimation();
//}
//push models to Vovks object
double check = 0;
//set weights at first time
for (int i = 0; i < expertsCount; i++)
{
models[i]->weight = (1.0 / expertsCount);
check += models[i]->weight;
models[i]->value = models[i]->getForecast()[step];
//cout << models[i]->value << " " << models[i]->weight << " " << forecast << endl;
}
//check experts representation
checkExperts();
//calculate first forecast
for (int i = 0; i < expertsCount; i++)
{
if (models[i]->isActive)
forecast += models[i]->value * (models[i]->weight + addWeightFromSleepEx/activeExpertsCount);
}
getNewExpertsValues();
//step++;
}
void Vovk::setBeta(double _beta){
beta = _beta;
}
Vovk::~Vovk() {
}
void Vovk::calculateTimeSeriaDiff(vector<double> timeSeria){
double diff = 0.0;
for (int i = 0; i < timeSeria.size() - 1; i++){
diff += fabs(timeSeria[i] - timeSeria[i + 1]);
}
timeSeriaDiff = (diff / (timeSeria.size() - 1)) * (1 + singleTrashhold);
}
void Vovk::checkExperts(){
TrackingControlSignal *tcs = new TrackingControlSignal();
activeExpertsCount = expertsCount;
addWeightFromSleepEx = 0.0;
vector<bool> expertsActivity = tcs->HistoricalExpertControl(models, timeSeriaDiff, expertsCount);
for (int i = 0; i < expertsCount; i++)
{
models[i]->isActive = expertsActivity[i];
if (!expertsActivity[i]){
addWeightFromSleepEx += models[i]->weight;
activeExpertsCount--;
}
}
}
void Vovk::getNewExpertsValues(){
for (int i = 0; i < expertsCount; i++){
//for 1 scale forecast
models[i]->value = models[i]->getForecast()[step];
}
step++;
}
//ret gt(x)
double Vovk::recalculateWeights(double nextRealValue){
double weightsSum = 0;
for (int i = 0; i < expertsCount; i++){
models[i]->weight = models[i]->weight * pow(beta, fabs(models[i]->value - nextRealValue));
weightsSum += models[i]->weight;
}
//normalize weights
double check = 0.0;
for (int i = 0; i < expertsCount; i++){
models[i]->weight = models[i]->weight / weightsSum;
check += models[i]->weight;
}
return log(weightsSum) / log(beta);//beta, weightsSum);
}
void Vovk::updateTS(double nextRealValue){
//change models weights with new real value
double gtx = recalculateWeights(nextRealValue);
forecast = 0.0;
//create new forecast from experts
getNewExpertsValues();
checkExperts();
//create aggregated forecast
double check = 0.0;
for (int i = 0; i < expertsCount; i++)
{
/*cout << i << ") ";
if (models[i]->isActive){
cout << "true ";
}
else{
cout << "false ";
}
cout << " " << models[i]->value << " " << models[i]->weight << endl;*/
if (models[i]->isActive){
check += models[i]->weight;
forecast += models[i]->value * (models[i]->weight + addWeightFromSleepEx / activeExpertsCount);
}
}
}
double Vovk::getForecast(){
return forecast;
}
//void Vovk::addMethod(AggModel model){
// models.push_back(model);
//}

53
project_template/Vovk.h Normal file
View File

@ -0,0 +1,53 @@
#ifndef VOVK_H
#define VOVK_H
#include "Method.h"
#include "Preparator.h"
struct AggModel {
char * name;
double weight;
double value;
Method* expert;
};
using namespace std;
class Vovk {
private:
/*int expertsCount = 0;
int activeExpertsCount = 0;
double beta = 0.5;
int step = 0;
double forecast = 0;
double addWeightFromSleepEx = 0.0;*/
int expertsCount;
int activeExpertsCount;
double beta;
int step;
double forecast;
double addWeightFromSleepEx;
vector<double> timeSeria;
Method** models;
void getNewExpertsValues();
void checkExperts();
//ret - log(beta, sum(1..n) weight * pow(beta, L))
double recalculateWeights(double nextRealValue);
//double timeSeriaDiff = 0;
double timeSeriaDiff;
Preparator *prep;
void calculateTimeSeriaDiff(vector<double> timeSeria);
public:
void setBeta(double beta);
bool useSingleTrashhold ;
double forecastHorizont;
double singleTrashhold;
bool useModelTrashhold;
double modelTrashhold;
Vovk(vector<double>, int, Method**);
~Vovk();
double getForecast();
void updateTS(double nextRealValue);
void addMethod(AggModel);
};
#endif

Binary file not shown.

Binary file not shown.

381
project_template/nlopt.h Normal file
View File

@ -0,0 +1,381 @@
/* Copyright (c) 2007-2014 Massachusetts Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NLOPT_H
#define NLOPT_H
#include <stddef.h> /* for ptrdiff_t and size_t */
/* Change 0 to 1 to use stdcall convention under Win32 */
#if 0 && (defined(_WIN32) || defined(__WIN32__))
# if defined(__GNUC__)
# define NLOPT_STDCALL __attribute__((stdcall))
# elif defined(_MSC_VER) || defined(_ICC) || defined(_STDCALL_SUPPORTED)
# define NLOPT_STDCALL __stdcall
# else
# define NLOPT_STDCALL
# endif
#else
# define NLOPT_STDCALL
#endif
/* for Windows compilers, you should add a line
*/
#define NLOPT_DLL
/*
when using NLopt from a DLL, in order to do the proper
Windows importing nonsense. */
#if defined(NLOPT_DLL) && (defined(_WIN32) || defined(__WIN32__)) && !defined(__LCC__)
/* annoying Windows syntax for calling functions in a DLL */
# if defined(NLOPT_DLL_EXPORT)
# define NLOPT_EXTERN(T) extern __declspec(dllexport) T NLOPT_STDCALL
# else
# define NLOPT_EXTERN(T) extern __declspec(dllimport) T NLOPT_STDCALL
# endif
#else
# define NLOPT_EXTERN(T) extern T NLOPT_STDCALL
#endif
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
typedef double (*nlopt_func)(unsigned n, const double *x,
double *gradient, /* NULL if not needed */
void *func_data);
typedef void (*nlopt_mfunc)(unsigned m, double *result,
unsigned n, const double *x,
double *gradient, /* NULL if not needed */
void *func_data);
/* A preconditioner, which preconditions v at x to return vpre.
(The meaning of "preconditioning" is algorithm-dependent.) */
typedef void (*nlopt_precond)(unsigned n, const double *x, const double *v,
double *vpre, void *data);
typedef enum {
/* Naming conventions:
NLOPT_{G/L}{D/N}_*
= global/local derivative/no-derivative optimization,
respectively
*_RAND algorithms involve some randomization.
*_NOSCAL algorithms are *not* scaled to a unit hypercube
(i.e. they are sensitive to the units of x)
*/
NLOPT_GN_DIRECT = 0,
NLOPT_GN_DIRECT_L,
NLOPT_GN_DIRECT_L_RAND,
NLOPT_GN_DIRECT_NOSCAL,
NLOPT_GN_DIRECT_L_NOSCAL,
NLOPT_GN_DIRECT_L_RAND_NOSCAL,
NLOPT_GN_ORIG_DIRECT,
NLOPT_GN_ORIG_DIRECT_L,
NLOPT_GD_STOGO,
NLOPT_GD_STOGO_RAND,
NLOPT_LD_LBFGS_NOCEDAL,
NLOPT_LD_LBFGS,
NLOPT_LN_PRAXIS,
NLOPT_LD_VAR1,
NLOPT_LD_VAR2,
NLOPT_LD_TNEWTON,
NLOPT_LD_TNEWTON_RESTART,
NLOPT_LD_TNEWTON_PRECOND,
NLOPT_LD_TNEWTON_PRECOND_RESTART,
NLOPT_GN_CRS2_LM,
NLOPT_GN_MLSL,
NLOPT_GD_MLSL,
NLOPT_GN_MLSL_LDS,
NLOPT_GD_MLSL_LDS,
NLOPT_LD_MMA,
NLOPT_LN_COBYLA,
NLOPT_LN_NEWUOA,
NLOPT_LN_NEWUOA_BOUND,
NLOPT_LN_NELDERMEAD,
NLOPT_LN_SBPLX,
NLOPT_LN_AUGLAG,
NLOPT_LD_AUGLAG,
NLOPT_LN_AUGLAG_EQ,
NLOPT_LD_AUGLAG_EQ,
NLOPT_LN_BOBYQA,
NLOPT_GN_ISRES,
/* new variants that require local_optimizer to be set,
not with older constants for backwards compatibility */
NLOPT_AUGLAG,
NLOPT_AUGLAG_EQ,
NLOPT_G_MLSL,
NLOPT_G_MLSL_LDS,
NLOPT_LD_SLSQP,
NLOPT_LD_CCSAQ,
NLOPT_GN_ESCH,
NLOPT_NUM_ALGORITHMS /* not an algorithm, just the number of them */
} nlopt_algorithm;
NLOPT_EXTERN(const char *) nlopt_algorithm_name(nlopt_algorithm a);
typedef enum {
NLOPT_FAILURE = -1, /* generic failure code */
NLOPT_INVALID_ARGS = -2,
NLOPT_OUT_OF_MEMORY = -3,
NLOPT_ROUNDOFF_LIMITED = -4,
NLOPT_FORCED_STOP = -5,
NLOPT_SUCCESS = 1, /* generic success code */
NLOPT_STOPVAL_REACHED = 2,
NLOPT_FTOL_REACHED = 3,
NLOPT_XTOL_REACHED = 4,
NLOPT_MAXEVAL_REACHED = 5,
NLOPT_MAXTIME_REACHED = 6
} nlopt_result;
#define NLOPT_MINF_MAX_REACHED NLOPT_STOPVAL_REACHED
NLOPT_EXTERN(void) nlopt_srand(unsigned long seed);
NLOPT_EXTERN(void) nlopt_srand_time(void);
NLOPT_EXTERN(void) nlopt_version(int *major, int *minor, int *bugfix);
/*************************** OBJECT-ORIENTED API **************************/
/* The style here is that we create an nlopt_opt "object" (an opaque pointer),
then set various optimization parameters, and then execute the
algorithm. In this way, we can add more and more optimization parameters
(including algorithm-specific ones) without breaking backwards
compatibility, having functions with zillions of parameters, or
relying non-reentrantly on global variables.*/
struct nlopt_opt_s; /* opaque structure, defined internally */
typedef struct nlopt_opt_s *nlopt_opt;
/* the only immutable parameters of an optimization are the algorithm and
the dimension n of the problem, since changing either of these could
have side-effects on lots of other parameters */
NLOPT_EXTERN(nlopt_opt) nlopt_create(nlopt_algorithm algorithm, unsigned n);
NLOPT_EXTERN(void) nlopt_destroy(nlopt_opt opt);
NLOPT_EXTERN(nlopt_opt) nlopt_copy(const nlopt_opt opt);
NLOPT_EXTERN(nlopt_result) nlopt_optimize(nlopt_opt opt, double *x,
double *opt_f);
NLOPT_EXTERN(nlopt_result) nlopt_set_min_objective(nlopt_opt opt, nlopt_func f,
void *f_data);
NLOPT_EXTERN(nlopt_result) nlopt_set_max_objective(nlopt_opt opt, nlopt_func f,
void *f_data);
NLOPT_EXTERN(nlopt_result) nlopt_set_precond_min_objective(nlopt_opt opt, nlopt_func f, nlopt_precond pre, void *f_data);
NLOPT_EXTERN(nlopt_result) nlopt_set_precond_max_objective(nlopt_opt opt, nlopt_func f, nlopt_precond pre, void *f_data);
NLOPT_EXTERN(nlopt_algorithm) nlopt_get_algorithm(const nlopt_opt opt);
NLOPT_EXTERN(unsigned) nlopt_get_dimension(const nlopt_opt opt);
/* constraints: */
NLOPT_EXTERN(nlopt_result) nlopt_set_lower_bounds(nlopt_opt opt,
const double *lb);
NLOPT_EXTERN(nlopt_result) nlopt_set_lower_bounds1(nlopt_opt opt, double lb);
NLOPT_EXTERN(nlopt_result) nlopt_get_lower_bounds(const nlopt_opt opt,
double *lb);
NLOPT_EXTERN(nlopt_result) nlopt_set_upper_bounds(nlopt_opt opt,
const double *ub);
NLOPT_EXTERN(nlopt_result) nlopt_set_upper_bounds1(nlopt_opt opt, double ub);
NLOPT_EXTERN(nlopt_result) nlopt_get_upper_bounds(const nlopt_opt opt,
double *ub);
NLOPT_EXTERN(nlopt_result) nlopt_remove_inequality_constraints(nlopt_opt opt);
NLOPT_EXTERN(nlopt_result) nlopt_add_inequality_constraint(nlopt_opt opt,
nlopt_func fc,
void *fc_data,
double tol);
NLOPT_EXTERN(nlopt_result) nlopt_add_precond_inequality_constraint(
nlopt_opt opt, nlopt_func fc, nlopt_precond pre, void *fc_data,
double tol);
NLOPT_EXTERN(nlopt_result) nlopt_add_inequality_mconstraint(nlopt_opt opt,
unsigned m,
nlopt_mfunc fc,
void *fc_data,
const double *tol);
NLOPT_EXTERN(nlopt_result) nlopt_remove_equality_constraints(nlopt_opt opt);
NLOPT_EXTERN(nlopt_result) nlopt_add_equality_constraint(nlopt_opt opt,
nlopt_func h,
void *h_data,
double tol);
NLOPT_EXTERN(nlopt_result) nlopt_add_precond_equality_constraint(
nlopt_opt opt, nlopt_func h, nlopt_precond pre, void *h_data,
double tol);
NLOPT_EXTERN(nlopt_result) nlopt_add_equality_mconstraint(nlopt_opt opt,
unsigned m,
nlopt_mfunc h,
void *h_data,
const double *tol);
/* stopping criteria: */
NLOPT_EXTERN(nlopt_result) nlopt_set_stopval(nlopt_opt opt, double stopval);
NLOPT_EXTERN(double) nlopt_get_stopval(const nlopt_opt opt);
NLOPT_EXTERN(nlopt_result) nlopt_set_ftol_rel(nlopt_opt opt, double tol);
NLOPT_EXTERN(double) nlopt_get_ftol_rel(const nlopt_opt opt);
NLOPT_EXTERN(nlopt_result) nlopt_set_ftol_abs(nlopt_opt opt, double tol);
NLOPT_EXTERN(double) nlopt_get_ftol_abs(const nlopt_opt opt);
NLOPT_EXTERN(nlopt_result) nlopt_set_xtol_rel(nlopt_opt opt, double tol);
NLOPT_EXTERN(double) nlopt_get_xtol_rel(const nlopt_opt opt);
NLOPT_EXTERN(nlopt_result) nlopt_set_xtol_abs1(nlopt_opt opt, double tol);
NLOPT_EXTERN(nlopt_result) nlopt_set_xtol_abs(nlopt_opt opt, const double *tol);
NLOPT_EXTERN(nlopt_result) nlopt_get_xtol_abs(const nlopt_opt opt,
double *tol);
NLOPT_EXTERN(nlopt_result) nlopt_set_maxeval(nlopt_opt opt, int maxeval);
NLOPT_EXTERN(int) nlopt_get_maxeval(const nlopt_opt opt);
NLOPT_EXTERN(nlopt_result) nlopt_set_maxtime(nlopt_opt opt, double maxtime);
NLOPT_EXTERN(double) nlopt_get_maxtime(const nlopt_opt opt);
NLOPT_EXTERN(nlopt_result) nlopt_force_stop(nlopt_opt opt);
NLOPT_EXTERN(nlopt_result) nlopt_set_force_stop(nlopt_opt opt, int val);
NLOPT_EXTERN(int) nlopt_get_force_stop(const nlopt_opt opt);
/* more algorithm-specific parameters */
NLOPT_EXTERN(nlopt_result) nlopt_set_local_optimizer(nlopt_opt opt,
const nlopt_opt local_opt);
NLOPT_EXTERN(nlopt_result) nlopt_set_population(nlopt_opt opt, unsigned pop);
NLOPT_EXTERN(unsigned) nlopt_get_population(const nlopt_opt opt);
NLOPT_EXTERN(nlopt_result) nlopt_set_vector_storage(nlopt_opt opt, unsigned dim);
NLOPT_EXTERN(unsigned) nlopt_get_vector_storage(const nlopt_opt opt);
NLOPT_EXTERN(nlopt_result) nlopt_set_default_initial_step(nlopt_opt opt,
const double *x);
NLOPT_EXTERN(nlopt_result) nlopt_set_initial_step(nlopt_opt opt,
const double *dx);
NLOPT_EXTERN(nlopt_result) nlopt_set_initial_step1(nlopt_opt opt, double dx);
NLOPT_EXTERN(nlopt_result) nlopt_get_initial_step(const nlopt_opt opt,
const double *x, double *dx);
/* the following are functions mainly designed to be used internally
by the Fortran and SWIG wrappers, allow us to tel nlopt_destroy and
nlopt_copy to do something to the f_data pointers (e.g. free or
duplicate them, respectively) */
typedef void* (*nlopt_munge)(void *p);
NLOPT_EXTERN(void) nlopt_set_munge(nlopt_opt opt,
nlopt_munge munge_on_destroy,
nlopt_munge munge_on_copy);
typedef void* (*nlopt_munge2)(void *p, void *data);
NLOPT_EXTERN(void) nlopt_munge_data(nlopt_opt opt,
nlopt_munge2 munge, void *data);
/*************************** DEPRECATED API **************************/
/* The new "object-oriented" API is preferred, since it allows us to
gracefully add new features and algorithm-specific options in a
re-entrant way, and we can automatically assume reasonable defaults
for unspecified parameters. */
/* Where possible (e.g. for gcc >= 3.1), enable a compiler warning
for code that uses a deprecated function */
#if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__==3 && __GNUC_MINOR__ > 0))
# define NLOPT_DEPRECATED __attribute__((deprecated))
#else
# define NLOPT_DEPRECATED
#endif
typedef double (*nlopt_func_old)(int n, const double *x,
double *gradient, /* NULL if not needed */
void *func_data);
NLOPT_EXTERN(nlopt_result) nlopt_minimize(
nlopt_algorithm algorithm,
int n, nlopt_func_old f, void *f_data,
const double *lb, const double *ub, /* bounds */
double *x, /* in: initial guess, out: minimizer */
double *minf, /* out: minimum */
double minf_max, double ftol_rel, double ftol_abs,
double xtol_rel, const double *xtol_abs,
int maxeval, double maxtime) NLOPT_DEPRECATED;
NLOPT_EXTERN(nlopt_result) nlopt_minimize_constrained(
nlopt_algorithm algorithm,
int n, nlopt_func_old f, void *f_data,
int m, nlopt_func_old fc, void *fc_data, ptrdiff_t fc_datum_size,
const double *lb, const double *ub, /* bounds */
double *x, /* in: initial guess, out: minimizer */
double *minf, /* out: minimum */
double minf_max, double ftol_rel, double ftol_abs,
double xtol_rel, const double *xtol_abs,
int maxeval, double maxtime) NLOPT_DEPRECATED;
NLOPT_EXTERN(nlopt_result) nlopt_minimize_econstrained(
nlopt_algorithm algorithm,
int n, nlopt_func_old f, void *f_data,
int m, nlopt_func_old fc, void *fc_data, ptrdiff_t fc_datum_size,
int p, nlopt_func_old h, void *h_data, ptrdiff_t h_datum_size,
const double *lb, const double *ub, /* bounds */
double *x, /* in: initial guess, out: minimizer */
double *minf, /* out: minimum */
double minf_max, double ftol_rel, double ftol_abs,
double xtol_rel, const double *xtol_abs,
double htol_rel, double htol_abs,
int maxeval, double maxtime) NLOPT_DEPRECATED;
NLOPT_EXTERN(void) nlopt_get_local_search_algorithm(nlopt_algorithm *deriv,
nlopt_algorithm *nonderiv,
int *maxeval) NLOPT_DEPRECATED;
NLOPT_EXTERN(void) nlopt_set_local_search_algorithm(nlopt_algorithm deriv,
nlopt_algorithm nonderiv,
int maxeval) NLOPT_DEPRECATED;
NLOPT_EXTERN(int) nlopt_get_stochastic_population(void) NLOPT_DEPRECATED;
NLOPT_EXTERN(void) nlopt_set_stochastic_population(int pop) NLOPT_DEPRECATED;
/*********************************************************************/
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif

596
project_template/nlopt.hpp Normal file
View File

@ -0,0 +1,596 @@
/* Copyright (c) 2007-2011 Massachusetts Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// C++ style wrapper around NLopt API
// nlopt.hpp is AUTOMATICALLY GENERATED from nlopt-in.hpp - edit the latter!
#ifndef NLOPT_HPP
#define NLOPT_HPP
#include "nlopt.h"
#include <vector>
#include <stdexcept>
#include <new>
#include <cstdlib>
#include <cstring>
#include <cmath>
// convenience overloading for below (not in nlopt:: since has nlopt_ prefix)
inline nlopt_result nlopt_get_initial_step(const nlopt_opt opt, double *dx) {
return nlopt_get_initial_step(opt, (const double *) NULL, dx);
}
namespace nlopt {
//////////////////////////////////////////////////////////////////////
// nlopt::* namespace versions of the C enumerated types
// AUTOMATICALLY GENERATED, DO NOT EDIT
// GEN_ENUMS_HERE
enum algorithm {
GN_DIRECT = 0,
GN_DIRECT_L,
GN_DIRECT_L_RAND,
GN_DIRECT_NOSCAL,
GN_DIRECT_L_NOSCAL,
GN_DIRECT_L_RAND_NOSCAL,
GN_ORIG_DIRECT,
GN_ORIG_DIRECT_L,
GD_STOGO,
GD_STOGO_RAND,
LD_LBFGS_NOCEDAL,
LD_LBFGS,
LN_PRAXIS,
LD_VAR1,
LD_VAR2,
LD_TNEWTON,
LD_TNEWTON_RESTART,
LD_TNEWTON_PRECOND,
LD_TNEWTON_PRECOND_RESTART,
GN_CRS2_LM,
GN_MLSL,
GD_MLSL,
GN_MLSL_LDS,
GD_MLSL_LDS,
LD_MMA,
LN_COBYLA,
LN_NEWUOA,
LN_NEWUOA_BOUND,
LN_NELDERMEAD,
LN_SBPLX,
LN_AUGLAG,
LD_AUGLAG,
LN_AUGLAG_EQ,
LD_AUGLAG_EQ,
LN_BOBYQA,
GN_ISRES,
AUGLAG,
AUGLAG_EQ,
G_MLSL,
G_MLSL_LDS,
LD_SLSQP,
LD_CCSAQ,
GN_ESCH,
NUM_ALGORITHMS /* not an algorithm, just the number of them */
};
enum result {
FAILURE = -1, /* generic failure code */
INVALID_ARGS = -2,
OUT_OF_MEMORY = -3,
ROUNDOFF_LIMITED = -4,
FORCED_STOP = -5,
SUCCESS = 1, /* generic success code */
STOPVAL_REACHED = 2,
FTOL_REACHED = 3,
XTOL_REACHED = 4,
MAXEVAL_REACHED = 5,
MAXTIME_REACHED = 6
};
// GEN_ENUMS_HERE
//////////////////////////////////////////////////////////////////////
typedef nlopt_func func; // nlopt::func synoynm
typedef nlopt_mfunc mfunc; // nlopt::mfunc synoynm
// alternative to nlopt_func that takes std::vector<double>
// ... unfortunately requires a data copy
typedef double (*vfunc)(const std::vector<double> &x,
std::vector<double> &grad, void *data);
//////////////////////////////////////////////////////////////////////
// NLopt-specific exceptions (corresponding to error codes):
class roundoff_limited : public std::runtime_error {
public:
roundoff_limited() : std::runtime_error("nlopt roundoff-limited") {}
};
class forced_stop : public std::runtime_error {
public:
forced_stop() : std::runtime_error("nlopt forced stop") {}
};
//////////////////////////////////////////////////////////////////////
class opt {
private:
nlopt_opt o;
void mythrow(nlopt_result ret) const {
switch (ret) {
case NLOPT_FAILURE: throw std::runtime_error("nlopt failure");
case NLOPT_OUT_OF_MEMORY: throw std::bad_alloc();
case NLOPT_INVALID_ARGS: throw std::invalid_argument("nlopt invalid argument");
case NLOPT_ROUNDOFF_LIMITED: throw roundoff_limited();
case NLOPT_FORCED_STOP: throw forced_stop();
default: break;
}
}
typedef struct {
opt *o;
mfunc mf; func f; void *f_data;
vfunc vf;
nlopt_munge munge_destroy, munge_copy; // non-NULL for SWIG wrappers
} myfunc_data;
// free/destroy f_data in nlopt_destroy and nlopt_copy, respectively
static void *free_myfunc_data(void *p) {
myfunc_data *d = (myfunc_data *) p;
if (d) {
if (d->f_data && d->munge_destroy) d->munge_destroy(d->f_data);
delete d;
}
return NULL;
}
static void *dup_myfunc_data(void *p) {
myfunc_data *d = (myfunc_data *) p;
if (d) {
void *f_data;
if (d->f_data && d->munge_copy) {
f_data = d->munge_copy(d->f_data);
if (!f_data) return NULL;
}
else
f_data = d->f_data;
myfunc_data *dnew = new myfunc_data;
if (dnew) {
*dnew = *d;
dnew->f_data = f_data;
}
return (void*) dnew;
}
else return NULL;
}
// nlopt_func wrapper that catches exceptions
static double myfunc(unsigned n, const double *x, double *grad, void *d_) {
myfunc_data *d = reinterpret_cast<myfunc_data*>(d_);
try {
return d->f(n, x, grad, d->f_data);
}
catch (std::bad_alloc&)
{ d->o->forced_stop_reason = NLOPT_OUT_OF_MEMORY; }
catch (std::invalid_argument&)
{ d->o->forced_stop_reason = NLOPT_INVALID_ARGS; }
catch (roundoff_limited&)
{ d->o->forced_stop_reason = NLOPT_ROUNDOFF_LIMITED; }
catch (forced_stop&)
{ d->o->forced_stop_reason = NLOPT_FORCED_STOP; }
catch (...)
{ d->o->forced_stop_reason = NLOPT_FAILURE; }
d->o->force_stop(); // stop gracefully, opt::optimize will re-throw
return HUGE_VAL;
}
// nlopt_mfunc wrapper that catches exceptions
static void mymfunc(unsigned m, double *result,
unsigned n, const double *x, double *grad, void *d_) {
myfunc_data *d = reinterpret_cast<myfunc_data*>(d_);
try {
d->mf(m, result, n, x, grad, d->f_data);
return;
}
catch (std::bad_alloc&)
{ d->o->forced_stop_reason = NLOPT_OUT_OF_MEMORY; }
catch (std::invalid_argument&)
{ d->o->forced_stop_reason = NLOPT_INVALID_ARGS; }
catch (roundoff_limited&)
{ d->o->forced_stop_reason = NLOPT_ROUNDOFF_LIMITED; }
catch (forced_stop&)
{ d->o->forced_stop_reason = NLOPT_FORCED_STOP; }
catch (...)
{ d->o->forced_stop_reason = NLOPT_FAILURE; }
d->o->force_stop(); // stop gracefully, opt::optimize will re-throw
for (unsigned i = 0; i < m; ++i) result[i] = HUGE_VAL;
}
std::vector<double> xtmp, gradtmp, gradtmp0; // scratch for myvfunc
// nlopt_func wrapper, using std::vector<double>
static double myvfunc(unsigned n, const double *x, double *grad, void *d_){
myfunc_data *d = reinterpret_cast<myfunc_data*>(d_);
try {
std::vector<double> &xv = d->o->xtmp;
if (n) std::memcpy(&xv[0], x, n * sizeof(double));
double val=d->vf(xv, grad ? d->o->gradtmp : d->o->gradtmp0, d->f_data);
if (grad && n) {
std::vector<double> &gradv = d->o->gradtmp;
std::memcpy(grad, &gradv[0], n * sizeof(double));
}
return val;
}
catch (std::bad_alloc&)
{ d->o->forced_stop_reason = NLOPT_OUT_OF_MEMORY; }
catch (std::invalid_argument&)
{ d->o->forced_stop_reason = NLOPT_INVALID_ARGS; }
catch (roundoff_limited&)
{ d->o->forced_stop_reason = NLOPT_ROUNDOFF_LIMITED; }
catch (forced_stop&)
{ d->o->forced_stop_reason = NLOPT_FORCED_STOP; }
catch (...)
{ d->o->forced_stop_reason = NLOPT_FAILURE; }
d->o->force_stop(); // stop gracefully, opt::optimize will re-throw
return HUGE_VAL;
}
void alloc_tmp() {
if (xtmp.size() != nlopt_get_dimension(o)) {
xtmp = std::vector<double>(nlopt_get_dimension(o));
gradtmp = std::vector<double>(nlopt_get_dimension(o));
}
}
result last_result;
double last_optf;
nlopt_result forced_stop_reason;
public:
// Constructors etc.
opt() : o(NULL), xtmp(0), gradtmp(0), gradtmp0(0),
last_result(nlopt::FAILURE), last_optf(HUGE_VAL),
forced_stop_reason(NLOPT_FORCED_STOP) {}
~opt() { nlopt_destroy(o); }
opt(algorithm a, unsigned n) :
o(nlopt_create(nlopt_algorithm(a), n)),
xtmp(0), gradtmp(0), gradtmp0(0),
last_result(nlopt::FAILURE), last_optf(HUGE_VAL),
forced_stop_reason(NLOPT_FORCED_STOP) {
if (!o) throw std::bad_alloc();
nlopt_set_munge(o, free_myfunc_data, dup_myfunc_data);
}
opt(const opt& f) : o(nlopt_copy(f.o)),
xtmp(f.xtmp), gradtmp(f.gradtmp), gradtmp0(0),
last_result(f.last_result), last_optf(f.last_optf),
forced_stop_reason(f.forced_stop_reason) {
if (f.o && !o) throw std::bad_alloc();
}
opt& operator=(opt const& f) {
if (this == &f) return *this; // self-assignment
nlopt_destroy(o);
o = nlopt_copy(f.o);
if (f.o && !o) throw std::bad_alloc();
xtmp = f.xtmp; gradtmp = f.gradtmp;
last_result = f.last_result; last_optf = f.last_optf;
forced_stop_reason = f.forced_stop_reason;
return *this;
}
// Do the optimization:
result optimize(std::vector<double> &x, double &opt_f) {
if (o && nlopt_get_dimension(o) != x.size())
throw std::invalid_argument("dimension mismatch");
forced_stop_reason = NLOPT_FORCED_STOP;
nlopt_result ret = nlopt_optimize(o, x.empty() ? NULL : &x[0], &opt_f);
last_result = result(ret);
last_optf = opt_f;
if (ret == NLOPT_FORCED_STOP)
mythrow(forced_stop_reason);
mythrow(ret);
return last_result;
}
// variant mainly useful for SWIG wrappers:
std::vector<double> optimize(const std::vector<double> &x0) {
std::vector<double> x(x0);
last_result = optimize(x, last_optf);
return x;
}
result last_optimize_result() const { return last_result; }
double last_optimum_value() const { return last_optf; }
// accessors:
algorithm get_algorithm() const {
if (!o) throw std::runtime_error("uninitialized nlopt::opt");
return algorithm(nlopt_get_algorithm(o));
}
const char *get_algorithm_name() const {
if (!o) throw std::runtime_error("uninitialized nlopt::opt");
return nlopt_algorithm_name(nlopt_get_algorithm(o));
}
unsigned get_dimension() const {
if (!o) throw std::runtime_error("uninitialized nlopt::opt");
return nlopt_get_dimension(o);
}
// Set the objective function
void set_min_objective(func f, void *f_data) {
myfunc_data *d = new myfunc_data;
if (!d) throw std::bad_alloc();
d->o = this; d->f = f; d->f_data = f_data; d->mf = NULL; d->vf = NULL;
d->munge_destroy = d->munge_copy = NULL;
mythrow(nlopt_set_min_objective(o, myfunc, d)); // d freed via o
}
void set_min_objective(vfunc vf, void *f_data) {
myfunc_data *d = new myfunc_data;
if (!d) throw std::bad_alloc();
d->o = this; d->f = NULL; d->f_data = f_data; d->mf = NULL; d->vf = vf;
d->munge_destroy = d->munge_copy = NULL;
mythrow(nlopt_set_min_objective(o, myvfunc, d)); // d freed via o
alloc_tmp();
}
void set_max_objective(func f, void *f_data) {
myfunc_data *d = new myfunc_data;
if (!d) throw std::bad_alloc();
d->o = this; d->f = f; d->f_data = f_data; d->mf = NULL; d->vf = NULL;
d->munge_destroy = d->munge_copy = NULL;
mythrow(nlopt_set_max_objective(o, myfunc, d)); // d freed via o
}
void set_max_objective(vfunc vf, void *f_data) {
myfunc_data *d = new myfunc_data;
if (!d) throw std::bad_alloc();
d->o = this; d->f = NULL; d->f_data = f_data; d->mf = NULL; d->vf = vf;
d->munge_destroy = d->munge_copy = NULL;
mythrow(nlopt_set_max_objective(o, myvfunc, d)); // d freed via o
alloc_tmp();
}
// for internal use in SWIG wrappers -- variant that
// takes ownership of f_data, with munging for destroy/copy
void set_min_objective(func f, void *f_data,
nlopt_munge md, nlopt_munge mc) {
myfunc_data *d = new myfunc_data;
if (!d) throw std::bad_alloc();
d->o = this; d->f = f; d->f_data = f_data; d->mf = NULL; d->vf = NULL;
d->munge_destroy = md; d->munge_copy = mc;
mythrow(nlopt_set_min_objective(o, myfunc, d)); // d freed via o
}
void set_max_objective(func f, void *f_data,
nlopt_munge md, nlopt_munge mc) {
myfunc_data *d = new myfunc_data;
if (!d) throw std::bad_alloc();
d->o = this; d->f = f; d->f_data = f_data; d->mf = NULL; d->vf = NULL;
d->munge_destroy = md; d->munge_copy = mc;
mythrow(nlopt_set_max_objective(o, myfunc, d)); // d freed via o
}
// Nonlinear constraints:
void remove_inequality_constraints() {
nlopt_result ret = nlopt_remove_inequality_constraints(o);
mythrow(ret);
}
void add_inequality_constraint(func f, void *f_data, double tol=0) {
myfunc_data *d = new myfunc_data;
if (!d) throw std::bad_alloc();
d->o = this; d->f = f; d->f_data = f_data; d->mf = NULL; d->vf = NULL;
d->munge_destroy = d->munge_copy = NULL;
mythrow(nlopt_add_inequality_constraint(o, myfunc, d, tol));
}
void add_inequality_constraint(vfunc vf, void *f_data, double tol=0) {
myfunc_data *d = new myfunc_data;
if (!d) throw std::bad_alloc();
d->o = this; d->f = NULL; d->f_data = f_data; d->mf = NULL; d->vf = vf;
d->munge_destroy = d->munge_copy = NULL;
mythrow(nlopt_add_inequality_constraint(o, myvfunc, d, tol));
alloc_tmp();
}
void add_inequality_mconstraint(mfunc mf, void *f_data,
const std::vector<double> &tol) {
myfunc_data *d = new myfunc_data;
if (!d) throw std::bad_alloc();
d->o = this; d->mf = mf; d->f_data = f_data; d->f = NULL; d->vf = NULL;
d->munge_destroy = d->munge_copy = NULL;
mythrow(nlopt_add_inequality_mconstraint(o, tol.size(), mymfunc, d,
tol.empty() ? NULL : &tol[0]));
}
void remove_equality_constraints() {
nlopt_result ret = nlopt_remove_equality_constraints(o);
mythrow(ret);
}
void add_equality_constraint(func f, void *f_data, double tol=0) {
myfunc_data *d = new myfunc_data;
if (!d) throw std::bad_alloc();
d->o = this; d->f = f; d->f_data = f_data; d->mf = NULL; d->vf = NULL;
d->munge_destroy = d->munge_copy = NULL;
mythrow(nlopt_add_equality_constraint(o, myfunc, d, tol));
}
void add_equality_constraint(vfunc vf, void *f_data, double tol=0) {
myfunc_data *d = new myfunc_data;
if (!d) throw std::bad_alloc();
d->o = this; d->f = NULL; d->f_data = f_data; d->mf = NULL; d->vf = vf;
d->munge_destroy = d->munge_copy = NULL;
mythrow(nlopt_add_equality_constraint(o, myvfunc, d, tol));
alloc_tmp();
}
void add_equality_mconstraint(mfunc mf, void *f_data,
const std::vector<double> &tol) {
myfunc_data *d = new myfunc_data;
if (!d) throw std::bad_alloc();
d->o = this; d->mf = mf; d->f_data = f_data; d->f = NULL; d->vf = NULL;
d->munge_destroy = d->munge_copy = NULL;
mythrow(nlopt_add_equality_mconstraint(o, tol.size(), mymfunc, d,
tol.empty() ? NULL : &tol[0]));
}
// For internal use in SWIG wrappers (see also above)
void add_inequality_constraint(func f, void *f_data,
nlopt_munge md, nlopt_munge mc,
double tol=0) {
myfunc_data *d = new myfunc_data;
if (!d) throw std::bad_alloc();
d->o = this; d->f = f; d->f_data = f_data; d->mf = NULL; d->vf = NULL;
d->munge_destroy = md; d->munge_copy = mc;
mythrow(nlopt_add_inequality_constraint(o, myfunc, d, tol));
}
void add_equality_constraint(func f, void *f_data,
nlopt_munge md, nlopt_munge mc,
double tol=0) {
myfunc_data *d = new myfunc_data;
if (!d) throw std::bad_alloc();
d->o = this; d->f = f; d->f_data = f_data; d->mf = NULL; d->vf = NULL;
d->munge_destroy = md; d->munge_copy = mc;
mythrow(nlopt_add_equality_constraint(o, myfunc, d, tol));
}
void add_inequality_mconstraint(mfunc mf, void *f_data,
nlopt_munge md, nlopt_munge mc,
const std::vector<double> &tol) {
myfunc_data *d = new myfunc_data;
if (!d) throw std::bad_alloc();
d->o = this; d->mf = mf; d->f_data = f_data; d->f = NULL; d->vf = NULL;
d->munge_destroy = md; d->munge_copy = mc;
mythrow(nlopt_add_inequality_mconstraint(o, tol.size(), mymfunc, d,
tol.empty() ? NULL : &tol[0]));
}
void add_equality_mconstraint(mfunc mf, void *f_data,
nlopt_munge md, nlopt_munge mc,
const std::vector<double> &tol) {
myfunc_data *d = new myfunc_data;
if (!d) throw std::bad_alloc();
d->o = this; d->mf = mf; d->f_data = f_data; d->f = NULL; d->vf = NULL;
d->munge_destroy = md; d->munge_copy = mc;
mythrow(nlopt_add_equality_mconstraint(o, tol.size(), mymfunc, d,
tol.empty() ? NULL : &tol[0]));
}
#define NLOPT_GETSET_VEC(name) \
void set_##name(double val) { \
mythrow(nlopt_set_##name##1(o, val)); \
} \
void get_##name(std::vector<double> &v) const { \
if (o && nlopt_get_dimension(o) != v.size()) \
throw std::invalid_argument("dimension mismatch"); \
mythrow(nlopt_get_##name(o, v.empty() ? NULL : &v[0])); \
} \
std::vector<double> get_##name() const { \
if (!o) throw std::runtime_error("uninitialized nlopt::opt"); \
std::vector<double> v(nlopt_get_dimension(o)); \
get_##name(v); \
return v; \
} \
void set_##name(const std::vector<double> &v) { \
if (o && nlopt_get_dimension(o) != v.size()) \
throw std::invalid_argument("dimension mismatch"); \
mythrow(nlopt_set_##name(o, v.empty() ? NULL : &v[0])); \
}
NLOPT_GETSET_VEC(lower_bounds)
NLOPT_GETSET_VEC(upper_bounds)
// stopping criteria:
#define NLOPT_GETSET(T, name) \
T get_##name() const { \
if (!o) throw std::runtime_error("uninitialized nlopt::opt"); \
return nlopt_get_##name(o); \
} \
void set_##name(T name) { \
mythrow(nlopt_set_##name(o, name)); \
}
NLOPT_GETSET(double, stopval)
NLOPT_GETSET(double, ftol_rel)
NLOPT_GETSET(double, ftol_abs)
NLOPT_GETSET(double, xtol_rel)
NLOPT_GETSET_VEC(xtol_abs)
NLOPT_GETSET(int, maxeval)
NLOPT_GETSET(double, maxtime)
NLOPT_GETSET(int, force_stop)
void force_stop() { set_force_stop(1); }
// algorithm-specific parameters:
void set_local_optimizer(const opt &lo) {
nlopt_result ret = nlopt_set_local_optimizer(o, lo.o);
mythrow(ret);
}
NLOPT_GETSET(unsigned, population)
NLOPT_GETSET(unsigned, vector_storage)
NLOPT_GETSET_VEC(initial_step)
void set_default_initial_step(const std::vector<double> &x) {
nlopt_result ret
= nlopt_set_default_initial_step(o, x.empty() ? NULL : &x[0]);
mythrow(ret);
}
void get_initial_step(const std::vector<double> &x, std::vector<double> &dx) const {
if (o && (nlopt_get_dimension(o) != x.size()
|| nlopt_get_dimension(o) != dx.size()))
throw std::invalid_argument("dimension mismatch");
nlopt_result ret = nlopt_get_initial_step(o, x.empty() ? NULL : &x[0],
dx.empty() ? NULL : &dx[0]);
mythrow(ret);
}
std::vector<double> get_initial_step_(const std::vector<double> &x) const {
if (!o) throw std::runtime_error("uninitialized nlopt::opt");
std::vector<double> v(nlopt_get_dimension(o));
get_initial_step(x, v);
return v;
}
};
#undef NLOPT_GETSET
#undef NLOPT_GETSET_VEC
//////////////////////////////////////////////////////////////////////
inline void srand(unsigned long seed) { nlopt_srand(seed); }
inline void srand_time() { nlopt_srand_time(); }
inline void version(int &major, int &minor, int &bugfix) {
nlopt_version(&major, &minor, &bugfix);
}
inline int version_major() {
int major, minor, bugfix;
nlopt_version(&major, &minor, &bugfix);
return major;
}
inline int version_minor() {
int major, minor, bugfix;
nlopt_version(&major, &minor, &bugfix);
return minor;
}
inline int version_bugfix() {
int major, minor, bugfix;
nlopt_version(&major, &minor, &bugfix);
return bugfix;
}
inline const char *algorithm_name(algorithm a) {
return nlopt_algorithm_name(nlopt_algorithm(a));
}
//////////////////////////////////////////////////////////////////////
} // namespace nlopt
#endif /* NLOPT_HPP */

View File

@ -0,0 +1,416 @@
#include "stdafx.h"
#include <iostream>
#include "Method.h"
#include "Dsa.h"
#include "Aic.h"
#include "AicWeights.h"
#include "Normalization.h"
#include "Mape.h"
#include "SMape.h"
#include "Vovk.h"
#include "NoTrendNoSeasonality.h"
#include "NoTrendAddSeasonality.h"
#include "NoTrendMultSeasonality.h"
#include "AddTrendNoSeasonality.h"
#include "AddTrendAddSeasonality.h"
#include "AddTrendMultSeasonality.h"
#include "MultTrendNoSeasonality.h"
#include "MultTrendAddSeasonality.h"
#include "MultTrendMultSeasonality.h"
#include "DATrendNoSeasonality.h"
#include "DATrendAddSeasonality.h"
#include "DATrendMultSeasonality.h"
#include "DMTrendNoSeasonality.h"
#include "DMTrendAddSeasonality.h"
#include "DMTrendMultSeasonality.h"
#include "Tsaur.h"
#include "A.h"
#include "Fuzzy.h"
#include "FuzzyWithSets.h"
#include "File.h"
#include <vector>
#include "Param.h"
#include <sstream>
#include <direct.h>
#include <string>
#include <limits>
#include <math.h>
#include "Transformation.h"
#include "nlopt.hpp"
#include "nlopt.h"
#include "BIC.h"
int iMethod; // íîìåð òåêóùåãî ìåòîäà
const int n = 29; // êîëè÷åñòâî ìåòîäîâ, ÷òîá ëèøíåãî ïàìÿòè íå æðàòü
int numberParam; // ÷èñëî ïàðàìåòðîâ ó ìåòîäà
Method** m = new Method*[n];
Estimation* est1 = new SMape();
int ii; // ñ÷åò÷èê èòåðàöèé
double round (double value) {
return floor(value + 0.5);
}
double myRound(double num) {
double n = ((double)round(num * 1000)) / 1000;
return n;
}
void printTs(vector<double> ts) {
for (unsigned int i = 0; i < ts.size(); i++) {
cout << ts[i];
cout << " ";
}
}
double getEstimation(const std::vector<double> &x, std::vector<double> &grad, void *f_data)
{
ii++; // ñ÷åò÷èê èòåðàöèé
int radix = 10; //ñèñòåìà ñ÷èñëåíèÿ
char sbuffer[10]; //ðåçóëüòàò
for (int iiParam = 0; iiParam < numberParam; iiParam++)
{
m[iMethod]->setParam(itoa(iiParam, sbuffer, radix), myRound(x[iiParam]));
}
m[iMethod]->createModelForEstimation();
double smapeValue = myRound(est1->getValue(m[iMethod]->x, m[iMethod]->getForecast()));
return smapeValue;
}
int main(int argc, char* argv[])
{
Param* bestParams = new Param();
double bestSmape = DBL_MAX;
double bestAic = DBL_MAX;
int bestMethodIndex = 0;
setlocale(LC_ALL, "Russian");
string path;
string fileName;
string s;
if (argc < 1) {
cout << "set ts file like 'project_template.exe 1.csv count_forecast period!!!";
return 0;
} else {
stringstream ss;
ss << argv[1];
ss >> s;
int found = 0;
int offset =0;
do {
found = s.find("\\", found +1);
if (found > 0) {
offset = found;
cout << found << "\n";
}
} while (found!=std::string::npos);
if (offset ==0) {
fileName = s.substr(offset, s.length());
} else {
fileName = s.substr(offset+1, s.length());
}
path = s.substr(0, offset);
}
// îáúåêò äëÿ ðàáîòû ñ ôàéëàìè: çàãðóçèòü è ñîõðàíèòü ÂÐ
vector<double> timeSeries = File::readFile(argv[1]);
Transformation *transform = new Transformation(timeSeries);
transform->seasonalPeriod = atof(argv[3]);
// timeSeries = transform->Normalization();
//transform->setTimeSeries(tsTransform);
transform->lambdaEstimation();
timeSeries = transform->ModifiedBoxCox();
Normalization * norm = new Normalization();
//timeSeries = norm->normalizeTimeSeria(timeSeries);
// ñêîëüêî òî÷åê áóäåì ïðîãíîçèðîâàòü
int pointForecast = 18;
if (strcmp(argv[2], "") != 0) {
pointForecast = atof(argv[2]);
}
int p = 12;
if (strcmp(argv[3], "") != 0) {
p = atof(argv[3]);
}
double alpha = 0.1;
double delta = 0.2;
double gamma = 0.4;
double phi = 0.1;
int countRulesIn = 1;
int countFuzzyParts = 2;
// äàëåå çàäàåì ïàðàìåòðû, ñïåöèôè÷íûå äëÿ ìåòîäîâ
//...
// òàê êàê èñïîëüçîâàòü áóäåì âñå ìåòîäû (èëè îáúåäèíÿòü â êîëëåêòèâû) íóæíî
// âñå èõ ïðîèíèöèàëèçèðîâàòü è çàãíàòü â ìàññèâ
m[0] = new NoTrendNoSeasonality(timeSeries, pointForecast);
m[1] = new NoTrendAddSeasonality(timeSeries, pointForecast);
m[2] = new NoTrendMultSeasonality(timeSeries, pointForecast);
m[3] = new AddTrendNoSeasonality(timeSeries, pointForecast);
m[4] = new MultTrendNoSeasonality(timeSeries, pointForecast);
m[5] = new DATrendNoSeasonality(timeSeries, pointForecast);
m[6] = new DMTrendNoSeasonality(timeSeries, pointForecast);
m[7] = new AddTrendAddSeasonality(timeSeries, pointForecast);
m[8] = new MultTrendAddSeasonality(timeSeries, pointForecast);
m[9] = new DATrendAddSeasonality(timeSeries, pointForecast);
m[10] = new DMTrendAddSeasonality(timeSeries, pointForecast);
m[11] = new AddTrendMultSeasonality(timeSeries, pointForecast);
m[12] = new MultTrendMultSeasonality(timeSeries, pointForecast);
m[13] = new DATrendMultSeasonality(timeSeries, pointForecast);
m[14] = new DMTrendMultSeasonality(timeSeries, pointForecast);
m[15] = new Dsa(timeSeries, pointForecast);
m[16] = new Fuzzy("None", "None", timeSeries, pointForecast);
m[17] = new Fuzzy("Add", "None", timeSeries, pointForecast);
m[18] = new Fuzzy("None", "Add", timeSeries, pointForecast);
m[19] = new Fuzzy("Add", "Add", timeSeries, pointForecast);
m[20] = new FuzzyWithSets("None", "None", timeSeries, pointForecast);
m[21] = new FuzzyWithSets("None", "Add", timeSeries, pointForecast);
m[22] = new FuzzyWithSets("None", "Mult", timeSeries, pointForecast);
m[23] = new FuzzyWithSets("Add", "None", timeSeries, pointForecast);
m[24] = new FuzzyWithSets("Add", "Add", timeSeries, pointForecast);
m[25] = new FuzzyWithSets("Add", "Mult", timeSeries, pointForecast);
m[26] = new FuzzyWithSets("Mult", "None", timeSeries, pointForecast);
m[27] = new FuzzyWithSets("Mult", "Add", timeSeries, pointForecast);
m[28] = new FuzzyWithSets("Mult", "Mult", timeSeries, pointForecast);
//m[29] = new Tsaur(timeSeries, pointForecast);
AicWeights *aicWeights = new AicWeights();
vector<double> aicValues;
vector<vector<double>> modelsResults;
vector<Param*> optimal;
string smapeResults = "";
for (int i = 15; i < n; i++) {
iMethod = i;
m[i]->setParam("p", p);
// âûçîâåì ìåòîä îïòèìèçàöèè îäíîãî ïàðàìåòðà
//Estimation *est1 = new SMape();
Estimation *est1 = new Bic(algoritm::RMSE, m[i]->getNamberParam());
//optimal.push_back(m[i]->optimize(est1));
numberParam = m[i]->getNamberParam();
if (numberParam == 1) // äëÿ îäíîãî ïàðàìåòðà ïðîùå ïåðåáîð ïî ñåòêå
{
optimal.push_back(m[i]->optimize(est1));
m[i]->setParam("alpha", optimal[optimal.size()-1]->alpha);
}
else
{
// âåêòîðà äëÿ íà÷àëüíûõ, ìèíèìàëüíûõ è ìàêñèìàëüíûõ çíà÷åíèé ïàðàìåòðîâ
std::vector<double> x(numberParam);
std::vector<double> lb(numberParam);
std::vector<double> ub(numberParam);
// óñòàíàâëèâàåì ïàðàìåòðû
for (int iParam = 0; iParam < numberParam; iParam++)
{
lb[iParam] = 0.01; // ìèíèìàëüíîå çíà÷åíèå ïàðàìåòðà
ub[iParam] = 0.99; // ìàêñèìàëüíîå çíà÷åíèå ïåðåìåòðà
x[iParam] = 0.3; // íà÷àëüíîå çíà÷åíèå ïàðàìåòðà
}
// ñîçäàåì îñíîâíîé ìåòîä îïòèìèçàöèè
nlopt::opt opt(nlopt::AUGLAG, numberParam);
// ñîçäàåì âñïîìàãàòåëüíûé ìåòîä îïòèìèçàöèè
nlopt::opt subOpt(nlopt::GN_ORIG_DIRECT_L, numberParam);
subOpt.set_lower_bounds(lb);
subOpt.set_upper_bounds(ub);
// óñòàíàâëèâàåì ïàðàìåòðû îñíîâíîãî ìåòîäà îïòèìèçàöèè
opt.set_lower_bounds(lb);
opt.set_upper_bounds(ub);
opt.set_local_optimizer(subOpt);
// â çàâèñèìîñòè îò ÷èñëà ïàðàìåòðîâ, óñòàíàâëèâàåì êîëè÷åñòâî èòåðàöèé îïòèìèçàöèè
if (numberParam == 2)
{
subOpt.set_maxeval(10000);
opt.set_maxeval(10000);
}
else if (numberParam == 3)
{
subOpt.set_maxeval(50000);
opt.set_maxeval(50000);
}
else
{
subOpt.set_maxeval(100000);
opt.set_maxeval(100000);
}
// çàïóñêàåì îïòèìèçàöèþ
// getEstimation - ìåòîä â ñàìîì ââåðõó, êîòðûé âîçâðàùàåò îøèáêó íà êàæäîé èòåðàöèè
double minf;
opt.set_min_objective(getEstimation, NULL);
nlopt::result subResult = opt.optimize(x, minf);
cout << minf << endl;
// ïîïûòàåìñÿ óëó÷øèòü ïàðàìåòðû
nlopt::opt ssubOpt(nlopt::LN_NELDERMEAD, numberParam);
ssubOpt.set_lower_bounds(lb);
ssubOpt.set_upper_bounds(ub);
ssubOpt.set_maxeval(500);
ssubOpt.set_min_objective(getEstimation, NULL);
nlopt::result Result = ssubOpt.optimize(x, minf);
cout << minf << endl;
if (m[i]->getNamberParam() > 1) {
optimal.push_back(new Param());
}
optimal[optimal.size()-1]->countFuzzyParts = x[0] * 100;
optimal[optimal.size()-1]->countRulesIn = x[1] * 5;
if (i == 15) {
optimal[optimal.size()-1]->sizeLabels = x[2] * 100;
} else {
optimal[optimal.size()-1]->gamma = x[2];
}
if (m[i]->getNamberParam() > 3) {
optimal[optimal.size()-1]->delta = x[3];
if (m[i]->getNamberParam() > 4) {
optimal[optimal.size()-1]->alpha = x[4];
}
}
// â âåêòîðå x íàéäåííûå ïàðàìåòðû, â min - smape
}
// ñîçäàåì ìîäåëü äëÿ òåñòèðîâàíèÿ ïðè ïîìîùè âûáðàííîãî ìåòîäà
// çàäàåì ïàðàìåòðû
m[i]->setParam("alpha", optimal[optimal.size()-1]->alpha);
m[i]->setParam("gamma", optimal[optimal.size()-1]->gamma);
m[i]->setParam("delta", optimal[optimal.size()-1]->delta);
m[i]->setParam("phi", optimal[optimal.size()-1]->phi);
m[i]->setParam("countRulesIn", optimal[optimal.size()-1]->countRulesIn);
m[i]->setParam("countFuzzyParts", optimal[optimal.size()-1]->countFuzzyParts);
m[i]->setParam("lb1", optimal[optimal.size()-1]->lb1);
m[i]->setParam("rb1", optimal[optimal.size()-1]->rb1);
m[i]->setParam("lb2", optimal[optimal.size()-1]->lb2);
m[i]->setParam("rb2", optimal[optimal.size()-1]->rb2);
m[i]->setParam("sizeLabels", optimal[optimal.size()-1]->sizeLabels);
// ñîçäàåì ìîäåëü
m[i]->createModelForEstimation();
// âû÷èñëÿåì îøèáêó
//aicValues.push_back(aic->getValue(4, m[i]->getXEstimation(), m[i]->getForecast()));
//aicValues.push_back(aic->getAiccValue(4, m[i]->getXEstimation(), m[i]->getForecast()));
//aicValues.push_back(aic->getBicValue(4, m[i]->getXEstimation(), m[i]->getForecast()));
//modelsResults.push_back(m[i]->getForecast());
SMape* smape = new SMape();
stringstream ss1;
ss1 << i;
string str1 = ss1.str();
stringstream ss2;
double sm = smape->getValue(m[i]->x, m[i]->getForecast());
double ai = optimal[optimal.size()-1]->estim;
ss2 << sm;
// îïðåäåëÿåì, ÿâëÿþòñÿ ëè äàííûå ïàðàìåòðû ëó÷øèìè
if (ai < bestAic) {
bestAic = ai;
bestParams = optimal[optimal.size()-1];
bestMethodIndex = i;
}
string str2 = ss2.str();
smapeResults = smapeResults + "Smape for " + str1 + " method: " + str2 + " ";
smapeResults = smapeResults + optimal[optimal.size()-1]->toString() + "\n";
// ñîçäàåì ìîäåëü ïðè ïîìîùè âûáðàííîãî ìåòîäà
// ïîëó÷èì è ñîõðàíèì ïðîãíîç
string target = path +"\\"+ fileName+"result";
_mkdir(target.c_str());
string fileNameOut = target + "\\";
char suff[3];
itoa(i, suff, 10);
fileNameOut.append(suff);
fileNameOut.append("out");
m[i]->createModel();
//File::writeFile(fileNameOut, norm->deNormalizeTimeSeria(m[i]->getForecast()));
//transform->setTimeSeries(m[i]->getForecast());
//transform->setTimeSeries(transform->invModifiedBoxCox());
transform->setTimeSeries(m[i]->getForecast());
File::writeFile(fileNameOut, transform->invModifiedBoxCox());
}
Method* bestMethod = m[bestMethodIndex];
// ïîñëå òîãî, êàê îòðàáîòàëè âñå ìîäåëè
// çàäàåì ëó÷øèå ïàðàìåòðû
bestMethod->setParam("alpha", bestParams->alpha);
bestMethod->setParam("gamma", bestParams->gamma);
bestMethod->setParam("delta", bestParams->delta);
bestMethod->setParam("phi", bestParams->phi);
bestMethod->setParam("countRulesIn", bestParams->countRulesIn);
bestMethod->setParam("countFuzzyParts", bestParams->countFuzzyParts);
bestMethod->setParam("lb1", bestParams->lb1);
bestMethod->setParam("rb1", bestParams->rb1);
bestMethod->setParam("lb2", bestParams->lb2);
bestMethod->setParam("rb2", bestParams->rb2);
bestMethod->setParam("sizeLabels", bestParams->sizeLabels);
bestMethod->createModel();
string target = path +"\\"+ fileName+"result";
string fileNameOut = target + "\\";
fileNameOut.append("best");
char _s[3];
itoa(bestMethodIndex, _s, 10);
fileNameOut.append(_s);
//File::writeFile(fileNameOut, norm->deNormalizeTimeSeria(bestMethod->getForecast()));
transform->setTimeSeries(bestMethod->getForecast());
File::writeFile(fileNameOut, transform->invModifiedBoxCox());
string smapeFileName = path +"\\"+ fileName+"result\\smape";
FILE * file = fopen(smapeFileName.c_str(), "w");
if (file) // åñëè åñòü äîñòóï ê ôàéëó,
{
bool result = fputs(smapeResults.c_str(), file); // è çàïèñûâàåì åå â ôàéë
if (!result) // åñëè çàïèñü ïðîèçîøëà óñïåøíî
cout << "Ñòðîêà â ôàéë óñïåøíî çàïèñàíà!"; // âûâîäèì ñîîáùåíèå
fclose(file);
}
return 0;
Vovk *vovk = new Vovk(timeSeries, pointForecast, m);
vector<double> res;
res.push_back(vovk->getForecast());
for (int i = 0; i < pointForecast - 1; i++){
//cout << i + 1 << " " << vovk->getForecast() << endl;
vovk->updateTS(res[res.size() - 1]);
res.push_back(vovk->getForecast());
}
res = norm->deNormalizeTimeSeria(res);
for (int i = 0; i < pointForecast - 1; i++){
cout << i + 1 << " " << res[i] << endl;
}
SMape *smape = new SMape();
cout << "Smape for Vovk " << " method: " << smape->getValue(norm->deNormalizeTimeSeria(m[0]->getXEstimation()), res) << "\n";
vector<double> weights = aicWeights->calculateWeights(aicValues);
vector<double> fuzzyAdoptiveWeights = aicWeights->calculateFuzzyAdaptiveWeights(timeSeries, modelsResults);
cout << "Smape for etalon forecast " << " method: " << smape->getValue(m[21]->getXEstimation(), m[21]->getXEstimation()) << "\n";
delete(m);
return 0;
}

View File

@ -0,0 +1,551 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Name="project_template"
ProjectGUID="{D68B91E2-1169-4096-AC00-5992226D29DF}"
RootNamespace="project_template"
Keyword="Win32Proj"
AssemblyReferenceSearchPaths="&quot;..\project_template&quot;;&quot;..\..\project_template&quot;"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
FavorSizeOrSpeed="1"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="2"
WarningLevel="3"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="2"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\BIC.cpp"
>
</File>
<File
RelativePath=".\File.cpp"
>
</File>
<File
RelativePath=".\Median.cpp"
>
</File>
<File
RelativePath=".\Method.cpp"
>
</File>
<File
RelativePath=".\Normalization.cpp"
>
</File>
<File
RelativePath=".\Param.cpp"
>
</File>
<File
RelativePath=".\Preparator.cpp"
>
</File>
<File
RelativePath=".\project_template.cpp"
>
</File>
<File
RelativePath=".\RMSE.cpp"
>
</File>
<File
RelativePath=".\stdafx.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\Transformation.cpp"
>
</File>
<File
RelativePath=".\Tsaur.cpp"
>
</File>
<File
RelativePath=".\Vovk.cpp"
>
</File>
<Filter
Name="Methods"
>
<File
RelativePath=".\AddTrendAddSeasonality.cpp"
>
</File>
<File
RelativePath=".\AddTrendMultSeasonality.cpp"
>
</File>
<File
RelativePath=".\AddTrendNoSeasonality.cpp"
>
</File>
<File
RelativePath=".\DATrendAddSeasonality.cpp"
>
</File>
<File
RelativePath=".\DATrendMultSeasonality.cpp"
>
</File>
<File
RelativePath=".\DATrendNoSeasonality.cpp"
>
</File>
<File
RelativePath=".\DMTrendAddSeasonality.cpp"
>
</File>
<File
RelativePath=".\DMTrendMultSeasonality.cpp"
>
</File>
<File
RelativePath=".\DMTrendNoSeasonality.cpp"
>
</File>
<File
RelativePath=".\Dsa.cpp"
>
</File>
<File
RelativePath=".\MultTrendAddSeasonality.cpp"
>
</File>
<File
RelativePath=".\MultTrendMultSeasonality.cpp"
>
</File>
<File
RelativePath=".\MultTrendNoSeasonality.cpp"
>
</File>
<File
RelativePath=".\NoTrendAddSeasonality.cpp"
>
</File>
<File
RelativePath=".\NoTrendMultSeasonality.cpp"
>
</File>
<File
RelativePath=".\NoTrendNoSeasonality.cpp"
>
</File>
</Filter>
<Filter
Name="Estimations"
>
<File
RelativePath=".\Aic.cpp"
>
</File>
<File
RelativePath=".\AicWeights.cpp"
>
</File>
<File
RelativePath=".\Mape.cpp"
>
</File>
<File
RelativePath=".\SMape.cpp"
>
</File>
</Filter>
<Filter
Name="Fuzzy"
>
<File
RelativePath=".\A.cpp"
>
</File>
<File
RelativePath=".\Fuzzy.cpp"
>
</File>
<File
RelativePath=".\FuzzyWithSets.cpp"
>
</File>
</Filter>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\BIC.h"
>
</File>
<File
RelativePath=".\Estimation.h"
>
</File>
<File
RelativePath=".\File.h"
>
</File>
<File
RelativePath=".\Median.h"
>
</File>
<File
RelativePath=".\Method.h"
>
</File>
<File
RelativePath=".\nlopt.h"
>
</File>
<File
RelativePath=".\nlopt.hpp"
>
</File>
<File
RelativePath=".\Normalization.h"
>
</File>
<File
RelativePath=".\Param.h"
>
</File>
<File
RelativePath=".\Preparator.h"
>
</File>
<File
RelativePath=".\RMSE.h"
>
</File>
<File
RelativePath=".\stdafx.h"
>
</File>
<File
RelativePath=".\targetver.h"
>
</File>
<File
RelativePath=".\TrackingControlSignal.h"
>
</File>
<File
RelativePath=".\Transformation.h"
>
</File>
<File
RelativePath=".\Tsaur.h"
>
</File>
<File
RelativePath=".\Vovk.h"
>
</File>
<Filter
Name="Methods"
>
<File
RelativePath=".\AddTrendAddSeasonality.h"
>
</File>
<File
RelativePath=".\AddTrendMultSeasonality.h"
>
</File>
<File
RelativePath=".\AddTrendNoSeasonality.h"
>
</File>
<File
RelativePath=".\DATrendAddSeasonality.h"
>
</File>
<File
RelativePath=".\DATrendMultSeasonality.h"
>
</File>
<File
RelativePath=".\DATrendNoSeasonality.h"
>
</File>
<File
RelativePath=".\DMTrendAddSeasonality.h"
>
</File>
<File
RelativePath=".\DMTrendMultSeasonality.h"
>
</File>
<File
RelativePath=".\DMTrendNoSeasonality.h"
>
</File>
<File
RelativePath=".\Dsa.h"
>
</File>
<File
RelativePath=".\MultTrendAddSeasonality.h"
>
</File>
<File
RelativePath=".\MultTrendMultSeasonality.h"
>
</File>
<File
RelativePath=".\MultTrendNoSeasonality.h"
>
</File>
<File
RelativePath=".\NoTrendAddSeasonality.h"
>
</File>
<File
RelativePath=".\NoTrendMultSeasonality.h"
>
</File>
<File
RelativePath=".\NoTrendNoSeasonality.h"
>
</File>
</Filter>
<Filter
Name="Estimations"
>
<File
RelativePath=".\Aic.h"
>
</File>
<File
RelativePath=".\AicWeights.h"
>
</File>
<File
RelativePath=".\Mape.h"
>
</File>
<File
RelativePath=".\SMape.h"
>
</File>
</Filter>
<Filter
Name="Fuzzy"
>
<File
RelativePath=".\A.h"
>
</File>
<File
RelativePath=".\Fuzzy.h"
>
</File>
<File
RelativePath=".\FuzzyWithSets.h"
>
</File>
</Filter>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
<File
RelativePath=".\ClassDiagram1.cd"
>
</File>
<File
RelativePath=".\libnlopt-0.dll"
>
</File>
<File
RelativePath=".\libnlopt-0.lib"
>
</File>
<File
RelativePath=".\ReadMe.txt"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioUserFile
ProjectType="Visual C++"
Version="9,00"
ShowAllFiles="false"
>
<Configurations>
<Configuration
Name="Debug|Win32"
>
<DebugSettings
Command="$(TargetPath)"
WorkingDirectory=""
CommandArguments=""
Attach="false"
DebuggerType="3"
Remote="1"
RemoteMachine="ADMIN-4A0D49B0D"
RemoteCommand=""
HttpUrl=""
PDBPath=""
SQLDebugging=""
Environment=""
EnvironmentMerge="true"
DebuggerFlavor=""
MPIRunCommand=""
MPIRunArguments=""
MPIRunWorkingDirectory=""
ApplicationCommand=""
ApplicationArguments=""
ShimCommand=""
MPIAcceptMode=""
MPIAcceptFilter=""
/>
</Configuration>
<Configuration
Name="Release|Win32"
>
<DebugSettings
Command="$(TargetPath)"
WorkingDirectory=""
CommandArguments=""
Attach="false"
DebuggerType="3"
Remote="1"
RemoteMachine="ADMIN-4A0D49B0D"
RemoteCommand=""
HttpUrl=""
PDBPath=""
SQLDebugging=""
Environment=""
EnvironmentMerge="true"
DebuggerFlavor=""
MPIRunCommand=""
MPIRunArguments=""
MPIRunWorkingDirectory=""
ApplicationCommand=""
ApplicationArguments=""
ShimCommand=""
MPIAcceptMode=""
MPIAcceptFilter=""
/>
</Configuration>
</Configurations>
</VisualStudioUserFile>

View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioUserFile
ProjectType="Visual C++"
Version="9,00"
ShowAllFiles="true"
>
<Configurations>
<Configuration
Name="Debug|Win32"
>
<DebugSettings
Command="$(TargetPath)"
WorkingDirectory=""
CommandArguments="..\\ts\\1 4 1"
Attach="false"
DebuggerType="3"
Remote="1"
RemoteMachine="ORION-ÏÊ"
RemoteCommand=""
HttpUrl=""
PDBPath=""
SQLDebugging=""
Environment=""
EnvironmentMerge="true"
DebuggerFlavor="0"
MPIRunCommand=""
MPIRunArguments=""
MPIRunWorkingDirectory=""
ApplicationCommand=""
ApplicationArguments=""
ShimCommand=""
MPIAcceptMode=""
MPIAcceptFilter=""
/>
</Configuration>
<Configuration
Name="Release|Win32"
>
<DebugSettings
Command="$(TargetPath)"
WorkingDirectory=""
CommandArguments="..\\ts\1"
Attach="false"
DebuggerType="3"
Remote="1"
RemoteMachine="ORION-ÏÊ"
RemoteCommand=""
HttpUrl=""
PDBPath=""
SQLDebugging=""
Environment=""
EnvironmentMerge="true"
DebuggerFlavor="0"
MPIRunCommand=""
MPIRunArguments=""
MPIRunWorkingDirectory=""
ApplicationCommand=""
ApplicationArguments=""
ShimCommand=""
MPIAcceptMode=""
MPIAcceptFilter=""
/>
</Configuration>
</Configurations>
</VisualStudioUserFile>

View File

@ -0,0 +1,162 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{D68B91E2-1169-4096-AC00-5992226D29DF}</ProjectGuid>
<RootNamespace>project_template</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>12.0.21005.1</_ProjectFileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="A.cpp" />
<ClCompile Include="AddTrendAddSeasonality.cpp" />
<ClCompile Include="AddTrendMultSeasonality.cpp" />
<ClCompile Include="AddTrendNoSeasonality.cpp" />
<ClCompile Include="AicWeights.cpp" />
<ClCompile Include="DATrendAddSeasonality.cpp" />
<ClCompile Include="DATrendMultSeasonality.cpp" />
<ClCompile Include="DATrendNoSeasonality.cpp" />
<ClCompile Include="DMTrendAddSeasonality.cpp" />
<ClCompile Include="DMTrendMultSeasonality.cpp" />
<ClCompile Include="DMTrendNoSeasonality.cpp" />
<ClCompile Include="File.cpp" />
<ClCompile Include="Fuzzy.cpp" />
<ClCompile Include="FuzzyWithSets.cpp" />
<ClCompile Include="MAT.cpp" />
<ClCompile Include="Method.cpp" />
<ClCompile Include="MultTrendAddSeasonality.cpp" />
<ClCompile Include="MultTrendMultSeasonality.cpp" />
<ClCompile Include="MultTrendNoSeasonality.cpp" />
<ClCompile Include="NoTrendAddSeasonality.cpp" />
<ClCompile Include="NoTrendMultSeasonality.cpp" />
<ClCompile Include="project_template.cpp" />
<ClCompile Include="Reporter.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="Dsa.cpp" />
<ClCompile Include="NoTrendNoSeasonality.cpp" />
<ClCompile Include="Aic.cpp" />
<ClCompile Include="Mape.cpp" />
<ClCompile Include="Vovk.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="A.h" />
<ClInclude Include="AddTrendAddSeasonality.h" />
<ClInclude Include="AddTrendMultSeasonality.h" />
<ClInclude Include="AddTrendNoSeasonality.h" />
<ClInclude Include="AicWeights.h" />
<ClInclude Include="DATrendAddSeasonality.h" />
<ClInclude Include="DATrendMultSeasonality.h" />
<ClInclude Include="DATrendNoSeasonality.h" />
<ClInclude Include="DMTrendAddSeasonality.h" />
<ClInclude Include="DMTrendMultSeasonality.h" />
<ClInclude Include="DMTrendNoSeasonality.h" />
<ClInclude Include="Estimation.h" />
<ClInclude Include="File.h" />
<ClInclude Include="Fuzzy.h" />
<ClInclude Include="FuzzyWithSets.h" />
<ClInclude Include="MAT.h" />
<ClInclude Include="Method.h" />
<ClInclude Include="MultTrendAddSeasonality.h" />
<ClInclude Include="MultTrendMultSeasonality.h" />
<ClInclude Include="MultTrendNoSeasonality.h" />
<ClInclude Include="NoTrendAddSeasonality.h" />
<ClInclude Include="NoTrendMultSeasonality.h" />
<ClInclude Include="Reporter.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="Dsa.h" />
<ClInclude Include="NoTrendNoSeasonality.h" />
<ClInclude Include="Aic.h" />
<ClInclude Include="Mape.h" />
<ClInclude Include="TrackingControlSignal.h" />
<ClInclude Include="Vovk.h" />
</ItemGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,222 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Source Files\Methods">
<UniqueIdentifier>{5d90801d-4ed6-4356-8b18-d8eb47265efa}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Estimations">
<UniqueIdentifier>{abb28eca-6911-465e-b9bd-9fa5690d4db4}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Header Files\Methods">
<UniqueIdentifier>{07a8211b-11b0-40e4-b1a3-0f4f3999ecee}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Estimations">
<UniqueIdentifier>{55e5d4a8-6f19-439d-b569-2d0161448794}</UniqueIdentifier>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
</Filter>
<Filter Include="Source Files\AggregationMethods">
<UniqueIdentifier>{f03145ee-d3fb-41c6-b262-5a21194ffff4}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\AggregationMethods">
<UniqueIdentifier>{c9ac4971-b0dd-420b-b475-de086bf4f99b}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="project_template.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Dsa.cpp">
<Filter>Source Files\Methods</Filter>
</ClCompile>
<ClCompile Include="NoTrendNoSeasonality.cpp">
<Filter>Source Files\Methods</Filter>
</ClCompile>
<ClCompile Include="Aic.cpp">
<Filter>Source Files\Estimations</Filter>
</ClCompile>
<ClCompile Include="Mape.cpp">
<Filter>Source Files\Estimations</Filter>
</ClCompile>
<ClCompile Include="Method.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="AddTrendAddSeasonality.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="AddTrendMultSeasonality.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="AddTrendNoSeasonality.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DATrendAddSeasonality.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DATrendMultSeasonality.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DATrendNoSeasonality.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DMTrendAddSeasonality.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DMTrendMultSeasonality.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DMTrendNoSeasonality.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="A.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MultTrendAddSeasonality.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MultTrendMultSeasonality.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MultTrendNoSeasonality.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="NoTrendAddSeasonality.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="NoTrendMultSeasonality.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Fuzzy.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="File.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="AicWeights.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MAT.cpp">
<Filter>Source Files\Methods</Filter>
</ClCompile>
<ClCompile Include="Vovk.cpp">
<Filter>Source Files\AggregationMethods</Filter>
</ClCompile>
<ClCompile Include="FuzzyWithSets.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Reporter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Estimation.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Method.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="targetver.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Dsa.h">
<Filter>Header Files\Methods</Filter>
</ClInclude>
<ClInclude Include="NoTrendNoSeasonality.h">
<Filter>Header Files\Methods</Filter>
</ClInclude>
<ClInclude Include="Aic.h">
<Filter>Header Files\Estimations</Filter>
</ClInclude>
<ClInclude Include="Mape.h">
<Filter>Header Files\Estimations</Filter>
</ClInclude>
<ClInclude Include="AddTrendAddSeasonality.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="AddTrendMultSeasonality.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="AddTrendNoSeasonality.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DATrendAddSeasonality.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DATrendMultSeasonality.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DATrendNoSeasonality.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DMTrendAddSeasonality.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DMTrendMultSeasonality.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DMTrendNoSeasonality.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="A.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MultTrendAddSeasonality.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MultTrendMultSeasonality.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MultTrendNoSeasonality.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="NoTrendAddSeasonality.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="NoTrendMultSeasonality.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Fuzzy.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="File.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="AicWeights.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MAT.h">
<Filter>Header Files\Methods</Filter>
</ClInclude>
<ClInclude Include="Vovk.h">
<Filter>Header Files\AggregationMethods</Filter>
</ClInclude>
<ClInclude Include="TrackingControlSignal.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="FuzzyWithSets.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Reporter.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ShowAllFiles>true</ShowAllFiles>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,8 @@
// stdafx.cpp : source file that includes just the standard includes
// project_template.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

15
project_template/stdafx.h Normal file
View File

@ -0,0 +1,15 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
// TODO: reference additional headers your program requires here

View File

@ -0,0 +1,13 @@
#pragma once
// The following macros define the minimum required platform. The minimum required platform
// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run
// your application. The macros work by enabling all features available on platform versions up to and
// including the version specified.
// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
#ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista.
#define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows.
#endif

Some files were not shown because too many files have changed in this diff Show More