Changeset 1389 for applications/robust
- Timestamp:
- 09/13/11 19:44:06 (13 years ago)
- Location:
- applications/robust
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/robust/main.cpp
r1384 r1389 28 28 29 29 const int max_model_order = 2; 30 const double apriorno = 0.0 01;30 const double apriorno = 0.01; 31 31 32 32 /* … … 99 99 if(has_constant) 100 100 { 101 my_rarx = new RARX(ar_components.size()+1,window_size,true, apriorno*sqrt(2.0),apriorno*sqrt(2.0),ar_components.size()+4);101 my_rarx = new RARX(ar_components.size()+1,window_size,true,sqrt(2*apriorno),sqrt(2*apriorno),ar_components.size()+4); 102 102 my_arx = NULL; 103 103 } 104 104 else 105 105 { 106 my_rarx = new RARX(ar_components.size(),window_size,false, apriorno*sqrt(2.0),apriorno*sqrt(2.0),ar_components.size()+3);106 my_rarx = new RARX(ar_components.size(),window_size,false,sqrt(2*apriorno),sqrt(2*apriorno),ar_components.size()+3); 107 107 my_arx = NULL; 108 108 } … … 274 274 vector<vector<string>> strings; 275 275 276 char* file_string = "C:\\ Users\\Hontik\\Desktop\\Bayes\\dataADClosePercDiff"; // "C:\\Users\\Hontik\\Desktop\\Bayes\\ar_normal_single"; //276 char* file_string = "C:\\ar_student_single"; //"C:\\Users\\Hontik\\Desktop\\Bayes\\dataADClosePercDiff"; // 277 277 278 278 char dfstring[80]; … … 332 332 char fstring[80]; 333 333 strcpy(fstring,file_string); 334 strcat(fstring,"lognc.txt");335 //strcat(fstring,"preds.txt");334 //strcat(fstring,"lognc.txt"); 335 strcat(fstring,"preds.txt"); 336 336 337 337 for(int time = max_model_order;time<data_matrix.cols();time++) //time<data_matrix.cols() … … 356 356 } 357 357 358 pair<vec,vec> predictions = (*model_ref)->predict( 20,time,&LapRNG);358 pair<vec,vec> predictions = (*model_ref)->predict(500,time,&LapRNG); 359 359 360 360 cout << predictions.first << endl << predictions.second << endl; … … 364 364 (*model_ref)->predictions.ins((*model_ref)->predictions.size(),avg_prediction); 365 365 366 /*366 367 367 myfilew.open(fstring,ios::app); 368 368 myfilew << avg_prediction << ","; 369 369 myfilew.close(); 370 */370 371 371 372 372 //preds.ins(0,data_matrix.get(0,time+1)); 373 373 } 374 374 375 /*375 376 376 myfilew.open(fstring,ios::app); 377 377 myfilew << data_matrix.get(0,time+1) << endl; 378 378 myfilew.close(); 379 */379 380 380 381 381 result_lognc.ins_col(result_lognc.cols(),cur_res_lognc); … … 424 424 } 425 425 426 /* 426 427 for(int i = 0;i<cur_res_lognc.size();i++) 427 428 { 428 429 myfilew << cur_res_lognc[i] << ' ';//zmenil som ciarku ze medzeru 429 430 } 431 */ 430 432 431 433 myfilew << endl; -
applications/robust/robustlib.h
r1384 r1389 21 21 using namespace std; 22 22 using namespace itpp; 23 24 static Exponential_RNG ExpRNG; 23 25 24 26 const double max_range = 5;//numeric_limits<double>::max()/10e-10; … … 1372 1374 { 1373 1375 condition_to_add = new condition(toadd); 1374 conditions.push_back( new_condition);1376 conditions.push_back(condition_to_add); 1375 1377 } 1376 1378 … … 2618 2620 pair<double,double> probability_and_sigma = choose_sigma(condition_and_simplex.second); 2619 2621 2620 int dimension = condition_and_simplex.second->vertices.size()-1; 2621 2622 mat jacobian(dimension,dimension); 2623 vec gradient = condition_and_simplex.first.right(dimension); 2624 2625 vertex* base_vert = *condition_and_simplex.second->vertices.begin(); 2626 2627 //// cout << "Base vertex coords(should be close to est. param.): " << base_vert->get_coordinates() << endl; 2622 int dimension = condition_and_simplex.second->vertices.size(); 2623 2624 mat jacobian(dimension,dimension-1); 2625 vec gradient = condition_and_simplex.first; 2628 2626 2629 2627 int row_count = 0; 2630 2628 2631 for(set<vertex*>::iterator vert_ref = ++condition_and_simplex.second->vertices.begin();vert_ref!=condition_and_simplex.second->vertices.end();vert_ref++) 2632 { 2633 vec current_coords = (*vert_ref)->get_coordinates(); 2634 2635 //// cout << "Coords of vertex[" << row_count << "]: " << current_coords << endl; 2636 2637 vec relative_coords = current_coords-base_vert->get_coordinates(); 2638 2639 jacobian.set_row(row_count,relative_coords); 2640 2629 for(set<vertex*>::iterator vert_ref = condition_and_simplex.second->vertices.begin();vert_ref!=condition_and_simplex.second->vertices.end();vert_ref++) 2630 { 2631 jacobian.set_row(row_count,(*vert_ref)->get_coordinates()); 2641 2632 row_count++; 2642 } 2643 2644 //// cout << "Jacobian: " << jacobian << endl; 2645 2646 /// \todo Is this correct? Are the random coordinates really jointly uniform? I don't know. 2633 } 2634 2635 ExpRNG.setup(1); 2636 2647 2637 vec sample_coords; 2648 double sampl ing_diff = 1;2649 for(int j = 0;j< number_of_parameters;j++)2650 { 2651 double rnumber = randu()*sampling_diff;2652 2653 sample_ coords.ins(0,rnumber);2654 2655 sampl ing_diff -= rnumber;2638 double sample_sum = 0; 2639 for(int j = 0;j<dimension;j++) 2640 { 2641 double rnumber = ExpRNG(); 2642 2643 sample_sum += rnumber; 2644 2645 sample_coords.ins(0,rnumber); 2656 2646 } 2657 2647 2658 sample_coords = jacobian.T()*sample_coords+(*base_vert).get_coordinates(); 2648 sample_coords /= sample_sum; 2649 2650 sample_coords = jacobian.T()*sample_coords; 2659 2651 2660 2652 vec extended_coords = sample_coords; … … 2662 2654 2663 2655 double exponent = extended_coords*condition_and_simplex.first; 2664 double sample_prob = 1/ condition_and_simplex.second->probability/pow(probability_and_sigma.second,(int)conditions.size()-number_of_parameters+3)*exp((-1)/probability_and_sigma.second*exponent);2656 double sample_prob = 1/pow(probability_and_sigma.second,(int)conditions.size()-number_of_parameters+3)*exp((-1)/probability_and_sigma.second*exponent); 2665 2657 sample_prob *= probability_and_sigma.first; 2666 2658