Changeset 1338 for applications/robust
- Timestamp:
- 04/27/11 19:00:36 (14 years ago)
- Location:
- applications/robust
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/robust/main.cpp
r1337 r1338 12 12 #include <iostream> 13 13 #include <fstream> 14 #include <itpp/ signal/poly.h>14 #include <itpp/itsignal.h> 15 15 16 16 using namespace itpp; … … 138 138 vector<vector<string>> strings; 139 139 140 char* file_strings[3] = {"c:\\data ADClosePercDiff", "c:\\ar_student_single","c:\\ar_cauchy_single"};140 char* file_strings[3] = {"c:\\dataCDClosePercDiff", "c:\\ar_student_single","c:\\ar_cauchy_single"}; 141 141 142 142 for(int i = 0;i<3;i++) … … 172 172 RARX* my_rarx = new RARX(2,30,false); 173 173 174 /*174 175 175 mat V0 = 0.0001 * eye ( 3 ); 176 176 ARX* my_arx = new ARX(0.97); … … 178 178 my_arx->set_constant ( false ); 179 179 my_arx->validate(); 180 */181 182 for(int k = 1;k< 170;k++)180 181 182 for(int k = 1;k<strings[j].size();k++) 183 183 { 184 184 vec condition; … … 199 199 conditions[k-3].ins(0,strings[j][k]); 200 200 201 // cout << "modi:" << conditions[k-3] << endl;201 //cout << "Condition:" << conditions[k-3] << endl; 202 202 203 203 my_rarx->bayes(conditions[k-3]); 204 //my_rarx->posterior->step_me(1); 204 205 205 206 vec cond_vec; 206 207 cond_vec.ins(0,conditions[k-3][0]); 207 208 208 //my_arx->bayes(cond_vec,conditions[k-3].right(2));209 my_arx->bayes(cond_vec,conditions[k-3].right(2)); 209 210 210 211 211 if(k> 5)212 if(k>8) 212 213 { 213 214 //my_rarx->posterior->step_me(0); … … 219 220 { 220 221 vec lap_sample = conditions[k-3].left(2); 222 //lap_sample.ins(lap_sample.size(),1.0); 221 223 222 224 lap_sample.ins(0,LapRNG()); … … 225 227 } 226 228 229 227 230 vec sample_pow = sample_prediction; 228 231 vec poly_coefs; … … 236 239 { 237 240 sample_pow = elem_mult(sample_pow,sample_prediction); 238 poly_coefs.ins(poly_coefs.size(), pow(-1,en)*poly_coef);241 poly_coefs.ins(poly_coefs.size(),((-1)^en)*poly_coef); 239 242 } 240 243 else … … 247 250 while(!stop_iteration); 248 251 249 cvec action = 250 251 252 cout << "MaxLik coords:" << my_rarx->posterior->minimal_vertex->get_coordinates() << endl; 252 // cout << "Coefficients: " << poly_coefs << endl; 253 254 cvec actions = roots(poly_coefs); 255 bool is_max = false; 256 for(int t = 0;t<actions.size();t++) 257 { 258 if(actions[t].imag() == 0 && actions[t].real()>-1 && actions[t].real()<1) 259 { 260 cout << "Action:" << actions[t].real() << endl; 261 is_max = true; 262 } 263 } 264 265 if(!is_max) 266 { 267 cout << "No maximum." << endl; 268 } 269 270 // cout << "MaxLik coords:" << my_rarx->posterior->minimal_vertex->get_coordinates() << endl; 253 271 254 272 double prediction = 0; … … 290 308 } 291 309 292 /* 310 cout << "Prediction: "<< prediction << endl; 311 293 312 enorm<ldmat>* pred_mat = my_arx->epredictor(conditions[k-3].left(2)); 294 313 double prediction2 = pred_mat->mean()[0]; 295 */314 296 315 297 316 ofstream myfile; 298 317 char fstring[80]; 299 //char f2string[80];318 char f2string[80]; 300 319 strcpy(fstring,file_strings[j]); 301 //strcpy(f2string,fstring);320 strcpy(f2string,fstring); 302 321 303 322 strcat(fstring,"pred.txt"); 304 //strcat(f2string,"2pred.txt");323 strcat(f2string,"2pred.txt"); 305 324 306 325 307 326 myfile.open(fstring,ios::app); 308 327 309 // myfile << my_rarx->posterior->minimal_vertex->get_coordinates()[0];328 // myfile << my_rarx->posterior->minimal_vertex->get_coordinates()[0]; 310 329 myfile << prediction; 311 330 … … 320 339 myfile.close(); 321 340 322 /*341 323 342 myfile.open(f2string,ios::app); 324 343 myfile << prediction2; … … 333 352 } 334 353 myfile.close(); 335 */354 336 355 337 356 } -
applications/robust/robustlib.cpp
r1335 r1338 33 33 { 34 34 double cur_prob = 0; 35 36 /* 37 if(should_integrate&&new_simplex->vertices.size()!=3) 38 { 39 cout << "Error: Wrong vertex count for integration!"; 40 } 41 */ 35 42 36 43 if(should_integrate) -
applications/robust/robustlib.h
r1337 r1338 883 883 { 884 884 current_parent->totallyneutralgrandchildren.insert(sender->totallyneutralchildren.begin(),sender->totallyneutralchildren.end()); 885 885 886 886 for(set<polyhedron*>::iterator tot_child_ref = sender->totallyneutralchildren.begin();tot_child_ref!=sender->totallyneutralchildren.end();tot_child_ref++) 887 887 { 888 888 (*tot_child_ref)->grandparents.insert(current_parent); 889 } 890 891 if(current_parent->totally_neutral == NULL) 892 { 893 current_parent->totally_neutral = sender->totally_neutral; 894 } 895 else 896 { 897 current_parent->totally_neutral = current_parent->totally_neutral && sender->totally_neutral; 889 898 } 890 899 … … 898 907 current_parent->neutralchildren.push_back(sender); 899 908 current_parent->positiveneutralvertices.insert(sender->positiveneutralvertices.begin(),sender->positiveneutralvertices.end()); 900 current_parent->negativeneutralvertices.insert(sender->negativeneutralvertices.begin(),sender->negativeneutralvertices.end()); 901 902 if(current_parent->totally_neutral == NULL) 903 { 904 current_parent->totally_neutral = sender->totally_neutral; 905 } 906 else 907 { 908 current_parent->totally_neutral = current_parent->totally_neutral && sender->totally_neutral; 909 } 909 current_parent->negativeneutralvertices.insert(sender->negativeneutralvertices.begin(),sender->negativeneutralvertices.end()); 910 910 911 911 if(sender->totally_neutral) … … 922 922 923 923 if(is_last) 924 { 924 { 925 925 926 /// \TODO Nechapu druhou podminku, zda se mi ze je to spatne.. Nemela by byt jen prvni? Nebo se jedna o nastaveni totalni neutrality? 927 if((current_parent->negativechildren.size()>0&¤t_parent->positivechildren.size()>0)|| 928 (current_parent->neutralchildren.size()>0&¤t_parent->totally_neutral==false)) 926 if((current_parent->negativechildren.size()>0&¤t_parent->positivechildren.size()>0) 927 ||(current_parent->neutralchildren.size()>0&¤t_parent->totallyneutralchildren.empty())) 929 928 { 930 929 for_splitting[level+1].push_back(current_parent); … … 981 980 current_parent->negativechildren.clear(); 982 981 current_parent->neutralchildren.clear(); 983 current_parent->totallyneutralchildren.clear();982 //current_parent->totallyneutralchildren.clear(); 984 983 current_parent->totallyneutralgrandchildren.clear(); 985 984 // current_parent->grandparents.clear(); … … 1002 1001 1003 1002 } 1004 1003 1004 sender->totallyneutralchildren.clear(); 1005 1005 } 1006 1006 } … … 1049 1049 { 1050 1050 1051 1051 /* 1052 1052 if(i==statistic.size()-1) 1053 1053 { … … 1055 1055 cout << "Order:" << ((toprow*)horiz_ref)->condition_order << endl; 1056 1056 } 1057 */ 1058 1059 cout << "Stepped." << endl; 1057 1060 1058 1061 /* … … 1259 1262 current_vertex->negativeneutralvertices.insert(current_vertex); 1260 1263 current_vertex->positiveneutralvertices.insert(current_vertex); 1261 } 1264 } 1265 else 1266 { 1267 current_vertex->totally_neutral = false; 1268 } 1262 1269 } 1263 1270 … … 1296 1303 if(should_remove) 1297 1304 { 1305 /* 1298 1306 for(int i = 0;i<for_merging.size();i++) 1299 1307 { … … 1305 1313 cout << endl; 1306 1314 } 1315 */ 1316 1317 cout << "Merging." << endl; 1307 1318 1308 1319 set<vertex*> vertices_to_be_reduced; … … 1407 1418 } 1408 1419 1420 /* 1409 1421 current_positive->totallyneutralchildren.insert(current_negative->totallyneutralchildren.begin(),current_negative->totallyneutralchildren.end()); 1410 1422 1411 1423 current_positive->totallyneutralchildren.erase(*merge_ref); 1424 */ 1412 1425 1413 1426 current_positive->totallyneutralgrandchildren.insert(current_negative->totallyneutralgrandchildren.begin(),current_negative->totallyneutralgrandchildren.end()); … … 1423 1436 current_positive->negativechildren.clear(); 1424 1437 current_positive->neutralchildren.clear(); 1425 current_positive->totallyneutralchildren.clear();1438 // current_positive->totallyneutralchildren.clear(); 1426 1439 current_positive->totallyneutralgrandchildren.clear(); 1427 1440 current_positive->positiveneutralvertices.clear(); … … 1558 1571 } 1559 1572 1573 /* 1560 1574 vector<int> sizevector; 1561 1575 for(int s = 0;s<statistic.size();s++) … … 1564 1578 cout << statistic.row_size(s) << ", "; 1565 1579 } 1566 1567 cout << endl; 1580 */ 1581 1582 //cout << endl; 1583 1584 // this->step_me(2); 1568 1585 1569 1586 if(should_add) … … 1722 1739 } 1723 1740 1724 1741 /* 1725 1742 sizevector.clear(); 1726 1743 for(int s = 0;s<statistic.size();s++) … … 1731 1748 1732 1749 cout << endl; 1750 */ 1733 1751 1734 1752 /* … … 1943 1961 1944 1962 //// cout << "Sigma: " << sigma << endl; 1945 //// cout << "Nr. of runs: " << number_of_runs << endl;1963 //// cout << "Nr. of sigma runs: " << number_of_runs << endl; 1946 1964 1947 1965 int dimension = (*s_ref)->vertices.size()-1; … … 2087 2105 sample_mat.ins_col(0,sample_coordinates); 2088 2106 2089 cout << sample_mat.cols() << ",";2107 // cout << sample_mat.cols() << ","; 2090 2108 } 2091 2109 … … 2096 2114 } 2097 2115 2098 cout << endl;2116 // cout << endl; 2099 2117 return sample_mat; 2100 2118 }