40 | | |
41 | | char* outfile_strings[18] = {"prsti_BO_.txt", "prsti_PA_.txt", "prsti_PL_.txt", "prsti_AD_.txt", "prsti_BP_.txt", "prsti_C__.txt", "prsti_CC_.txt", "prsti_CD_.txt", "prsti_CL_.txt", "prsti_CT_.txt", "prsti_CU_.txt", "prsti_ED_.txt", "prsti_FC2.txt", "prsti_FV2.txt", "prsti_GC_.txt", "prsti_HG_.txt", "prsti_HO_.txt", "prsti_HU_.txt"}; |
42 | | char* file_strings[18] = {"c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\BO_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\PA_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\PL_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\AD_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\BP_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\C__.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\CC_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\CD_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\CL_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\CT_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\CU_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\ED_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\FC2.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\FV2.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\GC_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\HG_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\HO_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\HU_.txt"}; |
43 | | //for (int a=0;a<18;a++) |
| 37 | //toto by bralo rozne subory, ale teraz to je zakomentovane, pouyivam len jeden |
| 38 | char* outfile_strings[19] = {"prsti_CL_.txt", "prsti_HO_.txt", "prsti_HU_.txt", "prsti_NG_.txt", "prsti_AD_.txt", "prsti_BP_.txt", "prsti_CD_.txt", "prsti_CU_.txt", "prsti_SF_.txt", "prsti_BO_.txt", "prsti_C__.txt", "prsti_CT_.txt", "prsti_MW_.txt", "prsti_W__.txt", "prsti_GC_.txt", "prsti_HG_.txt", "prsti_PA_.txt", "prsti_PL_.txt", "prsti_SI_.txt"}; |
| 39 | char* file_strings[19] = {"c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\CL_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\HO_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\HU_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\NG_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\AD_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\BP_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\CD_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\CU_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\SF_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\BO_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\C__.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\CT_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\MW_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\W__.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\GC_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\HG_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\PA_.txt","c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\PL_.txt","c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\SI_.txt"}; |
| 40 | //for (int a=0;a<20;a++) |
66 | | /* //to malo byt rpevedenie str na double, aspon mysslim |
67 | | std::istringstream stme,stmd; //je to dake chybne, aj cisla z toho ADdata cita/zapisuje trochu ine |
68 | | double d,e; |
69 | | vector<vec> data_rozdiel; |
70 | | for (int b=0;b<ADdata.size();b++) |
71 | | { |
72 | | vec pom; |
73 | | stmd.str(ADdata[b][0]); |
74 | | stmd >>d; |
75 | | for (int c=1;c<ADdata[b].size();c++) |
76 | | { |
77 | | stme.str(ADdata[b][c]); |
78 | | stme >>e; |
79 | | cout<<e<<' '<<d ; |
80 | | pom.ins(pom.size(),e-d); |
81 | | cout<<pom; |
82 | | } |
83 | | }*/ |
84 | | vector<vec> norm; //do norm zapisujeme normalizacne faktory |
85 | | for (int h=1;h<=2;h++) //cyklus ktory ovplzvnuje konstantu h=1- model s konstantou, h=2, bez konstanty |
| 63 | |
| 64 | vector<vec> norm; //do tychto poli zapisujeme normalizacne faktory |
| 65 | vector<vec> nfaktor; |
| 66 | for (int h=1;h<=2;h++) //cyklus ktory ovplyvnuje konstantu h=1- model s konstantou, h=2, bez konstanty |
123 | | pomocka.ins(pomocka.size(),Ar.posterior().lognc()); //nie je tu exponenciala! -aby to bolo mensie |
| 101 | condition.ins(0,predikce); |
| 102 | if (g+h!=3) Rar.bayes(condition.left(g+h-2)); // podmienka brani aby sme nepouzivali robust pre AR(o) model len s konstantou |
| 103 | //cout<< "Normalne rozdel" <<Ar.posterior().lognc(); |
| 104 | //cout << "Lapla normalizacny faktor" <<Rar.posterior->log_nc; |
| 105 | pomocka1.ins(pomocka1.size(),Ar.posterior().lognc()); //nie je tu exponenciala! -aby to bolo mensie |
| 106 | if (g+h!=3) pomocka2.ins(pomocka2.size(),exp(Rar.posterior->log_nc)); |
174 | | //nove pole namiesto norm, kde bude odcitane max a bude v spravnej forme, teda aj s exponencialov |
175 | | vector<vec> nfaktor; |
176 | | for (int j=1;j<norm.size();j++) |
177 | | { |
178 | | for (int i=1;j<norm[j].size();j++) |
179 | | { |
180 | | nfaktor[j][i]=exp(norm[j][i+4]-max[i]); |
181 | | } |
182 | | } |
183 | | |
184 | | |
| 163 | //v poli nfaktor uz mame zapisane normalizacne faktory pre Laplacovo rozdelenie, nie su take velke, preto nerobime odcitanie maxima |
| 164 | // teraz odcitujeme od tych y normalnym rozdelenim maximum a pridame dalej do pola nfaktor |
| 165 | for (int i=0;i<norm.size();i++) |
| 166 | { |
| 167 | vec riadok; |
| 168 | for (int j=0;j<5;j++) |
| 169 | { |
| 170 | riadok.ins(riadok.size(),norm[i][j]); //toto pridava tie cisla na zaciatku, ktore urcuju o aky model sa jedna |
| 171 | } |
| 172 | for (int j=0;j<norm[i].size()-5;j++) |
| 173 | { |
| 174 | riadok.ins(riadok.size(),exp(norm[i][j+5]-max[j])); |
| 175 | } |
| 176 | nfaktor.push_back(riadok); |
| 177 | } |
| 178 | // nfaktor ma 229 riadkov, to je 229 hypotez |
193 | | // v ramci riadku v poli norm su hodnoty pre jednu hypotezu v roznych casoch, pocitanie pravdepodobnosti z norm. faktorov |
194 | | for (m=0;m<norm[1].size()-4;m++) |
195 | | { double k=sumastlpec(m,norm,prsti); |
196 | | for(n=0;n < norm.size();n++) |
197 | | { |
198 | | prsti[n].ins(prsti[n].size(),norm[n][m+4]*prsti[n][m]/k); |
199 | | //prsti[n].ins(prsti[n].size(),norm[n][m+4]+prsti[n][m]-k); |
| 187 | // v ramci riadku v poli nfaktor su hodnoty pre jednu hypotezu v roznych casoch, pocitanie pravdepodobnosti z norm. faktorov |
| 188 | for (m=0;m<nfaktor[2].size()-5;m++) |
| 189 | { double k=sumastlpec(m,nfaktor,prsti); |
| 190 | for(n=0;n < nfaktor.size();n++) |
| 191 | { |
| 192 | prsti[n].ins(prsti[n].size(),nfaktor[n][m+5]*prsti[n][m]/k); |