Show
Ignore:
Timestamp:
03/21/11 09:01:57 (13 years ago)
Author:
sindj
Message:

Dokoncovani mergovani polyhedronu a oprava chyb. Mergovani je skoro dokonceno, ale je tam nekde skryta chybka. JS

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • applications/robust/main.cpp

    r1300 r1301  
    2121         
    2222        /* 
     23        // EXPERIMENT: 100 AR model generated time series of length of 30 from y_t=0.95*y_(t-1)+0.05*y_(t-2)+0.2*e_t,  
     24        // where e_t is normally, student(4) and cauchy distributed are tested using robust AR model, to obtain the  
     25        // variance of location parameter estimators and compare it to the classical setup. 
    2326        vector<vector<vector<string>>> string_lists; 
    2427        string_lists.push_back(vector<vector<string>>()); 
     
    5558        for(int j = 0;j<string_lists.size();j++) 
    5659        {  
    57                 /* 
     60                 
    5861                for(int i = 0;i<string_lists[j].size()-1;i++) 
    5962                { 
    6063                        vector<vec> conditions; 
    61                         emlig* emliga = new emlig(2); 
     64                        //emlig* emliga = new emlig(2); 
     65                        RARX* my_rarx = new RARX(2,30); 
     66 
    6267                        for(int k = 1;k<string_lists[j][i].size();k++) 
    6368                        { 
     
    8186                                        //cout << "modi:" << conditions[k-3] << endl; 
    8287 
    83                                         emliga->add_condition(conditions[k-3]); 
     88                                        my_rarx->bayes(conditions[k-3]); 
    8489 
    8590                                         
     
    9499 
    95100                        //emliga->step_me(0); 
     101                        /* 
    96102                        ofstream myfile; 
    97103                        myfile.open("c:\\robust_ar1.txt",ios::app); 
    98                         myfile << emliga->minimal_vertex->get_coordinates()[0] << ";"; 
     104                        myfile << my_rarx->minimal_vertex->get_coordinates()[0] << ";"; 
    99105                        myfile.close(); 
    100106 
     
    102108                        myfile << emliga->minimal_vertex->get_coordinates()[1] << ";"; 
    103109                        myfile.close(); 
     110                         
    104111 
    105112                        cout << "MaxLik coords:" << emliga->minimal_vertex->get_coordinates() << endl; 
     
    117124                myfile << endl; 
    118125                myfile.close(); 
    119         } 
    120     */ 
    121          
    122          
    123         emlig* emlig1 = new emlig(emlig_size); 
    124         emlig* emlig2 = new emlig(emlig_size); 
     126        }*/ 
     127     
     128         
     129        // EXPERIMENT: A moving window estimation and prediction of RARX is tested on data generated from  
     130    // y_t=0.95*y_(t-1)+0.05*y_(t-2)+0.2*e_t, where e_t is normally, student(4) and cauchy distributed. It 
     131    // can be compared to the classical setup. 
     132         
     133 
     134        vector<vector<string>> strings; 
     135 
     136        char* file_strings[3] = {"c:\\ar_student_single.txt", "c:\\ar_cauchy_single.txt","c:\\ar_normal_single.txt"}; 
     137 
     138        for(int i = 0;i<3;i++) 
     139        {                        
     140                ifstream myfile(file_strings[i]); 
     141                if (myfile.is_open()) 
     142                {                        
     143                        string line; 
     144                        getline(myfile,line); 
     145                                 
     146                        vector<string> parsed_line; 
     147                        while(line.find(',') != string::npos) 
     148                        { 
     149                                int loc = line.find(','); 
     150                                parsed_line.push_back(line.substr(0,loc)); 
     151                                line.erase(0,loc+1);                                     
     152                        }                                
     153 
     154                        strings.push_back(parsed_line); 
     155                         
     156                        myfile.close(); 
     157                } 
     158        } 
     159         
     160        for(int j = 0;j<strings.size();j++) 
     161        {                
     162                vector<vec> conditions; 
     163                //emlig* emliga = new emlig(2); 
     164                RARX* my_rarx = new RARX(2,0); 
     165 
     166                for(int k = 1;k<170;k++) 
     167                { 
     168                        vec condition; 
     169                        //condition.ins(0,1);                            
     170                        condition.ins(0,strings[j][k]);                          
     171                        conditions.push_back(condition); 
     172 
     173                        //cout << "orig:" << condition << endl; 
     174 
     175                        if(conditions.size()>1) 
     176                        {                
     177                                conditions[k-2].ins(0,strings[j][k]); 
     178                                         
     179                        } 
     180 
     181                        if(conditions.size()>2) 
     182                        { 
     183                                conditions[k-3].ins(0,strings[j][k]); 
     184 
     185                                // cout << "modi:" << conditions[k-3] << endl; 
     186 
     187                                my_rarx->bayes(conditions[k-3]); 
     188 
     189                                         
     190                                 
     191                                if(k>5) 
     192                                { 
     193                                        cout << "MaxLik coords:" << my_rarx->posterior->minimal_vertex->get_coordinates() << endl; 
     194 
     195                                        ofstream myfile; 
     196                                        char fstring[80]; 
     197                                        strcpy(fstring,file_strings[j]); 
     198                                        strcat(fstring,"_res.txt"); 
     199 
     200                                        myfile.open(fstring,ios::app); 
     201                                        myfile << my_rarx->posterior->minimal_vertex->get_coordinates()[0]; 
     202                                        if(k!=strings[j].size()-1) 
     203                                        { 
     204                                                myfile << ","; 
     205                                        } 
     206                                        else 
     207                                        { 
     208                                                myfile << endl; 
     209                                        } 
     210                                        myfile.close(); 
     211                                } 
     212                                         
     213                        }        
     214                         
     215                        //emliga->step_me(0); 
     216                        /* 
     217                        ofstream myfile; 
     218                        myfile.open("c:\\robust_ar1.txt",ios::app); 
     219                        myfile << my_rarx->minimal_vertex->get_coordinates()[0] << ";"; 
     220                        myfile.close(); 
     221 
     222                        myfile.open("c:\\robust_ar2.txt",ios::app); 
     223                        myfile << emliga->minimal_vertex->get_coordinates()[1] << ";"; 
     224                        myfile.close(); 
     225                         
     226 
     227                        cout << "MaxLik coords:" << emliga->minimal_vertex->get_coordinates() << endl; 
     228                        cout << "Step: " << i << endl;*/ 
     229                } 
     230        } 
     231                 
     232                /* 
     233                cout << "One experiment finished." << endl; 
     234 
     235                ofstream myfile; 
     236                myfile.open("c:\\robust_ar1.txt",ios::app); 
     237                myfile << endl; 
     238                myfile.close(); 
     239 
     240                myfile.open("c:\\robust_ar2.txt",ios::app); 
     241                myfile << endl; 
     242                myfile.close();*/ 
     243         
     244 
     245        //emlig* emlig1 = new emlig(emlig_size); 
     246 
     247        //emlig1->step_me(0); 
     248        //emlig* emlig2 = new emlig(emlig_size); 
    125249         
    126250        /* 
     
    142266        }*/ 
    143267         
    144          
     268        /* 
    145269    vec condition5 = "1.0 1.0 1.01";//"-0.3 1.7 1.5"; 
    146270 
    147271        emlig1->add_condition(condition5); 
    148          
    149         //vec condition1a = "1.0 1.0 1.01"; 
     272        //emlig1->step_me(0); 
     273 
     274 
     275        vec condition1a = "-1.0 1.02 0.5"; 
    150276        //vec condition1b = "1.0 1.0 1.01"; 
    151         //emlig1->add_condition(condition1a); 
     277        emlig1->add_condition(condition1a); 
    152278        //emlig2->add_condition(condition1b); 
    153279 
    154         //vec condition2a = "-1.0 1.0 1.0"; 
     280        vec condition2a = "-0.3 1.7 1.5"; 
    155281        //vec condition2b = "-1.0 1.0 1.0"; 
    156         //emlig1->add_condition(condition2a); 
     282        emlig1->add_condition(condition2a); 
    157283        //emlig2->add_condition(condition2b); 
    158284 
    159         //vec condition3a = "0.5 -1.01 1.0"; 
     285        vec condition3a = "0.5 -1.01 1.0"; 
    160286        //vec condition3b = "0.5 -1.01 1.0"; 
    161287 
    162         //emlig1->add_condition(condition3a); 
     288        emlig1->add_condition(condition3a); 
    163289        //emlig2->add_condition(condition3b);    
    164290 
    165         //vec condition4a = "-0.5 -1.0 1.0"; 
     291        vec condition4a = "-0.5 -1.0 1.0"; 
    166292        //vec condition4b = "-0.5 -1.0 1.0";     
    167293 
    168         //emlig1->add_condition(condition4a); 
     294        emlig1->add_condition(condition4a); 
    169295        //cout << "************************************************" << endl; 
    170296        //emlig2->add_condition(condition4b); 
     
    173299        //cout << emlig1->minimal_vertex->get_coordinates(); 
    174300         
    175         emlig1->remove_condition(condition5); 
     301        //emlig1->remove_condition(condition3a); 
     302        //emlig1->step_me(0); 
     303        //emlig1->remove_condition(condition2a); 
     304        //emlig1->remove_condition(condition1a); 
     305        //emlig1->remove_condition(condition5); 
     306         
    176307 
    177308        //emlig1->step_me(0); 
     
    183314 
    184315        //emlig1->remove_condition(condition1); 
    185  
    186          
    187  
    188          
    189         /* 
    190          
     316         
     317         
     318 
     319         
     320         
     321        /* 
    191322        for(int i = 0;i<100;i++) 
    192323        {