Changeset 1208
- Timestamp:
- 10/03/10 15:26:26 (14 years ago)
- Location:
- applications/robust
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/robust/main.cpp
r1186 r1208 8 8 9 9 #include "robustlib.h" 10 using namespace itpp; 10 11 11 12 //using namespace bdm; … … 13 14 int main ( int argc, char* argv[] ) { 14 15 15 emlig* emlig1 = new emlig(10); 16 emlig* emlig1 = new emlig(3); 17 18 vec condition = "3.0 -5.0 3.0 2.0"; 19 20 emlig1->add_condition(condition); 16 21 17 22 return 0; -
applications/robust/robustlib.h
r1207 r1208 18 18 19 19 const double max_range = numeric_limits<double>::max()/10e-5; 20 21 enum actions {MERGE, SPLIT}; 20 22 21 23 class polyhedron; … … 56 58 vector<polyhedron*> neutralchildren; 57 59 60 bool totally_neutral; 61 58 62 vector<polyhedron*> mergechildren; 59 63 … … 76 80 77 81 message_counter = 0; 82 83 totally_neutral = NULL; 78 84 } 79 85 … … 101 107 return false; 102 108 } 109 110 103 111 104 112 void set_state(double state_indicator, actions action) … … 143 151 vec coordinates; 144 152 145 enum actions {MERGE, SPLIT};153 146 154 147 155 public: … … 207 215 multiplicity = 1; 208 216 } 209 } 217 }; 210 218 211 219 … … 236 244 do 237 245 { 238 product = (*vertex_ref)-> coordinates*condition;239 } 240 while(product == 0) 246 product = (*vertex_ref)->get_coordinates()*condition; 247 } 248 while(product == 0); 241 249 242 250 if((product>0 && should_be_added)||(product<0 && !should_be_added)) … … 319 327 } 320 328 321 if(shouldsplit) 329 330 } 331 332 if(shouldsplit) 322 333 { 323 334 switch(sender->get_state(SPLIT)) … … 328 339 case 0: 329 340 current_parent->neutralchildren.push_back(sender); 341 342 if(current_parent->totally_neutral == NULL) 343 { 344 current_parent->totally_neutral = sender->totally_neutral; 345 } 346 else 347 { 348 current_parent->totally_neutral = current_parent->totally_neutral && sender->totally_neutral; 349 } 350 330 351 break; 331 352 case -1: … … 336 357 if(is_last) 337 358 { 338 if(current_parent->negativechildren.size()>0) 359 if((current_parent->negativechildren.size()>0&¤t_parent->positivechildren.size()>0)|| 360 (current_parent->neutralchildren.size()>0&¤t_parent->totally_neutral==false)) 339 361 { 340 if(current_parent->positivechildren.size()>0) 341 { 362 342 363 for_splitting[level+1].push_back(current_parent); 343 364 344 365 current_parent->set_state(0, SPLIT); 345 346 else347 348 349 350 351 352 }366 } 367 else if(current_parent->negativechildren.size()>0) 368 { 369 current_parent->set_state(-1, SPLIT); 370 371 current_parent->negativechildren.clear(); 372 current_parent->neutralchildren.clear(); 373 353 374 } 354 375 else if(current_parent->positivechildren.size()>0) … … 372 393 send_state_message(current_parent,shouldsplit,shouldmerge,level+1); 373 394 } 374 }375 395 376 396 } … … 404 424 } 405 425 406 void add_and_remove_condition(vec toremove, vec toadd) 407 { 426 void add_condition(vec toadd) 427 { 428 vec null_vector = ""; 429 430 add_and_remove_condition(toadd, null_vector); 431 } 432 433 void remove_condition(vec toremove) 434 { 435 vec null_vector = ""; 436 437 add_and_remove_condition(null_vector, toremove); 438 439 } 440 441 void add_and_remove_condition(vec toadd, vec toremove) 442 { 443 bool should_remove = (toremove.size() != 0); 444 bool should_add = (toadd.size() != 0); 445 408 446 vector<condition*>::iterator toremove_ref = conditions.end(); 409 447 bool condition_should_be_added = false; … … 411 449 for(vector<condition*>::iterator ref = conditions.begin();ref<conditions.end();ref++) 412 450 { 413 if( toremove != NULL)451 if(should_remove) 414 452 { 415 453 if((*ref)->value == toremove) 416 454 { 417 if( multiplicity>1)418 { 419 multiplicity--;455 if((*ref)->multiplicity>1) 456 { 457 (*ref)->multiplicity--; 420 458 421 459 alter_toprow_conditions(toremove,false); 422 460 423 toremove = NULL;461 should_remove = false; 424 462 } 425 463 else … … 430 468 } 431 469 432 if( toadd != NULL)433 { 434 if((* iterator)->value == toadd)470 if(should_add) 471 { 472 if((*ref)->value == toadd) 435 473 { 436 (* iterator)->multiplicity++;474 (*ref)->multiplicity++; 437 475 438 476 alter_toprow_conditions(toadd,true); 439 477 440 toadd = NULL;478 should_add = false; 441 479 } 442 480 else … … 461 499 for(vector<polyhedron*>::iterator horizontal_position = statistic[0].begin();horizontal_position<statistic[0].end();horizontal_position++) 462 500 { 463 vertex* current_vertex = (vertex*) horizontal_position;501 vertex* current_vertex = (vertex*)(*horizontal_position); 464 502 465 if(toadd != NULL) 466 { 467 current_vertex->set_state(toadd*current_vertex->coordinates,SPLIT); 468 } 503 if(should_add||should_remove) 504 { 505 vec appended_vec = current_vertex->get_coordinates(); 506 appended_vec.ins(0,1.0); 507 508 if(should_add) 509 { 510 current_vertex->set_state(toadd*appended_vec,SPLIT); 511 } 469 512 470 if(toremove != NULL) 471 { 472 current_vertex->set_state(toremove*current_vertex->coordinates,MERGE); 513 if(should_remove) 514 { 515 current_vertex->set_state(toremove*current_vertex->get_coordinates(),MERGE); 516 } 473 517 474 518 if(current_vertex->get_state(MERGE) == 0) … … 478 522 } 479 523 480 send_state_message(current_vertex, toadd != NULL, toremove != NULL, 0); 481 482 483 } 524 send_state_message(current_vertex, should_add, should_remove, 0); 525 } 526 527 for(vector<vector<polyhedron*>>::iterator vert_ref = for_splitting.begin();vert_ref<for_splitting.end();vert_ref++) 528 { 529 int original_size = (*vert_ref).size(); 530 531 for(int split_counter = 0;split_counter<original_size;split_counter++) 532 { 533 polyhedron* current_polyhedron = (*vert_ref)[original_size-1-split_counter]; 534 535 536 } 537 } 538 539 484 540 } 485 541 … … 690 746 }; 691 747 748 /* 749 692 750 //! Robust Bayesian AR model for Multicriteria-Laplace-Inverse-Gamma density 693 751 class RARX : public BM … … 707 765 } 708 766 709 }; 767 };*/ 768 710 769 711 770