Changeset 1338 for applications

Show
Ignore:
Timestamp:
04/27/11 19:00:36 (13 years ago)
Author:
sindj
Message:

Zacatky experimentovani v robustlib. Zacleneni vypoctu polynomialni rovnice pro optimalni akci s vyuzitim funkce itpp::roots(). Odstranovani zbylych chyb. JS

Location:
applications
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • applications/robust/main.cpp

    r1337 r1338  
    1212#include <iostream> 
    1313#include <fstream> 
    14 #include <itpp/signal/poly.h> 
     14#include <itpp/itsignal.h> 
    1515 
    1616using namespace itpp; 
     
    138138        vector<vector<string>> strings; 
    139139 
    140         char* file_strings[3] = {"c:\\dataADClosePercDiff", "c:\\ar_student_single","c:\\ar_cauchy_single"}; 
     140        char* file_strings[3] = {"c:\\dataCDClosePercDiff", "c:\\ar_student_single","c:\\ar_cauchy_single"}; 
    141141 
    142142        for(int i = 0;i<3;i++) 
     
    172172                RARX* my_rarx = new RARX(2,30,false); 
    173173                 
    174                 /* 
     174                 
    175175                mat V0 = 0.0001 * eye ( 3 ); 
    176176                ARX* my_arx = new ARX(0.97); 
     
    178178                my_arx->set_constant ( false ); 
    179179                my_arx->validate(); 
    180                 */ 
    181  
    182                 for(int k = 1;k<170;k++) 
     180                 
     181 
     182                for(int k = 1;k<strings[j].size();k++) 
    183183                { 
    184184                        vec condition; 
     
    199199                                conditions[k-3].ins(0,strings[j][k]); 
    200200 
    201                                 // cout << "modi:" << conditions[k-3] << endl; 
     201                                //cout << "Condition:" << conditions[k-3] << endl; 
    202202 
    203203                                my_rarx->bayes(conditions[k-3]); 
     204                                //my_rarx->posterior->step_me(1); 
    204205                                 
    205206                                vec cond_vec; 
    206207                                cond_vec.ins(0,conditions[k-3][0]); 
    207208                                 
    208                                 // my_arx->bayes(cond_vec,conditions[k-3].right(2)); 
     209                                my_arx->bayes(cond_vec,conditions[k-3].right(2)); 
    209210                                         
    210211                                 
    211                                 if(k>5) 
     212                                if(k>8) 
    212213                                { 
    213214                                        //my_rarx->posterior->step_me(0); 
     
    219220                                        { 
    220221                                                vec lap_sample = conditions[k-3].left(2); 
     222                                                //lap_sample.ins(lap_sample.size(),1.0); 
    221223                                                 
    222224                                                lap_sample.ins(0,LapRNG()); 
     
    225227                                        } 
    226228 
     229                                         
    227230                                        vec sample_pow = sample_prediction; 
    228231                                        vec poly_coefs; 
     
    236239                                                { 
    237240                                                        sample_pow = elem_mult(sample_pow,sample_prediction); 
    238                                                         poly_coefs.ins(poly_coefs.size(),pow(-1,en)*poly_coef); 
     241                                                        poly_coefs.ins(poly_coefs.size(),((-1)^en)*poly_coef); 
    239242                                                } 
    240243                                                else 
     
    247250                                        while(!stop_iteration); 
    248251 
    249                                         cvec action =  
    250                                          
    251                                          
    252                                         cout << "MaxLik coords:" << my_rarx->posterior->minimal_vertex->get_coordinates() << endl; 
     252                                        // cout << "Coefficients: " << poly_coefs << endl; 
     253                                                                                 
     254                                        cvec actions = roots(poly_coefs); 
     255                                        bool is_max = false; 
     256                                        for(int t = 0;t<actions.size();t++) 
     257                                        { 
     258                                                if(actions[t].imag() == 0 && actions[t].real()>-1 && actions[t].real()<1) 
     259                                                { 
     260                                                        cout << "Action:" << actions[t].real() << endl; 
     261                                                        is_max = true; 
     262                                                } 
     263                                        } 
     264 
     265                                        if(!is_max) 
     266                                        { 
     267                                                cout << "No maximum." << endl; 
     268                                        } 
     269 
     270                                        // cout << "MaxLik coords:" << my_rarx->posterior->minimal_vertex->get_coordinates() << endl; 
    253271 
    254272                                        double prediction = 0; 
     
    290308                                        } 
    291309 
    292                                         /* 
     310                                        cout << "Prediction: "<< prediction << endl; 
     311                                         
    293312                                        enorm<ldmat>* pred_mat = my_arx->epredictor(conditions[k-3].left(2)); 
    294313                                        double prediction2 = pred_mat->mean()[0]; 
    295                                         */ 
     314                                         
    296315 
    297316                                        ofstream myfile; 
    298317                                        char fstring[80]; 
    299                                         //char f2string[80]; 
     318                                        char f2string[80]; 
    300319                                        strcpy(fstring,file_strings[j]); 
    301                                         //strcpy(f2string,fstring); 
     320                                        strcpy(f2string,fstring); 
    302321 
    303322                                        strcat(fstring,"pred.txt"); 
    304                                         //strcat(f2string,"2pred.txt"); 
     323                                        strcat(f2string,"2pred.txt"); 
    305324                                         
    306325 
    307326                                        myfile.open(fstring,ios::app); 
    308327                                         
    309                                         //myfile << my_rarx->posterior->minimal_vertex->get_coordinates()[0]; 
     328                                        // myfile << my_rarx->posterior->minimal_vertex->get_coordinates()[0]; 
    310329                                        myfile << prediction; 
    311330                                         
     
    320339                                        myfile.close(); 
    321340 
    322                                         /* 
     341                                         
    323342                                        myfile.open(f2string,ios::app); 
    324343                                        myfile << prediction2; 
     
    333352                                        } 
    334353                                        myfile.close(); 
    335                                         */ 
     354                                         
    336355 
    337356                                }                                        
  • applications/robust/robustlib.cpp

    r1335 r1338  
    3333                                { 
    3434                                        double cur_prob = 0; 
     35 
     36                                        /* 
     37                                        if(should_integrate&&new_simplex->vertices.size()!=3) 
     38                                        { 
     39                                                cout << "Error: Wrong vertex count for integration!"; 
     40                                        } 
     41                                        */ 
    3542 
    3643                                        if(should_integrate) 
  • applications/robust/robustlib.h

    r1337 r1338  
    883883                                { 
    884884                                        current_parent->totallyneutralgrandchildren.insert(sender->totallyneutralchildren.begin(),sender->totallyneutralchildren.end()); 
    885  
     885                                         
    886886                                        for(set<polyhedron*>::iterator tot_child_ref = sender->totallyneutralchildren.begin();tot_child_ref!=sender->totallyneutralchildren.end();tot_child_ref++) 
    887887                                        { 
    888888                                                (*tot_child_ref)->grandparents.insert(current_parent); 
     889                                        } 
     890 
     891                                        if(current_parent->totally_neutral == NULL) 
     892                                        { 
     893                                                current_parent->totally_neutral = sender->totally_neutral; 
     894                                        } 
     895                                        else 
     896                                        { 
     897                                                current_parent->totally_neutral = current_parent->totally_neutral && sender->totally_neutral; 
    889898                                        } 
    890899 
     
    898907                                                current_parent->neutralchildren.push_back(sender); 
    899908                                                current_parent->positiveneutralvertices.insert(sender->positiveneutralvertices.begin(),sender->positiveneutralvertices.end()); 
    900                                                 current_parent->negativeneutralvertices.insert(sender->negativeneutralvertices.begin(),sender->negativeneutralvertices.end()); 
    901  
    902                                                 if(current_parent->totally_neutral == NULL) 
    903                                                 { 
    904                                                         current_parent->totally_neutral = sender->totally_neutral; 
    905                                                 } 
    906                                                 else 
    907                                                 { 
    908                                                         current_parent->totally_neutral = current_parent->totally_neutral && sender->totally_neutral; 
    909                                                 } 
     909                                                current_parent->negativeneutralvertices.insert(sender->negativeneutralvertices.begin(),sender->negativeneutralvertices.end());                                           
    910910 
    911911                                                if(sender->totally_neutral) 
     
    922922 
    923923                                        if(is_last) 
    924                                         { 
     924                                        {                                                
    925925                                                 
    926                                                 /// \TODO Nechapu druhou podminku, zda se mi ze je to spatne.. Nemela by byt jen prvni? Nebo se jedna o nastaveni totalni neutrality? 
    927                                                 if((current_parent->negativechildren.size()>0&&current_parent->positivechildren.size()>0)|| 
    928                                                                                                         (current_parent->neutralchildren.size()>0&&current_parent->totally_neutral==false)) 
     926                                                if((current_parent->negativechildren.size()>0&&current_parent->positivechildren.size()>0) 
     927                                                                                                        ||(current_parent->neutralchildren.size()>0&&current_parent->totallyneutralchildren.empty())) 
    929928                                                { 
    930929                                                        for_splitting[level+1].push_back(current_parent);                                                
     
    981980                                                                current_parent->negativechildren.clear(); 
    982981                                                                current_parent->neutralchildren.clear(); 
    983                                                                 current_parent->totallyneutralchildren.clear(); 
     982                                                                //current_parent->totallyneutralchildren.clear(); 
    984983                                                                current_parent->totallyneutralgrandchildren.clear(); 
    985984                                                                // current_parent->grandparents.clear(); 
     
    10021001                         
    10031002                        } 
    1004                          
     1003 
     1004                        sender->totallyneutralchildren.clear();                  
    10051005                }                
    10061006        } 
     
    10491049                        { 
    10501050                                 
    1051                                  
     1051                                /* 
    10521052                                if(i==statistic.size()-1) 
    10531053                                { 
     
    10551055                                        cout << "Order:" << ((toprow*)horiz_ref)->condition_order << endl; 
    10561056                                } 
     1057                                */ 
     1058 
     1059                                cout << "Stepped." << endl; 
    10571060                                 
    10581061                                /* 
     
    12591262                                                current_vertex->negativeneutralvertices.insert(current_vertex); 
    12601263                                                current_vertex->positiveneutralvertices.insert(current_vertex); 
    1261                                         }                                        
     1264                                        } 
     1265                                        else 
     1266                                        { 
     1267                                                current_vertex->totally_neutral = false; 
     1268                                        } 
    12621269                                } 
    12631270                         
     
    12961303                if(should_remove) 
    12971304                { 
     1305                        /* 
    12981306                        for(int i = 0;i<for_merging.size();i++) 
    12991307                        { 
     
    13051313                                cout << endl; 
    13061314                        } 
     1315                        */ 
     1316 
     1317                        cout << "Merging." << endl; 
    13071318 
    13081319                        set<vertex*> vertices_to_be_reduced;                     
     
    14071418                                                        } 
    14081419 
     1420                                                        /* 
    14091421                                                        current_positive->totallyneutralchildren.insert(current_negative->totallyneutralchildren.begin(),current_negative->totallyneutralchildren.end()); 
    14101422                                                         
    14111423                                                        current_positive->totallyneutralchildren.erase(*merge_ref); 
     1424                                                        */ 
    14121425 
    14131426                                                        current_positive->totallyneutralgrandchildren.insert(current_negative->totallyneutralgrandchildren.begin(),current_negative->totallyneutralgrandchildren.end()); 
     
    14231436                                                                current_positive->negativechildren.clear(); 
    14241437                                                                current_positive->neutralchildren.clear(); 
    1425                                                                 current_positive->totallyneutralchildren.clear(); 
     1438                                                                // current_positive->totallyneutralchildren.clear(); 
    14261439                                                                current_positive->totallyneutralgrandchildren.clear();                                                           
    14271440                                                                current_positive->positiveneutralvertices.clear(); 
     
    15581571                } 
    15591572                 
     1573                /* 
    15601574                vector<int> sizevector; 
    15611575                for(int s = 0;s<statistic.size();s++) 
     
    15641578                        cout << statistic.row_size(s) << ", "; 
    15651579                } 
    1566  
    1567                 cout << endl; 
     1580                */ 
     1581 
     1582                //cout << endl; 
     1583 
     1584                // this->step_me(2); 
    15681585 
    15691586                if(should_add) 
     
    17221739                } 
    17231740 
    1724                  
     1741                /* 
    17251742                sizevector.clear(); 
    17261743                for(int s = 0;s<statistic.size();s++) 
     
    17311748                 
    17321749                cout << endl; 
     1750                */ 
    17331751 
    17341752                /* 
     
    19431961 
    19441962                                //// cout << "Sigma: " << sigma << endl; 
    1945                                 //// cout << "Nr. of runs: " << number_of_runs << endl; 
     1963                                //// cout << "Nr. of sigma runs: " << number_of_runs << endl; 
    19461964 
    19471965                                int dimension = (*s_ref)->vertices.size()-1; 
     
    20872105                                        sample_mat.ins_col(0,sample_coordinates); 
    20882106 
    2089                                         cout << sample_mat.cols() << ","; 
     2107                                        // cout << sample_mat.cols() << ","; 
    20902108                                } 
    20912109 
     
    20962114                        } 
    20972115 
    2098                         cout << endl; 
     2116                        // cout << endl; 
    20992117                        return sample_mat; 
    21002118                } 
  • applications/trading_models/trading_models_main.cpp

    r1266 r1338  
    77 */ 
    88 
     9//<<<<<<< .mine 
     10#include "trading_models_lib.h" 
     11#include <iostream>  
     12#include "estim/arx.h" 
     13//======= 
    914#include "trading_models_lib.h" 
    1015#include "estim/arx.h" 
     16#include <vector> 
     17#include <string> 
     18#include <sstream> 
     19#include <fstream> 
     20 
     21 
     22//>>>>>>> .r1284 
    1123using namespace bdm; 
    1224 
    13  
    14  
    15 int main ( int argc, char* argv[] ) { 
    16  
    17         for(int i=0;i<10000;i++) 
     25/* 
     26string cislo(string s)   // tato procedura spracova tie cisla z toho textoveho suboru tak aby sa odstranilo to e-001 a boli v spravnom  
     27                                                //formate. Lebo predtym to vyhadyovalo divne cisla, nevedel som ci je to zato, ze bayes si  stym neporadi, ale yjavne nepomohlo 
     28{ 
     29        int b=s.find('e'); 
     30        string t=s.substr(0,b); 
     31        string poz=s.substr(b+1,s.size()); 
     32 
     33        istringstream g(poz); 
     34        int pozc; 
     35        g>>pozc; 
     36        istringstream k(t); 
     37        double csl; 
     38        k>>csl; 
     39        if (pozc<0) //pozc moze byt niekedy aj kladne 
    1840        { 
    19                 cout << i; 
     41                for(int i=1;i<=-pozc;i++) 
     42                csl/=10; 
     43        } else 
     44        {  
     45                for(int j=1;j<=pozc;j++) 
     46                csl*=10; 
    2047        } 
    21          //prior 
    22     mat V0 = 0.00001 * eye ( 2 ); 
    23     V0 ( 0, 0 ) = 0.1; // 
    24     ARX Ar; 
    25     Ar.set_statistics ( 1, V0 ); //nu is default (set to have finite moments) 
    26     Ar.set_constant ( true ); 
    27     Ar.validate(); 
    28     // forgetting is default: 1.0 
    29     mat Data = concat_vertical ( randn ( 1, 100 ), ones ( 1, 100 ) ); 
    30     Ar.bayes_batch ( Data ); 
    31  
    32  
    33 } 
    34  
     48         
     49        ostringstream o; 
     50        o<<csl; 
     51        return o.str(); 
     52} */ 
     53 
     54double sumastlpec(int k,vector<vec> pole,vector<vec> pravd) {  //robi sumu k-teho stlpca, pouzivam na konci pri ratani pravdepodobnosti 
     55        double r=0; 
     56        for (int i=0;i<pole.size();i++) 
     57        { 
     58                r+=pole[i][k]*pravd[i][k]; 
     59        } 
     60        return r; 
     61                } 
     62 
     63int main () { 
     64        vector<vector<string>> ADdata;     //nacitavanie dat do pola ADdata -funguje spravne 
     65                ifstream myfile("C:\\AD_dataupravene.txt"); 
     66                if (myfile.is_open()) 
     67                { 
     68                        while ( myfile.good() ) 
     69                        { 
     70                                string line; 
     71                                getline(myfile,line); 
     72                                vector<string> parsed_line;                               
     73                                while(line.find(' ') != string::npos) //jeden kanal je jeden riadok, na zaciatku a na konci {,}, data oddelene ciarkou a medzerou. 
     74                                { 
     75                                        line.erase(0,1);   //toto nie je yrovna peknz sposob,ale pri poslednom nacitani cisla v riadku sme uz nemali ziadnu medyeru a cyklus by sa posledny krat nevykonal, tak tu medzeru odstranujeme vzdy tu 
     76                                        int loc = line.find(',');   //ale pri poslednom cisla to nenajde ziadnu ciaarku, tak potom co prida do parsed_line? 
     77                                        parsed_line.push_back(line.substr(0,loc));       
     78                                        line.erase(0,loc+1);                            //odstranujeme ciarku za kazdym cislom 
     79                                }                                
     80                                ADdata.push_back(parsed_line); //3927 dat v riadku, 6 riadkov 
     81                        } 
     82                } 
     83                myfile.close();  //konec nacitavania dat 
     84 
     85                vector<vec> norm; //do norm zapisujeme normalizacne faktory 
     86                for (int h=1;h<=2;h++) //cyklus ktory ovplzvnuje konstantu h=1- model s konstantou, h=2, bez konstanty 
     87                {  
     88                        bool b;                 //b pouzivame pri set_constant 
     89                        if(h==2) 
     90                                b=false;    
     91                        else 
     92                                b=true; 
     93                        int g=2; 
     94                        while (g<=4)  //cyklus co meni rozmery matice V 
     95                        { 
     96                                mat V0 = 0.0001 * eye ( g ); // aj tato matica ma vplyv na normalizacny faktor, nemoze byt aj preto taky velky, ako inak by sa dala zvolit? 
     97                                 
     98                                int p=0; 
     99                                while (p<=1)  //tento cyklus prechadza vacsinou len raz, vtedy p=0 a nic to neovplvni, ale pri AR(2) modely to bude vykonavat 2 krat aj pre p=1, ked bude brat do condition aj rozne kanale z toho isteho casu  
     100                                { 
     101                                        int i=0; 
     102                                        while(i < ADdata.size()-p) //niekedy sa ten cyklus ma vykonat len raz, preto nepouzivam for cyklus 
     103                                        {        
     104                                                int j=p*(i+1); //j=0 alebo j=i+1 
     105                                         
     106                                                while(j < ADdata.size()) 
     107                                                { 
     108                                                        ARX Ar; 
     109                                                        Ar.set_statistics ( 1, V0 ); //nu is default (set to have finite moments) 
     110                                                        Ar.set_constant ( b ); 
     111                                                        Ar.validate();  // forgetting is default: 1.0 
     112                                                        vec pomocka;  //pri kazdej jednej hypoteze zapisujeme normalizacne faktory do pomocky, tu potom ako riadok pridame do norm 
     113                                                        for(int k = 0;k<341;k++) //prechadyame "po riadkoch", teda v case. Nejake hodnoty su len po index 340, dalej uz #INF000 
     114                                                        { 
     115                                                                vec condition;   
     116                                                                vec predikce; 
     117                                                                predikce.ins(0,ADdata[3][k+2]);                 //predpovede nacitavame a zadavame do Bayes zvlast 
     118                                                                condition.ins(0,ADdata[i][k+1]);                                         
     119                                                                condition.ins(0,ADdata[j][k+p]);//zmena i -> j aby to bralo regresory z roznych riadkov, ak p=1 bereme data z toho isteho casu 
     120                                                                 
     121                                                                cout << "Pred:" << predikce << ", "; 
     122                                                                cout << "Cond:" << condition << endl; 
     123                                                                 
     124                                                                Ar.bayes(predikce,condition.right(g+h-3));      //z condition berem len urcity pocet prvkov, bud 0, 1,alebo 2, lebo nepotrebujem vzdy vsetky (AR(1) model)                                       
     125                                                                pomocka.ins(pomocka.size(),Ar.posterior().lognc()); //nie je tu exponenciala! -aby to bolo mensie 
     126                                                        }                                        
     127                                                        norm.push_back(pomocka);   
     128                                                        if ((g==3 && h==2) || (g==4))  //tento cyklus sa bude opakovat, len ak mame maticu V0 roymeru 4x4, to je AR(2) model s konst, alebo podobne len g=3, h=2, teda AR(2)bez kons 
     129                                                        { 
     130                                                                j++; 
     131                                                        } else 
     132                                                        { 
     133                                                                j=ADdata.size();        //priradenim tejto hodnoty do j sa cyklus uz viac krat nevykona 
     134                                                        } 
     135                                                } 
     136                                                if (b==true && g==2) //pre model AR(0) s konstantou robi tento cyklus len raz, v ostatnych pripadoch viac-krat 
     137                                                { 
     138                                                        i=ADdata.size(); 
     139                                                } else 
     140                                                { 
     141                                                        i++; 
     142                                                } 
     143                                        } 
     144                                        if ((g==3 && h==2) || (g==4) ) 
     145                                        {p++;} else {p=2;} 
     146                                } 
     147                                if (h==2 && g==3) //pripad g=4, a konstanta zaroven nas uz nezaujima, vtedy to ukoncime 
     148                                { 
     149                                        g=5; //ak priradime takuto hodnotu, cyklus while sa uz nevykona 
     150                                } else 
     151                                { 
     152                                        g++; 
     153                                } 
     154                        } 
     155                } 
     156 
     157                /*  //tu je to povodne 
     158                mat V0 = 0.0001 * eye ( 2 );  //pre pripad samotnej konstanty 
     159                ARX Ar; 
     160                Ar.set_statistics ( 1, V0 ); //nu is default (set to have finite moments) 
     161                Ar.set_constant ( true ); 
     162                Ar.validate();                  // forgetting is default: 1.0 
     163                vector<double> pom1; 
     164                for(int k = 0;k<140;k++) //prechadyame "po riadkoch"  
     165                        { 
     166                                vec predikce; 
     167                                vec cond; 
     168                                cond.ins(0,ADdata[3][3]); 
     169                                predikce.ins(0,ADdata[3][k+2]);                 //predpovede nacitavame a zadavame do Bayes zvlast 
     170                                Ar.bayes(predikce,cond.right(0));                                        
     171                                pom1.push_back(exp(Ar.posterior().lognc())); 
     172                        }   
     173                norm.push_back(pom1);   
     174                 
     175                for (int a=2;a<=3;a++)  //AR(1) bez a potom s konstantou 
     176                { 
     177                        bool b=false;                   //b pouzivame pri set_constant 
     178                        if(a==3) 
     179                                b=true; 
     180                        mat V0 = 0.0001 * eye ( a );  //pre pripad samotnej konstanty 
     181                         
     182                        for (int p=0;p < ADdata.size();p++) 
     183                        { 
     184                                ARX Ar; 
     185                                Ar.set_statistics ( 1, V0 ); //nu is default (set to have finite moments) 
     186                                Ar.set_constant ( b ); 
     187                                Ar.validate();                  // forgetting is default: 1.0 
     188                                vector<double> pom1; 
     189                                for(int k = 0;k<140;k++) //prechadyame "po riadkoch"  
     190                                { 
     191                                        vec predikce; 
     192                                        vec condition; 
     193                                        condition.ins(0,ADdata[p][k]); 
     194                                        predikce.ins(0,ADdata[3][k+1]);                 //predpovede nacitavame a zadavame do Bayes zvlast 
     195                                        Ar.bayes(predikce,condition);                                    
     196                                        pom1.push_back(exp(Ar.posterior().lognc())); 
     197                                }   
     198                                norm.push_back(pom1);  //normalizacne faktory pre urcitu kombinaciu regresorov(teda po kazdom riadku) ulozi do pola norm 
     199                        } 
     200                } 
     201                 
     202                 
     203                for (int g=3;g<=4;g++)  //tento cyklus je az do konca, raz to robime s konstantou, raz bez. 
     204                { 
     205                        bool b;                 //b pouzivame pri set_constant 
     206                        if(g==3) 
     207                                b=false;    
     208                        else 
     209                                b=true; 
     210                        mat V0 = 0.0001 * eye ( g ); 
     211                        for(int i = 0;i < ADdata.size();i++) //po pocet riadkov, co bz malo byt 6 
     212                        { 
     213                                for(int j = i+1; j<ADdata.size();j++) 
     214                                { 
     215                                        ARX Ar; 
     216                                        Ar.set_statistics ( 1, V0 ); //nu is default (set to have finite moments) 
     217                                        Ar.set_constant ( b ); 
     218                                        Ar.validate(); 
     219                                                        // forgetting is default: 1.0 
     220                                        vector<double> pomocka; 
     221                                        for(int k = 0;k<140;k++) //prechadyame "po riadkoch"  
     222                                        { 
     223                                                vec condition;   
     224                                                vec predikce; 
     225                                                predikce.ins(0,ADdata[3][k+1]);                 //predpovede nacitavame a zadavame do Bayes zvlast 
     226                                                condition.ins(0,ADdata[i][k]);                                           
     227                                                condition.ins(0,ADdata[j][k]);//zmena i -> j qby to bralo regresory z roznych riadkov                    
     228                                                Ar.bayes(predikce,condition);                                    
     229                                                pomocka.push_back(exp(Ar.posterior().lognc())); 
     230                                        }                                        
     231                                        norm.push_back(pomocka);   
     232                                } 
     233                        }                
     234                        for(int i = 0;i < ADdata.size();i++) //po pocet riadkov, co bz malo byt 6 
     235                        { 
     236                                for(int j = 0; j<ADdata.size();j++) 
     237                                { 
     238                                        ARX Ar; 
     239                                        Ar.set_statistics ( 1, V0 ); //nu is default (set to have finite moments) 
     240                                        Ar.set_constant ( b ); 
     241                                        Ar.validate(); 
     242                                                        // forgetting is default: 1.0 
     243                                        vector<double> pomocka; 
     244                                        for(int k = 0;k<140;k++) //prechadyame "po riadkoch"  
     245                                        { 
     246                                                vec condition;   
     247                                                vec predikce; 
     248                                                predikce.ins(0,ADdata[3][k+2]);                 //predpovede nacitavame a zadavame do Bayes zvlast 
     249                                                condition.ins(0,ADdata[i][k]);  
     250                                                 
     251                                                condition.ins(0,ADdata[j][k+1]);//zmena i -> j qby to bralo regresory z roznych riadkov                  
     252                                                Ar.bayes(predikce,condition);                                    
     253                                                pomocka.push_back(Ar.posterior().lognc()); 
     254                                        }   
     255                                         
     256                                        norm.push_back(pomocka);   
     257                                } 
     258                        } 
     259                }*/ 
     260                        vector<vec> prsti; //hypotez je 85 
     261                        int m,n,p; 
     262                        for(p=0;p<115;p++) //inicializuem apriorne pravdepodobnosti 
     263                        { 
     264                                vec k; 
     265                                k.ins(0,1/115.); 
     266                                prsti.push_back(k); 
     267                        } 
     268                        // v ramci riadku v poli norm su hodnoty pre jednu hypotezu v roznych casoch, pocitanie pravdepodobnosti z norm. faktorov 
     269                        for (m=0;m<norm[1].size();m++)  
     270                        {       double k=sumastlpec(m,norm,prsti); 
     271                                for(n=0;n < norm.size();n++) 
     272                                { 
     273                                        prsti[n].ins(prsti[n].size(),norm[n][m]*prsti[n][m]/k);                          
     274                                } 
     275                        }                
     276                        ofstream file;  //zapis pravdepodobnosti do suboru 
     277                        file.open("prsti_hypot.txt"); 
     278                        for(int i=0;i < prsti.size();i++) 
     279                        { 
     280                                for(int j=0;j < prsti[i].size();j++) 
     281                                { 
     282                                        if(j!=prsti[i].size()-1) 
     283                                        { 
     284                                                file << prsti[i][j]<<" "; 
     285                                        }else 
     286                                        { 
     287                                                file<<prsti[i][j]<<endl; 
     288                                        }                                        
     289                                } 
     290                        } 
     291                        file<<endl; 
     292                        file.close(); 
     293                 
     294        } 
     295 
     296 
     297