[976] | 1 | |
---|
| 2 | /*! |
---|
| 3 | \file |
---|
| 4 | \brief Robust |
---|
| 5 | \author Vasek Smidl |
---|
| 6 | |
---|
| 7 | */ |
---|
| 8 | |
---|
[1337] | 9 | #include "estim/arx.h" |
---|
[976] | 10 | #include "robustlib.h" |
---|
[1216] | 11 | #include <vector> |
---|
[1284] | 12 | #include <iostream> |
---|
[1282] | 13 | #include <fstream> |
---|
[1376] | 14 | //#include <itpp/itsignal.h> |
---|
[1361] | 15 | #include "windows.h" |
---|
| 16 | #include "ddeml.h" |
---|
| 17 | #include "stdio.h" |
---|
[1282] | 18 | |
---|
[1361] | 19 | //#include "DDEClient.h" |
---|
| 20 | //#include <conio.h> |
---|
[1358] | 21 | |
---|
[1361] | 22 | |
---|
[1208] | 23 | using namespace itpp; |
---|
[1337] | 24 | using namespace bdm; |
---|
[976] | 25 | |
---|
[1361] | 26 | //const int emlig_size = 2; |
---|
| 27 | //const int utility_constant = 5; |
---|
[1268] | 28 | |
---|
[1384] | 29 | const int max_model_order = 2; |
---|
[1389] | 30 | const double apriorno = 0.01; |
---|
[1272] | 31 | |
---|
[1376] | 32 | /* |
---|
[1361] | 33 | HDDEDATA CALLBACK DdeCallback( |
---|
[1376] | 34 | UINT uType, // Transaction type. |
---|
| 35 | UINT uFmt, // Clipboard data format. |
---|
| 36 | HCONV hconv, // Handle to the conversation. |
---|
| 37 | HSZ hsz1, // Handle to a string. |
---|
| 38 | HSZ hsz2, // Handle to a string. |
---|
| 39 | HDDEDATA hdata, // Handle to a global memory object. |
---|
| 40 | DWORD dwData1, // Transaction-specific data. |
---|
| 41 | DWORD dwData2) // Transaction-specific data. |
---|
[1361] | 42 | { |
---|
[1376] | 43 | return 0; |
---|
[1361] | 44 | } |
---|
| 45 | |
---|
| 46 | void DDERequest(DWORD idInst, HCONV hConv, char* szItem) |
---|
| 47 | { |
---|
| 48 | HSZ hszItem = DdeCreateStringHandle(idInst, szItem, 0); |
---|
| 49 | HDDEDATA hData = DdeClientTransaction(NULL,0,hConv,hszItem,CF_TEXT, |
---|
[1365] | 50 | XTYP_ADVSTART,TIMEOUT_ASYNC , NULL); //TIMEOUT_ASYNC |
---|
[1361] | 51 | if (hData==NULL) |
---|
| 52 | { |
---|
| 53 | printf("Request failed: %s\n", szItem); |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | if (hData==0) |
---|
| 57 | { |
---|
| 58 | printf("Request failed: %s\n", szItem); |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | |
---|
[1367] | 62 | DWORD WINAPI ThrdFunc( LPVOID n ) |
---|
| 63 | { |
---|
| 64 | return 0; |
---|
| 65 | } |
---|
[1376] | 66 | */ |
---|
[1367] | 67 | |
---|
[1361] | 68 | class model |
---|
| 69 | { |
---|
| 70 | public: |
---|
[1376] | 71 | set<pair<int,int>> ar_components; |
---|
[1358] | 72 | |
---|
[1361] | 73 | // Best thing would be to inherit the two models from a single souce, this is planned, but now structurally |
---|
| 74 | // problematic. |
---|
[1376] | 75 | RARX* my_rarx; //vzmenovane parametre pre triedu model |
---|
[1379] | 76 | ARXwin* my_arx; |
---|
[1361] | 77 | |
---|
| 78 | bool has_constant; |
---|
[1376] | 79 | int window_size; //musi byt vacsia ako pocet krokov ak to nema ovplyvnit |
---|
[1361] | 80 | int predicted_channel; |
---|
| 81 | mat* data_matrix; |
---|
[1383] | 82 | vec predictions; |
---|
[1361] | 83 | |
---|
[1376] | 84 | model(set<pair<int,int>> ar_components, //funkcie treidz model-konstruktor |
---|
[1361] | 85 | bool robust, |
---|
| 86 | bool has_constant, |
---|
| 87 | int window_size, |
---|
[1376] | 88 | int predicted_channel, |
---|
[1361] | 89 | mat* data_matrix) |
---|
[1358] | 90 | { |
---|
[1376] | 91 | this->ar_components.insert(ar_components.begin(),ar_components.end()); |
---|
| 92 | this->has_constant = has_constant; |
---|
| 93 | this->window_size = window_size; |
---|
| 94 | this->predicted_channel = predicted_channel; |
---|
| 95 | this->data_matrix = data_matrix; |
---|
[1361] | 96 | |
---|
| 97 | if(robust) |
---|
| 98 | { |
---|
| 99 | if(has_constant) |
---|
| 100 | { |
---|
[1389] | 101 | my_rarx = new RARX(ar_components.size()+1,window_size,true,sqrt(2*apriorno),sqrt(2*apriorno),ar_components.size()+4); |
---|
[1361] | 102 | my_arx = NULL; |
---|
| 103 | } |
---|
[1376] | 104 | else |
---|
[1361] | 105 | { |
---|
[1389] | 106 | my_rarx = new RARX(ar_components.size(),window_size,false,sqrt(2*apriorno),sqrt(2*apriorno),ar_components.size()+3); |
---|
[1361] | 107 | my_arx = NULL; |
---|
| 108 | } |
---|
| 109 | } |
---|
| 110 | else |
---|
| 111 | { |
---|
| 112 | my_rarx = NULL; |
---|
[1379] | 113 | my_arx = new ARXwin(); |
---|
[1361] | 114 | mat V0; |
---|
| 115 | |
---|
| 116 | if(has_constant) |
---|
| 117 | { |
---|
[1376] | 118 | V0 = apriorno * eye(ar_components.size()+2); //aj tu konst |
---|
[1384] | 119 | //V0(0,0) = 0; |
---|
[1379] | 120 | my_arx->set_constant(true); |
---|
[1361] | 121 | } |
---|
| 122 | else |
---|
| 123 | { |
---|
| 124 | |
---|
[1376] | 125 | V0 = apriorno * eye(ar_components.size()+1);//menit konstantu |
---|
[1384] | 126 | //V0(0,0) = 0; |
---|
[1361] | 127 | my_arx->set_constant(false); |
---|
| 128 | |
---|
| 129 | } |
---|
| 130 | |
---|
[1384] | 131 | my_arx->set_statistics(1, V0, V0.rows()+2); |
---|
[1379] | 132 | my_arx->set_parameters(window_size); |
---|
[1361] | 133 | my_arx->validate(); |
---|
| 134 | } |
---|
[1358] | 135 | } |
---|
[1361] | 136 | |
---|
[1376] | 137 | void data_update(int time) //vlozime cas a ono vlozi do data_vector podmineky(conditions) a predikce, ktore pouzije do bayes |
---|
[1358] | 138 | { |
---|
[1376] | 139 | vec data_vector; |
---|
| 140 | for(set<pair<int,int>>::iterator ar_iterator = ar_components.begin();ar_iterator!=ar_components.end();ar_iterator++) |
---|
| 141 | { //ar?iterator ide len od 1 pod 2, alebo niekedy len 1 |
---|
| 142 | data_vector.ins(data_vector.size(),(*data_matrix).get(ar_iterator->first,time-ar_iterator->second)); |
---|
| 143 | // do data vector vlozi pre dany typ regresoru prislusne cisla z data_matrix. Ale ako? preco time-ar_iterator->second? |
---|
[1358] | 144 | } |
---|
[1376] | 145 | if(my_rarx!=NULL) |
---|
[1383] | 146 | { //pre robust priradi az tu do data_vector aj predikciu |
---|
[1376] | 147 | data_vector.ins(0,(*data_matrix).get(predicted_channel,time)); |
---|
| 148 | my_rarx->bayes(data_vector); |
---|
| 149 | } |
---|
[1358] | 150 | else |
---|
| 151 | { |
---|
[1376] | 152 | vec pred_vec;//tu sa predikcia zadava zvlast |
---|
| 153 | pred_vec.ins(0,(*data_matrix).get(predicted_channel,time)); |
---|
| 154 | my_arx->bayes(pred_vec,data_vector); |
---|
[1361] | 155 | } |
---|
| 156 | } |
---|
| 157 | |
---|
[1376] | 158 | pair<vec,vec> predict(int sample_size, int time, itpp::Laplace_RNG* LapRNG) //nerozumiem, ale vraj to netreba, nepouziva to |
---|
[1367] | 159 | { |
---|
[1376] | 160 | vec condition_vector; |
---|
| 161 | for(set<pair<int,int>>::iterator ar_iterator = ar_components.begin();ar_iterator!=ar_components.end();ar_iterator++) |
---|
[1367] | 162 | { |
---|
[1376] | 163 | condition_vector.ins(condition_vector.size(),(*data_matrix).get(ar_iterator->first,time-ar_iterator->second+1)); |
---|
| 164 | } |
---|
[1367] | 165 | |
---|
[1376] | 166 | if(my_rarx!=NULL) |
---|
| 167 | { |
---|
| 168 | pair<vec,mat> imp_samples = my_rarx->posterior->importance_sample(sample_size); |
---|
[1367] | 169 | |
---|
[1376] | 170 | //cout << imp_samples.first << endl; |
---|
| 171 | |
---|
| 172 | vec sample_prediction; |
---|
| 173 | for(int t = 0;t<sample_size;t++) |
---|
[1367] | 174 | { |
---|
[1376] | 175 | vec lap_sample = condition_vector; |
---|
[1367] | 176 | |
---|
[1376] | 177 | if(has_constant) |
---|
[1367] | 178 | { |
---|
[1376] | 179 | lap_sample.ins(lap_sample.size(),1.0); |
---|
[1367] | 180 | } |
---|
[1376] | 181 | |
---|
| 182 | lap_sample.ins(0,(*LapRNG)()); |
---|
[1367] | 183 | |
---|
[1376] | 184 | sample_prediction.ins(0,lap_sample*imp_samples.second.get_col(t)); |
---|
[1367] | 185 | } |
---|
| 186 | |
---|
[1376] | 187 | return pair<vec,vec>(imp_samples.first,sample_prediction); |
---|
| 188 | } |
---|
| 189 | else |
---|
| 190 | { |
---|
[1383] | 191 | mat samples = my_arx->posterior().sample_mat(sample_size); |
---|
[1376] | 192 | |
---|
| 193 | vec sample_prediction; |
---|
| 194 | for(int t = 0;t<sample_size;t++) |
---|
| 195 | { |
---|
| 196 | vec gau_sample = condition_vector; |
---|
[1367] | 197 | |
---|
[1376] | 198 | if(has_constant) |
---|
[1367] | 199 | { |
---|
[1376] | 200 | gau_sample.ins(gau_sample.size(),1.0); |
---|
[1367] | 201 | } |
---|
[1376] | 202 | |
---|
[1383] | 203 | gau_sample.ins(gau_sample.size(),randn()); |
---|
[1367] | 204 | |
---|
[1376] | 205 | sample_prediction.ins(0,gau_sample*samples.get_col(t)); |
---|
[1367] | 206 | } |
---|
[1376] | 207 | |
---|
| 208 | return pair<vec,vec>(ones(sample_prediction.size()),sample_prediction); |
---|
[1367] | 209 | } |
---|
| 210 | |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | |
---|
[1376] | 214 | static set<set<pair<int,int>>> possible_models_recurse(int max_order,int number_of_channels) |
---|
[1361] | 215 | { |
---|
[1376] | 216 | set<set<pair<int,int>>> created_model_types; |
---|
[1361] | 217 | |
---|
[1376] | 218 | if(max_order == 1)//ukoncovacia vetva |
---|
[1361] | 219 | { |
---|
[1376] | 220 | for(int channel = 0;channel<number_of_channels;channel++)//pre AR 1 model vytvori kombinace kanalov v prvom kroku poyadu |
---|
[1358] | 221 | { |
---|
[1376] | 222 | set<pair<int,int>> returned_type; |
---|
| 223 | returned_type.insert(pair<int,int>(channel,1)); //?? |
---|
| 224 | created_model_types.insert(returned_type); |
---|
[1358] | 225 | } |
---|
[1361] | 226 | |
---|
| 227 | return created_model_types; |
---|
| 228 | } |
---|
| 229 | else |
---|
| 230 | { |
---|
[1376] | 231 | created_model_types = possible_models_recurse(max_order-1,number_of_channels);//tu uz mame ulozene kombinace o jeden krok dozadu //rekuryivne volanie |
---|
| 232 | set<set<pair<int,int>>> returned_types; |
---|
[1361] | 233 | |
---|
[1376] | 234 | for(set<set<pair<int,int>>>::iterator model_ref = created_model_types.begin();model_ref!=created_model_types.end();model_ref++) |
---|
[1361] | 235 | { |
---|
| 236 | |
---|
| 237 | for(int order = 1; order<=max_order; order++) |
---|
[1358] | 238 | { |
---|
[1361] | 239 | for(int channel = 0;channel<number_of_channels;channel++) |
---|
| 240 | { |
---|
[1376] | 241 | set<pair<int,int>> returned_type; |
---|
| 242 | pair<int,int> new_pair = pair<int,int>(channel,order);//?? |
---|
| 243 | if(find((*model_ref).begin(),(*model_ref).end(),new_pair)==(*model_ref).end()) //?? |
---|
[1361] | 244 | { |
---|
[1376] | 245 | returned_type.insert((*model_ref).begin(),(*model_ref).end()); //co vlozi na zaciatok retuned_type? |
---|
| 246 | returned_type.insert(new_pair); |
---|
| 247 | |
---|
| 248 | |
---|
| 249 | returned_types.insert(returned_type); |
---|
[1361] | 250 | } |
---|
| 251 | } |
---|
[1358] | 252 | } |
---|
| 253 | } |
---|
[1361] | 254 | |
---|
[1376] | 255 | created_model_types.insert(returned_types.begin(),returned_types.end()); |
---|
[1361] | 256 | |
---|
| 257 | return created_model_types; |
---|
| 258 | } |
---|
[1358] | 259 | } |
---|
[1361] | 260 | }; |
---|
| 261 | |
---|
| 262 | |
---|
| 263 | |
---|
| 264 | |
---|
[1383] | 265 | int main ( int argc, char* argv[] ) |
---|
| 266 | { |
---|
[1358] | 267 | |
---|
[1376] | 268 | // EXPERIMENT: A moving window estimation and prediction of RARX is tested on data generated from |
---|
| 269 | // y_t=0.95*y_(t-1)+0.05*y_(t-2)+0.2*e_t, where e_t is normally, student(4) and cauchy distributed. It |
---|
| 270 | // can be compared to the classical setup. |
---|
| 271 | |
---|
| 272 | itpp::Laplace_RNG LapRNG = Laplace_RNG(); |
---|
[1301] | 273 | |
---|
[1376] | 274 | vector<vector<string>> strings; |
---|
[1301] | 275 | |
---|
[1389] | 276 | char* file_string = "C:\\ar_student_single"; //"C:\\Users\\Hontik\\Desktop\\Bayes\\dataADClosePercDiff"; // |
---|
[1301] | 277 | |
---|
[1376] | 278 | char dfstring[80]; |
---|
| 279 | strcpy(dfstring,file_string); |
---|
| 280 | strcat(dfstring,".txt"); |
---|
| 281 | |
---|
| 282 | |
---|
| 283 | mat data_matrix; |
---|
| 284 | ifstream myfile(dfstring); |
---|
| 285 | if (myfile.is_open()) |
---|
| 286 | { |
---|
| 287 | string line; |
---|
| 288 | while(getline(myfile,line)) |
---|
| 289 | { |
---|
| 290 | vec data_vector; |
---|
| 291 | while(line.find(',') != string::npos) //zmenil som ciarku za medzeru |
---|
| 292 | { |
---|
[1383] | 293 | //line.erase(0,1); // toto som sem pridal |
---|
[1376] | 294 | int loc2 = line.find('\n'); |
---|
| 295 | int loc = line.find(','); |
---|
| 296 | data_vector.ins(data_vector.size(),atof(line.substr(0,loc).c_str())); |
---|
| 297 | line.erase(0,loc+1); |
---|
| 298 | } |
---|
[1301] | 299 | |
---|
[1376] | 300 | data_matrix.ins_row(data_matrix.rows(),data_vector); |
---|
| 301 | } |
---|
[1361] | 302 | |
---|
[1376] | 303 | myfile.close(); |
---|
| 304 | } |
---|
| 305 | else |
---|
| 306 | { |
---|
| 307 | cout << "Can't open data file!" << endl; |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | //konec nacitavania dat |
---|
| 311 | set<set<pair<int,int>>> model_types = model::possible_models_recurse(max_model_order,data_matrix.rows()); //volanie funkce kde robi kombinace modelov |
---|
| 312 | //to priradime do model_types, data_matrix.row urcuje pocet kanalov dat |
---|
| 313 | vector<model*> models; |
---|
| 314 | for(set<set<pair<int,int>>>::iterator model_type = model_types.begin();model_type!=model_types.end();model_type++) |
---|
| 315 | {// prechadza rozne typy kanalov, a poctu regresorov |
---|
[1383] | 316 | for(int window_size = 50;window_size < 51;window_size++) |
---|
[1376] | 317 | { |
---|
[1384] | 318 | models.push_back(new model((*model_type),true,true,window_size,0,&data_matrix)); // to su len konstruktory, len inicializujeme rozne typy |
---|
| 319 | models.push_back(new model((*model_type),false,true,window_size,0,&data_matrix)); |
---|
[1376] | 320 | models.push_back(new model((*model_type),true,false,window_size,0,&data_matrix)); |
---|
[1384] | 321 | models.push_back(new model((*model_type),false,false,window_size,0,&data_matrix)); |
---|
[1376] | 322 | } |
---|
[1365] | 323 | |
---|
[1379] | 324 | //set<pair<int,int>> empty_list; |
---|
| 325 | //models.push_back(new model(empty_list,false,true,100,0,&data_matrix)); |
---|
[1376] | 326 | } |
---|
| 327 | |
---|
| 328 | mat result_lognc; |
---|
| 329 | // mat result_preds; |
---|
| 330 | |
---|
[1383] | 331 | ofstream myfilew; |
---|
| 332 | char fstring[80]; |
---|
| 333 | strcpy(fstring,file_string); |
---|
[1389] | 334 | //strcat(fstring,"lognc.txt"); |
---|
| 335 | strcat(fstring,"preds.txt"); |
---|
[1383] | 336 | |
---|
[1376] | 337 | for(int time = max_model_order;time<data_matrix.cols();time++) //time<data_matrix.cols() |
---|
| 338 | { //pocet stlpcov data_matrix je pocet casovych krokov |
---|
| 339 | vec cur_res_lognc; |
---|
| 340 | // vec preds; |
---|
| 341 | vector<string> nazvy; |
---|
| 342 | for(vector<model*>::iterator model_ref = models.begin();model_ref!=models.end();model_ref++) |
---|
| 343 | {//posuvam s apo models, co je pole modelov urobene o cyklus vyssie. Teda som v case time a robim to tam pre vsetky typy modelov, kombinace regresorov |
---|
| 344 | (*model_ref)->data_update(time); //pozret sa preco je toto tu nutne |
---|
[1379] | 345 | |
---|
| 346 | cout << "Updated." << endl; |
---|
[1376] | 347 | //if (time = max_model_order) nazvy.push_back(models.model_ref]);// ako by som mohol dostat nazov modelu? |
---|
| 348 | |
---|
| 349 | if((*model_ref)->my_rarx!=NULL) //vklada normalizacnz faktor do cur_res_lognc |
---|
| 350 | { |
---|
[1384] | 351 | cur_res_lognc.ins(cur_res_lognc.size(),(*model_ref)->my_rarx->posterior->_ll()); |
---|
[1361] | 352 | } |
---|
[1376] | 353 | else |
---|
| 354 | { |
---|
[1384] | 355 | cur_res_lognc.ins(cur_res_lognc.size(),(*model_ref)->my_arx->_ll()); |
---|
[1376] | 356 | } |
---|
[1367] | 357 | |
---|
[1389] | 358 | pair<vec,vec> predictions = (*model_ref)->predict(500,time,&LapRNG); |
---|
[1367] | 359 | |
---|
[1383] | 360 | cout << predictions.first << endl << predictions.second << endl; |
---|
[1361] | 361 | |
---|
[1383] | 362 | double avg_prediction = (predictions.first*predictions.second)/(predictions.first*ones(predictions.first.size())); |
---|
| 363 | |
---|
| 364 | (*model_ref)->predictions.ins((*model_ref)->predictions.size(),avg_prediction); |
---|
| 365 | |
---|
[1389] | 366 | |
---|
[1383] | 367 | myfilew.open(fstring,ios::app); |
---|
| 368 | myfilew << avg_prediction << ","; |
---|
| 369 | myfilew.close(); |
---|
[1389] | 370 | |
---|
[1383] | 371 | |
---|
| 372 | //preds.ins(0,data_matrix.get(0,time+1)); |
---|
[1376] | 373 | } |
---|
[1367] | 374 | |
---|
[1389] | 375 | |
---|
[1383] | 376 | myfilew.open(fstring,ios::app); |
---|
| 377 | myfilew << data_matrix.get(0,time+1) << endl; |
---|
| 378 | myfilew.close(); |
---|
[1389] | 379 | |
---|
[1383] | 380 | |
---|
[1376] | 381 | result_lognc.ins_col(result_lognc.cols(),cur_res_lognc); |
---|
| 382 | // result_preds.ins_col(result_preds.cols(),preds); |
---|
| 383 | |
---|
[1384] | 384 | // cout << "Updated." << endl; |
---|
[1383] | 385 | |
---|
[1301] | 386 | |
---|
[1383] | 387 | myfilew.open(fstring,ios::app); |
---|
| 388 | |
---|
| 389 | // myfile << my_rarx->posterior->minimal_vertex->get_coordinates()[0]; |
---|
| 390 | |
---|
| 391 | if(time == max_model_order) |
---|
| 392 | { |
---|
| 393 | for(int i = 0;i<cur_res_lognc.size();i++) |
---|
[1301] | 394 | { |
---|
[1383] | 395 | for(set<pair<int,int>>::iterator ar_ref = models[i]->ar_components.begin();ar_ref != models[i]->ar_components.end();ar_ref++) |
---|
| 396 | { |
---|
| 397 | myfilew << (*ar_ref).second << (*ar_ref).first; |
---|
| 398 | } |
---|
[1301] | 399 | |
---|
[1383] | 400 | myfilew << "."; |
---|
[1301] | 401 | |
---|
[1383] | 402 | if(models[i]->my_arx == NULL) |
---|
| 403 | { |
---|
| 404 | myfilew << "1"; |
---|
| 405 | } |
---|
| 406 | else |
---|
| 407 | { |
---|
| 408 | myfilew << "0"; |
---|
| 409 | } |
---|
[1301] | 410 | |
---|
[1383] | 411 | if(models[i]->has_constant) |
---|
[1301] | 412 | { |
---|
[1383] | 413 | myfilew << "1"; |
---|
| 414 | } |
---|
| 415 | else |
---|
| 416 | { |
---|
| 417 | myfilew << "0"; |
---|
| 418 | } |
---|
[1324] | 419 | |
---|
[1383] | 420 | myfilew << ","; |
---|
[1376] | 421 | } |
---|
[1337] | 422 | |
---|
[1383] | 423 | myfilew << endl; |
---|
| 424 | } |
---|
| 425 | |
---|
[1389] | 426 | /* |
---|
[1383] | 427 | for(int i = 0;i<cur_res_lognc.size();i++) |
---|
| 428 | { |
---|
| 429 | myfilew << cur_res_lognc[i] << ' ';//zmenil som ciarku ze medzeru |
---|
| 430 | } |
---|
[1389] | 431 | */ |
---|
[1301] | 432 | |
---|
[1383] | 433 | myfilew << endl; |
---|
| 434 | |
---|
| 435 | myfilew.close(); |
---|
| 436 | |
---|
| 437 | } |
---|
| 438 | |
---|
[1301] | 439 | |
---|
[1337] | 440 | |
---|
| 441 | // EXPERIMENT: One step ahead price prediction. Comparison of classical and robust model using optimal trading |
---|
| 442 | // with maximization of logarithm of one-step ahead wealth. |
---|
| 443 | |
---|
| 444 | |
---|
[1301] | 445 | |
---|
| 446 | /* |
---|
| 447 | cout << "One experiment finished." << endl; |
---|
| 448 | |
---|
| 449 | ofstream myfile; |
---|
| 450 | myfile.open("c:\\robust_ar1.txt",ios::app); |
---|
| 451 | myfile << endl; |
---|
| 452 | myfile.close(); |
---|
| 453 | |
---|
| 454 | myfile.open("c:\\robust_ar2.txt",ios::app); |
---|
| 455 | myfile << endl; |
---|
| 456 | myfile.close();*/ |
---|
[1300] | 457 | |
---|
[1301] | 458 | |
---|
| 459 | //emlig* emlig1 = new emlig(emlig_size); |
---|
| 460 | |
---|
| 461 | //emlig1->step_me(0); |
---|
| 462 | //emlig* emlig2 = new emlig(emlig_size); |
---|
[1300] | 463 | |
---|
[1267] | 464 | /* |
---|
| 465 | emlig1->set_correction_factors(4); |
---|
[1266] | 466 | |
---|
[1267] | 467 | for(int j = 0;j<emlig1->correction_factors.size();j++) |
---|
| 468 | { |
---|
| 469 | for(set<my_ivec>::iterator vec_ref = emlig1->correction_factors[j].begin();vec_ref!=emlig1->correction_factors[j].end();vec_ref++) |
---|
| 470 | { |
---|
[1268] | 471 | cout << j << " "; |
---|
| 472 | |
---|
[1267] | 473 | for(int i=0;i<(*vec_ref).size();i++) |
---|
| 474 | { |
---|
| 475 | cout << (*vec_ref)[i]; |
---|
| 476 | } |
---|
| 477 | |
---|
| 478 | cout << endl; |
---|
| 479 | } |
---|
[1268] | 480 | }*/ |
---|
| 481 | |
---|
[1301] | 482 | /* |
---|
[1300] | 483 | vec condition5 = "1.0 1.0 1.01";//"-0.3 1.7 1.5"; |
---|
| 484 | |
---|
[1299] | 485 | emlig1->add_condition(condition5); |
---|
[1301] | 486 | //emlig1->step_me(0); |
---|
| 487 | |
---|
| 488 | |
---|
| 489 | vec condition1a = "-1.0 1.02 0.5"; |
---|
[1300] | 490 | //vec condition1b = "1.0 1.0 1.01"; |
---|
[1301] | 491 | emlig1->add_condition(condition1a); |
---|
[1300] | 492 | //emlig2->add_condition(condition1b); |
---|
[1267] | 493 | |
---|
[1301] | 494 | vec condition2a = "-0.3 1.7 1.5"; |
---|
[1300] | 495 | //vec condition2b = "-1.0 1.0 1.0"; |
---|
[1301] | 496 | emlig1->add_condition(condition2a); |
---|
[1300] | 497 | //emlig2->add_condition(condition2b); |
---|
[1234] | 498 | |
---|
[1301] | 499 | vec condition3a = "0.5 -1.01 1.0"; |
---|
[1300] | 500 | //vec condition3b = "0.5 -1.01 1.0"; |
---|
[1280] | 501 | |
---|
[1301] | 502 | emlig1->add_condition(condition3a); |
---|
[1300] | 503 | //emlig2->add_condition(condition3b); |
---|
[1280] | 504 | |
---|
[1301] | 505 | vec condition4a = "-0.5 -1.0 1.0"; |
---|
[1300] | 506 | //vec condition4b = "-0.5 -1.0 1.0"; |
---|
| 507 | |
---|
[1301] | 508 | emlig1->add_condition(condition4a); |
---|
[1300] | 509 | //cout << "************************************************" << endl; |
---|
| 510 | //emlig2->add_condition(condition4b); |
---|
| 511 | //cout << "************************************************" << endl; |
---|
| 512 | |
---|
[1299] | 513 | //cout << emlig1->minimal_vertex->get_coordinates(); |
---|
[1300] | 514 | |
---|
[1301] | 515 | //emlig1->remove_condition(condition3a); |
---|
| 516 | //emlig1->step_me(0); |
---|
| 517 | //emlig1->remove_condition(condition2a); |
---|
| 518 | //emlig1->remove_condition(condition1a); |
---|
| 519 | //emlig1->remove_condition(condition5); |
---|
| 520 | |
---|
[1275] | 521 | |
---|
[1299] | 522 | //emlig1->step_me(0); |
---|
| 523 | //emlig2->step_me(0); |
---|
| 524 | |
---|
[1282] | 525 | |
---|
| 526 | // DA SE POUZIT PRO VYPIS DO SOUBORU |
---|
[1275] | 527 | // emlig1->step_me(0); |
---|
| 528 | |
---|
| 529 | //emlig1->remove_condition(condition1); |
---|
| 530 | |
---|
[1301] | 531 | |
---|
[1275] | 532 | |
---|
| 533 | |
---|
[1301] | 534 | |
---|
[1275] | 535 | /* |
---|
[1282] | 536 | for(int i = 0;i<100;i++) |
---|
[1219] | 537 | { |
---|
[1282] | 538 | cout << endl << "Step:" << i << endl; |
---|
[1208] | 539 | |
---|
[1268] | 540 | double condition[emlig_size+1]; |
---|
[1220] | 541 | |
---|
[1268] | 542 | for(int k = 0;k<=emlig_size;k++) |
---|
| 543 | { |
---|
[1272] | 544 | condition[k] = (rand()-RAND_MAX/2)/1000.0; |
---|
[1268] | 545 | } |
---|
| 546 | |
---|
[1216] | 547 | |
---|
[1268] | 548 | vec* condition_vec = new vec(condition,emlig_size+1); |
---|
[1219] | 549 | emlig1->add_condition(*condition_vec); |
---|
[1271] | 550 | |
---|
[1272] | 551 | /* |
---|
| 552 | for(polyhedron* toprow_ref = emlig1->statistic.rows[emlig_size]; toprow_ref != emlig1->statistic.end_poly; toprow_ref = toprow_ref->next_poly) |
---|
| 553 | { |
---|
| 554 | cout << ((toprow*)toprow_ref)->probability << endl; |
---|
| 555 | } |
---|
| 556 | */ |
---|
[1275] | 557 | /* |
---|
[1271] | 558 | cout << emlig1->statistic_rowsize(emlig_size) << endl << endl; |
---|
[1268] | 559 | |
---|
[1272] | 560 | /* |
---|
[1271] | 561 | if(i-emlig1->number_of_parameters >= 0) |
---|
| 562 | { |
---|
| 563 | pause(30); |
---|
| 564 | } |
---|
[1272] | 565 | */ |
---|
[1219] | 566 | |
---|
[1271] | 567 | // emlig1->step_me(i); |
---|
[1219] | 568 | |
---|
[1272] | 569 | /* |
---|
[1219] | 570 | vector<int> sizevector; |
---|
| 571 | for(int s = 0;s<=emlig1->number_of_parameters;s++) |
---|
| 572 | { |
---|
| 573 | sizevector.push_back(emlig1->statistic_rowsize(s)); |
---|
| 574 | } |
---|
[1272] | 575 | */ |
---|
[1275] | 576 | //} |
---|
| 577 | |
---|
[1219] | 578 | |
---|
| 579 | |
---|
| 580 | |
---|
| 581 | /* |
---|
| 582 | emlig1->step_me(1); |
---|
| 583 | |
---|
| 584 | vec condition = "2.0 0.0 1.0"; |
---|
| 585 | |
---|
[1208] | 586 | emlig1->add_condition(condition); |
---|
| 587 | |
---|
[1216] | 588 | vector<int> sizevector; |
---|
| 589 | for(int s = 0;s<=emlig1->number_of_parameters;s++) |
---|
| 590 | { |
---|
| 591 | sizevector.push_back(emlig1->statistic_rowsize(s)); |
---|
| 592 | } |
---|
| 593 | |
---|
[1219] | 594 | emlig1->step_me(2); |
---|
[1216] | 595 | |
---|
[1219] | 596 | condition = "2.0 1.0 0.0"; |
---|
[1216] | 597 | |
---|
| 598 | emlig1->add_condition(condition); |
---|
| 599 | |
---|
| 600 | sizevector.clear(); |
---|
| 601 | for(int s = 0;s<=emlig1->number_of_parameters;s++) |
---|
| 602 | { |
---|
| 603 | sizevector.push_back(emlig1->statistic_rowsize(s)); |
---|
| 604 | } |
---|
[1219] | 605 | */ |
---|
[1216] | 606 | |
---|
[1376] | 607 | return 0; |
---|
| 608 | } |
---|
[976] | 609 | |
---|
[1282] | 610 | |
---|