Show
Ignore:
Timestamp:
09/29/11 16:28:33 (13 years ago)
Author:
sindj
Message:

Sampling finished. First experiments set up properly - sampling from posterior on parameters. JS

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • applications/robust/main.cpp

    r1395 r1396  
    2929const int max_model_order = 1; 
    3030const double apriorno     = 0.01; 
     31const int max_window_size = 121; 
    3132 
    3233/* 
     
    148149                                 
    149150                                V0  = apriorno * eye(ar_components.size()+1);//menit konstantu 
    150                                 //V0(0,0) = 0; 
     151                                //V0(0,1) = -0.01; 
     152                                //V0(1,0) = -0.01; 
    151153                                my_arx->set_constant(false);                             
    152154                                 
     
    156158                        my_arx->set_parameters(window_size); 
    157159                        my_arx->validate(); 
     160 
     161                        vec mean = my_arx->posterior().mean(); 
     162                        cout << mean << endl; 
    158163                } 
    159164        } 
     
    190195                if(my_rarx!=NULL) 
    191196                { 
    192                         pair<vec,mat> imp_samples = my_rarx->posterior->importance_sample(sample_size); 
     197                        pair<vec,mat> imp_samples = my_rarx->posterior->sample(sample_size,false); 
    193198 
    194199                        //cout << imp_samples.first << endl;                     
     
    298303        vector<vector<string>> strings; 
    299304 
    300         char* file_string =  "C:\\ar_student_single"; // "C:\\dataADClosePercDiff"; //   
     305        char* file_string =  "C:\\results\\cauchy"; // "C:\\dataADClosePercDiff"; //   
    301306 
    302307        char dfstring[80]; 
     
    338343        for(set<set<pair<int,int>>>::iterator model_type = model_types.begin();model_type!=model_types.end();model_type++) 
    339344        {// prechadza rozne typy kanalov, a poctu regresorov 
    340                 for(int window_size = 50;window_size < 51;window_size++) 
    341                 { 
    342                         models.push_back(new model((*model_type),true,true,window_size,0,&data_matrix));   // to su len konstruktory, len inicializujeme rozne typy 
    343                         models.push_back(new model((*model_type),false,true,window_size,0,&data_matrix)); 
     345                for(int window_size = max_window_size-1;window_size < max_window_size;window_size++) 
     346                { 
     347                        //models.push_back(new model((*model_type),true,true,window_size,0,&data_matrix));   // to su len konstruktory, len inicializujeme rozne typy 
     348                        //models.push_back(new model((*model_type),false,true,window_size,0,&data_matrix)); 
    344349                        models.push_back(new model((*model_type),true,false,window_size,0,&data_matrix)); 
    345350                        models.push_back(new model((*model_type),false,false,window_size,0,&data_matrix));               
     
    360365 
    361366        for(int time = max_model_order;time<data_matrix.cols();time++) //time<data_matrix.cols()  
    362         {       //pocet stlpcov data_matrix je pocet casovych krokov 
     367        {        
     368                if(time==max_window_size) 
     369                { 
     370                        exit(1); 
     371                } 
     372                 
     373                //pocet stlpcov data_matrix je pocet casovych krokov 
    363374                vec cur_res_lognc; 
    364375                // vec preds; 
     
    373384                        if((*model_ref)->my_rarx!=NULL) //vklada normalizacni faktor do cur_res_lognc 
    374385                        { 
     386                                cout << "Maxlik vertex:" << (*model_ref)->my_rarx->posterior->minimal_vertex->get_coordinates() << endl; 
    375387                                cur_res_lognc.ins(cur_res_lognc.size(),(*model_ref)->my_rarx->posterior->_ll());                                 
    376388                        } 
     
    379391                                cur_res_lognc.ins(cur_res_lognc.size(),(*model_ref)->my_arx->_ll()); 
    380392                        } 
    381  
    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                         } 
    393393                         
    394                         for(int i=0;i<(*model_ref)->ar_components.size()+1;i++) 
    395                         { 
     394                        if(time == max_window_size-1) 
     395                        { 
     396                                //*********************** 
     397                                int sample_size = 100000; 
     398                                //*********************** 
     399                                 
     400                                pair<vec,mat> samples; 
     401                                if((*model_ref)->my_arx!=NULL) 
     402                                { 
     403                                        mat samp_mat = (*model_ref)->my_arx->posterior().sample_mat(sample_size); 
     404                                        samples = pair<vec,mat>(ones(samp_mat.cols()),samp_mat); 
     405                                } 
     406                                else 
     407                                { 
     408                                        samples = (*model_ref)->my_rarx->posterior->sample(sample_size,true);                                    
     409                                } 
     410 
    396411                                char fstring[80];                                        
    397412                                strcpy(fstring,file_string); 
     
    399414                                strcat(fstring,".txt"); 
    400415                                 
    401                                 cout << samples.first << endl; 
     416                                //cout << samples.first << endl; 
    402417                                 
    403418                                myfilew.open(fstring,ios::app); 
    404                                 myfilew << samples.first << endl << samples.second << endl << zeros(samples.first.size()) << endl;  
    405                                 myfilew.close(); 
    406                         }                        
     419                                 
     420                                /* 
     421                                for(int i = 0;i<samples.first.size();i++) 
     422                                { 
     423                                        myfilew << samples.first.get(i) << ","; 
     424                                } 
     425                                myfilew << endl; 
     426                                */ 
     427 
     428                                for(int j = 0;j<samples.second.rows()+1;j++) 
     429                                {                        
     430                                        for(int i = 0;i<samples.second.cols();i++) 
     431                                        { 
     432                                                if(j!=samples.second.rows()) 
     433                                                { 
     434                                                        myfilew << samples.second.get(j,i) << ","; 
     435                                                } 
     436                                                /* 
     437                                                else 
     438                                                { 
     439                                                        myfilew << "0,"; 
     440                                                } 
     441                                                */ 
     442                                        }                                
     443                                        myfilew << endl; 
     444                                } 
     445 
     446                                cout << "*************************************" << endl; 
     447 
     448                                myfilew.close();                                 
     449                        } 
    407450                         
    408451                        /* // PREDICTIONS