[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 | |
---|
[1383] | 29 | const int max_model_order = 1; |
---|
| 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 | { |
---|
| 101 | my_rarx = new RARX(ar_components.size()+1,window_size,true); |
---|
| 102 | my_arx = NULL; |
---|
| 103 | } |
---|
[1376] | 104 | else |
---|
[1361] | 105 | { |
---|
| 106 | my_rarx = new RARX(ar_components.size(),window_size,false); |
---|
| 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 |
---|
[1383] | 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 |
---|
[1383] | 126 | V0(0,0) = 0; |
---|
[1361] | 127 | my_arx->set_constant(false); |
---|
| 128 | |
---|
| 129 | } |
---|
| 130 | |
---|
[1379] | 131 | my_arx->set_statistics(1, V0, V0.rows()+1); |
---|
| 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 | |
---|
[1383] | 276 | char* file_string = "c:\\ar_normal_single"; // "c:\\dataTYClosePercDiff"; // |
---|
[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 | { |
---|
[1383] | 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)); |
---|
[1383] | 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); |
---|
| 334 | strcat(fstring,"lognc.txt"); |
---|
| 335 | //strcat(fstring,"preds.txt"); |
---|
| 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 | { |
---|
[1383] | 351 | cur_res_lognc.ins(cur_res_lognc.size(),(*model_ref)->my_rarx->posterior->log_nc); |
---|
[1361] | 352 | } |
---|
[1376] | 353 | else |
---|
| 354 | { |
---|
| 355 | cur_res_lognc.ins(cur_res_lognc.size(),(*model_ref)->my_arx->posterior().lognc()); |
---|
| 356 | } |
---|
[1367] | 357 | |
---|
[1383] | 358 | pair<vec,vec> predictions = (*model_ref)->predict(20,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 | |
---|
| 366 | /* |
---|
| 367 | myfilew.open(fstring,ios::app); |
---|
| 368 | myfilew << avg_prediction << ","; |
---|
| 369 | myfilew.close(); |
---|
| 370 | */ |
---|
| 371 | |
---|
| 372 | //preds.ins(0,data_matrix.get(0,time+1)); |
---|
[1376] | 373 | } |
---|
[1367] | 374 | |
---|
[1383] | 375 | /* |
---|
| 376 | myfilew.open(fstring,ios::app); |
---|
| 377 | myfilew << data_matrix.get(0,time+1) << endl; |
---|
| 378 | myfilew.close(); |
---|
| 379 | */ |
---|
| 380 | |
---|
[1376] | 381 | result_lognc.ins_col(result_lognc.cols(),cur_res_lognc); |
---|
| 382 | // result_preds.ins_col(result_preds.cols(),preds); |
---|
| 383 | |
---|
| 384 | // cout << "Updated." << endl; |
---|
[1301] | 385 | |
---|
| 386 | |
---|
[1383] | 387 | |
---|
| 388 | |
---|
[1301] | 389 | |
---|
[1383] | 390 | myfilew.open(fstring,ios::app); |
---|
| 391 | |
---|
| 392 | // myfile << my_rarx->posterior->minimal_vertex->get_coordinates()[0]; |
---|
| 393 | |
---|
| 394 | if(time == max_model_order) |
---|
| 395 | { |
---|
| 396 | for(int i = 0;i<cur_res_lognc.size();i++) |
---|
[1301] | 397 | { |
---|
[1383] | 398 | for(set<pair<int,int>>::iterator ar_ref = models[i]->ar_components.begin();ar_ref != models[i]->ar_components.end();ar_ref++) |
---|
| 399 | { |
---|
| 400 | myfilew << (*ar_ref).second << (*ar_ref).first; |
---|
| 401 | } |
---|
[1301] | 402 | |
---|
[1383] | 403 | myfilew << "."; |
---|
[1301] | 404 | |
---|
[1383] | 405 | if(models[i]->my_arx == NULL) |
---|
| 406 | { |
---|
| 407 | myfilew << "1"; |
---|
| 408 | } |
---|
| 409 | else |
---|
| 410 | { |
---|
| 411 | myfilew << "0"; |
---|
| 412 | } |
---|
[1301] | 413 | |
---|
[1383] | 414 | if(models[i]->has_constant) |
---|
[1301] | 415 | { |
---|
[1383] | 416 | myfilew << "1"; |
---|
| 417 | } |
---|
| 418 | else |
---|
| 419 | { |
---|
| 420 | myfilew << "0"; |
---|
| 421 | } |
---|
[1324] | 422 | |
---|
[1383] | 423 | myfilew << ","; |
---|
[1376] | 424 | } |
---|
[1337] | 425 | |
---|
[1383] | 426 | myfilew << endl; |
---|
| 427 | } |
---|
| 428 | |
---|
| 429 | for(int i = 0;i<cur_res_lognc.size();i++) |
---|
| 430 | { |
---|
| 431 | myfilew << cur_res_lognc[i] << ' ';//zmenil som ciarku ze medzeru |
---|
| 432 | } |
---|
[1301] | 433 | |
---|
[1383] | 434 | myfilew << endl; |
---|
| 435 | |
---|
| 436 | myfilew.close(); |
---|
| 437 | |
---|
| 438 | } |
---|
| 439 | |
---|
[1301] | 440 | |
---|
[1337] | 441 | |
---|
| 442 | // EXPERIMENT: One step ahead price prediction. Comparison of classical and robust model using optimal trading |
---|
| 443 | // with maximization of logarithm of one-step ahead wealth. |
---|
| 444 | |
---|
| 445 | |
---|
[1301] | 446 | |
---|
| 447 | /* |
---|
| 448 | cout << "One experiment finished." << endl; |
---|
| 449 | |
---|
| 450 | ofstream myfile; |
---|
| 451 | myfile.open("c:\\robust_ar1.txt",ios::app); |
---|
| 452 | myfile << endl; |
---|
| 453 | myfile.close(); |
---|
| 454 | |
---|
| 455 | myfile.open("c:\\robust_ar2.txt",ios::app); |
---|
| 456 | myfile << endl; |
---|
| 457 | myfile.close();*/ |
---|
[1300] | 458 | |
---|
[1301] | 459 | |
---|
| 460 | //emlig* emlig1 = new emlig(emlig_size); |
---|
| 461 | |
---|
| 462 | //emlig1->step_me(0); |
---|
| 463 | //emlig* emlig2 = new emlig(emlig_size); |
---|
[1300] | 464 | |
---|
[1267] | 465 | /* |
---|
| 466 | emlig1->set_correction_factors(4); |
---|
[1266] | 467 | |
---|
[1267] | 468 | for(int j = 0;j<emlig1->correction_factors.size();j++) |
---|
| 469 | { |
---|
| 470 | for(set<my_ivec>::iterator vec_ref = emlig1->correction_factors[j].begin();vec_ref!=emlig1->correction_factors[j].end();vec_ref++) |
---|
| 471 | { |
---|
[1268] | 472 | cout << j << " "; |
---|
| 473 | |
---|
[1267] | 474 | for(int i=0;i<(*vec_ref).size();i++) |
---|
| 475 | { |
---|
| 476 | cout << (*vec_ref)[i]; |
---|
| 477 | } |
---|
| 478 | |
---|
| 479 | cout << endl; |
---|
| 480 | } |
---|
[1268] | 481 | }*/ |
---|
| 482 | |
---|
[1301] | 483 | /* |
---|
[1300] | 484 | vec condition5 = "1.0 1.0 1.01";//"-0.3 1.7 1.5"; |
---|
| 485 | |
---|
[1299] | 486 | emlig1->add_condition(condition5); |
---|
[1301] | 487 | //emlig1->step_me(0); |
---|
| 488 | |
---|
| 489 | |
---|
| 490 | vec condition1a = "-1.0 1.02 0.5"; |
---|
[1300] | 491 | //vec condition1b = "1.0 1.0 1.01"; |
---|
[1301] | 492 | emlig1->add_condition(condition1a); |
---|
[1300] | 493 | //emlig2->add_condition(condition1b); |
---|
[1267] | 494 | |
---|
[1301] | 495 | vec condition2a = "-0.3 1.7 1.5"; |
---|
[1300] | 496 | //vec condition2b = "-1.0 1.0 1.0"; |
---|
[1301] | 497 | emlig1->add_condition(condition2a); |
---|
[1300] | 498 | //emlig2->add_condition(condition2b); |
---|
[1234] | 499 | |
---|
[1301] | 500 | vec condition3a = "0.5 -1.01 1.0"; |
---|
[1300] | 501 | //vec condition3b = "0.5 -1.01 1.0"; |
---|
[1280] | 502 | |
---|
[1301] | 503 | emlig1->add_condition(condition3a); |
---|
[1300] | 504 | //emlig2->add_condition(condition3b); |
---|
[1280] | 505 | |
---|
[1301] | 506 | vec condition4a = "-0.5 -1.0 1.0"; |
---|
[1300] | 507 | //vec condition4b = "-0.5 -1.0 1.0"; |
---|
| 508 | |
---|
[1301] | 509 | emlig1->add_condition(condition4a); |
---|
[1300] | 510 | //cout << "************************************************" << endl; |
---|
| 511 | //emlig2->add_condition(condition4b); |
---|
| 512 | //cout << "************************************************" << endl; |
---|
| 513 | |
---|
[1299] | 514 | //cout << emlig1->minimal_vertex->get_coordinates(); |
---|
[1300] | 515 | |
---|
[1301] | 516 | //emlig1->remove_condition(condition3a); |
---|
| 517 | //emlig1->step_me(0); |
---|
| 518 | //emlig1->remove_condition(condition2a); |
---|
| 519 | //emlig1->remove_condition(condition1a); |
---|
| 520 | //emlig1->remove_condition(condition5); |
---|
| 521 | |
---|
[1275] | 522 | |
---|
[1299] | 523 | //emlig1->step_me(0); |
---|
| 524 | //emlig2->step_me(0); |
---|
| 525 | |
---|
[1282] | 526 | |
---|
| 527 | // DA SE POUZIT PRO VYPIS DO SOUBORU |
---|
[1275] | 528 | // emlig1->step_me(0); |
---|
| 529 | |
---|
| 530 | //emlig1->remove_condition(condition1); |
---|
| 531 | |
---|
[1301] | 532 | |
---|
[1275] | 533 | |
---|
| 534 | |
---|
[1301] | 535 | |
---|
[1275] | 536 | /* |
---|
[1282] | 537 | for(int i = 0;i<100;i++) |
---|
[1219] | 538 | { |
---|
[1282] | 539 | cout << endl << "Step:" << i << endl; |
---|
[1208] | 540 | |
---|
[1268] | 541 | double condition[emlig_size+1]; |
---|
[1220] | 542 | |
---|
[1268] | 543 | for(int k = 0;k<=emlig_size;k++) |
---|
| 544 | { |
---|
[1272] | 545 | condition[k] = (rand()-RAND_MAX/2)/1000.0; |
---|
[1268] | 546 | } |
---|
| 547 | |
---|
[1216] | 548 | |
---|
[1268] | 549 | vec* condition_vec = new vec(condition,emlig_size+1); |
---|
[1219] | 550 | emlig1->add_condition(*condition_vec); |
---|
[1271] | 551 | |
---|
[1272] | 552 | /* |
---|
| 553 | for(polyhedron* toprow_ref = emlig1->statistic.rows[emlig_size]; toprow_ref != emlig1->statistic.end_poly; toprow_ref = toprow_ref->next_poly) |
---|
| 554 | { |
---|
| 555 | cout << ((toprow*)toprow_ref)->probability << endl; |
---|
| 556 | } |
---|
| 557 | */ |
---|
[1275] | 558 | /* |
---|
[1271] | 559 | cout << emlig1->statistic_rowsize(emlig_size) << endl << endl; |
---|
[1268] | 560 | |
---|
[1272] | 561 | /* |
---|
[1271] | 562 | if(i-emlig1->number_of_parameters >= 0) |
---|
| 563 | { |
---|
| 564 | pause(30); |
---|
| 565 | } |
---|
[1272] | 566 | */ |
---|
[1219] | 567 | |
---|
[1271] | 568 | // emlig1->step_me(i); |
---|
[1219] | 569 | |
---|
[1272] | 570 | /* |
---|
[1219] | 571 | vector<int> sizevector; |
---|
| 572 | for(int s = 0;s<=emlig1->number_of_parameters;s++) |
---|
| 573 | { |
---|
| 574 | sizevector.push_back(emlig1->statistic_rowsize(s)); |
---|
| 575 | } |
---|
[1272] | 576 | */ |
---|
[1275] | 577 | //} |
---|
| 578 | |
---|
[1219] | 579 | |
---|
| 580 | |
---|
| 581 | |
---|
| 582 | /* |
---|
| 583 | emlig1->step_me(1); |
---|
| 584 | |
---|
| 585 | vec condition = "2.0 0.0 1.0"; |
---|
| 586 | |
---|
[1208] | 587 | emlig1->add_condition(condition); |
---|
| 588 | |
---|
[1216] | 589 | vector<int> sizevector; |
---|
| 590 | for(int s = 0;s<=emlig1->number_of_parameters;s++) |
---|
| 591 | { |
---|
| 592 | sizevector.push_back(emlig1->statistic_rowsize(s)); |
---|
| 593 | } |
---|
| 594 | |
---|
[1219] | 595 | emlig1->step_me(2); |
---|
[1216] | 596 | |
---|
[1219] | 597 | condition = "2.0 1.0 0.0"; |
---|
[1216] | 598 | |
---|
| 599 | emlig1->add_condition(condition); |
---|
| 600 | |
---|
| 601 | sizevector.clear(); |
---|
| 602 | for(int s = 0;s<=emlig1->number_of_parameters;s++) |
---|
| 603 | { |
---|
| 604 | sizevector.push_back(emlig1->statistic_rowsize(s)); |
---|
| 605 | } |
---|
[1219] | 606 | */ |
---|
[1216] | 607 | |
---|
[1376] | 608 | return 0; |
---|
| 609 | } |
---|
[976] | 610 | |
---|
[1282] | 611 | |
---|