Changeset 1396 for applications/robust/main.cpp
- Timestamp:
- 09/29/11 16:28:33 (13 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/robust/main.cpp
r1395 r1396 29 29 const int max_model_order = 1; 30 30 const double apriorno = 0.01; 31 const int max_window_size = 121; 31 32 32 33 /* … … 148 149 149 150 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; 151 153 my_arx->set_constant(false); 152 154 … … 156 158 my_arx->set_parameters(window_size); 157 159 my_arx->validate(); 160 161 vec mean = my_arx->posterior().mean(); 162 cout << mean << endl; 158 163 } 159 164 } … … 190 195 if(my_rarx!=NULL) 191 196 { 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); 193 198 194 199 //cout << imp_samples.first << endl; … … 298 303 vector<vector<string>> strings; 299 304 300 char* file_string = "C:\\ ar_student_single"; // "C:\\dataADClosePercDiff"; //305 char* file_string = "C:\\results\\cauchy"; // "C:\\dataADClosePercDiff"; // 301 306 302 307 char dfstring[80]; … … 338 343 for(set<set<pair<int,int>>>::iterator model_type = model_types.begin();model_type!=model_types.end();model_type++) 339 344 {// 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 typy343 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)); 344 349 models.push_back(new model((*model_type),true,false,window_size,0,&data_matrix)); 345 350 models.push_back(new model((*model_type),false,false,window_size,0,&data_matrix)); … … 360 365 361 366 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 363 374 vec cur_res_lognc; 364 375 // vec preds; … … 373 384 if((*model_ref)->my_rarx!=NULL) //vklada normalizacni faktor do cur_res_lognc 374 385 { 386 cout << "Maxlik vertex:" << (*model_ref)->my_rarx->posterior->minimal_vertex->get_coordinates() << endl; 375 387 cur_res_lognc.ins(cur_res_lognc.size(),(*model_ref)->my_rarx->posterior->_ll()); 376 388 } … … 379 391 cur_res_lognc.ins(cur_res_lognc.size(),(*model_ref)->my_arx->_ll()); 380 392 } 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 else390 {391 samples = (*model_ref)->my_rarx->posterior->importance_sample(sample_size);392 }393 393 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 396 411 char fstring[80]; 397 412 strcpy(fstring,file_string); … … 399 414 strcat(fstring,".txt"); 400 415 401 cout << samples.first << endl;416 //cout << samples.first << endl; 402 417 403 418 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 } 407 450 408 451 /* // PREDICTIONS