Changeset 1393 for applications
- Timestamp:
- 09/19/11 13:43:58 (13 years ago)
- Location:
- applications/robust
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/robust/main.cpp
r1390 r1393 27 27 //const int utility_constant = 5; 28 28 29 const int max_model_order = 2;29 const int max_model_order = 1; 30 30 const double apriorno = 0.01; 31 31 … … 81 81 mat* data_matrix; 82 82 vec predictions; 83 char name[80]; 83 84 84 85 model(set<pair<int,int>> ar_components, //funkcie treidz model-konstruktor … … 90 91 { 91 92 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 92 108 this->has_constant = has_constant; 109 110 if(has_constant) 111 { 112 strcat(name,"C"); 113 } 114 93 115 this->window_size = window_size; 94 116 this->predicted_channel = predicted_channel; … … 97 119 if(robust) 98 120 { 121 strcat(name,"R"); 122 99 123 if(has_constant) 100 124 { … … 168 192 pair<vec,mat> imp_samples = my_rarx->posterior->importance_sample(sample_size); 169 193 170 //cout << imp_samples.first << endl; 194 //cout << imp_samples.first << endl; 171 195 172 196 vec sample_prediction; … … 180 204 } 181 205 182 lap_sample.ins( 0,(*LapRNG)());206 lap_sample.ins(lap_sample.size(),(*LapRNG)()); 183 207 184 208 sample_prediction.ins(0,lap_sample*imp_samples.second.get_col(t)); … … 186 210 187 211 return pair<vec,vec>(imp_samples.first,sample_prediction); 188 } 212 } 189 213 else 190 214 { … … 274 298 vector<vector<string>> strings; 275 299 276 char* file_string = "C:\\ dataADClosePercDiff"; // "C:\\ar_student_single"; //300 char* file_string = "C:\\results\\ar_student_single"; // "C:\\dataADClosePercDiff"; // 277 301 278 302 char dfstring[80]; … … 330 354 331 355 ofstream myfilew; 332 char fstring[80];333 strcpy(fstring,file_string);356 //char fstring[80]; 357 //strcpy(fstring,file_string); 334 358 //strcat(fstring,"lognc.txt"); 335 strcat(fstring,"preds.txt");359 //strcat(fstring,"preds.txt"); 336 360 337 361 for(int time = max_model_order;time<data_matrix.cols();time++) //time<data_matrix.cols() … … 347 371 //if (time = max_model_order) nazvy.push_back(models.model_ref]);// ako by som mohol dostat nazov modelu? 348 372 349 if((*model_ref)->my_rarx!=NULL) //vklada normalizacn zfaktor do cur_res_lognc373 if((*model_ref)->my_rarx!=NULL) //vklada normalizacni faktor do cur_res_lognc 350 374 { 351 375 cur_res_lognc.ins(cur_res_lognc.size(),(*model_ref)->my_rarx->posterior->_ll()); … … 356 380 } 357 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 } 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 358 409 pair<vec,vec> predictions = (*model_ref)->predict(500,time,&LapRNG); 359 410 … … 363 414 364 415 (*model_ref)->predictions.ins((*model_ref)->predictions.size(),avg_prediction); 365 366 416 367 417 myfilew.open(fstring,ios::app); 368 myfilew << avg_prediction << ","; 418 myfilew << avg_prediction << ","; 369 419 myfilew.close(); 370 420 */ 371 421 372 422 //preds.ins(0,data_matrix.get(0,time+1)); … … 374 424 375 425 426 /* // REAL PRICE 376 427 myfilew.open(fstring,ios::app); 377 428 myfilew << data_matrix.get(0,time+1) << endl; 378 429 myfilew.close(); 379 430 */ 380 431 381 432 result_lognc.ins_col(result_lognc.cols(),cur_res_lognc); … … 384 435 // cout << "Updated." << endl; 385 436 386 437 /* 387 438 myfilew.open(fstring,ios::app); 388 439 … … 424 475 } 425 476 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(); 431 487 */ 432 433 myfilew << endl;434 435 myfilew.close();436 488 437 489 } -
applications/robust/robustlib.h
r1390 r1393 2657 2657 sample_prob *= probability_and_sigma.first; 2658 2658 2659 sample_coords.ins( 0,probability_and_sigma.second);2659 sample_coords.ins(sample_coords.size(),probability_and_sigma.second); 2660 2660 2661 2661 samples.ins_col(0,sample_coords);