Changeset 1393 for applications

Show
Ignore:
Timestamp:
09/19/11 13:43:58 (13 years ago)
Author:
sindj
Message:
 
Location:
applications/robust
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • applications/robust/main.cpp

    r1390 r1393  
    2727//const int utility_constant = 5; 
    2828 
    29 const int max_model_order = 2; 
     29const int max_model_order = 1; 
    3030const double apriorno     = 0.01; 
    3131 
     
    8181        mat* data_matrix; 
    8282        vec  predictions; 
     83        char name[80]; 
    8384         
    8485        model(set<pair<int,int>> ar_components, //funkcie treidz model-konstruktor 
     
    9091        { 
    9192                this->ar_components.insert(ar_components.begin(),ar_components.end()); 
     93 
     94                strcpy(name,"M"); 
     95 
     96                for(set<pair<int,int>>::iterator ar_ref = ar_components.begin();ar_ref!=ar_components.end();ar_ref++) 
     97                { 
     98                        char buffer1[2]; 
     99                        char buffer2[2]; 
     100                        itoa((*ar_ref).first,buffer1,10); 
     101                        itoa((*ar_ref).second,buffer2,10); 
     102 
     103                        strcat(name,buffer1); 
     104                        strcat(name,buffer2); 
     105                        strcat(name,"_"); 
     106                } 
     107 
    92108                this->has_constant      = has_constant; 
     109 
     110                if(has_constant) 
     111                { 
     112                        strcat(name,"C"); 
     113                } 
     114 
    93115                this->window_size       = window_size; 
    94116                this->predicted_channel = predicted_channel; 
     
    97119                if(robust) 
    98120                { 
     121                        strcat(name,"R"); 
     122 
    99123                        if(has_constant) 
    100124                        { 
     
    168192                        pair<vec,mat> imp_samples = my_rarx->posterior->importance_sample(sample_size); 
    169193 
    170                         //cout << imp_samples.first << endl; 
     194                        //cout << imp_samples.first << endl;                     
    171195                         
    172196                        vec sample_prediction;                   
     
    180204                                } 
    181205                                 
    182                                 lap_sample.ins(0,(*LapRNG)()); 
     206                                lap_sample.ins(lap_sample.size(),(*LapRNG)()); 
    183207 
    184208                                sample_prediction.ins(0,lap_sample*imp_samples.second.get_col(t));                               
     
    186210 
    187211                        return pair<vec,vec>(imp_samples.first,sample_prediction); 
    188                 } 
     212                }        
    189213                else 
    190214                { 
     
    274298        vector<vector<string>> strings; 
    275299 
    276         char* file_string =  "C:\\dataADClosePercDiff"; // "C:\\ar_student_single"; //  
     300        char* file_string =  "C:\\results\\ar_student_single"; // "C:\\dataADClosePercDiff"; //  
    277301 
    278302        char dfstring[80]; 
     
    330354 
    331355        ofstream myfilew; 
    332         char fstring[80];                                        
    333         strcpy(fstring,file_string); 
     356        //char fstring[80];                                      
     357        //strcpy(fstring,file_string); 
    334358        //strcat(fstring,"lognc.txt"); 
    335         strcat(fstring,"preds.txt"); 
     359        //strcat(fstring,"preds.txt");   
    336360 
    337361        for(int time = max_model_order;time<data_matrix.cols();time++) //time<data_matrix.cols()  
     
    347371                        //if (time = max_model_order) nazvy.push_back(models.model_ref]);// ako by som mohol dostat nazov modelu? 
    348372 
    349                         if((*model_ref)->my_rarx!=NULL) //vklada normalizacnz faktor do cur_res_lognc 
     373                        if((*model_ref)->my_rarx!=NULL) //vklada normalizacni faktor do cur_res_lognc 
    350374                        { 
    351375                                cur_res_lognc.ins(cur_res_lognc.size(),(*model_ref)->my_rarx->posterior->_ll());                                 
     
    356380                        } 
    357381 
     382                        int sample_size = 10; 
     383                        pair<vec,mat> samples; 
     384                        if((*model_ref)->my_arx!=NULL) 
     385                        { 
     386                                mat samp_mat = (*model_ref)->my_arx->posterior().sample_mat(sample_size); 
     387                                samples = pair<vec,mat>(ones(samp_mat.rows()),samp_mat); 
     388                        } 
     389                        else 
     390                        { 
     391                                samples = (*model_ref)->my_rarx->posterior->importance_sample(sample_size); 
     392                        } 
     393                         
     394                        for(int i=0;i<(*model_ref)->ar_components.size()+1;i++) 
     395                        { 
     396                                char fstring[80];                                        
     397                                strcpy(fstring,file_string); 
     398                                strcat(fstring,(*model_ref)->name); 
     399                                strcat(fstring,".txt"); 
     400                                 
     401                                cout << samples.first << endl; 
     402                                 
     403                                myfilew.open(fstring,ios::app); 
     404                                myfilew << samples.first << endl << samples.second << endl << zeros(samples.first.size()) << endl;  
     405                                myfilew.close(); 
     406                        }                        
     407                         
     408                        /* // PREDICTIONS 
    358409                        pair<vec,vec> predictions = (*model_ref)->predict(500,time,&LapRNG); 
    359410 
     
    363414 
    364415                        (*model_ref)->predictions.ins((*model_ref)->predictions.size(),avg_prediction); 
    365                          
    366                          
     416                                         
    367417                        myfilew.open(fstring,ios::app); 
    368                         myfilew << avg_prediction << ","; 
     418                        myfilew << avg_prediction << ",";  
    369419                        myfilew.close(); 
    370                          
     420                        */ 
    371421 
    372422                        //preds.ins(0,data_matrix.get(0,time+1)); 
     
    374424 
    375425                 
     426                /* // REAL PRICE 
    376427                myfilew.open(fstring,ios::app); 
    377428                myfilew << data_matrix.get(0,time+1) << endl; 
    378429                myfilew.close(); 
    379                  
     430                */ 
    380431 
    381432                result_lognc.ins_col(result_lognc.cols(),cur_res_lognc); 
     
    384435                // cout << "Updated." << endl;   
    385436                                                         
    386  
     437                /* 
    387438                myfilew.open(fstring,ios::app); 
    388439                 
     
    424475                } 
    425476                 
    426                 /* 
    427                 for(int i = 0;i<cur_res_lognc.size();i++) 
    428                 { 
    429                         myfilew << cur_res_lognc[i] << ' ';//zmenil som ciarku ze medzeru 
    430                 } 
     477                 
     478                // for(int i = 0;i<cur_res_lognc.size();i++) 
     479                // { 
     480                //         myfilew << cur_res_lognc[i] << ' ';//zmenil som ciarku ze medzeru 
     481                // } 
     482                 
     483 
     484                myfilew << endl;                                 
     485                 
     486                myfilew.close(); 
    431487                */ 
    432  
    433                 myfilew << endl;                                 
    434                  
    435                 myfilew.close(); 
    436488                 
    437489} 
  • applications/robust/robustlib.h

    r1390 r1393  
    26572657                        sample_prob *= probability_and_sigma.first; 
    26582658 
    2659                         sample_coords.ins(0,probability_and_sigma.second); 
     2659                        sample_coords.ins(sample_coords.size(),probability_and_sigma.second); 
    26602660 
    26612661                        samples.ins_col(0,sample_coords);